diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh index c6856ca1a..e66c2c40f 100755 --- a/fs_mgr/tests/adb-remount-test.sh +++ b/fs_mgr/tests/adb-remount-test.sh @@ -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; 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`" [ -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 | @@ -998,16 +1035,16 @@ adb_sh ls -l /dev/block/by-name/ /dev/block/mapper/ /dev/null | esac size=`adb_su cat /sys/block/${device}/size 2>/dev/null &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 &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 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 &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 &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 &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 &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 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 &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` 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 &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 &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 &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 &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