Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd9335d4 authored by Yi-Yo Chiang's avatar Yi-Yo Chiang
Browse files

adb-remount-test: Add LOG() function

Right now there are a lot of log commands in the form of
  "echo <color code><log type><color code> [msg]... >&2"
which is painful to read, and test writers often accidentally omit the
trailing ">&2".

Add a LOG() function which takes care of the log formatting and stderr
redirecting once and for all.
Also bulk edit existing log commands to use LOG() everywhere.

Bug: 243116800
Test: adb-remount-test --color
Change-Id: I04beb9e09b28c08a3a6f4309bf2d4b6de906df90
parent 0331a322
Loading
Loading
Loading
Loading
+119 −82
Original line number Diff line number Diff line
@@ -69,6 +69,43 @@ screen_wait=true
##  Helper Functions
##

[ "USAGE: LOG [RUN|OK|PASSED|WARNING|ERROR|FAILED|INFO] [message]..." ]
LOG() {
  case "${1}" in
    R*)
      shift
      echo "${GREEN}[ RUN      ]${NORMAL}" "${@}"
      ;;
    OK)
      shift
      echo "${GREEN}[       OK ]${NORMAL}" "${@}"
      ;;
    P*)
      shift
      echo "${GREEN}[  PASSED  ]${NORMAL}" "${@}"
      ;;
    W*)
      shift
      echo "${YELLOW}[  WARNING ]${NORMAL}" "${@}"
      ;;
    E*)
      shift
      echo "${RED}[    ERROR ]${NORMAL}" "${@}"
      ;;
    F*)
      shift
      echo "${RED}[  FAILED  ]${NORMAL}" "${@}"
      ;;
    I*)
      shift
      echo "${BLUE}[     INFO ]${NORMAL}" "${@}"
      ;;
    *)
      echo "${BLUE}[     INFO ]${NORMAL}" "${@}"
      ;;
  esac >&2
}

