diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh index a1e94ddc1..e6d55d9fa 100755 --- a/fs_mgr/tests/adb-remount-test.sh +++ b/fs_mgr/tests/adb-remount-test.sh @@ -231,17 +231,6 @@ adb_cat() { return ${ret} } -[ "USAGE: adb_ls >stdout - -Returns: filename or directoru content to stdout with carriage returns skipped, - true if the ls had no errors" ] -adb_ls() { - local OUTPUT="`adb_sh ls ${1} /dev/null`" - local ret=${?} - echo "${OUTPUT}" | tr -d '\r' - return ${ret} -} - [ "USAGE: adb_test Returns: exit status of the test expression" ] @@ -648,9 +637,6 @@ die() { shift 2 fi >&2 LOG FAILED "${@}" - cleanup - restore - test_duration exit 1 } @@ -735,7 +721,7 @@ skip_administrative_mounts() { local exclude_filesystems=( "overlay" "tmpfs" "none" "sysfs" "proc" "selinuxfs" "debugfs" "bpf" "binfmt_misc" "cg2_bpf" "pstore" "tracefs" "adb" "mtp" "ptp" "devpts" - "ramdumpfs" "binder" "securityfs" "functionfs" "rootfs" + "ramdumpfs" "binder" "securityfs" "functionfs" "rootfs" "fuse" ) local exclude_devices=( "\/sys\/kernel\/debug" "\/data\/media" "\/dev\/block\/loop[0-9]*" @@ -760,8 +746,10 @@ or output from df Filters out all apex and vendor override administrative overlay mounts uninteresting to the test" ] skip_unrelated_mounts() { - grep -v "^overlay.* /\(apex\|bionic\|system\|vendor\)/[^ ]" | - grep -v "[%] /\(data_mirror\|apex\|bionic\|system\|vendor\)/[^ ][^ ]*$" + grep -vE \ + -e "^overlay.* /(apex|bionic|system|vendor)/[^ ]" \ + -e "^[^ ]+ /apex/[^ ]" \ + -e "[%] /(data_mirror|apex|bionic|system|vendor)/[^ ]+$" } [ "USAGE: surgically_wipe_overlayfs @@ -885,10 +873,32 @@ if ! ${color}; then NORMAL="" fi +exit_handler() { + cleanup || true + local err=0 + if ! restore; then + LOG ERROR "restore failed" + err=1 + fi >&2 + test_duration || true + if [ "${err}" != 0 ]; then + exit "${err}" + fi +} +trap 'exit_handler' EXIT + if ${print_time}; then LOG INFO "start $(date)" fi +if [ -z "${ANDROID_SERIAL}" ]; then + inAdb || die "no device or more than one device in adb mode" + D=$(adb devices | awk '$2 == "device" { print $1; exit }') + [ -n "${D}" ] || die "cannot get device serial" + ANDROID_SERIAL="${D}" +fi +export ANDROID_SERIAL + inFastboot && die "device in fastboot mode" inRecovery && die "device in recovery mode" if ! inAdb; then @@ -913,9 +923,6 @@ fi # Collect characteristics of the device and report. -D=`get_property ro.serialno` -[ -n "${D}" ] || D=`get_property ro.boot.serialno` -[ -z "${D}" -o -n "${ANDROID_SERIAL}" ] || ANDROID_SERIAL=${D} USB_SERIAL= if [ -n "${ANDROID_SERIAL}" -a "Darwin" != "${HOSTOS}" ]; then USB_SERIAL="`find /sys/devices -name serial | grep usb || true`" @@ -929,8 +936,8 @@ if [ -n "${USB_SERIAL}" ]; then USB_ADDRESS=${USB_SERIAL%/serial} USB_ADDRESS=usb${USB_ADDRESS##*/} fi -[ -z "${ANDROID_SERIAL}${USB_ADDRESS}" ] || - USB_DEVICE=`usb_devnum` +USB_DEVICE=$(usb_devnum) +[ -z "${ANDROID_SERIAL}${USB_ADDRESS}${USB_DEVICE}" ] || LOG INFO "${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE}" BUILD_DESCRIPTION=`get_property ro.build.description` [ -z "${BUILD_DESCRIPTION}" ] || @@ -943,14 +950,23 @@ ACTIVE_SLOT=`get_active_slot` LOG INFO "active slot is ${ACTIVE_SLOT}" # Acquire list of system partitions +FSTAB_SUFFIXES=( + "$(get_property ro.boot.fstab_suffix)" + "$(get_property ro.boot.hardware)" + "$(get_property ro.boot.hardware.platform)" +) +FSTAB_PATTERN='\.('"$(join_with "|" "${FSTAB_SUFFIXES[@]}")"')$' +FSTAB_FILE=$(adb_su ls -1 '/vendor/etc/fstab*' ") -PARTITIONS=`adb_su cat /vendor/etc/fstab* /dev/null; then - D=`echo / / - echo "${D}" | grep -v /dev/root` -fi -D=`echo "${D}" | cut -s -d' ' -f1 | sort -u` +D=$(adb_sh grep " ro," /proc/mounts &1 | grep "Filesystem features:.*shared_blocks" >/dev/null && no_dedupe=false done -D=`adb_sh df -k ${D} &2 if [ X"${D}" = X"${D##* 100[%] }" ] && ${no_dedupe} ; then overlayfs_needed=false @@ -1156,11 +1170,7 @@ adb_unroot adb_sh find ${MOUNTS} /dev/null 2>/dev/null || true adb_root -D=`adb remount 2>&1` -ret=${?} -echo "${D}" >&2 -[ ${ret} != 0 ] || - [ X"${D}" = X"${D##*remount failed}" ] || +adb remount >&2 || die -t "${T}" "adb remount failed" D=`adb_sh df -k /dev/null 2>/dev/null || true fi # If overlayfs has a nested security problem, this will fail. -B="`adb_ls /system/`" || - die "adb ls /system" -[ X"${B}" != X"${B#*priv-app}" ] || - die "adb ls /system/priv-app" +adb_sh ls /system >/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 reboot # Only root can read vendor if sepolicy permissions are as expected. @@ -1448,22 +1456,19 @@ else fi B="`adb_cat /system/hello`" check_eq "${A}" "${B}" system after flash vendor - B="`adb_ls /system/`" || - die "adb ls /system" - [ X"${B}" != X"${B#*priv-app}" ] || - die "adb ls /system/priv-app" + adb_sh ls /system >/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" - B="`adb_cat /vendor/hello`" if ${is_userspace_fastboot} || ! ${overlayfs_needed}; then - check_eq "cat: /vendor/hello: No such file or directory" "${B}" \ - vendor content after flash vendor + adb_test -e /vendor/hello && + die "vendor content after flash vendor" else LOG WARNING "user fastboot missing required to invalidate, ignoring a failure" - check_eq "cat: /vendor/hello: No such file or directory" "${B}" \ - --warning vendor content after flash vendor + adb_test -e /vendor/hello && + LOG WARNING "vendor content after flash vendor" fi check_eq "${SYSTEM_INO}" "`adb_sh stat --format=%i /system/hello &2 adb_sh rm /system/hello /system/priv-app/hello &2 || die -t ${T} "cleanup hello" -B="`adb_cat /system/hello`" -check_eq "cat: /system/hello: No such file or directory" "${B}" after rm -B="`adb_cat /system/priv-app/hello`" -check_eq "cat: /system/priv-app/hello: No such file or directory" "${B}" after rm -B="`adb_cat /vendor/hello`" -check_eq "cat: /vendor/hello: No such file or directory" "${B}" after rm +adb_test -e /system/hello && + die "/system/hello lingers after rm" +adb_test -e /system/priv-app/hello && + die "/system/priv-app/hello lingers after rm" +adb_test -e /vendor/hello && + die "/vendor/hello lingers after rm" for i in ${MOUNTS}; do adb_sh rm ${i}/hello /dev/null || true done @@ -1554,12 +1559,7 @@ if ${is_bootloader_fastboot} && [ -n "${scratch_partition}" ]; then [ X"${D}" != X"${D##*[Uu]sing overlayfs}" ] && LOG OK "${scratch_partition} recreated" || die -t ${T} "setup for overlayfs" - D=`adb remount 2>&1` - err=${?} - echo "${D}" >&2 - [ ${err} != 0 ] || - [ X"${D}" = X"${D##*remount failed}" ] || - ( echo "${D}" && false ) >&2 || + adb remount >&2 || die -t ${T} "remount failed" fi @@ -1627,13 +1627,5 @@ adb_sh grep " \(/system\|/\) .* rw," /proc/mounts >/dev/null