adb-remount-test: Refactor prologue & /sys/module/overlay mining
While doing precondition check, verify that device is debuggable and
unlocked.
The /sys/module/overlay mining code had some remarkably written chained
... && ... || ... expressions. This is also remarkably unreadable for
those untrained of bash command chaining pitfalls.
Just rewrite these with plain old if-then-else expressions.
Bug: 243116800
Test: adb-remount-test
Change-Id: I56b1dea5b9147755a43462682a51bc5802ee64c1
diff --git a/fs_mgr/tests/adb-remount-test.sh b/fs_mgr/tests/adb-remount-test.sh
index 0157f46..617ba26 100755
--- a/fs_mgr/tests/adb-remount-test.sh
+++ b/fs_mgr/tests/adb-remount-test.sh
@@ -213,15 +213,6 @@
adb_sh getprop ${1} </dev/null
}
-[ "USAGE: isDebuggable
-
-Returns: true if device is (likely) a debug build" ]
-isDebuggable() {
- if inAdb && [ 1 != "`get_property ro.debuggable`" ]; then
- false
- fi
-}
-
[ "USAGE: adb_su <commands> </dev/stdin >/dev/stdout 2>/dev/stderr
Returns: true if the command running as root succeeded" ]
@@ -905,7 +896,13 @@
adb_wait ${ADB_WAIT}
fi
inAdb || die "specified device not in adb mode"
-isDebuggable || die "device not a debug build"
+[ "1" = "$(get_property ro.debuggable)" ] || die "device not a debug build"
+[ "orange" = "$(get_property ro.boot.verifiedbootstate)" ] || die "device not bootloader unlocked"
+can_restore_verity=true
+if [ "2" != "$(get_property partition.system.verified)" ]; then
+ LOG WARNING "device might not support verity"
+ can_restore_verity=false
+fi
enforcing=true
if ! adb_su getenforce </dev/null | grep 'Enforcing' >/dev/null; then
LOG WARNING "device does not have sepolicy in enforcing mode"
@@ -985,8 +982,33 @@
LOG INFO "partition ${name} device ${device} size ${size}K"
done
+LOG RUN "Checking kernel support for overlayfs"
+
overlayfs_supported=true
-can_restore_verity=false
+adb_root || die "becoming root to mine kernel information"
+if ! adb_test -d /sys/module/overlay; then
+ if adb_sh grep -q "nodev${TAB}overlay" /proc/filesystems; then
+ LOG OK "overlay module present"
+ else
+ LOG WARNING "overlay module not present"
+ overlayfs_supported=false
+ fi
+fi >&2
+if ${overlayfs_supported}; then
+ if adb_test -f /sys/module/overlay/parameters/override_creds; then
+ LOG OK "overlay module supports override_creds"
+ else
+ case "$(adb_sh uname -r </dev/null)" in
+ 4.[456789].* | 4.[1-9][0-9]* | [56789].*)
+ LOG WARNING "overlay module does not support override_creds"
+ overlayfs_supported=false
+ ;;
+ *)
+ LOG OK "overlay module uses caller's creds"
+ ;;
+ esac
+ fi
+fi
restore() {
LOG INFO "restoring device"
@@ -1030,7 +1052,6 @@
# Can we test remount -R command?
if [ "orange" = "$(get_property ro.boot.verifiedbootstate)" ] &&
[ "2" = "$(get_property partition.system.verified)" ]; then
- can_restore_verity=true
LOG RUN "Testing adb shell su root remount -R command"
@@ -1058,35 +1079,10 @@
LOG OK "adb shell su root remount -R command"
fi
-LOG RUN "Testing kernel support for overlayfs"
+LOG RUN "Checking current overlayfs status"
adb_wait || die "wait for device failed"
-adb_root ||
- die "initial setup"
-
-adb_test -d /sys/module/overlay ||
- adb_sh grep "nodev${TAB}overlay" /proc/filesystems </dev/null >/dev/null 2>/dev/null &&
- LOG OK "overlay module present" ||
- (
- LOG WARNING "overlay module not present" &&
- false
- ) ||
- overlayfs_supported=false
-if ${overlayfs_supported}; then
- adb_test -f /sys/module/overlay/parameters/override_creds &&
- LOG OK "overlay module supports override_creds" ||
- case `adb_sh uname -r </dev/null` in
- 4.[456789].* | 4.[1-9][0-9]* | [56789].*)
- LOG WARNING "overlay module does not support override_creds" &&
- overlayfs_supported=false
- ;;
- *)
- LOG OK "overlay module uses caller's creds"
- ;;
- esac
-fi
-
-LOG RUN "Checking current overlayfs status"
+adb_root || die "adb root failed"
# We can not universally use adb enable-verity to ensure device is
# in a overlayfs disabled state since it can prevent reboot on