Mark Salyzyn | b304f6d | 2017-08-04 13:35:51 -0700 | [diff] [blame] | 1 | #! /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 | |
| 19 | SPACE=" " |
| 20 | ESCAPE="" |
| 21 | TAB=" " |
| 22 | GREEN="${ESCAPE}[38;5;40m" |
| 23 | RED="${ESCAPE}[38;5;196m" |
| 24 | NORMAL="${ESCAPE}[0m" |
| 25 | |
| 26 | # Helper functions |
| 27 | |
| 28 | [ "USAGE: inFastboot |
| 29 | |
| 30 | Returns: true if device is in fastboot mode" ] |
| 31 | inFastboot() { |
| 32 | fastboot devices | grep "^${ANDROID_SERIAL}[${SPACE}${TAB}]" > /dev/null |
| 33 | } |
| 34 | |
| 35 | [ "USAGE: format_duration <seconds> |
| 36 | |
| 37 | human readable output whole seconds, whole minutes or mm:ss" ] |
| 38 | format_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 | |
| 62 | wait_for_screen_timeout=900 |
| 63 | [ "USAGE: wait_for_screen [-n] [TIMEOUT] |
| 64 | |
| 65 | -n - echo newline at exit |
| 66 | TIMEOUT - default `format_duration ${wait_for_screen_timeout}`" ] |
| 67 | wait_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 | |
| 104 | Returns true if (regex) lval matches rval" ] |
| 105 | EXPECT_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 | |
| 128 | Returns true if current return (regex) value is true and the result matches" ] |
| 129 | EXPECT_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 | |
| 142 | if not prefixed with a minus (-), <expected> will become a series of expected |
| 143 | matches: |
| 144 | |
| 145 | bootstat: Canonical boot reason: <expected_property_value> |
| 146 | |
| 147 | If prefixed with a minus, <expected> will look for an exact match after |
| 148 | removing the minux prefix. All expected content is _dropped_ from the output |
| 149 | and in essence forms a known blacklist, unexpected content will show. |
| 150 | |
| 151 | Report any logs, minus a known blacklist, preserve the current exit status" ] |
| 152 | report_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} |
| 161 | bootstat: Canonical boot reason: ${i}" |
| 162 | fi |
| 163 | done |
| 164 | adb logcat -b all -d | |
Mark Salyzyn | 08b0256 | 2017-09-18 10:07:07 -0700 | [diff] [blame^] | 165 | grep bootstat[^e] | |
Mark Salyzyn | b304f6d | 2017-08-04 13:35:51 -0700 | [diff] [blame] | 166 | grep -v -F "bootstat: Service started: /system/bin/bootstat --record_boot_complete${match} |
| 167 | bootstat: Failed to read /data/misc/bootstat/post_decrypt_time_elapsed: No such file or directory |
| 168 | bootstat: Failed to parse boot time record: /data/misc/bootstat/post_decrypt_time_elapsed |
| 169 | bootstat: Service started: /system/bin/bootstat --record_boot_reason |
| 170 | bootstat: Service started: /system/bin/bootstat --record_time_since_factory_reset |
| 171 | bootstat: Service started: /system/bin/bootstat -l |
| 172 | bootstat: Battery level at shutdown 100% |
| 173 | bootstat: Battery level at startup 100% |
| 174 | init : Parsing file /system/etc/init/bootstat.rc... |
| 175 | init : processing action (post-fs-data) from (/system/etc/init/bootstat.rc |
| 176 | init : processing action (boot) from (/system/etc/init/bootstat.rc |
| 177 | init : processing action (ro.boot.bootreason=*) from (/system/etc/init/bootstat.rc |
| 178 | init : processing action (sys.boot_completed=1 && sys.logbootcomplete=1) from (/system/etc/init/bootstat.rc |
| 179 | init : Command 'exec - system log -- /system/bin/bootstat --record_boot_complete' action=sys.boot_completed=1 && sys.logbootcomplete=1 (/system/etc/init/bootstat.rc: |
| 180 | init : Command 'exec - system log -- /system/bin/bootstat --record_boot_reason' action=sys.boot_completed=1 && sys.logbootcomplete=1 (/system/etc/init/bootstat.rc: |
| 181 | init : 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 | |
| 196 | Record start of test, preserve exit status" ] |
| 197 | start_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 | |
| 206 | Document duration and success of test, preserve exit status" ] |
| 207 | end_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 | |
| 223 | All tests below are wrapped with this helper" ] |
| 224 | wrap_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 | |
| 237 | Check property for CTS compliance with our expectations. Return a cleansed |
| 238 | string representing what is acceptable. |
| 239 | |
| 240 | NB: must roughly match heuristics in system/core/bootstat/bootstat.cpp" ] |
| 241 | validate_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 | |
| 285 | properties 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." ] |
| 291 | test_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 | |
| 316 | ota 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 | |
| 327 | Decision to change the build itself rather than trick bootstat by |
| 328 | rummaging through its data files was made." ] |
| 329 | test_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 | |
| 368 | fast and fake (touch build_date on device to make it different)" ] |
| 369 | test_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 | |
| 381 | Simple 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 | |
| 387 | We interleave the simple reboot tests between the hard/complex ones |
| 388 | as a means of checking sanity and any persistent side effect of the |
| 389 | other tests." ] |
| 390 | blind_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 | |
| 404 | cold 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" ] |
| 409 | test_cold() { |
| 410 | blind_reboot_test |
| 411 | } |
| 412 | |
| 413 | [ "USAGE: test_factory_reset |
| 414 | |
| 415 | factory_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 | |
| 422 | Decision to rummage through bootstat data files was made as |
| 423 | a _real_ factory_reset is too destructive to the device." ] |
| 424 | test_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 Salyzyn | 277eca1 | 2017-09-11 15:22:57 -0700 | [diff] [blame] | 430 | EXPECT_PROPERTY persist.sys.boot.reason "reboot,.*" |
| 431 | report_bootstat_logs reboot,factory_reset reboot, reboot,adb \ |
Mark Salyzyn | b304f6d | 2017-08-04 13:35:51 -0700 | [diff] [blame] | 432 | "-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 | |
| 438 | factory_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 | |
| 446 | For realz, and disruptive" ] |
| 447 | test_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 | |
| 468 | hard 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" ] |
| 473 | test_hard() { |
| 474 | blind_reboot_test |
| 475 | } |
| 476 | |
| 477 | [ "USAGE: test_battery |
| 478 | |
| 479 | battery test (trick): |
| 480 | - echo healthd: battery l=2 | adb shell su root tee /dev/kmsg ; adb reboot warm |
| 481 | - (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)" ] |
| 499 | test_battery() { |
| 500 | echo "INFO: expected duration of ${TEST} test roughly two minutes" >&2 |
| 501 | echo healthd: battery l=2 | adb shell su root tee /dev/kmsg >/dev/null |
| 502 | adb reboot warm >&2 |
| 503 | wait_for_screen |
| 504 | adb shell su root \ |
| 505 | cat /proc/fs/pstore/console-ramoops \ |
| 506 | /proc/fs/pstore/console-ramoops-0 2>/dev/null | |
| 507 | grep 'healthd: battery l=' | |
| 508 | tail -1 | |
| 509 | grep 'healthd: battery l=2' >/dev/null || ( |
| 510 | if ! EXPECT_PROPERTY sys.boot.reason reboot,battery >/dev/null 2>/dev/null; then |
| 511 | # retry |
| 512 | echo healthd: battery l=2 | adb shell su root tee /dev/kmsg >/dev/null |
| 513 | adb reboot warm >&2 |
| 514 | wait_for_screen |
| 515 | fi |
| 516 | ) |
| 517 | |
| 518 | EXPECT_PROPERTY sys.boot.reason shutdown,battery |
| 519 | EXPECT_PROPERTY persist.sys.boot.reason reboot,warm |
| 520 | report_bootstat_logs shutdown,battery "-bootstat: Battery level at shutdown 2%" |
| 521 | } |
| 522 | |
| 523 | [ "USAGE: test_unknown |
| 524 | |
| 525 | unknown test |
| 526 | - adb reboot unknown |
| 527 | - (wait until screen is up, boot has completed) |
| 528 | - adb shell getprop sys.boot.reason |
| 529 | - NB: should report reboot,unknown |
| 530 | - NB: expect log \"... I bootstat: Unknown boot reason: reboot,unknown\"" ] |
| 531 | test_unknown() { |
| 532 | blind_reboot_test reboot,unknown |
| 533 | } |
| 534 | |
| 535 | [ "USAGE: test_kernel_panic |
| 536 | |
| 537 | kernel_panic test: |
| 538 | - echo c | adb shell su root tee /proc/sysrq-trigger |
| 539 | - (wait until screen is up, boot has completed) |
| 540 | - adb shell getprop sys.boot.reason |
| 541 | - NB: should report kernel_panic,sysrq" ] |
| 542 | test_kernel_panic() { |
| 543 | echo "INFO: expected duration of ${TEST} test > 2 minutes" >&2 |
| 544 | echo c | adb shell su root tee /proc/sysrq-trigger >/dev/null |
| 545 | wait_for_screen |
| 546 | EXPECT_PROPERTY sys.boot.reason kernel_panic,sysrq |
| 547 | EXPECT_PROPERTY persist.sys.boot.reason kernel_panic,sysrq |
| 548 | report_bootstat_logs kernel_panic,sysrq |
| 549 | } |
| 550 | |
| 551 | [ "USAGE: test_warm |
| 552 | |
| 553 | warm test |
| 554 | - adb reboot warm |
| 555 | - (wait until screen is up, boot has completed) |
| 556 | - adb shell getprop sys.boot.reason |
| 557 | - NB: should report warm" ] |
| 558 | test_warm() { |
| 559 | blind_reboot_test |
| 560 | } |
| 561 | |
| 562 | [ "USAGE: test_thermal_shutdown |
| 563 | |
| 564 | thermal shutdown test: |
| 565 | - adb shell setprop sys.powerctl shutdown,thermal |
| 566 | - (power up the device) |
| 567 | - (wait until screen is up, boot has completed) |
| 568 | - adb shell getprop sys.boot.reason |
| 569 | - NB: should report shutdown,thermal" ] |
| 570 | test_thermal_shutdown() { |
| 571 | echo "INFO: expected duration of ${TEST} test roughly a minute plus" >&2 |
| 572 | echo " power on request" >&2 |
| 573 | adb shell setprop sys.powerctl shutdown,thermal |
| 574 | sleep 5 |
| 575 | echo -n "WARNING: Please power device back up, waiting ... " >&2 |
| 576 | wait_for_screen -n >&2 |
| 577 | EXPECT_PROPERTY sys.boot.reason shutdown,thermal |
| 578 | EXPECT_PROPERTY persist.sys.boot.reason shutdown,thermal |
| 579 | report_bootstat_logs shutdown,thermal |
| 580 | } |
| 581 | |
| 582 | [ "USAGE: test_userrequested_shutdown |
| 583 | |
| 584 | userrequested shutdown test: |
| 585 | - adb shell setprop sys.powerctl shutdown,userrequested |
| 586 | - (power up the device) |
| 587 | - (wait until screen is up, boot has completed) |
| 588 | - adb shell getprop sys.boot.reason |
| 589 | - NB: should report shutdown,userrequested" ] |
| 590 | test_userrequested_shutdown() { |
| 591 | echo "INFO: expected duration of ${TEST} test roughly a minute plus" >&2 |
| 592 | echo " power on request" >&2 |
| 593 | adb shell setprop sys.powerctl shutdown,userrequested |
| 594 | sleep 5 |
| 595 | echo -n "WARNING: Please power device back up, waiting ... " >&2 |
| 596 | wait_for_screen -n >&2 |
| 597 | EXPECT_PROPERTY sys.boot.reason shutdown,userrequested |
| 598 | EXPECT_PROPERTY persist.sys.boot.reason shutdown,userrequested |
| 599 | report_bootstat_logs shutdown,userrequested |
| 600 | } |
| 601 | |
Mark Salyzyn | 277eca1 | 2017-09-11 15:22:57 -0700 | [diff] [blame] | 602 | [ "USAGE: test_shell_reboot |
| 603 | |
| 604 | shell reboot test: |
| 605 | - adb shell reboot |
| 606 | - (wait until screen is up, boot has completed) |
| 607 | - adb shell getprop sys.boot.reason |
| 608 | - NB: should report reboot,shell" ] |
| 609 | test_shell_reboot() { |
| 610 | echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2 |
| 611 | adb shell reboot |
| 612 | wait_for_screen |
| 613 | EXPECT_PROPERTY sys.boot.reason reboot,shell |
| 614 | EXPECT_PROPERTY persist.sys.boot.reason reboot,shell |
| 615 | report_bootstat_logs reboot,shell |
| 616 | } |
| 617 | |
| 618 | [ "USAGE: test_adb_reboot |
| 619 | |
| 620 | adb reboot test: |
| 621 | - adb reboot |
| 622 | - (wait until screen is up, boot has completed) |
| 623 | - adb shell getprop sys.boot.reason |
| 624 | - NB: should report reboot,adb" ] |
| 625 | test_adb_reboot() { |
| 626 | echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2 |
| 627 | adb reboot |
| 628 | wait_for_screen |
| 629 | EXPECT_PROPERTY sys.boot.reason reboot,adb |
| 630 | EXPECT_PROPERTY persist.sys.boot.reason reboot,adb |
| 631 | report_bootstat_logs reboot,adb |
| 632 | } |
| 633 | |
Mark Salyzyn | b304f6d | 2017-08-04 13:35:51 -0700 | [diff] [blame] | 634 | [ "USAGE: ${0##*/} [-s SERIAL] [tests] |
| 635 | |
| 636 | Mainline executive to run the above tests" ] |
| 637 | |
| 638 | # Rudimentary argument parsing |
| 639 | |
| 640 | if [ ${#} -ge 2 -a X"-s" = X"${1}" ]; then |
| 641 | export ANDROID_SERIAL="${2}" |
| 642 | shift 2 |
| 643 | fi |
| 644 | |
| 645 | if [ X"--help" = X"${1}" -o X"-h" = X"${1}" -o X"-?" = X"${1}" ]; then |
| 646 | echo "USAGE: ${0##*/} [-s SERIAL] [tests]" |
| 647 | echo tests - `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null` |
| 648 | exit 0 |
| 649 | fi |
| 650 | |
| 651 | # Check if all conditions for the script are sane |
| 652 | |
| 653 | if [ -z "${ANDROID_SERIAL}" ]; then |
| 654 | ndev=`( |
| 655 | adb devices | grep -v 'List of devices attached' |
| 656 | fastboot devices |
| 657 | ) | |
| 658 | grep -v "^[${SPACE}${TAB}]*\$" | |
| 659 | wc -l` |
| 660 | if [ ${ndev} -gt 1 ]; then |
| 661 | echo "ERROR: no target device specified, ${ndev} connected" >&2 |
| 662 | echo "${RED}[ FAILED ]${NORMAL}" |
| 663 | exit 1 |
| 664 | fi |
| 665 | echo "WARNING: no target device specified" >&2 |
| 666 | fi |
| 667 | |
| 668 | ret=0 |
| 669 | |
| 670 | # Test Series |
| 671 | if [ X"all" = X"${*}" ]; then |
| 672 | # automagically pick up all test_<function>s. |
| 673 | eval set nothing `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null` |
| 674 | if [ X"nothing" = X"${1}" ]; then |
| 675 | shift 1 |
| 676 | fi |
| 677 | fi |
| 678 | if [ -z "$*" ]; then |
| 679 | # automagically pick up all test_<function>, except test_optional_<function>. |
| 680 | eval set nothing `sed -n 's/^test_\([^ ()]*\)() {/\1/p' $0 </dev/null | |
| 681 | grep -v '^optional_'` |
| 682 | if [ -z "${2}" ]; then |
| 683 | # Hard coded should shell fail to find them above (search/permission issues) |
| 684 | eval set ota cold factory_reset hard battery unknown kernel_panic warm \ |
Mark Salyzyn | 277eca1 | 2017-09-11 15:22:57 -0700 | [diff] [blame] | 685 | thermal_shutdown userrequested_shutdown shell_reboot adb_reboot |
Mark Salyzyn | b304f6d | 2017-08-04 13:35:51 -0700 | [diff] [blame] | 686 | fi |
| 687 | if [ X"nothing" = X"${1}" ]; then |
| 688 | shift 1 |
| 689 | fi |
| 690 | fi |
| 691 | echo "INFO: selected test(s): ${@}" >&2 |
| 692 | echo |
| 693 | failures= |
| 694 | successes= |
| 695 | for t in "${@}"; do |
| 696 | wrap_test ${t} |
| 697 | retval=${?} |
| 698 | if [ 0 = ${retval} ]; then |
| 699 | if [ -z "${successes}" ]; then |
| 700 | successes=${t} |
| 701 | else |
| 702 | successes="${successes} ${t}" |
| 703 | fi |
| 704 | else |
| 705 | ret=${retval} |
| 706 | if [ -z "${failures}" ]; then |
| 707 | failures=${t} |
| 708 | else |
| 709 | failures="${failures} ${t}" |
| 710 | fi |
| 711 | fi |
| 712 | echo |
| 713 | done |
| 714 | |
| 715 | if [ -n "${successes}" ]; then |
| 716 | echo "${GREEN}[ PASSED ]${NORMAL} ${successes}" |
| 717 | fi |
| 718 | if [ -n "${failures}" ]; then |
| 719 | echo "${RED}[ FAILED ]${NORMAL} ${failures}" |
| 720 | fi |
| 721 | exit ${ret} |