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