[ "USAGE: inFastboot

Returns: true if device is in fastboot mode" ]
@@ -144,7 +181,7 @@ adb_date() {

Returns: the logcat output" ]
adb_logcat() {
  echo "${RED}[     INFO ]${NORMAL} logcat ${@}" >&2 &&
  LOG INFO "logcat ${*}"
  adb logcat "${@}" </dev/null |
    tr -d '\r' |
    grep -v 'logd    : logdr: UID=' |
@@ -165,7 +202,7 @@ avc_check() {
  if [ -z "${L}" ]; then
    return
  fi
  echo "${YELLOW}[  WARNING ]${NORMAL} unlabeled sepolicy violations:" >&2
  LOG WARNING "unlabeled sepolicy violations:"
  echo "${L}" | sed "s/^/${INDENT}/" >&2
}

@@ -311,7 +348,7 @@ adb_wait() {
  if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then
    local active_slot=`get_active_slot`
    if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then
      echo "${YELLOW}[  WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" >&2
      LOG WARNING "Active slot changed from ${ACTIVE_SLOT} to ${active_slot}"
    fi
  fi
  local end=`date +%s`
@@ -340,8 +377,8 @@ adb_wait() {
      ;;
  esac
  if ${_print_time} || [ -n "${reason}" ]; then
    echo "${BLUE}[     INFO ]${NORMAL} adb wait duration ${diff_time}${reason}"
  fi >&2
    LOG INFO "adb wait duration ${diff_time}${reason}"
  fi

  return ${ret}
}
@@ -414,8 +451,8 @@ fastboot_wait() {
  if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then
    local active_slot=`get_active_slot`
    if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then
      echo "${YELLOW}[  WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}"
    fi >&2
      LOG WARNING "Active slot changed from ${ACTIVE_SLOT} to ${active_slot}"
    fi
  fi
  return ${ret}
}
@@ -439,8 +476,8 @@ recovery_wait() {
  if [ 0 = ${ret} -a -n "${ACTIVE_SLOT}" ]; then
    local active_slot=`get_active_slot`
    if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then
      echo "${YELLOW}[  WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}"
    fi >&2
      LOG WARNING "Active slot changed from ${ACTIVE_SLOT} to ${active_slot}"
    fi
  fi
  return ${ret}
}
@@ -498,7 +535,7 @@ wait_for_screen() {
    counter=$(( ${counter} + 1 ))
    if [ ${counter} -gt ${timeout} ]; then
      ${exit_function}
      echo "ERROR: wait_for_screen() timed out (`format_duration ${timeout}`)" >&2
      LOG ERROR "wait_for_screen() timed out ($(format_duration ${timeout}))"
      return 1
    fi
    sleep 1
@@ -594,12 +631,12 @@ Prints the duration of the test
Returns: reports duration" ]
test_duration() {
  if ${print_time}; then
    echo "${BLUE}[     INFO ]${NORMAL} end `date`"
    LOG INFO "end $(date)"
    [ -n "${start_time}" ] || return
    end_time=`date +%s`
    local diff_time=$(( ${end_time} - ${start_time} ))
    echo "${BLUE}[     INFO ]${NORMAL} duration `format_duration ${diff_time}`"
  fi >&2
    LOG INFO "duration $(format_duration ${diff_time})"
  fi
}

[ "USAGE: die [-d|-t <epoch>] [message] >/dev/stderr
@@ -619,7 +656,7 @@ die() {
    fi
    shift 2
  fi >&2
  echo "${RED}[  FAILED  ]${NORMAL} ${@}" >&2
  LOG FAILED "${@}"
  cleanup
  restore
  test_duration
@@ -798,7 +835,7 @@ surgically_wipe_overlayfs() {
  local wiped_anything=false
  for d in ${OVERLAYFS_BACKING}; do
    if adb_su test -d "/${d}/overlay" </dev/null; then
      echo "${BLUE}[     INFO ]${NORMAL} /${d}/overlay is setup, surgically wiping" >&2
      LOG INFO "/${d}/overlay is setup, surgically wiping"
      adb_su rm -rf "/${d}/overlay" </dev/null
      wiped_anything=true
    fi
@@ -911,20 +948,20 @@ if ! ${color}; then
fi

if ${print_time}; then
  echo "${BLUE}[     INFO ]${NORMAL}" start `date` >&2
  LOG INFO "start $(date)"
fi

inFastboot && die "device in fastboot mode"
inRecovery && die "device in recovery mode"
if ! inAdb; then
  echo "${YELLOW}[  WARNING ]${NORMAL} device not in adb mode" >&2
  LOG WARNING "device not in adb mode"
  adb_wait ${ADB_WAIT}
fi
inAdb || die "specified device not in adb mode"
isDebuggable || die "device not a debug build"
enforcing=true
if ! adb_su getenforce </dev/null | grep 'Enforcing' >/dev/null; then
  echo "${YELLOW}[  WARNING ]${NORMAL} device does not have sepolicy in enforcing mode" >&2
  LOG WARNING "device does not have sepolicy in enforcing mode"
  enforcing=false
fi

@@ -950,16 +987,16 @@ if [ -n "${USB_SERIAL}" ]; then
fi
[ -z "${ANDROID_SERIAL}${USB_ADDRESS}" ] ||
  USB_DEVICE=`usb_devnum`
  echo "${BLUE}[     INFO ]${NORMAL}" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} >&2
  LOG INFO "${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE}"
BUILD_DESCRIPTION=`get_property ro.build.description`
[ -z "${BUILD_DESCRIPTION}" ] ||
  echo "${BLUE}[     INFO ]${NORMAL} ${BUILD_DESCRIPTION}" >&2
  LOG INFO "${BUILD_DESCRIPTION}"
KERNEL_VERSION="`adb_su cat /proc/version </dev/null 2>/dev/null`"
[ -z "${KERNEL_VERSION}" ] ||
  echo "${BLUE}[     INFO ]${NORMAL} ${KERNEL_VERSION}" >&2
  LOG INFO "${KERNEL_VERSION}"
ACTIVE_SLOT=`get_active_slot`
[ -z "${ACTIVE_SLOT}" ] ||
  echo "${BLUE}[     INFO ]${NORMAL} active slot is ${ACTIVE_SLOT}" >&2
  LOG INFO "active slot is ${ACTIVE_SLOT}"

# Acquire list of system partitions

@@ -976,7 +1013,7 @@ MOUNTS="`for i in ${PARTITIONS}; do
           echo /${i}
         done |
         tr '\n' ' '`"
echo "${BLUE}[     INFO ]${NORMAL} System Partitions list: ${PARTITIONS}" >&2
LOG INFO "System Partitions list: ${PARTITIONS}"

# Report existing partition sizes
adb_sh ls -l /dev/block/by-name/ /dev/block/mapper/ </dev/null 2>/dev/null |
@@ -998,16 +1035,16 @@ adb_sh ls -l /dev/block/by-name/ /dev/block/mapper/ </dev/null 2>/dev/null |
    esac
    size=`adb_su cat /sys/block/${device}/size 2>/dev/null </dev/null` &&
      size=$(( ${size} / 2 )) &&
      echo "${BLUE}[     INFO ]${NORMAL} partition ${name} device ${device} size ${size}K" >&2
      LOG INFO "partition ${name} device ${device} size ${size}K"
  done

# If reboot too soon after fresh flash, could trip device update failure logic
if ${screen_wait}; then
  echo "${YELLOW}[  WARNING ]${NORMAL} waiting for screen to come up. Consider --no-wait-screen option" >&2
  LOG WARNING "waiting for screen to come up. Consider --no-wait-screen option"
fi
if ! wait_for_screen && ${screen_wait}; then
  screen_wait=false
  echo "${YELLOW}[  WARNING ]${NORMAL} not healthy, no launcher, skipping wait for screen" >&2
  LOG WARNING "not healthy, no launcher, skipping wait for screen"
fi

# Can we test remount -R command?
@@ -1041,14 +1078,14 @@ else
      adb_wait ${ADB_WAIT}
  }

  echo "${GREEN}[ RUN      ]${NORMAL} Testing adb shell su root remount -R command" >&2
  LOG RUN "Testing adb shell su root remount -R command"

  avc_check
  T=`adb_date`
  adb_su remount -R system </dev/null
  err=${?}
  if [ "${err}" != 0 ]; then
    echo "${YELLOW}[  WARNING ]${NORMAL} adb shell su root remount -R system = ${err}, likely did not reboot!" >&2
    LOG WARNING "adb shell su root remount -R system = ${err}, likely did not reboot!"
    T="-t ${T}"
  else
    # Rebooted, logcat will be meaningless, and last logcat will likely be clear
@@ -1064,10 +1101,10 @@ ${INDENT}ro.boot.verifiedbootstate=\"`get_property ro.boot.verifiedbootstate`\"
${INDENT}partition.system.verified=\"`get_property partition.system.verified`\""
  fi

  echo "${GREEN}[       OK ]${NORMAL} adb shell su root remount -R command" >&2
  LOG OK "adb shell su root remount -R command"
fi

echo "${GREEN}[ RUN      ]${NORMAL} Testing kernel support for overlayfs" >&2
LOG RUN "Testing kernel support for overlayfs"

adb_wait || die "wait for device failed"
adb_root ||
@@ -1075,27 +1112,27 @@ adb_root ||

adb_test -d /sys/module/overlay ||
  adb_sh grep "nodev${TAB}overlay" /proc/filesystems </dev/null >/dev/null 2>/dev/null &&
  echo "${GREEN}[       OK ]${NORMAL} overlay module present" >&2 ||
  LOG OK "overlay module present" ||
  (
    echo "${YELLOW}[  WARNING ]${NORMAL} overlay module not present" >&2 &&
    LOG WARNING "overlay module not present" &&
      false
  ) ||
  overlayfs_supported=false
if ${overlayfs_supported}; then
  adb_test -f /sys/module/overlay/parameters/override_creds &&
    echo "${GREEN}[       OK ]${NORMAL} overlay module supports override_creds" >&2 ||
    LOG OK "overlay module supports override_creds" ||
    case `adb_sh uname -r </dev/null` in
      4.[456789].* | 4.[1-9][0-9]* | [56789].*)
        echo "${YELLOW}[  WARNING ]${NORMAL} overlay module does not support override_creds" >&2 &&
        LOG WARNING "overlay module does not support override_creds" &&
        overlayfs_supported=false
        ;;
      *)
        echo "${GREEN}[       OK ]${NORMAL} overlay module uses caller's creds" >&2
        LOG OK "overlay module uses caller's creds"
        ;;
    esac
fi

echo "${GREEN}[ RUN      ]${NORMAL} Checking current overlayfs status" >&2
LOG RUN "Checking current overlayfs status"

# We can not universally use adb enable-verity to ensure device is
# in a overlayfs disabled state since it can prevent reboot on
@@ -1103,7 +1140,7 @@ echo "${GREEN}[ RUN ]${NORMAL} Checking current overlayfs status" >&2
# So lets do our best to surgically wipe the overlayfs state without
# having to go through enable-verity transition.
if surgically_wipe_overlayfs; then
  echo "${YELLOW}[  WARNING ]${NORMAL} rebooting before test" >&2
  LOG WARNING "rebooting before test"
  adb_reboot &&
    adb_wait ${ADB_WAIT} ||
    die "lost device after reboot after wipe `usb_status`"
@@ -1112,7 +1149,7 @@ if surgically_wipe_overlayfs; then
fi
is_overlayfs_mounted &&
  die "overlay takeover unexpected at this phase"
echo "${GREEN}[       OK ]${NORMAL} no overlay present before setup" >&2
LOG OK "no overlay present before setup"

overlayfs_needed=true
D=`adb_sh cat /proc/mounts </dev/null |
@@ -1146,7 +1183,7 @@ elif ! ${overlayfs_supported}; then
  die "need overlayfs, but do not have it"
fi

echo "${GREEN}[ RUN      ]${NORMAL} disable-verity -R" >&2
LOG RUN "disable-verity -R"

L=
T=$(adb_date)
@@ -1160,7 +1197,7 @@ fi

# Fuzzy search for a line that contains "overlay" and "fail". Informational only.
if echo "${H}" | grep -i "overlay" | grep -iq "fail"; then
  echo "${YELLOW}[  WARNING ]${NORMAL} overlayfs setup whined" >&2
  LOG WARNING "overlayfs setup whined"
fi

adb_wait "${ADB_WAIT}" &&
@@ -1173,7 +1210,7 @@ if ${overlayfs_needed}; then
  fi
fi

echo "${GREEN}[ RUN      ]${NORMAL} remount" >&2
LOG RUN "remount"

# Feed log with selinux denials as baseline before overlays
adb_unroot
@@ -1200,17 +1237,17 @@ if ${overlayfs_needed}; then
    die -t ${T} "overlay takeover failed"
  fi
  echo "${D}" | grep "^overlay .* /system\$" >/dev/null ||
   echo "${YELLOW}[  WARNING ]${NORMAL} overlay takeover not complete" >&2
   LOG WARNING "overlay takeover not complete"
  if [ -z "${virtual_ab}" ]; then
    scratch_partition=scratch
  fi
  if echo "${D}" | grep " /mnt/scratch" >/dev/null; then
    echo "${BLUE}[     INFO ]${NORMAL} using ${scratch_partition} dynamic partition for overrides" >&2
    LOG INFO "using ${scratch_partition} dynamic partition for overrides"
  fi
  M=`adb_sh cat /proc/mounts </dev/null |
     sed -n 's@\([^ ]*\) /mnt/scratch \([^ ]*\) .*@\2 on \1@p'`
  [ -n "${M}" ] &&
    echo "${BLUE}[     INFO ]${NORMAL} scratch filesystem ${M}" >&2
    LOG INFO "scratch filesystem ${M}"
  uses_dynamic_scratch=true
  if [ "${M}" != "${M##*/dev/block/by-name/}" ]; then
    uses_dynamic_scratch=false
@@ -1224,10 +1261,10 @@ if ${overlayfs_needed}; then
                done` &&
    [ -n "${scratch_size}" ] ||
    die "scratch size"
  echo "${BLUE}[     INFO ]${NORMAL} scratch size ${scratch_size}KB" >&2
  LOG INFO "scratch size ${scratch_size}KB"
  for d in ${OVERLAYFS_BACKING}; do
    if adb_test -d /${d}/overlay/system/upper; then
      echo "${BLUE}[     INFO ]${NORMAL} /${d}/overlay is setup" >&2
      LOG INFO "/${d}/overlay is setup"
    fi
  done

@@ -1278,7 +1315,7 @@ fi

# Check something.

echo "${GREEN}[ RUN      ]${NORMAL} push content to ${MOUNTS}" >&2
LOG RUN "push content to ${MOUNTS}"

A="Hello World! $(date)"
for i in ${MOUNTS}; do
@@ -1312,11 +1349,11 @@ adb pull /system/lib/bootstrap/libc.so ${tempdir}/libc.so.fromdevice >/dev/null
diff ${tempdir}/libc.so ${tempdir}/libc.so.fromdevice > /dev/null ||
  die "libc.so differ"

echo "${GREEN}[ RUN      ]${NORMAL} reboot to confirm content persistent" >&2
LOG RUN "reboot to confirm content persistent"

fixup_from_recovery() {
  inRecovery || return 1
  echo "${YELLOW}[    ERROR ]${NORMAL} Device in recovery" >&2
  LOG ERROR "Device in recovery"
  adb reboot </dev/null
  adb_wait ${ADB_WAIT}
}
@@ -1336,8 +1373,8 @@ if ${overlayfs_needed}; then
  adb_su sed -n '1,/overlay \/system/p' /proc/mounts </dev/null |
    skip_administrative_mounts |
    grep -v ' \(erofs\|squashfs\|ext4\|f2fs\|vfat\) ' &&
    echo "${YELLOW}[  WARNING ]${NORMAL} overlay takeover after first stage init" >&2 ||
    echo "${GREEN}[       OK ]${NORMAL} overlay takeover in first stage init" >&2
    LOG WARNING "overlay takeover after first stage init" ||
    LOG OK "overlay takeover in first stage init"
fi

if ${enforcing}; then
@@ -1345,7 +1382,7 @@ if ${enforcing}; then
    die "device not in unroot'd state"
  B="`adb_cat /vendor/hello 2>&1`"
  check_eq "cat: /vendor/hello: Permission denied" "${B}" vendor after reboot w/o root
  echo "${GREEN}[       OK ]${NORMAL} /vendor content correct MAC after reboot" >&2
  LOG OK "/vendor content correct MAC after reboot"
  # Feed unprivileged log with selinux denials as a result of overlays
  wait_for_screen
  adb_sh find ${MOUNTS} </dev/null >/dev/null 2>/dev/null || true
@@ -1363,7 +1400,7 @@ adb_root ||
for i in ${MOUNTS}; do
  B="`adb_cat ${i}/hello`"
  check_eq "${A}" "${B}" ${i#/} after reboot
  echo "${GREEN}[       OK ]${NORMAL} ${i} content remains after reboot" >&2
  LOG OK "${i} content remains after reboot"
done

check_eq "${SYSTEM_INO}" "`adb_sh stat --format=%i /system/hello </dev/null`" system inode after reboot
@@ -1381,9 +1418,9 @@ rm -rf ${tempdir}
cleanup() {
  true
}
echo "${GREEN}[       OK ]${NORMAL} /system/lib/bootstrap/libc.so content remains after reboot" >&2
LOG OK "/system/lib/bootstrap/libc.so content remains after reboot"

echo "${GREEN}[ RUN      ]${NORMAL} flash vendor, confirm its content disappears" >&2
LOG RUN "flash vendor, confirm its content disappears"

H=`adb_sh echo '${HOSTNAME}' </dev/null 2>/dev/null`
is_bootloader_fastboot=false
@@ -1392,20 +1429,20 @@ is_bootloader_fastboot=false
is_userspace_fastboot=false

if ! ${is_bootloader_fastboot}; then
  echo "${YELLOW}[  WARNING ]${NORMAL} does not support fastboot, skipping" >&2
  LOG WARNING "does not support fastboot, skipping"
elif [ -z "${ANDROID_PRODUCT_OUT}" ]; then
  echo "${YELLOW}[  WARNING ]${NORMAL} build tree not setup, skipping" >&2
  LOG WARNING "build tree not setup, skipping"
elif [ ! -s "${ANDROID_PRODUCT_OUT}/vendor.img" ]; then
  echo "${YELLOW}[  WARNING ]${NORMAL} vendor image missing, skipping" >&2
  LOG WARNING "vendor image missing, skipping"
elif [ "${ANDROID_PRODUCT_OUT}" = "${ANDROID_PRODUCT_OUT%*/${H}}" ]; then
  echo "${YELLOW}[  WARNING ]${NORMAL} wrong vendor image, skipping" >&2
  LOG WARNING "wrong vendor image, skipping"
elif [ -z "${ANDROID_HOST_OUT}" ]; then
  echo "${YELLOW}[  WARNING ]${NORMAL} please run lunch, skipping" >&2
  LOG WARNING "please run lunch, skipping"
elif ! (
          adb_cat /vendor/build.prop |
          cmp -s ${ANDROID_PRODUCT_OUT}/vendor/build.prop
       ) >/dev/null 2>/dev/null; then
  echo "${YELLOW}[  WARNING ]${NORMAL} vendor image signature mismatch, skipping" >&2
  LOG WARNING "vendor image signature mismatch, skipping"
else
  wait_for_screen
  avc_check
@@ -1439,19 +1476,19 @@ else
        die "Reboot into fastboot"
    fi
    if ${uses_dynamic_scratch}; then
      echo "${BLUE}[     INFO ]${NORMAL} expect fastboot erase ${scratch_partition} to fail" >&2
      LOG INFO "expect fastboot erase ${scratch_partition} to fail"
      fastboot erase ${scratch_partition} &&
        ( fastboot reboot || true) &&
        die "fastboot can erase ${scratch_partition}"
    fi
    echo "${BLUE}[     INFO ]${NORMAL} expect fastboot format ${scratch_partition} to fail" >&2
    LOG INFO "expect fastboot format ${scratch_partition} to fail"
    fastboot format ${scratch_partition} &&
      ( fastboot reboot || true) &&
      die "fastboot can format ${scratch_partition}"
  fi
  fastboot reboot ||
    die "can not reboot out of fastboot"
  echo "${YELLOW}[  WARNING ]${NORMAL} adb after fastboot" >&2
  LOG WARNING "adb after fastboot"
  adb_wait ${ADB_WAIT} ||
    fixup_from_recovery ||
    die "did not reboot after formatting ${scratch_partition} `usb_status`"
@@ -1469,8 +1506,8 @@ else
      if ${is_userspace_fastboot}; then
        die  "overlay supposed to be minus /vendor takeover after flash vendor"
      else
        echo "${YELLOW}[  WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2
        echo "${YELLOW}[  WARNING ]${NORMAL} overlay supposed to be minus /vendor takeover after flash vendor" >&2
        LOG WARNING "user fastboot missing required to invalidate, ignoring a failure"
        LOG WARNING "overlay supposed to be minus /vendor takeover after flash vendor"
      fi
  fi
  B="`adb_cat /system/hello`"
@@ -1488,7 +1525,7 @@ else
    check_eq "cat: /vendor/hello: No such file or directory" "${B}" \
             vendor content after flash vendor
  else
    echo "${YELLOW}[  WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2
    LOG WARNING "user fastboot missing required to invalidate, ignoring a failure"
    check_eq "cat: /vendor/hello: No such file or directory" "${B}" \
             --warning vendor content after flash vendor
  fi
@@ -1498,7 +1535,7 @@ else
fi

wait_for_screen
echo "${GREEN}[ RUN      ]${NORMAL} remove test content (cleanup)" >&2
LOG RUN "remove test content (cleanup)"

T=`adb_date`
H=`adb remount 2>&1`
@@ -1506,7 +1543,7 @@ err=${?}
L=
D="${H%?Now reboot your device for settings to take effect*}"
if [ X"${H}" != X"${D}" ]; then
  echo "${YELLOW}[  WARNING ]${NORMAL} adb remount requires a reboot after partial flash (legacy avb)" >&2
  LOG WARNING "adb remount requires a reboot after partial flash (legacy avb)"
  L=`adb_logcat -b all -v nsec -t ${T} 2>&1`
  adb_reboot &&
    adb_wait ${ADB_WAIT} &&
@@ -1534,7 +1571,7 @@ done

if ${is_bootloader_fastboot} && [ -n "${scratch_partition}" ]; then

  echo "${GREEN}[ RUN      ]${NORMAL} test fastboot flash to ${scratch_partition} recovery" >&2
  LOG RUN "test fastboot flash to ${scratch_partition} recovery"

  avc_check
  adb reboot fastboot </dev/null ||
@@ -1564,7 +1601,7 @@ if ${is_bootloader_fastboot} && [ -n "${scratch_partition}" ]; then
  err=${?}
  if [ X"${D}" != "${D%?Now reboot your device for settings to take effect*}" ]
  then
    echo "${YELLOW}[  WARNING ]${NORMAL} adb disable-verity requires a reboot after partial flash" >&2
    LOG WARNING "adb disable-verity requires a reboot after partial flash"
    adb_reboot &&
      adb_wait ${ADB_WAIT} &&
      adb_root ||
@@ -1579,7 +1616,7 @@ if ${is_bootloader_fastboot} && [ -n "${scratch_partition}" ]; then
  [ ${err} = 0 ] &&
    [ X"${D}" = X"${D##*setup failed}" ] &&
    [ X"${D}" != X"${D##*[Uu]sing overlayfs}" ] &&
    echo "${GREEN}[       OK ]${NORMAL} ${scratch_partition} recreated" >&2 ||
    LOG OK "${scratch_partition} recreated" ||
    die -t ${T} "setup for overlayfs"
  D=`adb remount 2>&1`
  err=${?}
@@ -1590,17 +1627,17 @@ if ${is_bootloader_fastboot} && [ -n "${scratch_partition}" ]; then
    die -t ${T} "remount failed"
fi

echo "${GREEN}[ RUN      ]${NORMAL} test raw remount commands" >&2
LOG RUN "test raw remount commands"

fixup_from_fastboot() {
  inFastboot || return 1
  if [ -n "${ACTIVE_SLOT}" ]; then
    local active_slot=`get_active_slot`
    if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then
      echo "${YELLOW}[    ERROR ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}"
      LOG WARNING "Active slot changed from ${ACTIVE_SLOT} to ${active_slot}"
    else
      echo "${YELLOW}[    ERROR ]${NORMAL} Active slot to be set to ${ACTIVE_SLOT}"
    fi >&2
      LOG WARNING "Active slot to be set to ${ACTIVE_SLOT}"
    fi
    fastboot --set-active=${ACTIVE_SLOT}
  fi
  fastboot reboot
@@ -1618,7 +1655,7 @@ adb_su mount -o rw,remount /vendor </dev/null ||
  die "remount command"
adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null ||
  die "/vendor is not read-write"
echo "${GREEN}[       OK ]${NORMAL} mount -o rw,remount command works" >&2
LOG OK "mount -o rw,remount command works"

# Prerequisite is a prepped device from above.
adb_reboot &&
@@ -1633,7 +1670,7 @@ adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null ||
  die "/vendor is not read-write"
adb_sh grep " /system .* rw," /proc/mounts >/dev/null </dev/null &&
  die "/vendor is not read-only"
echo "${GREEN}[       OK ]${NORMAL} remount command works from setup" >&2
LOG OK "remount command works from setup"

# Prerequisite is an overlayfs deconstructed device but with verity disabled.
# This also saves a lot of 'noise' from the command doing a mkfs on backing
@@ -1652,7 +1689,7 @@ adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null </dev/null ||
  die "/vendor is not read-write"
adb_sh grep " \(/system\|/\) .* rw," /proc/mounts >/dev/null </dev/null &&
  die "/system is not read-only"
echo "${GREEN}[       OK ]${NORMAL} remount command works from scratch" >&2
LOG OK "remount command works from scratch"

if ! restore; then
  restore() {
@@ -1664,7 +1701,7 @@ fi
err=0

if ${overlayfs_supported}; then
  echo "${GREEN}[ RUN      ]${NORMAL} test 'adb remount -R'" >&2
  LOG RUN "test 'adb remount -R'"
  avc_check
  adb_root ||
    die "adb root in preparation for adb remount -R"
@@ -1686,7 +1723,7 @@ ${INDENT}ro.boot.verifiedbootstate=\"`get_property ro.boot.verifiedbootstate`\"
${INDENT}partition.system.verified=\"`get_property partition.system.verified`\""
  fi

  echo "${GREEN}[       OK ]${NORMAL} 'adb remount -R' command" >&2
  LOG OK "'adb remount -R' command"

  restore
  err=${?}
@@ -1699,6 +1736,6 @@ restore() {
[ ${err} = 0 ] ||
  die "failed to restore verity"

echo "${GREEN}[  PASSED  ]${NORMAL} adb remount" >&2
LOG PASSED "adb remount test"

test_duration