blob: 6d2f5d7b548c180f58df7ecd94206d45b322544d [file] [log] [blame]
Mark Salyzynb304f6d2017-08-04 13:35:51 -07001#! /bin/bash
2#
3# Bootstat boot reason tests
4#
5# throughout testing:
6# - manual tests can only run on eng/userdebug builds
7# - watch adb logcat -b all -d -s bootstat
8# - watch adb logcat -b all -d | audit2allow
9# - wait until screen is up, boot has completed, can mean wait for
10# sys.boot_completed=1 and sys.logbootcomplete=1 to be true
11#
12# All test frames, and nothing else, must be function names prefixed and
13# specifiged with the pattern 'test_<test>() {' as this is also how the
14# script discovers the full list of tests by inspecting its own code.
15#
16
17# Helper variables
18
19SPACE=" "
20ESCAPE=""
21TAB=" "
22GREEN="${ESCAPE}[38;5;40m"
23RED="${ESCAPE}[38;5;196m"
24NORMAL="${ESCAPE}[0m"
25
26# Helper functions
27
28[ "USAGE: inFastboot
29
30Returns: true if device is in fastboot mode" ]
31inFastboot() {
32 fastboot devices | grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null
33}
34
35[ "USAGE: format_duration <seconds>
36
37human readable output whole seconds, whole minutes or mm:ss" ]
38format_duration() {
39 if [ -z "${1}" ]; then
40 echo unknown
41 return
42 fi
43 seconds=`expr ${1} % 60`
44 minutes=`expr ${1} / 60`
45 if [ 0 -eq ${minutes} ]; then
46 if [ 1 -eq ${1} ]; then
47 echo 1 second
48 return
49 fi
50 echo ${1} seconds
51 return
52 elif [ 60 -eq ${1} ]; then
53 echo 1 minute
54 return
55 elif [ 0 -eq ${seconds} ]; then
56 echo ${minutes} minutes
57 return
58 fi
59 echo ${minutes}:`expr ${seconds} / 10``expr ${seconds} % 10`
60}
61
62wait_for_screen_timeout=900
63[ "USAGE: wait_for_screen [-n] [TIMEOUT]
64
65-n - echo newline at exit
66TIMEOUT - default `format_duration ${wait_for_screen_timeout}`" ]
67wait_for_screen() {
68 exit_function=true
69 if [ X"-n" = X"${1}" ]; then
70 exit_function=echo
71 shift
72 fi
73 timeout=${wait_for_screen_timeout}
74 if [ ${#} -gt 0 ]; then
75 timeout=${1}
76 shift
77 fi
78 counter=0
79 while true; do
80 [ 0 = ${counter} ] ||
81 adb wait-for-device </dev/null >/dev/null 2>/dev/null
82 vals=`adb shell getprop </dev/null 2>/dev/null |
83 sed -n 's/[[]sys[.]\(boot_completed\|logbootcomplete\)[]]: [[]\([01]\)[]]$/\1=\2/p'`
84 [ 0 = ${counter} ] ||
85 sleep 1
86 if [ "${vals}" = "`echo boot_completed=1 ; echo logbootcomplete=1`" ]; then
87 break
88 fi
89 if [ "${vals}" = "`echo logbootcomplete=1 ; echo boot_completed=1`" ]; then
90 break
91 fi
92 counter=`expr ${counter} + 1`
93 if [ ${counter} -gt ${timeout} ]; then
94 ${exit_function}
95 echo "ERROR: wait_for_screen() timed out (`format_duration ${timeout}`)" >&2
96 return 1
97 fi
98 done
99 ${exit_function}
100}
101
102[ "USAGE: EXPECT_EQ <lval> <rval> [message]
103
104Returns true if (regex) lval matches rval" ]
105EXPECT_EQ() {
106 lval="${1}"
107 rval="${2}"
108 shift 2
109 if ! ( echo X"${rval}" | grep '^X'"${lval}"'$' >/dev/null 2>/dev/null ); then
110 echo "ERROR: expected \"${lval}\" got \"${rval}\"" >&2
111 if [ -n "${*}" ] ; then
112 echo " ${*}" >&2
113 fi
114 return 1
115 fi
116 if [ -n "${*}" ] ; then
117 if [ X"${lval}" != X"${rval}" ]; then
118 echo "INFO: ok \"${lval}\"(=\"${rval}\") ${*}" >&2
119 else
120 echo "INFO: ok \"${lval}\" ${*}" >&2
121 fi
122 fi
123 return 0
124}
125
126[ "USAGE: EXPECT_PROPERTY <prop> <value>
127
128Returns true if current return (regex) value is true and the result matches" ]
129EXPECT_PROPERTY() {
130 save_ret=${?}
131 property="${1}"
132 value="${2}"
133 shift 2
134 val=`adb shell getprop ${property} 2>&1`
135 EXPECT_EQ "${value}" "${val}" for Android property ${property} ||
136 save_ret=${?}
137 return ${save_ret}
138}
139
140[ "USAGE: report_bootstat_logs <expected> ...
141
142if not prefixed with a minus (-), <expected> will become a series of expected
143matches:
144
145 bootstat: Canonical boot reason: <expected_property_value>
146
147If prefixed with a minus, <expected> will look for an exact match after
148removing the minux prefix. All expected content is _dropped_ from the output
149and in essence forms a known blacklist, unexpected content will show.
150
151Report any logs, minus a known blacklist, preserve the current exit status" ]
152report_bootstat_logs() {
153 save_ret=${?}
154 match=
155 for i in ${*}; do
156 if [ X"${i}" != X"${i#-}" ] ; then
157 match="${match}
158${i#-}"
159 else
160 match="${match}
161bootstat: Canonical boot reason: ${i}"
162 fi
163 done
164 adb logcat -b all -d |
Mark Salyzyn08b02562017-09-18 10:07:07 -0700165 grep bootstat[^e] |
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700166 grep -v -F "bootstat: Service started: /system/bin/bootstat --record_boot_complete${match}
167bootstat: Failed to read /data/misc/bootstat/post_decrypt_time_elapsed: No such file or directory
168bootstat: Failed to parse boot time record: /data/misc/bootstat/post_decrypt_time_elapsed
169bootstat: Service started: /system/bin/bootstat --record_boot_reason
170bootstat: Service started: /system/bin/bootstat --record_time_since_factory_reset
171bootstat: Service started: /system/bin/bootstat -l
172bootstat: Battery level at shutdown 100%
173bootstat: Battery level at startup 100%
174init : Parsing file /system/etc/init/bootstat.rc...
175init : processing action (post-fs-data) from (/system/etc/init/bootstat.rc
176init : processing action (boot) from (/system/etc/init/bootstat.rc
177init : processing action (ro.boot.bootreason=*) from (/system/etc/init/bootstat.rc
178init : processing action (sys.boot_completed=1 && sys.logbootcomplete=1) from (/system/etc/init/bootstat.rc
179init : Command 'exec - system log -- /system/bin/bootstat --record_boot_complete' action=sys.boot_completed=1 && sys.logbootcomplete=1 (/system/etc/init/bootstat.rc:
180init : Command 'exec - system log -- /system/bin/bootstat --record_boot_reason' action=sys.boot_completed=1 && sys.logbootcomplete=1 (/system/etc/init/bootstat.rc:
181init : Command 'exec - system log -- /system/bin/bootstat --record_time_since_factory_reset' action=sys.boot_completed=1 && sys.logbootcomplete=1 (/system/etc/init/bootstat.rc:
182 (/system/bin/bootstat --record_boot_complete)'...
183 (/system/bin/bootstat --record_boot_complete)' (pid${SPACE}
184 (/system/bin/bootstat --record_boot_reason)'...
185 (/system/bin/bootstat --record_boot_reason)' (pid${SPACE}
186 (/system/bin/bootstat --record_time_since_factory_reset)'...
187 (/system/bin/bootstat --record_time_since_factory_reset)' (pid${SPACE}
188 (/system/bin/bootstat -l)'...
189 (/system/bin/bootstat -l)' (pid " |
190 grep -v 'bootstat: Unknown boot reason: $' # Hikey Special
191 return ${save_ret}
192}
193
194[ "USAGE: start_test [message]
195
196Record start of test, preserve exit status" ]
197start_test() {
198 save_ret=${?}
199 START=`date +%s`
200 echo "${GREEN}[ RUN ]${NORMAL} ${TEST} ${*}"
201 return ${save_ret}
202}
203
204[ "USAGE: end_test [message]
205
206Document duration and success of test, preserve exit status" ]
207end_test() {
208 save_ret=${?}
209 END=`date +%s`
210 duration=`expr ${END} - ${START} 2>/dev/null`
211 [ 0 = ${duration} ] ||
212 echo INFO: ${TEST} test duration `format_duration ${duration}` >&2
213 if [ ${save_ret} = 0 ]; then
214 echo "${GREEN}[ OK ]${NORMAL} ${TEST} ${*}"
215 else
216 echo "${RED}[ FAILED ]${NORMAL} ${TEST} ${*}"
217 fi
218 return ${save_ret}
219}
220
221[ "USAGE: wrap_test <test> [message]
222
223All tests below are wrapped with this helper" ]
224wrap_test() {
225 if [ -z "${1}" -o X"nothing" = X"${1}" ]; then
226 return
227 fi
228 TEST=${1}
229 shift
230 start_test ${1}
231 eval test_${TEST}
232 end_test ${2}
233}
234
235[ "USAGE: validate_property <property>
236
237Check property for CTS compliance with our expectations. Return a cleansed
238string representing what is acceptable.
239
240NB: must roughly match heuristics in system/core/bootstat/bootstat.cpp" ]
241validate_property() {
242 var=`adb shell getprop ${1} 2>&1`
243 var=`echo -n ${var} |
244 tr '[A-Z]' '[a-z]' |
245 tr ' \f\t\r\n' '_____'`
246 case ${var} in
247 watchdog) ;;
248 watchdog,?*) ;;
249 kernel_panic) ;;
250 kernel_panic,?*) ;;
251 recovery) ;;
252 recovery,?*) ;;
253 bootloader) ;;
254 bootloader,?*) ;;
255 cold) ;;
256 cold,?*) ;;
257 hard) ;;
258 hard,?*) ;;
259 warm) ;;
260 warm,?*) ;;
261 shutdown) ;;
262 shutdown,?*) ;;
263 reboot) ;;
264 reboot,?*) ;;
265 # Aliases
266 *wdog* | *watchdog* ) var="watchdog" ;;
267 *powerkey* ) var="cold,powerkey" ;;
268 *panic* | *kernel_panic*) var="kernel_panic" ;;
269 *thermal*) var="shutdown,thermal" ;;
270 *s3_wakeup*) var="warm,s3_wakeup" ;;
271 *hw_reset*) var="hard,hw_reset" ;;
272 *bootloader*) var="bootloader" ;;
273 ?*) var="reboot,${var}" ;;
274 *) var="reboot" ;;
275 esac
276 echo ${var}
277}
278
279#
280# Actual test frames
281#
282
283[ "USAGE: test_properties
284
285properties test
286- (wait until screen is up, boot has completed)
287- adb shell getprop ro.boot.bootreason (bootloader reason)
288- adb shell getprop persist.sys.boot.reason (last reason)
289- adb shell getprop sys.boot.reason (system reason)
290- NB: all should have a value that is compliant with our known set." ]
291test_properties() {
292 wait_for_screen
293 retval=0
294 check_set="ro.boot.bootreason persist.sys.boot.reason sys.boot.reason"
295 bootloader=""
296 # NB: this test could fail if performed _after_ optional_factory_reset test
297 # and will report
298 # ERROR: expected "reboot" got ""
299 # for Android property persist.sys.boot.reason
300 # following is mitigation for the persist.sys.boot.reason, skip it
301 if [ "reboot,factory_reset" = `validate_property ro.boot_bootreason` ]; then
302 check_set="ro.boot.bootreason sys.boot.reason"
303 bootloader="bootloader"
304 fi
305 for prop in ${check_set}; do
306 reason=`validate_property ${prop}`
307 EXPECT_PROPERTY ${prop} ${reason} || retval=${?}
308 done
309 # sys.boot.reason is last for a reason
310 report_bootstat_logs ${reason} ${bootloader}
311 return ${retval}
312}
313
314[ "USAGE: test_ota
315
316ota test
317- rm out/.kati_stamp-* out/build_date.txt out/build_number.txt
318- rm out/target/product/*/*/*.prop
319- rm -r out/target/product/*/obj/ETC/system_build_prop_intermediates
320- m
321- NB: ro.build.date.utc should update
322- fastboot flashall
323- (wait until screen is up, boot has completed)
324- adb shell getprop sys.boot.reason
325- NB: should report ota
326
327Decision to change the build itself rather than trick bootstat by
328rummaging through its data files was made." ]
329test_ota() {
330 echo "INFO: expected duration of ${TEST} test about 5 minutes or more" >&2
331 echo " extended by build and flashing times" >&2
332 if [ -z "${TARGET_PRODUCT}" -o \
333 -z "${ANDROID_PRODUCT_OUT}" -o \
334 -z "${ANDROID_BUILD_TOP}" -o \
335 -z "${TARGET_BUILD_VARIANT}" ]; then
336 echo "ERROR: Missing envsetup.sh and lunch" >&2
337 return 1
338 fi
339 rm ${ANDROID_PRODUCT_OUT%/out/*}/out/.kati_stamp-* ||
340 true
341 rm ${ANDROID_PRODUCT_OUT%/out/*}/out/build_date.txt ||
342 true
343 rm ${ANDROID_PRODUCT_OUT%/out/*}/out/build_number.txt ||
344 true
345 rm ${ANDROID_PRODUCT_OUT}/*/*.prop ||
346 true
347 rm -r ${ANDROID_PRODUCT_OUT}/obj/ETC/system_build_prop_intermediates ||
348 true
349 pushd ${ANDROID_BUILD_TOP} >&2
350 make -j50 >&2
351 if [ ${?} != 0 ]; then
352 popd >&2
353 return 1
354 fi
355 if ! inFastboot; then
356 adb reboot-bootloader >&2
357 fi
358 fastboot flashall >&2
359 popd >&2
360 wait_for_screen
361 EXPECT_PROPERTY sys.boot.reason "\(reboot,ota\|bootloader\)"
362 EXPECT_PROPERTY persist.sys.boot.reason reboot,bootloader
363 report_bootstat_logs reboot,ota bootloader
364}
365
366[ "USAGE: test_optional_ota
367
368fast and fake (touch build_date on device to make it different)" ]
369test_optional_ota() {
370 echo "INFO: expected duration of ${TEST} test about 45 seconds" >&2
371 adb shell su root touch /data/misc/bootstat/build_date >&2
372 adb reboot ota
373 wait_for_screen
374 EXPECT_PROPERTY sys.boot.reason reboot,ota
375 EXPECT_PROPERTY persist.sys.boot.reason reboot,ota
376 report_bootstat_logs reboot,ota
377}
378
379[ "USAGE: [TEST=<test>] blind_reboot_test [<match>]
380
381Simple tests helper
382- adb reboot <test>
383- (wait until screen is up, boot has completed)
384- adb shell getprop sys.boot.reason
385- NB: should report <test>, or overriden <match>
386
387We interleave the simple reboot tests between the hard/complex ones
388as a means of checking sanity and any persistent side effect of the
389other tests." ]
390blind_reboot_test() {
391 if [ -z "${1}" ]; then
392 set ${TEST}
393 fi
394 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
395 adb reboot ${TEST}
396 wait_for_screen
397 EXPECT_PROPERTY sys.boot.reason ${1}
398 EXPECT_PROPERTY persist.sys.boot.reason reboot,${TEST}
399 report_bootstat_logs ${1}
400}
401
402[ "USAGE: test_cold
403
404cold test
405- adb reboot cold
406- (wait until screen is up, boot has completed)
407- adb shell getprop sys.boot.reason
408- NB: should report cold" ]
409test_cold() {
410 blind_reboot_test
411}
412
413[ "USAGE: test_factory_reset
414
415factory_reset test
416- adb shell su root rm /data/misc/bootstat/build_date
417- adb reboot
418- (wait until screen is up, boot has completed)
419- adb shell getprop sys.boot.reason
420- NB: should report factory_reset
421
422Decision to rummage through bootstat data files was made as
423a _real_ factory_reset is too destructive to the device." ]
424test_factory_reset() {
425 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
426 adb shell su root rm /data/misc/bootstat/build_date >&2
427 adb reboot >&2
428 wait_for_screen
429 EXPECT_PROPERTY sys.boot.reason reboot,factory_reset
Mark Salyzyn277eca12017-09-11 15:22:57 -0700430 EXPECT_PROPERTY persist.sys.boot.reason "reboot,.*"
431 report_bootstat_logs reboot,factory_reset reboot, reboot,adb \
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700432 "-bootstat: Failed to read /data/misc/bootstat/build_date: No such file or directory" \
433 "-bootstat: Failed to parse boot time record: /data/misc/bootstat/build_date"
434}
435
436[ "USAGE: test_optional_factory_reset
437
438factory_reset test
439- adb reboot-bootloader
440- fastboot format userdata
441- fastboot reboot
442- (wait until screen is up, boot has completed)
443- adb shell getprop sys.boot.reason
444- NB: should report factory_reset
445
446For realz, and disruptive" ]
447test_optional_factory_reset() {
448 echo "INFO: expected duration of ${TEST} test roughly a minute" >&2
449 if ! inFastboot; then
450 adb reboot-bootloader
451 fi
452 fastboot format userdata >&2
453 fastboot reboot >&2
454 wait_for_screen
455 EXPECT_PROPERTY sys.boot.reason reboot,factory_reset
456 EXPECT_PROPERTY persist.sys.boot.reason ""
457 report_bootstat_logs reboot,factory_reset bootloader \
458 "-bootstat: Failed to read /data/misc/bootstat/last_boot_time_utc: No such file or directory" \
459 "-bootstat: Failed to parse boot time record: /data/misc/bootstat/last_boot_time_utc" \
460 "-bootstat: Failed to read /data/misc/bootstat/build_date: No such file or directory" \
461 "-bootstat: Failed to parse boot time record: /data/misc/bootstat/build_date" \
462 "-bootstat: Failed to read /data/misc/bootstat/factory_reset: No such file or directory" \
463 "-bootstat: Failed to parse boot time record: /data/misc/bootstat/factory_reset"
464}
465
466[ "USAGE: test_hard
467
468hard test:
469- adb reboot hard
470- (wait until screen is up, boot has completed)
471- adb shell getprop sys.boot.reason
472- NB: should report hard" ]
473test_hard() {
474 blind_reboot_test
475}
476
477[ "USAGE: test_battery
478
479battery test (trick):
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700480- echo healthd: battery l=2 | adb shell su root tee /dev/kmsg ; adb reboot cold
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700481- (wait until screen is up, boot has completed)
482- adb shell getprop sys.boot.reason
483- NB: should report reboot,battery, unless healthd managed to log
484 before reboot in above trick.
485
486- Bonus points (manual extras)
487- Make sure the following is added to the /init.rc file in post-fs
488 section before logd is started:
489 + setprop logd.kernel false
490 + rm /sys/fs/pstore/console-ramoops
491 + rm /sys/fs/pstore/console-ramoops-0
492 + write /dev/kmsg \"healthd: battery l=2
493 +\"
494- adb reboot fs
495- (wait until screen is up, boot has completed)
496- adb shell getprop sys.boot.reason
497- NB: should report reboot,battery
498- (replace set logd.kernel true to the above, and retry test)" ]
499test_battery() {
500 echo "INFO: expected duration of ${TEST} test roughly two minutes" >&2
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700501 # Send it _many_ times to combat devices with flakey pstore
502 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
503 echo healthd: battery l=2 | adb shell su root tee /dev/kmsg >/dev/null
504 done
505 adb reboot cold >&2
506 adb wait-for-device
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700507 wait_for_screen
508 adb shell su root \
509 cat /proc/fs/pstore/console-ramoops \
510 /proc/fs/pstore/console-ramoops-0 2>/dev/null |
511 grep 'healthd: battery l=' |
512 tail -1 |
513 grep 'healthd: battery l=2' >/dev/null || (
514 if ! EXPECT_PROPERTY sys.boot.reason reboot,battery >/dev/null 2>/dev/null; then
515 # retry
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700516 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
517 echo healthd: battery l=2 | adb shell su root tee /dev/kmsg >/dev/null
518 done
519 adb reboot cold >&2
520 adb wait-for-device
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700521 wait_for_screen
522 fi
523 )
524
525 EXPECT_PROPERTY sys.boot.reason shutdown,battery
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700526 EXPECT_PROPERTY persist.sys.boot.reason reboot,cold
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700527 report_bootstat_logs shutdown,battery "-bootstat: Battery level at shutdown 2%"
528}
529
530[ "USAGE: test_unknown
531
532unknown test
533- adb reboot unknown
534- (wait until screen is up, boot has completed)
535- adb shell getprop sys.boot.reason
536- NB: should report reboot,unknown
537- NB: expect log \"... I bootstat: Unknown boot reason: reboot,unknown\"" ]
538test_unknown() {
539 blind_reboot_test reboot,unknown
540}
541
542[ "USAGE: test_kernel_panic
543
544kernel_panic test:
545- echo c | adb shell su root tee /proc/sysrq-trigger
546- (wait until screen is up, boot has completed)
547- adb shell getprop sys.boot.reason
548- NB: should report kernel_panic,sysrq" ]
549test_kernel_panic() {
550 echo "INFO: expected duration of ${TEST} test > 2 minutes" >&2
551 echo c | adb shell su root tee /proc/sysrq-trigger >/dev/null
552 wait_for_screen
553 EXPECT_PROPERTY sys.boot.reason kernel_panic,sysrq
554 EXPECT_PROPERTY persist.sys.boot.reason kernel_panic,sysrq
555 report_bootstat_logs kernel_panic,sysrq
556}
557
558[ "USAGE: test_warm
559
560warm test
561- adb reboot warm
562- (wait until screen is up, boot has completed)
563- adb shell getprop sys.boot.reason
564- NB: should report warm" ]
565test_warm() {
566 blind_reboot_test
567}
568
569[ "USAGE: test_thermal_shutdown
570
571thermal shutdown test:
572- adb shell setprop sys.powerctl shutdown,thermal
573- (power up the device)
574- (wait until screen is up, boot has completed)
575- adb shell getprop sys.boot.reason
576- NB: should report shutdown,thermal" ]
577test_thermal_shutdown() {
578 echo "INFO: expected duration of ${TEST} test roughly a minute plus" >&2
579 echo " power on request" >&2
580 adb shell setprop sys.powerctl shutdown,thermal
581 sleep 5
582 echo -n "WARNING: Please power device back up, waiting ... " >&2
583 wait_for_screen -n >&2
584 EXPECT_PROPERTY sys.boot.reason shutdown,thermal
585 EXPECT_PROPERTY persist.sys.boot.reason shutdown,thermal
586 report_bootstat_logs shutdown,thermal
587}
588
589[ "USAGE: test_userrequested_shutdown
590
591userrequested shutdown test:
592- adb shell setprop sys.powerctl shutdown,userrequested
593- (power up the device)
594- (wait until screen is up, boot has completed)
595- adb shell getprop sys.boot.reason
596- NB: should report shutdown,userrequested" ]
597test_userrequested_shutdown() {
598 echo "INFO: expected duration of ${TEST} test roughly a minute plus" >&2
599 echo " power on request" >&2
600 adb shell setprop sys.powerctl shutdown,userrequested
601 sleep 5
602 echo -n "WARNING: Please power device back up, waiting ... " >&2
603 wait_for_screen -n >&2
604 EXPECT_PROPERTY sys.boot.reason shutdown,userrequested
605 EXPECT_PROPERTY persist.sys.boot.reason shutdown,userrequested
606 report_bootstat_logs shutdown,userrequested
607}
608
Mark Salyzyn277eca12017-09-11 15:22:57 -0700609[ "USAGE: test_shell_reboot
610
611shell reboot test:
612- adb shell reboot
613- (wait until screen is up, boot has completed)
614- adb shell getprop sys.boot.reason
615- NB: should report reboot,shell" ]
616test_shell_reboot() {
617 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
618 adb shell reboot
619 wait_for_screen
620 EXPECT_PROPERTY sys.boot.reason reboot,shell
621 EXPECT_PROPERTY persist.sys.boot.reason reboot,shell
622 report_bootstat_logs reboot,shell
623}
624
625[ "USAGE: test_adb_reboot
626
627adb reboot test:
628- adb reboot
629- (wait until screen is up, boot has completed)
630- adb shell getprop sys.boot.reason
631- NB: should report reboot,adb" ]
632test_adb_reboot() {
633 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
634 adb reboot
635 wait_for_screen
636 EXPECT_PROPERTY sys.boot.reason reboot,adb
637 EXPECT_PROPERTY persist.sys.boot.reason reboot,adb
638 report_bootstat_logs reboot,adb
639}
640
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700641[ "USAGE: ${0##*/} [-s SERIAL] [tests]
642
643Mainline executive to run the above tests" ]
644
645# Rudimentary argument parsing
646
647if [ ${#} -ge 2 -a X"-s" = X"${1}" ]; then
648 export ANDROID_SERIAL="${2}"
649 shift 2
650fi
651
652if [ X"--help" = X"${1}" -o X"-h" = X"${1}" -o X"-?" = X"${1}" ]; then
653 echo "USAGE: ${0##*/} [-s SERIAL] [tests]"
654 echo tests - `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null`
655 exit 0
656fi
657
658# Check if all conditions for the script are sane
659
660if [ -z "${ANDROID_SERIAL}" ]; then
661 ndev=`(
662 adb devices | grep -v 'List of devices attached'
663 fastboot devices
664 ) |
665 grep -v "^[${SPACE}${TAB}]*\$" |
666 wc -l`
667 if [ ${ndev} -gt 1 ]; then
668 echo "ERROR: no target device specified, ${ndev} connected" >&2
669 echo "${RED}[ FAILED ]${NORMAL}"
670 exit 1
671 fi
672 echo "WARNING: no target device specified" >&2
673fi
674
675ret=0
676
677# Test Series
678if [ X"all" = X"${*}" ]; then
679 # automagically pick up all test_<function>s.
680 eval set nothing `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null`
681 if [ X"nothing" = X"${1}" ]; then
682 shift 1
683 fi
684fi
685if [ -z "$*" ]; then
686 # automagically pick up all test_<function>, except test_optional_<function>.
687 eval set nothing `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null |
688 grep -v '^optional_'`
689 if [ -z "${2}" ]; then
690 # Hard coded should shell fail to find them above (search/permission issues)
691 eval set ota cold factory_reset hard battery unknown kernel_panic warm \
Mark Salyzyn277eca12017-09-11 15:22:57 -0700692 thermal_shutdown userrequested_shutdown shell_reboot adb_reboot
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700693 fi
694 if [ X"nothing" = X"${1}" ]; then
695 shift 1
696 fi
697fi
698echo "INFO: selected test(s): ${@}" >&2
699echo
700failures=
701successes=
702for t in "${@}"; do
703 wrap_test ${t}
704 retval=${?}
705 if [ 0 = ${retval} ]; then
706 if [ -z "${successes}" ]; then
707 successes=${t}
708 else
709 successes="${successes} ${t}"
710 fi
711 else
712 ret=${retval}
713 if [ -z "${failures}" ]; then
714 failures=${t}
715 else
716 failures="${failures} ${t}"
717 fi
718 fi
719 echo
720done
721
722if [ -n "${successes}" ]; then
723 echo "${GREEN}[ PASSED ]${NORMAL} ${successes}"
724fi
725if [ -n "${failures}" ]; then
726 echo "${RED}[ FAILED ]${NORMAL} ${failures}"
727fi
728exit ${ret}