blob: b76011a0495e6864613e01ada78e5dedb9270250 [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
Mark Salyzyn557a9d42017-09-15 13:02:19 -0700179 (/system/bin/bootstat --record_boot_complete --record_boot_reason --record_time_since_factory_reset -l)'
180 (/system/bin/bootstat -r post_decrypt_time_elapsed)'
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700181init : Command 'exec - system log -- /system/bin/bootstat --record_boot_complete' action=sys.boot_completed=1 && sys.logbootcomplete=1 (/system/etc/init/bootstat.rc:
182init : Command 'exec - system log -- /system/bin/bootstat --record_boot_reason' action=sys.boot_completed=1 && sys.logbootcomplete=1 (/system/etc/init/bootstat.rc:
183init : 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:
184 (/system/bin/bootstat --record_boot_complete)'...
185 (/system/bin/bootstat --record_boot_complete)' (pid${SPACE}
186 (/system/bin/bootstat --record_boot_reason)'...
187 (/system/bin/bootstat --record_boot_reason)' (pid${SPACE}
188 (/system/bin/bootstat --record_time_since_factory_reset)'...
189 (/system/bin/bootstat --record_time_since_factory_reset)' (pid${SPACE}
190 (/system/bin/bootstat -l)'...
191 (/system/bin/bootstat -l)' (pid " |
192 grep -v 'bootstat: Unknown boot reason: $' # Hikey Special
193 return ${save_ret}
194}
195
196[ "USAGE: start_test [message]
197
198Record start of test, preserve exit status" ]
199start_test() {
200 save_ret=${?}
201 START=`date +%s`
202 echo "${GREEN}[ RUN ]${NORMAL} ${TEST} ${*}"
203 return ${save_ret}
204}
205
206[ "USAGE: end_test [message]
207
208Document duration and success of test, preserve exit status" ]
209end_test() {
210 save_ret=${?}
211 END=`date +%s`
212 duration=`expr ${END} - ${START} 2>/dev/null`
213 [ 0 = ${duration} ] ||
214 echo INFO: ${TEST} test duration `format_duration ${duration}` >&2
215 if [ ${save_ret} = 0 ]; then
216 echo "${GREEN}[ OK ]${NORMAL} ${TEST} ${*}"
217 else
218 echo "${RED}[ FAILED ]${NORMAL} ${TEST} ${*}"
219 fi
220 return ${save_ret}
221}
222
223[ "USAGE: wrap_test <test> [message]
224
225All tests below are wrapped with this helper" ]
226wrap_test() {
227 if [ -z "${1}" -o X"nothing" = X"${1}" ]; then
228 return
229 fi
230 TEST=${1}
231 shift
232 start_test ${1}
233 eval test_${TEST}
234 end_test ${2}
235}
236
237[ "USAGE: validate_property <property>
238
239Check property for CTS compliance with our expectations. Return a cleansed
240string representing what is acceptable.
241
242NB: must roughly match heuristics in system/core/bootstat/bootstat.cpp" ]
243validate_property() {
244 var=`adb shell getprop ${1} 2>&1`
245 var=`echo -n ${var} |
246 tr '[A-Z]' '[a-z]' |
247 tr ' \f\t\r\n' '_____'`
248 case ${var} in
249 watchdog) ;;
250 watchdog,?*) ;;
251 kernel_panic) ;;
252 kernel_panic,?*) ;;
253 recovery) ;;
254 recovery,?*) ;;
255 bootloader) ;;
256 bootloader,?*) ;;
257 cold) ;;
258 cold,?*) ;;
259 hard) ;;
260 hard,?*) ;;
261 warm) ;;
262 warm,?*) ;;
263 shutdown) ;;
264 shutdown,?*) ;;
265 reboot) ;;
266 reboot,?*) ;;
267 # Aliases
268 *wdog* | *watchdog* ) var="watchdog" ;;
269 *powerkey* ) var="cold,powerkey" ;;
270 *panic* | *kernel_panic*) var="kernel_panic" ;;
271 *thermal*) var="shutdown,thermal" ;;
272 *s3_wakeup*) var="warm,s3_wakeup" ;;
273 *hw_reset*) var="hard,hw_reset" ;;
274 *bootloader*) var="bootloader" ;;
275 ?*) var="reboot,${var}" ;;
276 *) var="reboot" ;;
277 esac
278 echo ${var}
279}
280
281#
282# Actual test frames
283#
284
285[ "USAGE: test_properties
286
287properties test
288- (wait until screen is up, boot has completed)
289- adb shell getprop ro.boot.bootreason (bootloader reason)
290- adb shell getprop persist.sys.boot.reason (last reason)
291- adb shell getprop sys.boot.reason (system reason)
292- NB: all should have a value that is compliant with our known set." ]
293test_properties() {
294 wait_for_screen
295 retval=0
296 check_set="ro.boot.bootreason persist.sys.boot.reason sys.boot.reason"
297 bootloader=""
298 # NB: this test could fail if performed _after_ optional_factory_reset test
299 # and will report
300 # ERROR: expected "reboot" got ""
301 # for Android property persist.sys.boot.reason
302 # following is mitigation for the persist.sys.boot.reason, skip it
303 if [ "reboot,factory_reset" = `validate_property ro.boot_bootreason` ]; then
304 check_set="ro.boot.bootreason sys.boot.reason"
305 bootloader="bootloader"
306 fi
307 for prop in ${check_set}; do
308 reason=`validate_property ${prop}`
309 EXPECT_PROPERTY ${prop} ${reason} || retval=${?}
310 done
311 # sys.boot.reason is last for a reason
312 report_bootstat_logs ${reason} ${bootloader}
313 return ${retval}
314}
315
316[ "USAGE: test_ota
317
318ota test
319- rm out/.kati_stamp-* out/build_date.txt out/build_number.txt
320- rm out/target/product/*/*/*.prop
321- rm -r out/target/product/*/obj/ETC/system_build_prop_intermediates
322- m
323- NB: ro.build.date.utc should update
324- fastboot flashall
325- (wait until screen is up, boot has completed)
326- adb shell getprop sys.boot.reason
327- NB: should report ota
328
329Decision to change the build itself rather than trick bootstat by
330rummaging through its data files was made." ]
331test_ota() {
332 echo "INFO: expected duration of ${TEST} test about 5 minutes or more" >&2
333 echo " extended by build and flashing times" >&2
334 if [ -z "${TARGET_PRODUCT}" -o \
335 -z "${ANDROID_PRODUCT_OUT}" -o \
336 -z "${ANDROID_BUILD_TOP}" -o \
337 -z "${TARGET_BUILD_VARIANT}" ]; then
338 echo "ERROR: Missing envsetup.sh and lunch" >&2
339 return 1
340 fi
341 rm ${ANDROID_PRODUCT_OUT%/out/*}/out/.kati_stamp-* ||
342 true
343 rm ${ANDROID_PRODUCT_OUT%/out/*}/out/build_date.txt ||
344 true
345 rm ${ANDROID_PRODUCT_OUT%/out/*}/out/build_number.txt ||
346 true
347 rm ${ANDROID_PRODUCT_OUT}/*/*.prop ||
348 true
349 rm -r ${ANDROID_PRODUCT_OUT}/obj/ETC/system_build_prop_intermediates ||
350 true
351 pushd ${ANDROID_BUILD_TOP} >&2
352 make -j50 >&2
353 if [ ${?} != 0 ]; then
354 popd >&2
355 return 1
356 fi
357 if ! inFastboot; then
358 adb reboot-bootloader >&2
359 fi
360 fastboot flashall >&2
361 popd >&2
362 wait_for_screen
363 EXPECT_PROPERTY sys.boot.reason "\(reboot,ota\|bootloader\)"
364 EXPECT_PROPERTY persist.sys.boot.reason reboot,bootloader
365 report_bootstat_logs reboot,ota bootloader
366}
367
368[ "USAGE: test_optional_ota
369
370fast and fake (touch build_date on device to make it different)" ]
371test_optional_ota() {
372 echo "INFO: expected duration of ${TEST} test about 45 seconds" >&2
Mark Salyzyna16e4372017-09-20 08:36:12 -0700373 echo "WARNING: ${TEST} requires userdebug build" >&2
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700374 adb shell su root touch /data/misc/bootstat/build_date >&2
375 adb reboot ota
376 wait_for_screen
377 EXPECT_PROPERTY sys.boot.reason reboot,ota
378 EXPECT_PROPERTY persist.sys.boot.reason reboot,ota
379 report_bootstat_logs reboot,ota
380}
381
382[ "USAGE: [TEST=<test>] blind_reboot_test [<match>]
383
384Simple tests helper
385- adb reboot <test>
386- (wait until screen is up, boot has completed)
387- adb shell getprop sys.boot.reason
388- NB: should report <test>, or overriden <match>
389
390We interleave the simple reboot tests between the hard/complex ones
391as a means of checking sanity and any persistent side effect of the
392other tests." ]
393blind_reboot_test() {
394 if [ -z "${1}" ]; then
395 set ${TEST}
396 fi
397 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
398 adb reboot ${TEST}
399 wait_for_screen
400 EXPECT_PROPERTY sys.boot.reason ${1}
401 EXPECT_PROPERTY persist.sys.boot.reason reboot,${TEST}
402 report_bootstat_logs ${1}
403}
404
405[ "USAGE: test_cold
406
407cold test
408- adb reboot cold
409- (wait until screen is up, boot has completed)
410- adb shell getprop sys.boot.reason
411- NB: should report cold" ]
412test_cold() {
413 blind_reboot_test
414}
415
416[ "USAGE: test_factory_reset
417
418factory_reset test
419- adb shell su root rm /data/misc/bootstat/build_date
420- adb reboot
421- (wait until screen is up, boot has completed)
422- adb shell getprop sys.boot.reason
423- NB: should report factory_reset
424
425Decision to rummage through bootstat data files was made as
426a _real_ factory_reset is too destructive to the device." ]
427test_factory_reset() {
428 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
Mark Salyzyna16e4372017-09-20 08:36:12 -0700429 echo "WARNING: ${TEST} requires userdebug build" >&2
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700430 adb shell su root rm /data/misc/bootstat/build_date >&2
431 adb reboot >&2
432 wait_for_screen
433 EXPECT_PROPERTY sys.boot.reason reboot,factory_reset
Mark Salyzyn277eca12017-09-11 15:22:57 -0700434 EXPECT_PROPERTY persist.sys.boot.reason "reboot,.*"
435 report_bootstat_logs reboot,factory_reset reboot, reboot,adb \
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700436 "-bootstat: Failed to read /data/misc/bootstat/build_date: No such file or directory" \
437 "-bootstat: Failed to parse boot time record: /data/misc/bootstat/build_date"
438}
439
440[ "USAGE: test_optional_factory_reset
441
442factory_reset test
443- adb reboot-bootloader
444- fastboot format userdata
445- fastboot reboot
446- (wait until screen is up, boot has completed)
447- adb shell getprop sys.boot.reason
448- NB: should report factory_reset
449
450For realz, and disruptive" ]
451test_optional_factory_reset() {
452 echo "INFO: expected duration of ${TEST} test roughly a minute" >&2
453 if ! inFastboot; then
454 adb reboot-bootloader
455 fi
456 fastboot format userdata >&2
457 fastboot reboot >&2
458 wait_for_screen
459 EXPECT_PROPERTY sys.boot.reason reboot,factory_reset
460 EXPECT_PROPERTY persist.sys.boot.reason ""
461 report_bootstat_logs reboot,factory_reset bootloader \
462 "-bootstat: Failed to read /data/misc/bootstat/last_boot_time_utc: No such file or directory" \
463 "-bootstat: Failed to parse boot time record: /data/misc/bootstat/last_boot_time_utc" \
464 "-bootstat: Failed to read /data/misc/bootstat/build_date: No such file or directory" \
465 "-bootstat: Failed to parse boot time record: /data/misc/bootstat/build_date" \
466 "-bootstat: Failed to read /data/misc/bootstat/factory_reset: No such file or directory" \
467 "-bootstat: Failed to parse boot time record: /data/misc/bootstat/factory_reset"
468}
469
470[ "USAGE: test_hard
471
472hard test:
473- adb reboot hard
474- (wait until screen is up, boot has completed)
475- adb shell getprop sys.boot.reason
476- NB: should report hard" ]
477test_hard() {
478 blind_reboot_test
479}
480
481[ "USAGE: test_battery
482
483battery test (trick):
Mark Salyzyna16e4372017-09-20 08:36:12 -0700484- echo healthd: battery l=2<space> | adb shell su root tee /dev/kmsg
485- adb reboot cold
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700486- (wait until screen is up, boot has completed)
487- adb shell getprop sys.boot.reason
488- NB: should report reboot,battery, unless healthd managed to log
489 before reboot in above trick.
490
491- Bonus points (manual extras)
492- Make sure the following is added to the /init.rc file in post-fs
493 section before logd is started:
494 + setprop logd.kernel false
495 + rm /sys/fs/pstore/console-ramoops
496 + rm /sys/fs/pstore/console-ramoops-0
Mark Salyzyna16e4372017-09-20 08:36:12 -0700497 + write /dev/kmsg \"healthd: battery l=2${SPACE}
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700498 +\"
499- adb reboot fs
500- (wait until screen is up, boot has completed)
501- adb shell getprop sys.boot.reason
502- NB: should report reboot,battery
503- (replace set logd.kernel true to the above, and retry test)" ]
504test_battery() {
505 echo "INFO: expected duration of ${TEST} test roughly two minutes" >&2
Mark Salyzyna16e4372017-09-20 08:36:12 -0700506 echo "WARNING: ${TEST} requires userdebug build" >&2
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700507 # Send it _many_ times to combat devices with flakey pstore
508 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
Mark Salyzyna16e4372017-09-20 08:36:12 -0700509 echo 'healthd: battery l=2 ' | adb shell su root tee /dev/kmsg >/dev/null
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700510 done
511 adb reboot cold >&2
512 adb wait-for-device
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700513 wait_for_screen
514 adb shell su root \
515 cat /proc/fs/pstore/console-ramoops \
516 /proc/fs/pstore/console-ramoops-0 2>/dev/null |
517 grep 'healthd: battery l=' |
518 tail -1 |
Mark Salyzyna16e4372017-09-20 08:36:12 -0700519 grep 'healthd: battery l=2 ' >/dev/null || (
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700520 if ! EXPECT_PROPERTY sys.boot.reason reboot,battery >/dev/null 2>/dev/null; then
521 # retry
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700522 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
Mark Salyzyna16e4372017-09-20 08:36:12 -0700523 echo 'healthd: battery l=2 ' | adb shell su root tee /dev/kmsg >/dev/null
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700524 done
525 adb reboot cold >&2
526 adb wait-for-device
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700527 wait_for_screen
528 fi
529 )
530
531 EXPECT_PROPERTY sys.boot.reason shutdown,battery
Mark Salyzyn8a30fca2017-09-18 10:48:39 -0700532 EXPECT_PROPERTY persist.sys.boot.reason reboot,cold
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700533 report_bootstat_logs shutdown,battery "-bootstat: Battery level at shutdown 2%"
534}
535
536[ "USAGE: test_unknown
537
538unknown test
539- adb reboot unknown
540- (wait until screen is up, boot has completed)
541- adb shell getprop sys.boot.reason
542- NB: should report reboot,unknown
543- NB: expect log \"... I bootstat: Unknown boot reason: reboot,unknown\"" ]
544test_unknown() {
545 blind_reboot_test reboot,unknown
546}
547
548[ "USAGE: test_kernel_panic
549
550kernel_panic test:
551- echo c | adb shell su root tee /proc/sysrq-trigger
552- (wait until screen is up, boot has completed)
553- adb shell getprop sys.boot.reason
554- NB: should report kernel_panic,sysrq" ]
555test_kernel_panic() {
556 echo "INFO: expected duration of ${TEST} test > 2 minutes" >&2
Mark Salyzyna16e4372017-09-20 08:36:12 -0700557 echo "WARNING: ${TEST} requires userdebug build" >&2
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700558 echo c | adb shell su root tee /proc/sysrq-trigger >/dev/null
559 wait_for_screen
560 EXPECT_PROPERTY sys.boot.reason kernel_panic,sysrq
561 EXPECT_PROPERTY persist.sys.boot.reason kernel_panic,sysrq
562 report_bootstat_logs kernel_panic,sysrq
563}
564
565[ "USAGE: test_warm
566
567warm test
568- adb reboot warm
569- (wait until screen is up, boot has completed)
570- adb shell getprop sys.boot.reason
571- NB: should report warm" ]
572test_warm() {
573 blind_reboot_test
574}
575
576[ "USAGE: test_thermal_shutdown
577
578thermal shutdown test:
579- adb shell setprop sys.powerctl shutdown,thermal
580- (power up the device)
581- (wait until screen is up, boot has completed)
582- adb shell getprop sys.boot.reason
583- NB: should report shutdown,thermal" ]
584test_thermal_shutdown() {
585 echo "INFO: expected duration of ${TEST} test roughly a minute plus" >&2
586 echo " power on request" >&2
587 adb shell setprop sys.powerctl shutdown,thermal
588 sleep 5
589 echo -n "WARNING: Please power device back up, waiting ... " >&2
590 wait_for_screen -n >&2
591 EXPECT_PROPERTY sys.boot.reason shutdown,thermal
592 EXPECT_PROPERTY persist.sys.boot.reason shutdown,thermal
593 report_bootstat_logs shutdown,thermal
594}
595
596[ "USAGE: test_userrequested_shutdown
597
598userrequested shutdown test:
599- adb shell setprop sys.powerctl shutdown,userrequested
600- (power up the device)
601- (wait until screen is up, boot has completed)
602- adb shell getprop sys.boot.reason
603- NB: should report shutdown,userrequested" ]
604test_userrequested_shutdown() {
605 echo "INFO: expected duration of ${TEST} test roughly a minute plus" >&2
606 echo " power on request" >&2
607 adb shell setprop sys.powerctl shutdown,userrequested
608 sleep 5
609 echo -n "WARNING: Please power device back up, waiting ... " >&2
610 wait_for_screen -n >&2
611 EXPECT_PROPERTY sys.boot.reason shutdown,userrequested
612 EXPECT_PROPERTY persist.sys.boot.reason shutdown,userrequested
613 report_bootstat_logs shutdown,userrequested
614}
615
Mark Salyzyn277eca12017-09-11 15:22:57 -0700616[ "USAGE: test_shell_reboot
617
618shell reboot test:
619- adb shell reboot
620- (wait until screen is up, boot has completed)
621- adb shell getprop sys.boot.reason
622- NB: should report reboot,shell" ]
623test_shell_reboot() {
624 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
625 adb shell reboot
626 wait_for_screen
627 EXPECT_PROPERTY sys.boot.reason reboot,shell
628 EXPECT_PROPERTY persist.sys.boot.reason reboot,shell
629 report_bootstat_logs reboot,shell
630}
631
632[ "USAGE: test_adb_reboot
633
634adb reboot test:
635- adb reboot
636- (wait until screen is up, boot has completed)
637- adb shell getprop sys.boot.reason
638- NB: should report reboot,adb" ]
639test_adb_reboot() {
640 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
641 adb reboot
642 wait_for_screen
643 EXPECT_PROPERTY sys.boot.reason reboot,adb
644 EXPECT_PROPERTY persist.sys.boot.reason reboot,adb
645 report_bootstat_logs reboot,adb
646}
647
Mark Salyzyna16e4372017-09-20 08:36:12 -0700648[ "USAGE: test_Its_Just_So_Hard_reboot
649
650Its Just So Hard reboot test:
651- adb shell reboot 'Its Just So Hard'
652- (wait until screen is up, boot has completed)
653- adb shell getprop sys.boot.reason
654- NB: should report reboot,its_just_so_hard
655- NB: expect log \"... I bootstat: Unknown boot reason: reboot,its_just_so_hard\"" ]
656test_Its_Just_So_Hard_reboot() {
657 echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
658 echo "INFO: ${TEST} cleanup requires userdebug build" >&2
659 adb shell 'reboot "Its Just So Hard"'
660 wait_for_screen
661 EXPECT_PROPERTY sys.boot.reason reboot,its_just_so_hard
662 EXPECT_PROPERTY persist.sys.boot.reason "reboot,Its Just So Hard"
663 adb shell su root setprop persist.sys.boot.reason reboot,its_just_so_hard
664 EXPECT_PROPERTY persist.sys.boot.reason reboot,its_just_so_hard
665 report_bootstat_logs reboot,its_just_so_hard
666}
667
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700668[ "USAGE: ${0##*/} [-s SERIAL] [tests]
669
670Mainline executive to run the above tests" ]
671
672# Rudimentary argument parsing
673
674if [ ${#} -ge 2 -a X"-s" = X"${1}" ]; then
675 export ANDROID_SERIAL="${2}"
676 shift 2
677fi
678
679if [ X"--help" = X"${1}" -o X"-h" = X"${1}" -o X"-?" = X"${1}" ]; then
680 echo "USAGE: ${0##*/} [-s SERIAL] [tests]"
681 echo tests - `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null`
682 exit 0
683fi
684
685# Check if all conditions for the script are sane
686
687if [ -z "${ANDROID_SERIAL}" ]; then
688 ndev=`(
689 adb devices | grep -v 'List of devices attached'
690 fastboot devices
691 ) |
692 grep -v "^[${SPACE}${TAB}]*\$" |
693 wc -l`
694 if [ ${ndev} -gt 1 ]; then
695 echo "ERROR: no target device specified, ${ndev} connected" >&2
696 echo "${RED}[ FAILED ]${NORMAL}"
697 exit 1
698 fi
699 echo "WARNING: no target device specified" >&2
700fi
701
702ret=0
703
704# Test Series
705if [ X"all" = X"${*}" ]; then
706 # automagically pick up all test_<function>s.
707 eval set nothing `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null`
708 if [ X"nothing" = X"${1}" ]; then
709 shift 1
710 fi
711fi
712if [ -z "$*" ]; then
713 # automagically pick up all test_<function>, except test_optional_<function>.
714 eval set nothing `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null |
715 grep -v '^optional_'`
716 if [ -z "${2}" ]; then
717 # Hard coded should shell fail to find them above (search/permission issues)
718 eval set ota cold factory_reset hard battery unknown kernel_panic warm \
Mark Salyzyn277eca12017-09-11 15:22:57 -0700719 thermal_shutdown userrequested_shutdown shell_reboot adb_reboot
Mark Salyzynb304f6d2017-08-04 13:35:51 -0700720 fi
721 if [ X"nothing" = X"${1}" ]; then
722 shift 1
723 fi
724fi
725echo "INFO: selected test(s): ${@}" >&2
726echo
727failures=
728successes=
729for t in "${@}"; do
730 wrap_test ${t}
731 retval=${?}
732 if [ 0 = ${retval} ]; then
733 if [ -z "${successes}" ]; then
734 successes=${t}
735 else
736 successes="${successes} ${t}"
737 fi
738 else
739 ret=${retval}
740 if [ -z "${failures}" ]; then
741 failures=${t}
742 else
743 failures="${failures} ${t}"
744 fi
745 fi
746 echo
747done
748
749if [ -n "${successes}" ]; then
750 echo "${GREEN}[ PASSED ]${NORMAL} ${successes}"
751fi
752if [ -n "${failures}" ]; then
753 echo "${RED}[ FAILED ]${NORMAL} ${failures}"
754fi
755exit ${ret}