Skip to content

Commit d88715a

Browse files
author
Mark Salyzyn
committed
fs_mgr: adb-remount-test.sh: Port to MAC OS/X
This script did not run on a MAC, adjust so that it is usable. Signed-off-by: Mark Salyzyn <[email protected]> Bug: 161454607 Test: script can be used to test and replicate reported problem Change-Id: Id1c97b9cd85d150a96733b8d39e40f6a4bcc0721
1 parent 3591c2a commit d88715a

File tree

1 file changed

+69
-42
lines changed

1 file changed

+69
-42
lines changed

fs_mgr/tests/adb-remount-test.sh

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ USAGE="USAGE: `basename ${0}` [--help] [--serial <SerialNumber>] [options]
1515
1616
adb remount tests
1717
18-
--color Dress output with highlighting colors
19-
--help This help
20-
--no-wait-screen Do not wait for display screen to settle
21-
--print-time Report the test duration
22-
--serial Specify device (must if multiple are present)
23-
--wait-adb <duration> adb wait timeout
24-
--wait-fastboot <duration> fastboot wait timeout
18+
-c --color Dress output with highlighting colors
19+
-h --help This help
20+
-D --no-wait-screen Do not wait for display screen to settle
21+
-t --print-time Report the test duration
22+
-s --serial Specify device (must if multiple are present)"
23+
if [ -n "`which timeout`" ]; then
24+
USAGE="${USAGE}
25+
-a --wait-adb <duration> adb wait timeout
26+
-f --wait-fastboot <duration> fastboot wait timeout"
27+
fi
28+
USAGE="${USAGE}
2529
2630
Conditions:
2731
- Must be a userdebug build.
@@ -72,7 +76,7 @@ inFastboot() {
7276
if [ -n "${ANDROID_SERIAL}" ]; then
7377
grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null
7478
else
75-
wc -l | grep '^1$' >/dev/null
79+
wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null
7680
fi
7781
}
7882

@@ -85,7 +89,7 @@ inAdb() {
8589
if [ -n "${ANDROID_SERIAL}" ]; then
8690
grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null
8791
else
88-
wc -l | grep '^1$' >/dev/null
92+
wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null
8993
fi
9094
}
9195

