From 7da7fa4d09883274fd934951cb0d8ca35e4143f8 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 remount RW test * Check mount flag changes (ro/rw) before and after "adb remount". * Add comment explaining what's going on with the |uses_dynamic_scratch| and |scratch_partition| variables. * Add rich logs reporting infomation about the scratch partition. * Add rich error messages. * Filter out /data devices and external volumes (vold managed device) when checking RW partitions. We are only interested in system partitions. * Remove redundant "remount from setup" test from end-of-file, as they are testing the same thing as the refactored remount test. Total test runtime reduced by one reboot. Bug: 243116800 Test: adb-remount-test Change-Id: Icda5bff78372bebfe2e166d8537a06be66fff886 --- fs_mgr/tests/adb-remount-test.sh | 157 ++++++++++++++++--------------- 1 file changed, 83 insertions(+), 74 deletions(-) diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh index e6d55d9fa..d96186053 100755 --- a/fs_mgr/tests/adb-remount-test.sh +++ b/fs_mgr/tests/adb-remount-test.sh @@ -725,6 +725,7 @@ skip_administrative_mounts() { ) local exclude_devices=( "\/sys\/kernel\/debug" "\/data\/media" "\/dev\/block\/loop[0-9]*" + "\/dev\/block\/vold\/[^ ]+" "${exclude_filesystems[@]}" ) local exclude_mount_points=( @@ -1162,80 +1163,110 @@ if ${overlayfs_needed}; then fi LOG OK "adb remount -R" +################################################################################ +# Precondition is a verity-disabled device with overlayfs already setup. +LOG RUN "Testing adb remount RW" -LOG RUN "remount" +if ! ${overlayfs_needed}; then + LOG WARNING "Reboot to RO (device doesn't use overlayfs)" + adb_reboot && + adb_wait "${ADB_WAIT}" || + die "lost device after reboot to RO $(usb_status)" +fi # 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 failed" -D=`adb_sh df -k /dev/null || - LOG WARNING "overlay takeover not complete" - if [ -z "${virtual_ab}" ]; then + M=$(adb_sh cat /proc/mounts /dev/null; then - LOG INFO "using ${scratch_partition} dynamic partition for overrides" - fi - M=`adb_sh cat /proc/mounts /dev/null | - while read device kblocks used available use mounted on; do - if [ "/mnt/scratch" = "\${mounted}" ]; then - echo \${kblocks} - fi - done` && - [ -n "${scratch_size}" ] || - die "scratch size" - LOG INFO "scratch size ${scratch_size}KB" + LOG INFO "scratch device ${scratch_device} filesystem ${scratch_filesystem} size ${scratch_size}KiB" + for d in ${OVERLAYFS_BACKING}; do if adb_test -d /${d}/overlay/system/upper; then LOG INFO "/${d}/overlay is setup" fi done - ( echo "${H}" && + ( echo "${H}" echo "${D}" - ) >&2 && - echo "${D}" | grep "^overlay .* /system\$" >/dev/null || - die "overlay takeover after remount" - !(adb_sh grep "^overlay " /proc/mounts &2 + echo "${D}" | grep ' /system$' >/dev/null || + die -t "${T}" "expected overlay to takeover /system after remount" + adb_sh grep "^overlay " /proc/mounts /dev/null; then - D=`echo / / - echo "${D}" | grep -v /dev/root` - fi - D=`echo "${D}" | cut -s -d' ' -f1 | sort -u` + + data_device=$(adb_sh cat /proc/mounts &2 bad_rw=false for d in ${D}; do if adb_sh tune2fs -l $d &1 | @@ -1248,18 +1279,11 @@ if ${overlayfs_needed}; then bad_rw=true fi done - [ -z "${D}" ] || - D=`adb_sh df -k ${D} &2 ${bad_rw} && die "remount overlayfs missed a spot (rw)" -else - if [ ${ret} = 0 ]; then - die -t ${T} "unexpected overlay takeover" - fi fi +LOG OK "adb remount RW" + # Check something. LOG RUN "push content to ${MOUNTS}" @@ -1593,21 +1617,6 @@ adb_sh grep " /vendor .* rw," /proc/mounts >/dev/null /dev/null /dev/null /dev/null