From 4cf5421edc6ecbc2a26fd4eb5ead94f793bc362f Mon Sep 17 00:00:00 2001 From: Yi-Yo Chiang Date: Sat, 27 Aug 2022 14:02:07 +0800 Subject: [PATCH] adb-remount-test: Refactor fastboot flash vendor test Instead of relying on a local dev tree (which CI machines never have), just pull the vendor partition image from device. This way we can have CI coverage on fastbootd as well. Stop redefining cleanup() hook, just toss all temporary files to $TMPDIR and always clean up $TMPDIR on exit. Clarify logs and error messages. Bug: 243116800 Test: adb-remount-test Change-Id: I08fb8df58a61c03db3274b22b51e40a1a8f41095 --- fs_mgr/tests/adb-remount-test.sh | 149 +++++++++++++------------------ 1 file changed, 64 insertions(+), 85 deletions(-) diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh index d96186053..949cec642 100755 --- a/fs_mgr/tests/adb-remount-test.sh +++ b/fs_mgr/tests/adb-remount-test.sh @@ -55,7 +55,6 @@ RED="${ESCAPE}[31m" YELLOW="${ESCAPE}[33m" BLUE="${ESCAPE}[34m" NORMAL="${ESCAPE}[0m" -TMPDIR=${TMPDIR:-/tmp} print_time=false start_time=`date +%s` ACTIVE_SLOT= @@ -588,22 +587,13 @@ get_active_slot() { [ "USAGE: restore -Do nothing: should be redefined when necessary. Called after cleanup. +Do nothing: should be redefined when necessary. Returns: reverses configurations" ] restore() { true } -[ "USAGE: cleanup - -Do nothing: should be redefined when necessary - -Returns: cleans up any latent resources" ] -cleanup() { - true -} - [ "USAGE: test_duration >/dev/stderr Prints the duration of the test @@ -874,8 +864,10 @@ if ! ${color}; then NORMAL="" fi +TMPDIR= + exit_handler() { - cleanup || true + [ -n "${TMPDIR}" ] && rm -rf "${TMPDIR}" local err=0 if ! restore; then LOG ERROR "restore failed" @@ -888,6 +880,8 @@ exit_handler() { } trap 'exit_handler' EXIT +TMPDIR=$(mktemp -d) + if ${print_time}; then LOG INFO "start $(date)" fi @@ -1305,19 +1299,15 @@ check_ne "${SYSTEM_INO}" "${VENDOR_INO}" vendor and system inode # Download libc.so, append some garbage, push back, and check if the file # is updated. -tempdir="`mktemp -d`" -cleanup() { - rm -rf ${tempdir} -} -adb pull /system/lib/bootstrap/libc.so ${tempdir} >/dev/null || +adb pull /system/lib/bootstrap/libc.so "${TMPDIR}/libc.so" >/dev/null || die "pull libc.so from device" garbage="D105225BBFCB1EB8AB8EBDB7094646F0" -echo "${garbage}" >> ${tempdir}/libc.so -adb push ${tempdir}/libc.so /system/lib/bootstrap/libc.so >/dev/null || +echo "${garbage}" >>"${TMPDIR}/libc.so" +adb push "${TMPDIR}/libc.so" /system/lib/bootstrap/libc.so >/dev/null || die "push libc.so to device" -adb pull /system/lib/bootstrap/libc.so ${tempdir}/libc.so.fromdevice >/dev/null || +adb pull /system/lib/bootstrap/libc.so "${TMPDIR}/libc.so.fromdevice" >/dev/null || die "pull libc.so from device" -diff ${tempdir}/libc.so ${tempdir}/libc.so.fromdevice > /dev/null || +diff "${TMPDIR}/libc.so" "${TMPDIR}/libc.so.fromdevice" > /dev/null || die "libc.so differ" LOG RUN "reboot to confirm content persistent" @@ -1379,87 +1369,85 @@ adb_sh find ${MOUNTS} /dev/null 2>/dev/null || true # Check if the updated libc.so is persistent after reboot. adb_root && - adb pull /system/lib/bootstrap/libc.so ${tempdir}/libc.so.fromdevice >/dev/null || + adb pull /system/lib/bootstrap/libc.so "${TMPDIR}/libc.so.fromdevice" >/dev/null || die "pull libc.so from device" -diff ${tempdir}/libc.so ${tempdir}/libc.so.fromdevice > /dev/null || die "libc.so differ" -rm -rf ${tempdir} -cleanup() { - true -} +diff "${TMPDIR}/libc.so" "${TMPDIR}/libc.so.fromdevice" > /dev/null || die "libc.so differ" LOG OK "/system/lib/bootstrap/libc.so content remains after reboot" -LOG RUN "flash vendor, confirm its content disappears" +################################################################################ +LOG RUN "flash vendor, and confirm vendor override disappears" -H=`adb_sh echo '${HOSTNAME}' /dev/null` -is_bootloader_fastboot=false +is_bootloader_fastboot=true # cuttlefish? -[ X"${H}" != X"${H#vsoc}" ] || is_bootloader_fastboot=true +[[ "$(get_property ro.product.device)" == vsoc* ]] && + is_bootloader_fastboot=false is_userspace_fastboot=false if ! ${is_bootloader_fastboot}; then - LOG WARNING "does not support fastboot, skipping" -elif [ -z "${ANDROID_PRODUCT_OUT}" ]; then - LOG WARNING "build tree not setup, skipping" -elif [ ! -s "${ANDROID_PRODUCT_OUT}/vendor.img" ]; then - LOG WARNING "vendor image missing, skipping" -elif [ "${ANDROID_PRODUCT_OUT}" = "${ANDROID_PRODUCT_OUT%*/${H}}" ]; then - LOG WARNING "wrong vendor image, skipping" -elif [ -z "${ANDROID_HOST_OUT}" ]; then - 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 - LOG WARNING "vendor image signature mismatch, skipping" + LOG WARNING "does not support fastboot flash, skipping" else wait_for_screen + adb_root || die "adb root" + + VENDOR_DEVICE_CANDIDATES=( + "/dev/block/mapper/vendor"{_${ACTIVE_SLOT},} + "/dev/block/by-name/vendor"{_${ACTIVE_SLOT},} + ) + for b in "${VENDOR_DEVICE_CANDIDATES[@]}"; do + if adb_test -e "${b}"; then + adb pull "${b}" "${TMPDIR}/vendor.img" || die "adb pull ${b}" + LOG INFO "pulled ${b} from device as vendor.img" + break + fi + done + [ -f "${TMPDIR}/vendor.img" ] || + die "cannot find block device of vendor partition" + avc_check adb reboot fastboot /dev/null || die "ls /system" adb_test -d /system/priv-app || die "[ -d /system/priv-app ]" - B="`adb_cat /system/priv-app/hello`" - check_eq "${A}" "${B}" system/priv-app after flash vendor - adb_root || - die "adb root" - if ${is_userspace_fastboot} || ! ${overlayfs_needed}; then - adb_test -e /vendor/hello && + check_eq "${A}" "$(adb_cat /system/priv-app/hello)" "/system/priv-app content after flash vendor" + adb_root || die "adb root" + if adb_test -e /vendor/hello; then + if ${is_userspace_fastboot} || ! ${overlayfs_needed}; then die "vendor content after flash vendor" - else - LOG WARNING "user fastboot missing required to invalidate, ignoring a failure" - adb_test -e /vendor/hello && + else + LOG WARNING "fastbootd missing required to invalidate, ignoring a failure" LOG WARNING "vendor content after flash vendor" + fi fi - - check_eq "${SYSTEM_INO}" "`adb_sh stat --format=%i /system/hello &2 wait_for_screen + +################################################################################ LOG RUN "remove test content (cleanup)" T=`adb_date` @@ -1541,19 +1527,12 @@ if ${is_bootloader_fastboot} && [ -n "${scratch_partition}" ]; then avc_check adb reboot fastboot /dev/null && fastboot_wait ${FASTBOOT_WAIT} || die "reboot into fastboot to flash scratch `usb_status`" fastboot flash --force ${scratch_partition} ${img} err=${?} - cleanup - cleanup() { - true - } fastboot reboot || die "can not reboot out of fastboot" [ 0 -eq ${err} ] ||