@@ -100,7 +104,7 @@ inRecovery() {
100104
grep "^${ANDROID_SERIAL}[${SPACE}${TAB}][${SPACE}${TAB}]*recovery\$" >/dev/null
101105
return ${?}
102106
fi
103-
if echo "${list}" | wc -l | grep '^1$' >/dev/null; then
107+
if echo "${list}" | wc -l | grep "^[${SPACE}${TAB}]*1\$" >/dev/null; then
104108
echo "${list}" |
105109
grep "[${SPACE}${TAB}]recovery\$" >/dev/null
106110
return ${?}
@@ -143,7 +147,7 @@ adb_logcat() {
143147
adb logcat "${@}" </dev/null |
144148
tr -d '\r' |
145149
grep -v 'logd : logdr: UID=' |
146-
sed -e '${/------- beginning of kernel/d}' -e 's/^[0-1][0-9]-[0-3][0-9] //'
150+
sed -e '${ /------- beginning of kernel/d }' -e 's/^[0-1][0-9]-[0-3][0-9] //'
147151
}
148152

149153
[ "USAGE: avc_check >/dev/stderr
@@ -284,7 +288,7 @@ adb_wait() {
284288
local start=`date +%s`
285289
local duration=
286290
local ret
287-
if [ -n "${1}" ]; then
291+
if [ -n "${1}" -a -n "`which timeout`" ]; then
288292
USB_DEVICE=`usb_devnum --next`
289293
duration=`format_duration ${1}`
290294
echo -n ". . . waiting ${duration}" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}"
@@ -359,18 +363,22 @@ usb_status() {
359363
echo "(In adb mode `adb_user`)"
360364
else
361365
echo "(USB stack borken for ${USB_ADDRESS})"
362-
USB_DEVICE=`usb_devnum`
363-
if [ -n "${USB_DEVICE}" ]; then
364-
echo "# lsusb -v -s ${USB_DEVICE#dev}"
365-
local D=`lsusb -v -s ${USB_DEVICE#dev} 2>&1`
366-
if [ -n "${D}" ]; then
367-
echo "${D}"
368-
else
369-
lsusb -v
366+
if [ -n "`which usb_devnum`" ]; then
367+
USB_DEVICE=`usb_devnum`
368+
if [ -n "`which lsusb`" ]; then
369+
if [ -n "${USB_DEVICE}" ]; then
370+
echo "# lsusb -v -s ${USB_DEVICE#dev}"
371+
local D=`lsusb -v -s ${USB_DEVICE#dev} 2>&1`
372+
if [ -n "${D}" ]; then
373+
echo "${D}"
374+
else
375+
lsusb -v
376+
fi
377+
else
378+
echo "# lsusb -v (expected device missing)"
379+
lsusb -v
380+
fi
370381
fi
371-
else
372-
echo "# lsusb -v (expected device missing)"
373-
lsusb -v
374382
fi >&2
375383
fi
376384
}
@@ -382,7 +390,7 @@ fastboot_wait() {
382390
local ret
383391
# fastboot has no wait-for-device, but it does an automatic
384392
# wait and requires (even a nonsensical) command to do so.
385-
if [ -n "${1}" ]; then
393+
if [ -n "${1}" -a -n "`which timeout`" ]; then
386394
USB_DEVICE=`usb_devnum --next`
387395
echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}"
388396
timeout --preserve-status --signal=KILL ${1} fastboot wait-for-device >/dev/null 2>/dev/null
@@ -409,7 +417,7 @@ fastboot_wait() {
409417
Returns: waits until the device has returned for recovery or optional timeout" ]
410418
recovery_wait() {
411419
local ret
412-
if [ -n "${1}" ]; then
420+
if [ -n "${1}" -a -n "`which timeout`" ]; then
413421
USB_DEVICE=`usb_devnum --next`
414422
echo -n ". . . waiting `format_duration ${1}`" ${ANDROID_SERIAL} ${USB_ADDRESS} ${USB_DEVICE} "${CR}"
415423
timeout --preserve-status --signal=KILL ${1} adb wait-for-recovery 2>/dev/null
@@ -754,13 +762,28 @@ skip_unrelated_mounts() {
754762
## MAINLINE
755763
##
756764

757-
OPTIONS=`getopt --alternative --unquoted \
758-
--longoptions help,serial:,colour,color,no-colour,no-color \
759-
--longoptions wait-adb:,wait-fastboot: \
760-
--longoptions wait-screen,wait-display \
761-
--longoptions no-wait-screen,no-wait-display \
762-
--longoptions gtest_print_time,print-time \
763-
-- "?hs:" ${*}` ||
765+
HOSTOS=`uname`
766+
GETOPTS="--alternative --unquoted
767+
--longoptions help,serial:,colour,color,no-colour,no-color
768+
--longoptions wait-adb:,wait-fastboot:
769+
--longoptions wait-screen,wait-display
770+
--longoptions no-wait-screen,no-wait-display
771+
--longoptions gtest_print_time,print-time
772+
--"
773+
if [ "Darwin" = "${HOSTOS}" ]; then
774+
GETOPTS=
775+
USAGE="`echo \"${USAGE}\" |
776+
sed 's/--color/ /g
777+
1s/--help/-h/
778+
s/--help/ /g
779+
s/--no-wait-screen/ /g
780+
s/--print-time/ /g
781+
1s/--serial/-s/
782+
s/--serial/ /g
783+
s/--wait-adb/ /g
784+
s/--wait-fastboot/ /g'`"
785+
fi
786+
OPTIONS=`getopt ${GETOPTS} "?a:cCdDf:hs:t" ${*}` ||
764787
( echo "${USAGE}" >&2 ; false ) ||
765788
die "getopt failure"
766789
set -- ${OPTIONS}
@@ -776,26 +799,26 @@ while [ ${#} -gt 0 ]; do
776799
export ANDROID_SERIAL=${2}
777800
shift
778801
;;
779-
--color | --colour)
802+
-c | --color | --colour)
780803
color=true
781804
;;
782-
--no-color | --no-colour)
805+
-C | --no-color | --no-colour)
783806
color=false
784807
;;
785-
--no-wait-display | --no-wait-screen)
808+
-D | --no-wait-display | --no-wait-screen)
786809
screen_wait=false
787810
;;
788-
--wait-display | --wait-screen)
811+
-d | --wait-display | --wait-screen)
789812
screen_wait=true
790813
;;
791-
--print-time | --gtest_print_time)
814+
-t | --print-time | --gtest_print_time)
792815
print_time=true
793816
;;
794-
--wait-adb)
817+
-a | --wait-adb)
795818
ADB_WAIT=${2}
796819
shift
797820
;;
798-
--wait-fastboot)
821+
-f | --wait-fastboot)
799822
FASTBOOT_WAIT=${2}
800823
shift
801824
;;
@@ -847,9 +870,13 @@ D=`get_property ro.serialno`
847870
[ -n "${D}" ] || D=`get_property ro.boot.serialno`
848871
[ -z "${D}" -o -n "${ANDROID_SERIAL}" ] || ANDROID_SERIAL=${D}
849872
USB_SERIAL=
850-
[ -z "${ANDROID_SERIAL}" ] || USB_SERIAL=`find /sys/devices -name serial |
851-
grep usb |
852-
xargs -r grep -l ${ANDROID_SERIAL}`
873+
if [ -n "${ANDROID_SERIAL}" -a "Darwin" != "${HOSTOS}" ]; then
874+
USB_SERIAL="`find /sys/devices -name serial | grep usb`"
875+
if [ -n "${USB_SERIAL}" ]; then
876+
USB_SERIAL=`echo "${USB_SERIAL}" |
877+
xargs grep -l ${ANDROID_SERIAL}`
878+
fi
879+
fi
853880
USB_ADDRESS=
854881
if [ -n "${USB_SERIAL}" ]; then
855882
USB_ADDRESS=${USB_SERIAL%/serial}

0 commit comments

Comments
 (0)