From 2f0bcd93c2b6ecd5e6234649534f05ecc6648dd2 Mon Sep 17 00:00:00 2001 From: Yi-Yo Chiang Date: Sat, 27 Aug 2022 14:02:08 +0800 Subject: [PATCH] adb-remount-test: Refactor raw remount & remount from scratch test Move "raw remount test" right after "disable-verity -R test". Device is expected to be in a clean state right after disable-verity, so we can perform "raw remount test" immediately after. This saves us one reboot. Move "remount from scratch test" right before "remount -R test". Since they both require overlay teardown state, group them together so we only need to teardown (and reboot) once. This saves us one reboot. Total test runtime reduced by two reboots. Bug: 243116800 Test: adb-remount-test Change-Id: Ifd95ba713f1819a7d31e88cd70077dc306c64c58 --- fs_mgr/tests/adb-remount-test.sh | 184 +++++++++++++++---------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh index 949cec642..879dea154 100755 --- a/fs_mgr/tests/adb-remount-test.sh +++ b/fs_mgr/tests/adb-remount-test.sh @@ -760,9 +760,11 @@ surgically_wipe_overlayfs() { ${wiped_anything} } -[ "USAGE: is_overlayfs_mounted +[ "USAGE: is_overlayfs_mounted [mountpoint] -Returns: true if overlayfs is mounted" ] +Diagnostic output of overlayfs df lines to stderr. + +Returns: true if overlayfs is mounted [on mountpoint]" ] is_overlayfs_mounted() { local df_output=$(adb_su df -k &2 + if [ "${#}" -gt 0 ] && ! ( echo "${overlay_mounts}" | grep -qE " ${1}\$" ); then + return 1 + fi >/dev/null 2>/dev/null return 0 } @@ -1123,14 +1128,47 @@ if [ "2" = "$(get_property partition.system.verified)" ]; then fi if ${overlayfs_needed}; then is_overlayfs_mounted || - die "no overlay takeover after adb disable-verity -R" + die -d "no overlay takeover after adb disable-verity -R" LOG OK "overlay takeover after adb disable-verity -R" fi LOG OK "adb disable-verity -R" +################################################################################ +# Precondition is a verity-disabled device with overlayfs already setup. +LOG RUN "Testing raw remount commands" -LOG RUN "Testing adb remount -R" +adb_sh grep -qE " (/system|/) [^ ]* rw," /proc/mounts &2 || + die -t "${T}" "adb remount vendor" +adb_sh grep -q " /vendor [^ ]* rw," /proc/mounts &2 || + die -t "${T}" "adb remount vendor from scratch" +if ${overlayfs_needed}; then + is_overlayfs_mounted /vendor || + die -t "${T}" "expected overlay takeover /vendor" + is_overlayfs_mounted /system 2>/dev/null && + die -t "${T}" "unexpected overlay takeover /system" +fi +adb_sh grep -q " /vendor [^ ]* rw," /proc/mounts &2 || die -t "${T}" "adb remount -R failed" @@ -1151,16 +1214,16 @@ if [ "2" = "$(get_property partition.system.verified)" ]; then die "verity not disabled after adb remount -R" fi if ${overlayfs_needed}; then - is_overlayfs_mounted || - die "no overlay takeover after adb remount -R" + is_overlayfs_mounted /system || + die -d "expected overlay takeover /system" + is_overlayfs_mounted /vendor 2>/dev/null || + die -d "expected overlay takeover /vendor" LOG OK "overlay takeover after adb remount -R" fi LOG OK "adb remount -R" -################################################################################ -# Precondition is a verity-disabled device with overlayfs already setup. -LOG RUN "Testing adb remount RW" - +# For devices using overlayfs, remount -R should reboot after overlayfs setup. +# For legacy device, manual reboot to ensure device clean state. if ! ${overlayfs_needed}; then LOG WARNING "Reboot to RO (device doesn't use overlayfs)" adb_reboot && @@ -1168,35 +1231,32 @@ if ! ${overlayfs_needed}; then die "lost device after reboot to RO $(usb_status)" fi +################################################################################ +# Precondition is a verity-disabled device with overlayfs already setup. +LOG RUN "Testing adb remount RW" + # Feed log with selinux denials as baseline before overlays adb_unroot adb_sh find ${MOUNTS} /dev/null 2>/dev/null || true adb_root -adb_sh grep -q " /vendor [^ ]* rw," /proc/mounts &2 || - die -t "${T}" "adb remount vendor" -adb_sh grep -q " /vendor [^ ]* rw," /proc/mounts &2 || die -t "${T}" "adb remount" adb_sh grep -qE " (/system|/) [^ ]* rw," /proc/mounts &2 - echo "${D}" | grep ' /system$' >/dev/null || + is_overlayfs_mounted /system 2>/dev/null || die -t "${T}" "expected overlay to takeover /system after remount" adb_sh grep "^overlay " /proc/mounts &2 && - echo "${D}" | grep "^overlay .* /system\$" >/dev/null || + is_overlayfs_mounted /system || die "overlay /system takeover after flash vendor" - echo "${D}" | grep "^overlay .* /vendor\$" >/dev/null && + if is_overlayfs_mounted /vendor 2>/dev/null; then if ${is_userspace_fastboot}; then die "overlay supposed to be minus /vendor takeover after flash vendor" else LOG WARNING "fastbootd missing required to invalidate, ignoring a failure" LOG WARNING "overlay supposed to be minus /vendor takeover after flash vendor" fi + fi fi check_eq "${A}" "$(adb_cat /system/hello)" "/system content after flash vendor" check_eq "${SYSTEM_INO}" "$(adb_sh stat --format=%i /system/hello /dev/null /dev/null /dev/null &2 -adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null /dev/null