Loading fs_mgr/tests/adb-remount-test.sh +114 −80 Original line number Diff line number Diff line Loading @@ -15,13 +15,17 @@ USAGE="USAGE: `basename ${0}` [--help] [--serial <SerialNumber>] [options] adb remount tests --color Dress output with highlighting colors --help This help --no-wait-screen Do not wait for display screen to settle --print-time Report the test duration --serial Specify device (must if multiple are present) --wait-adb <duration> adb wait timeout --wait-fastboot <duration> fastboot wait timeout -c --color Dress output with highlighting colors -h --help This help -D --no-wait-screen Do not wait for display screen to settle -t --print-time Report the test duration -s --serial Specify device (must if multiple are present)" if [ -n "`which timeout`" ]; then USAGE="${USAGE} -a --wait-adb <duration> adb wait timeout -f --wait-fastboot <duration> fastboot wait timeout" fi USAGE="${USAGE} Conditions: - Must be a userdebug build. Loading @@ -46,10 +50,10 @@ TAB="`echo | tr '\n' '\t'`" ESCAPE="`echo | tr '\n' '\033'`" # A _real_ embedded carriage return character CR="`echo | tr '\n' '\r'`" GREEN="${ESCAPE}[38;5;40m" RED="${ESCAPE}[38;5;196m" ORANGE="${ESCAPE}[38;5;255:165:0m" BLUE="${ESCAPE}[35m" GREEN="${ESCAPE}[32m" RED="${ESCAPE}[31m" YELLOW="${ESCAPE}[33m" BLUE="${ESCAPE}[34m" NORMAL="${ESCAPE}[0m" TMPDIR=${TMPDIR:-/tmp} print_time=false Loading @@ -72,7 +76,7 @@ inFastboot() { if [ -n "${ANDROID_SERIAL}" ]; then grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null else wc -l | grep '^1$' >/dev/null wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null fi } Loading @@ -85,7 +89,7 @@ inAdb() { if [ -n "${ANDROID_SERIAL}" ]; then grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null else wc -l | grep '^1$' >/dev/null wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null fi } Loading @@ -100,7 +104,7 @@ inRecovery() { grep "^${ANDROID_SERIAL}[${SPACE}${TAB}][${SPACE}${TAB}]*recovery\$" >/dev/null return ${?} fi if echo "${list}" | wc -l | grep '^1$' >/dev/null; then if echo "${list}" | wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null; then echo "${list}" | grep "[${SPACE}${TAB}]recovery\$" >/dev/null return ${?} Loading Loading @@ -160,7 +164,7 @@ avc_check() { if [ -z "${L}" ]; then return fi echo "${ORANGE}[ WARNING ]${NORMAL} unlabeled sepolicy violations:" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} unlabeled sepolicy violations:" >&2 echo "${L}" | sed "s/^/${INDENT}/" >&2 } Loading Loading @@ -284,7 +288,7 @@ adb_wait() { local start=`date +%s` local duration= local ret if [ -n "${1}" ]; then if [ -n "${1}" -a -n "`which timeout`" ]; then USB_DEVICE=`usb_devnum --next` duration=`format_duration ${1}` echo -n ". . . waiting ${duration}" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" Loading @@ -299,7 +303,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 "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" >&2 fi fi local end=`date +%s` Loading Loading @@ -359,7 +363,9 @@ usb_status() { echo "(In adb mode `adb_user`)" else echo "(USB stack borken for ${USB_ADDRESS})" if [ -n "`which usb_devnum`" ]; then USB_DEVICE=`usb_devnum` if [ -n "`which lsusb`" ]; then if [ -n "${USB_DEVICE}" ]; then echo "# lsusb -v -s ${USB_DEVICE#dev}" local D=`lsusb -v -s ${USB_DEVICE#dev} 2>&1` Loading @@ -371,6 +377,8 @@ usb_status() { else echo "# lsusb -v (expected device missing)" lsusb -v fi fi fi >&2 fi } Loading @@ -382,7 +390,7 @@ fastboot_wait() { local ret # fastboot has no wait-for-device, but it does an automatic # wait and requires (even a nonsensical) command to do so. if [ -n "${1}" ]; then if [ -n "${1}" -a -n "`which timeout`" ]; then USB_DEVICE=`usb_devnum --next` echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" timeout --preserve-status --signal=KILL ${1} fastboot wait-for-device >/dev/null 2>/dev/null Loading @@ -398,7 +406,7 @@ 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 "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" echo "${YELLOW}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" fi >&2 fi return ${ret} Loading @@ -409,7 +417,7 @@ fastboot_wait() { Returns: waits until the device has returned for recovery or optional timeout" ] recovery_wait() { local ret if [ -n "${1}" ]; then if [ -n "${1}" -a -n "`which timeout`" ]; then USB_DEVICE=`usb_devnum --next` echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" timeout --preserve-status --signal=KILL ${1} adb wait-for-recovery 2>/dev/null Loading @@ -423,7 +431,7 @@ 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 "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" echo "${YELLOW}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" fi >&2 fi return ${ret} Loading Loading @@ -732,6 +740,7 @@ skip_administrative_mounts() { grep -v \ -e "^\(overlay\|tmpfs\|none\|sysfs\|proc\|selinuxfs\|debugfs\|bpf\) " \ -e "^\(binfmt_misc\|cg2_bpf\|pstore\|tracefs\|adb\|mtp\|ptp\|devpts\) " \ -e "^\(ramdumpfs\) " \ -e " functionfs " \ -e "^\(/data/media\|/dev/block/loop[0-9]*\) " \ -e "^rootfs / rootfs rw," \ Loading @@ -753,13 +762,28 @@ skip_unrelated_mounts() { ## MAINLINE ## OPTIONS=`getopt --alternative --unquoted \ --longoptions help,serial:,colour,color,no-colour,no-color \ --longoptions wait-adb:,wait-fastboot: \ --longoptions wait-screen,wait-display \ --longoptions no-wait-screen,no-wait-display \ --longoptions gtest_print_time,print-time \ -- "?hs:" ${*}` || HOSTOS=`uname` GETOPTS="--alternative --unquoted --longoptions help,serial:,colour,color,no-colour,no-color --longoptions wait-adb:,wait-fastboot: --longoptions wait-screen,wait-display --longoptions no-wait-screen,no-wait-display --longoptions gtest_print_time,print-time --" if [ "Darwin" = "${HOSTOS}" ]; then GETOPTS= USAGE="`echo \"${USAGE}\" | sed 's/--color/ /g 1s/--help/-h/ s/--help/ /g s/--no-wait-screen/ /g s/--print-time/ /g 1s/--serial/-s/ s/--serial/ /g s/--wait-adb/ /g s/--wait-fastboot/ /g'`" fi OPTIONS=`getopt ${GETOPTS} "?a:cCdDf:hs:t" ${*}` || ( echo "${USAGE}" >&2 ; false ) || die "getopt failure" set -- ${OPTIONS} Loading @@ -775,26 +799,26 @@ while [ ${#} -gt 0 ]; do export ANDROID_SERIAL=${2} shift ;; --color | --colour) -c | --color | --colour) color=true ;; --no-color | --no-colour) -C | --no-color | --no-colour) color=false ;; --no-wait-display | --no-wait-screen) -D | --no-wait-display | --no-wait-screen) screen_wait=false ;; --wait-display | --wait-screen) -d | --wait-display | --wait-screen) screen_wait=true ;; --print-time | --gtest_print_time) -t | --print-time | --gtest_print_time) print_time=true ;; --wait-adb) -a | --wait-adb) ADB_WAIT=${2} shift ;; --wait-fastboot) -f | --wait-fastboot) FASTBOOT_WAIT=${2} shift ;; Loading @@ -815,7 +839,7 @@ done if ! ${color}; then GREEN="" RED="" ORANGE="" YELLOW="" BLUE="" NORMAL="" fi Loading @@ -827,14 +851,14 @@ fi inFastboot && die "device in fastboot mode" inRecovery && die "device in recovery mode" if ! inAdb; then echo "${ORANGE}[ WARNING ]${NORMAL} device not in adb mode" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} device not in adb mode" >&2 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 "${ORANGE}[ WARNING ]${NORMAL} device does not have sepolicy in enforcing mode" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} device does not have sepolicy in enforcing mode" >&2 enforcing=false fi Loading @@ -846,9 +870,13 @@ D=`get_property ro.serialno` [ -n "${D}" ] || D=`get_property ro.boot.serialno` [ -z "${D}" -o -n "${ANDROID_SERIAL}" ] || ANDROID_SERIAL=${D} USB_SERIAL= [ -z "${ANDROID_SERIAL}" ] || USB_SERIAL=`find /sys/devices -name serial | grep usb | xargs -r grep -l ${ANDROID_SERIAL}` if [ -n "${ANDROID_SERIAL}" -a "Darwin" != "${HOSTOS}" ]; then USB_SERIAL="`find /sys/devices -name serial | grep usb`" if [ -n "${USB_SERIAL}" ]; then USB_SERIAL=`echo "${USB_SERIAL}" | xargs grep -l ${ANDROID_SERIAL}` fi fi USB_ADDRESS= if [ -n "${USB_SERIAL}" ]; then USB_ADDRESS=${USB_SERIAL%/serial} Loading @@ -860,13 +888,16 @@ fi BUILD_DESCRIPTION=`get_property ro.build.description` [ -z "${BUILD_DESCRIPTION}" ] || echo "${BLUE}[ INFO ]${NORMAL} ${BUILD_DESCRIPTION}" >&2 KERNEL_VERSION="`adb_su cat /proc/version </dev/null 2>/dev/null`" [ -z "${KERNEL_VERSION}" ] || echo "${BLUE}[ INFO ]${NORMAL} ${KERNEL_VERSION}" >&2 ACTIVE_SLOT=`get_active_slot` [ -z "${ACTIVE_SLOT}" ] || echo "${BLUE}[ INFO ]${NORMAL} active slot is ${ACTIVE_SLOT}" >&2 # Acquire list of system partitions PARTITIONS=`adb_su cat /vendor/etc/fstab* | PARTITIONS=`adb_su cat /vendor/etc/fstab* </dev/null | skip_administrative_mounts | sed -n "s@^\([^ ${TAB}/][^ ${TAB}/]*\)[ ${TAB}].*[, ${TAB}]ro[, ${TAB}].*@\1@p" | sort -u | Loading Loading @@ -903,9 +934,12 @@ adb_sh ls -l /dev/block/by-name/ /dev/block/mapper/ </dev/null 2>/dev/null | 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 fi if ! wait_for_screen && ${screen_wait}; then screen_wait=false echo "${ORANGE}[ WARNING ]${NORMAL} not healthy, no launcher, skipping wait for screen" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} not healthy, no launcher, skipping wait for screen" >&2 fi # Can we test remount -R command? Loading Loading @@ -954,7 +988,7 @@ else adb_su remount -R system </dev/null err=${?} if [ "${err}" != 0 ]; then echo "${ORANGE}[ WARNING ]${NORMAL} adb shell su root remount -R system = ${err}, likely did not reboot!" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} adb shell su root remount -R system = ${err}, likely did not reboot!" >&2 T="-t ${T}" else # Rebooted, logcat will be meaningless, and last logcat will likely be clear Loading @@ -980,7 +1014,7 @@ adb_sh ls -d /sys/module/overlay </dev/null >/dev/null 2>/dev/null || adb_sh grep "nodev${TAB}overlay" /proc/filesystems </dev/null >/dev/null 2>/dev/null && echo "${GREEN}[ OK ]${NORMAL} overlay module present" >&2 || ( echo "${ORANGE}[ WARNING ]${NORMAL} overlay module not present" >&2 && echo "${YELLOW}[ WARNING ]${NORMAL} overlay module not present" >&2 && false ) || overlayfs_supported=false Loading @@ -989,7 +1023,7 @@ if ${overlayfs_supported}; then echo "${GREEN}[ OK ]${NORMAL} overlay module supports override_creds" >&2 || case `adb_sh uname -r </dev/null` in 4.[456789].* | 4.[1-9][0-9]* | [56789].*) echo "${ORANGE}[ WARNING ]${NORMAL} overlay module does not support override_creds" >&2 && echo "${YELLOW}[ WARNING ]${NORMAL} overlay module does not support override_creds" >&2 && overlayfs_supported=false ;; *) Loading @@ -1011,14 +1045,14 @@ echo "${GREEN}[ RUN ]${NORMAL} Checking current overlayfs status" >&2 reboot=false for d in ${OVERLAYFS_BACKING}; do if adb_sh ls -d /${d}/overlay </dev/null >/dev/null 2>/dev/null; then echo "${ORANGE}[ WARNING ]${NORMAL} /${d}/overlay is setup, surgically wiping" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} /${d}/overlay is setup, surgically wiping" >&2 adb_sh rm -rf /${d}/overlay </dev/null || die "/${d}/overlay wipe" reboot=true fi done if ${reboot}; then echo "${ORANGE}[ WARNING ]${NORMAL} rebooting before test" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} rebooting before test" >&2 adb_reboot && adb_wait ${ADB_WAIT} || die "lost device after reboot after wipe `usb_status`" Loading @@ -1030,7 +1064,7 @@ D=`adb_sh df -k </dev/null` && D=`echo "${D}" | grep -v " /vendor/..*$" | grep "^overlay "` && echo "${H}" && echo "${D}" && echo "${ORANGE}[ WARNING ]${NORMAL} overlays present before setup" >&2 || echo "${YELLOW}[ WARNING ]${NORMAL} overlays present before setup" >&2 || echo "${GREEN}[ OK ]${NORMAL} no overlay present before setup" >&2 overlayfs_needed=true D=`adb_sh cat /proc/mounts </dev/null | Loading Loading @@ -1083,7 +1117,7 @@ rebooted=false if [ X"${D}" != X"${H}" ]; then echo "${H}" if [ X"${D}" != X"${D##*setup failed}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} overlayfs setup whined" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} overlayfs setup whined" >&2 fi D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && Loading Loading @@ -1130,7 +1164,7 @@ if [ X"${D}" != X"${D##*Successfully disabled verity}" ]; then elif ${rebooted}; then echo "${GREEN}[ OK ]${NORMAL} verity already disabled" >&2 else echo "${ORANGE}[ WARNING ]${NORMAL} verity already disabled" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} verity already disabled" >&2 fi echo "${GREEN}[ RUN ]${NORMAL} remount" >&2 Loading Loading @@ -1160,7 +1194,7 @@ if ${overlayfs_needed}; then die -t ${T} "overlay takeover failed" fi echo "${D}" | grep "^overlay .* /system\$" >/dev/null || echo "${ORANGE}[ WARNING ]${NORMAL} overlay takeover not complete" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} overlay takeover not complete" >&2 if [ -z "${virtual_ab}" ]; then scratch_partition=scratch fi Loading Loading @@ -1292,7 +1326,7 @@ echo "${GREEN}[ RUN ]${NORMAL} reboot to confirm content persistent" >&2 fixup_from_recovery() { inRecovery || return 1 echo "${ORANGE}[ ERROR ]${NORMAL} Device in recovery" >&2 echo "${YELLOW}[ ERROR ]${NORMAL} Device in recovery" >&2 adb reboot </dev/null adb_wait ${ADB_WAIT} } Loading @@ -1312,7 +1346,7 @@ 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 "${ORANGE}[ WARNING ]${NORMAL} overlay takeover after first stage init" >&2 || echo "${YELLOW}[ WARNING ]${NORMAL} overlay takeover after first stage init" >&2 || echo "${GREEN}[ OK ]${NORMAL} overlay takeover in first stage init" >&2 fi Loading Loading @@ -1373,20 +1407,20 @@ is_bootloader_fastboot=false is_userspace_fastboot=false if ! ${is_bootloader_fastboot}; then echo "${ORANGE}[ WARNING ]${NORMAL} does not support fastboot, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} does not support fastboot, skipping" elif [ -z "${ANDROID_PRODUCT_OUT}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} build tree not setup, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} build tree not setup, skipping" elif [ ! -s "${ANDROID_PRODUCT_OUT}/vendor.img" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} vendor image missing, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} vendor image missing, skipping" elif [ "${ANDROID_PRODUCT_OUT}" = "${ANDROID_PRODUCT_OUT%*/${H}}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} wrong vendor image, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} wrong vendor image, skipping" elif [ -z "${ANDROID_HOST_OUT}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} please run lunch, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} 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 "${ORANGE}[ WARNING ]${NORMAL} vendor image signature mismatch, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} vendor image signature mismatch, skipping" else wait_for_screen avc_check Loading Loading @@ -1432,7 +1466,7 @@ else fi fastboot reboot || die "can not reboot out of fastboot" echo "${ORANGE}[ WARNING ]${NORMAL} adb after fastboot" echo "${YELLOW}[ WARNING ]${NORMAL} adb after fastboot" adb_wait ${ADB_WAIT} || fixup_from_recovery || die "did not reboot after formatting ${scratch_partition} `usb_status`" Loading @@ -1449,8 +1483,8 @@ else if ${is_userspace_fastboot}; then die "overlay supposed to be minus /vendor takeover after flash vendor" else echo "${ORANGE}[ WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2 echo "${ORANGE}[ WARNING ]${NORMAL} overlay supposed to be minus /vendor takeover after flash vendor" >&2 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 fi fi B="`adb_cat /system/hello`" Loading @@ -1468,7 +1502,7 @@ else check_eq "cat: /vendor/hello: No such file or directory" "${B}" \ vendor content after flash vendor else echo "${ORANGE}[ WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2 check_eq "cat: /vendor/hello: No such file or directory" "${B}" \ --warning vendor content after flash vendor fi Loading @@ -1489,7 +1523,7 @@ err=${?} L= D="${H%?Now reboot your device for settings to take effect*}" if [ X"${H}" != X"${D}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} adb remount requires a reboot after partial flash (legacy avb)" echo "${YELLOW}[ WARNING ]${NORMAL} 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} && Loading Loading @@ -1547,7 +1581,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 "${ORANGE}[ WARNING ]${NORMAL} adb disable-verity requires a reboot after partial flash" echo "${YELLOW}[ WARNING ]${NORMAL} adb disable-verity requires a reboot after partial flash" adb_reboot && adb_wait ${ADB_WAIT} && adb_root || Loading Loading @@ -1580,9 +1614,9 @@ fixup_from_fastboot() { if [ -n "${ACTIVE_SLOT}" ]; then local active_slot=`get_active_slot` if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then echo "${ORANGE}[ ERROR ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" echo "${YELLOW}[ ERROR ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" else echo "${ORANGE}[ ERROR ]${NORMAL} Active slot to be set to ${ACTIVE_SLOT}" echo "${YELLOW}[ ERROR ]${NORMAL} Active slot to be set to ${ACTIVE_SLOT}" fi >&2 fastboot --set-active=${ACTIVE_SLOT} fi Loading Loading
fs_mgr/tests/adb-remount-test.sh +114 −80 Original line number Diff line number Diff line Loading @@ -15,13 +15,17 @@ USAGE="USAGE: `basename ${0}` [--help] [--serial <SerialNumber>] [options] adb remount tests --color Dress output with highlighting colors --help This help --no-wait-screen Do not wait for display screen to settle --print-time Report the test duration --serial Specify device (must if multiple are present) --wait-adb <duration> adb wait timeout --wait-fastboot <duration> fastboot wait timeout -c --color Dress output with highlighting colors -h --help This help -D --no-wait-screen Do not wait for display screen to settle -t --print-time Report the test duration -s --serial Specify device (must if multiple are present)" if [ -n "`which timeout`" ]; then USAGE="${USAGE} -a --wait-adb <duration> adb wait timeout -f --wait-fastboot <duration> fastboot wait timeout" fi USAGE="${USAGE} Conditions: - Must be a userdebug build. Loading @@ -46,10 +50,10 @@ TAB="`echo | tr '\n' '\t'`" ESCAPE="`echo | tr '\n' '\033'`" # A _real_ embedded carriage return character CR="`echo | tr '\n' '\r'`" GREEN="${ESCAPE}[38;5;40m" RED="${ESCAPE}[38;5;196m" ORANGE="${ESCAPE}[38;5;255:165:0m" BLUE="${ESCAPE}[35m" GREEN="${ESCAPE}[32m" RED="${ESCAPE}[31m" YELLOW="${ESCAPE}[33m" BLUE="${ESCAPE}[34m" NORMAL="${ESCAPE}[0m" TMPDIR=${TMPDIR:-/tmp} print_time=false Loading @@ -72,7 +76,7 @@ inFastboot() { if [ -n "${ANDROID_SERIAL}" ]; then grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null else wc -l | grep '^1$' >/dev/null wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null fi } Loading @@ -85,7 +89,7 @@ inAdb() { if [ -n "${ANDROID_SERIAL}" ]; then grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null else wc -l | grep '^1$' >/dev/null wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null fi } Loading @@ -100,7 +104,7 @@ inRecovery() { grep "^${ANDROID_SERIAL}[${SPACE}${TAB}][${SPACE}${TAB}]*recovery\$" >/dev/null return ${?} fi if echo "${list}" | wc -l | grep '^1$' >/dev/null; then if echo "${list}" | wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null; then echo "${list}" | grep "[${SPACE}${TAB}]recovery\$" >/dev/null return ${?} Loading Loading @@ -160,7 +164,7 @@ avc_check() { if [ -z "${L}" ]; then return fi echo "${ORANGE}[ WARNING ]${NORMAL} unlabeled sepolicy violations:" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} unlabeled sepolicy violations:" >&2 echo "${L}" | sed "s/^/${INDENT}/" >&2 } Loading Loading @@ -284,7 +288,7 @@ adb_wait() { local start=`date +%s` local duration= local ret if [ -n "${1}" ]; then if [ -n "${1}" -a -n "`which timeout`" ]; then USB_DEVICE=`usb_devnum --next` duration=`format_duration ${1}` echo -n ". . . waiting ${duration}" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" Loading @@ -299,7 +303,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 "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" >&2 fi fi local end=`date +%s` Loading Loading @@ -359,7 +363,9 @@ usb_status() { echo "(In adb mode `adb_user`)" else echo "(USB stack borken for ${USB_ADDRESS})" if [ -n "`which usb_devnum`" ]; then USB_DEVICE=`usb_devnum` if [ -n "`which lsusb`" ]; then if [ -n "${USB_DEVICE}" ]; then echo "# lsusb -v -s ${USB_DEVICE#dev}" local D=`lsusb -v -s ${USB_DEVICE#dev} 2>&1` Loading @@ -371,6 +377,8 @@ usb_status() { else echo "# lsusb -v (expected device missing)" lsusb -v fi fi fi >&2 fi } Loading @@ -382,7 +390,7 @@ fastboot_wait() { local ret # fastboot has no wait-for-device, but it does an automatic # wait and requires (even a nonsensical) command to do so. if [ -n "${1}" ]; then if [ -n "${1}" -a -n "`which timeout`" ]; then USB_DEVICE=`usb_devnum --next` echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" timeout --preserve-status --signal=KILL ${1} fastboot wait-for-device >/dev/null 2>/dev/null Loading @@ -398,7 +406,7 @@ 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 "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" echo "${YELLOW}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" fi >&2 fi return ${ret} Loading @@ -409,7 +417,7 @@ fastboot_wait() { Returns: waits until the device has returned for recovery or optional timeout" ] recovery_wait() { local ret if [ -n "${1}" ]; then if [ -n "${1}" -a -n "`which timeout`" ]; then USB_DEVICE=`usb_devnum --next` echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}" timeout --preserve-status --signal=KILL ${1} adb wait-for-recovery 2>/dev/null Loading @@ -423,7 +431,7 @@ 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 "${ORANGE}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" echo "${YELLOW}[ WARNING ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" fi >&2 fi return ${ret} Loading Loading @@ -732,6 +740,7 @@ skip_administrative_mounts() { grep -v \ -e "^\(overlay\|tmpfs\|none\|sysfs\|proc\|selinuxfs\|debugfs\|bpf\) " \ -e "^\(binfmt_misc\|cg2_bpf\|pstore\|tracefs\|adb\|mtp\|ptp\|devpts\) " \ -e "^\(ramdumpfs\) " \ -e " functionfs " \ -e "^\(/data/media\|/dev/block/loop[0-9]*\) " \ -e "^rootfs / rootfs rw," \ Loading @@ -753,13 +762,28 @@ skip_unrelated_mounts() { ## MAINLINE ## OPTIONS=`getopt --alternative --unquoted \ --longoptions help,serial:,colour,color,no-colour,no-color \ --longoptions wait-adb:,wait-fastboot: \ --longoptions wait-screen,wait-display \ --longoptions no-wait-screen,no-wait-display \ --longoptions gtest_print_time,print-time \ -- "?hs:" ${*}` || HOSTOS=`uname` GETOPTS="--alternative --unquoted --longoptions help,serial:,colour,color,no-colour,no-color --longoptions wait-adb:,wait-fastboot: --longoptions wait-screen,wait-display --longoptions no-wait-screen,no-wait-display --longoptions gtest_print_time,print-time --" if [ "Darwin" = "${HOSTOS}" ]; then GETOPTS= USAGE="`echo \"${USAGE}\" | sed 's/--color/ /g 1s/--help/-h/ s/--help/ /g s/--no-wait-screen/ /g s/--print-time/ /g 1s/--serial/-s/ s/--serial/ /g s/--wait-adb/ /g s/--wait-fastboot/ /g'`" fi OPTIONS=`getopt ${GETOPTS} "?a:cCdDf:hs:t" ${*}` || ( echo "${USAGE}" >&2 ; false ) || die "getopt failure" set -- ${OPTIONS} Loading @@ -775,26 +799,26 @@ while [ ${#} -gt 0 ]; do export ANDROID_SERIAL=${2} shift ;; --color | --colour) -c | --color | --colour) color=true ;; --no-color | --no-colour) -C | --no-color | --no-colour) color=false ;; --no-wait-display | --no-wait-screen) -D | --no-wait-display | --no-wait-screen) screen_wait=false ;; --wait-display | --wait-screen) -d | --wait-display | --wait-screen) screen_wait=true ;; --print-time | --gtest_print_time) -t | --print-time | --gtest_print_time) print_time=true ;; --wait-adb) -a | --wait-adb) ADB_WAIT=${2} shift ;; --wait-fastboot) -f | --wait-fastboot) FASTBOOT_WAIT=${2} shift ;; Loading @@ -815,7 +839,7 @@ done if ! ${color}; then GREEN="" RED="" ORANGE="" YELLOW="" BLUE="" NORMAL="" fi Loading @@ -827,14 +851,14 @@ fi inFastboot && die "device in fastboot mode" inRecovery && die "device in recovery mode" if ! inAdb; then echo "${ORANGE}[ WARNING ]${NORMAL} device not in adb mode" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} device not in adb mode" >&2 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 "${ORANGE}[ WARNING ]${NORMAL} device does not have sepolicy in enforcing mode" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} device does not have sepolicy in enforcing mode" >&2 enforcing=false fi Loading @@ -846,9 +870,13 @@ D=`get_property ro.serialno` [ -n "${D}" ] || D=`get_property ro.boot.serialno` [ -z "${D}" -o -n "${ANDROID_SERIAL}" ] || ANDROID_SERIAL=${D} USB_SERIAL= [ -z "${ANDROID_SERIAL}" ] || USB_SERIAL=`find /sys/devices -name serial | grep usb | xargs -r grep -l ${ANDROID_SERIAL}` if [ -n "${ANDROID_SERIAL}" -a "Darwin" != "${HOSTOS}" ]; then USB_SERIAL="`find /sys/devices -name serial | grep usb`" if [ -n "${USB_SERIAL}" ]; then USB_SERIAL=`echo "${USB_SERIAL}" | xargs grep -l ${ANDROID_SERIAL}` fi fi USB_ADDRESS= if [ -n "${USB_SERIAL}" ]; then USB_ADDRESS=${USB_SERIAL%/serial} Loading @@ -860,13 +888,16 @@ fi BUILD_DESCRIPTION=`get_property ro.build.description` [ -z "${BUILD_DESCRIPTION}" ] || echo "${BLUE}[ INFO ]${NORMAL} ${BUILD_DESCRIPTION}" >&2 KERNEL_VERSION="`adb_su cat /proc/version </dev/null 2>/dev/null`" [ -z "${KERNEL_VERSION}" ] || echo "${BLUE}[ INFO ]${NORMAL} ${KERNEL_VERSION}" >&2 ACTIVE_SLOT=`get_active_slot` [ -z "${ACTIVE_SLOT}" ] || echo "${BLUE}[ INFO ]${NORMAL} active slot is ${ACTIVE_SLOT}" >&2 # Acquire list of system partitions PARTITIONS=`adb_su cat /vendor/etc/fstab* | PARTITIONS=`adb_su cat /vendor/etc/fstab* </dev/null | skip_administrative_mounts | sed -n "s@^\([^ ${TAB}/][^ ${TAB}/]*\)[ ${TAB}].*[, ${TAB}]ro[, ${TAB}].*@\1@p" | sort -u | Loading Loading @@ -903,9 +934,12 @@ adb_sh ls -l /dev/block/by-name/ /dev/block/mapper/ </dev/null 2>/dev/null | 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 fi if ! wait_for_screen && ${screen_wait}; then screen_wait=false echo "${ORANGE}[ WARNING ]${NORMAL} not healthy, no launcher, skipping wait for screen" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} not healthy, no launcher, skipping wait for screen" >&2 fi # Can we test remount -R command? Loading Loading @@ -954,7 +988,7 @@ else adb_su remount -R system </dev/null err=${?} if [ "${err}" != 0 ]; then echo "${ORANGE}[ WARNING ]${NORMAL} adb shell su root remount -R system = ${err}, likely did not reboot!" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} adb shell su root remount -R system = ${err}, likely did not reboot!" >&2 T="-t ${T}" else # Rebooted, logcat will be meaningless, and last logcat will likely be clear Loading @@ -980,7 +1014,7 @@ adb_sh ls -d /sys/module/overlay </dev/null >/dev/null 2>/dev/null || adb_sh grep "nodev${TAB}overlay" /proc/filesystems </dev/null >/dev/null 2>/dev/null && echo "${GREEN}[ OK ]${NORMAL} overlay module present" >&2 || ( echo "${ORANGE}[ WARNING ]${NORMAL} overlay module not present" >&2 && echo "${YELLOW}[ WARNING ]${NORMAL} overlay module not present" >&2 && false ) || overlayfs_supported=false Loading @@ -989,7 +1023,7 @@ if ${overlayfs_supported}; then echo "${GREEN}[ OK ]${NORMAL} overlay module supports override_creds" >&2 || case `adb_sh uname -r </dev/null` in 4.[456789].* | 4.[1-9][0-9]* | [56789].*) echo "${ORANGE}[ WARNING ]${NORMAL} overlay module does not support override_creds" >&2 && echo "${YELLOW}[ WARNING ]${NORMAL} overlay module does not support override_creds" >&2 && overlayfs_supported=false ;; *) Loading @@ -1011,14 +1045,14 @@ echo "${GREEN}[ RUN ]${NORMAL} Checking current overlayfs status" >&2 reboot=false for d in ${OVERLAYFS_BACKING}; do if adb_sh ls -d /${d}/overlay </dev/null >/dev/null 2>/dev/null; then echo "${ORANGE}[ WARNING ]${NORMAL} /${d}/overlay is setup, surgically wiping" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} /${d}/overlay is setup, surgically wiping" >&2 adb_sh rm -rf /${d}/overlay </dev/null || die "/${d}/overlay wipe" reboot=true fi done if ${reboot}; then echo "${ORANGE}[ WARNING ]${NORMAL} rebooting before test" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} rebooting before test" >&2 adb_reboot && adb_wait ${ADB_WAIT} || die "lost device after reboot after wipe `usb_status`" Loading @@ -1030,7 +1064,7 @@ D=`adb_sh df -k </dev/null` && D=`echo "${D}" | grep -v " /vendor/..*$" | grep "^overlay "` && echo "${H}" && echo "${D}" && echo "${ORANGE}[ WARNING ]${NORMAL} overlays present before setup" >&2 || echo "${YELLOW}[ WARNING ]${NORMAL} overlays present before setup" >&2 || echo "${GREEN}[ OK ]${NORMAL} no overlay present before setup" >&2 overlayfs_needed=true D=`adb_sh cat /proc/mounts </dev/null | Loading Loading @@ -1083,7 +1117,7 @@ rebooted=false if [ X"${D}" != X"${H}" ]; then echo "${H}" if [ X"${D}" != X"${D##*setup failed}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} overlayfs setup whined" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} overlayfs setup whined" >&2 fi D=`adb_sh df -k </dev/null` && H=`echo "${D}" | head -1` && Loading Loading @@ -1130,7 +1164,7 @@ if [ X"${D}" != X"${D##*Successfully disabled verity}" ]; then elif ${rebooted}; then echo "${GREEN}[ OK ]${NORMAL} verity already disabled" >&2 else echo "${ORANGE}[ WARNING ]${NORMAL} verity already disabled" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} verity already disabled" >&2 fi echo "${GREEN}[ RUN ]${NORMAL} remount" >&2 Loading Loading @@ -1160,7 +1194,7 @@ if ${overlayfs_needed}; then die -t ${T} "overlay takeover failed" fi echo "${D}" | grep "^overlay .* /system\$" >/dev/null || echo "${ORANGE}[ WARNING ]${NORMAL} overlay takeover not complete" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} overlay takeover not complete" >&2 if [ -z "${virtual_ab}" ]; then scratch_partition=scratch fi Loading Loading @@ -1292,7 +1326,7 @@ echo "${GREEN}[ RUN ]${NORMAL} reboot to confirm content persistent" >&2 fixup_from_recovery() { inRecovery || return 1 echo "${ORANGE}[ ERROR ]${NORMAL} Device in recovery" >&2 echo "${YELLOW}[ ERROR ]${NORMAL} Device in recovery" >&2 adb reboot </dev/null adb_wait ${ADB_WAIT} } Loading @@ -1312,7 +1346,7 @@ 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 "${ORANGE}[ WARNING ]${NORMAL} overlay takeover after first stage init" >&2 || echo "${YELLOW}[ WARNING ]${NORMAL} overlay takeover after first stage init" >&2 || echo "${GREEN}[ OK ]${NORMAL} overlay takeover in first stage init" >&2 fi Loading Loading @@ -1373,20 +1407,20 @@ is_bootloader_fastboot=false is_userspace_fastboot=false if ! ${is_bootloader_fastboot}; then echo "${ORANGE}[ WARNING ]${NORMAL} does not support fastboot, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} does not support fastboot, skipping" elif [ -z "${ANDROID_PRODUCT_OUT}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} build tree not setup, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} build tree not setup, skipping" elif [ ! -s "${ANDROID_PRODUCT_OUT}/vendor.img" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} vendor image missing, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} vendor image missing, skipping" elif [ "${ANDROID_PRODUCT_OUT}" = "${ANDROID_PRODUCT_OUT%*/${H}}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} wrong vendor image, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} wrong vendor image, skipping" elif [ -z "${ANDROID_HOST_OUT}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} please run lunch, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} 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 "${ORANGE}[ WARNING ]${NORMAL} vendor image signature mismatch, skipping" echo "${YELLOW}[ WARNING ]${NORMAL} vendor image signature mismatch, skipping" else wait_for_screen avc_check Loading Loading @@ -1432,7 +1466,7 @@ else fi fastboot reboot || die "can not reboot out of fastboot" echo "${ORANGE}[ WARNING ]${NORMAL} adb after fastboot" echo "${YELLOW}[ WARNING ]${NORMAL} adb after fastboot" adb_wait ${ADB_WAIT} || fixup_from_recovery || die "did not reboot after formatting ${scratch_partition} `usb_status`" Loading @@ -1449,8 +1483,8 @@ else if ${is_userspace_fastboot}; then die "overlay supposed to be minus /vendor takeover after flash vendor" else echo "${ORANGE}[ WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2 echo "${ORANGE}[ WARNING ]${NORMAL} overlay supposed to be minus /vendor takeover after flash vendor" >&2 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 fi fi B="`adb_cat /system/hello`" Loading @@ -1468,7 +1502,7 @@ else check_eq "cat: /vendor/hello: No such file or directory" "${B}" \ vendor content after flash vendor else echo "${ORANGE}[ WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2 echo "${YELLOW}[ WARNING ]${NORMAL} user fastboot missing required to invalidate, ignoring a failure" >&2 check_eq "cat: /vendor/hello: No such file or directory" "${B}" \ --warning vendor content after flash vendor fi Loading @@ -1489,7 +1523,7 @@ err=${?} L= D="${H%?Now reboot your device for settings to take effect*}" if [ X"${H}" != X"${D}" ]; then echo "${ORANGE}[ WARNING ]${NORMAL} adb remount requires a reboot after partial flash (legacy avb)" echo "${YELLOW}[ WARNING ]${NORMAL} 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} && Loading Loading @@ -1547,7 +1581,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 "${ORANGE}[ WARNING ]${NORMAL} adb disable-verity requires a reboot after partial flash" echo "${YELLOW}[ WARNING ]${NORMAL} adb disable-verity requires a reboot after partial flash" adb_reboot && adb_wait ${ADB_WAIT} && adb_root || Loading Loading @@ -1580,9 +1614,9 @@ fixup_from_fastboot() { if [ -n "${ACTIVE_SLOT}" ]; then local active_slot=`get_active_slot` if [ X"${ACTIVE_SLOT}" != X"${active_slot}" ]; then echo "${ORANGE}[ ERROR ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" echo "${YELLOW}[ ERROR ]${NORMAL} Active slot changed from ${ACTIVE_SLOT} to ${active_slot}" else echo "${ORANGE}[ ERROR ]${NORMAL} Active slot to be set to ${ACTIVE_SLOT}" echo "${YELLOW}[ ERROR ]${NORMAL} Active slot to be set to ${ACTIVE_SLOT}" fi >&2 fastboot --set-active=${ACTIVE_SLOT} fi Loading