diff options
author | Mark Salyzyn | 2018-03-16 11:05:59 -0500 |
---|---|---|
committer | Mark Salyzyn | 2018-03-16 13:41:17 -0500 |
commit | 25900dd77254e568432f5055ab5426fcb932537e (patch) | |
tree | f1cf79f13cc4ab05cfc782c25e6724add03fdf11 /bootstat | |
parent | 1e7d1c77fa384c0016da66781a5a10a3fd61f85a (diff) | |
download | platform-system-core-25900dd77254e568432f5055ab5426fcb932537e.tar.gz platform-system-core-25900dd77254e568432f5055ab5426fcb932537e.tar.xz platform-system-core-25900dd77254e568432f5055ab5426fcb932537e.zip |
bootstat: add support for regex in aliasReasons and powerkeys
Add support for regex in aliasReasons for the alias member. Use this
new feature to check powerkey|power_key|PowerKey for a single entry.
Test: boot_reason_test.sh
Bug: 63736262
Change-Id: Ia6add99b9e33f3197643dbaab88dde20aa726f90
Diffstat (limited to 'bootstat')
-rwxr-xr-x | bootstat/boot_reason_test.sh | 32 | ||||
-rw-r--r-- | bootstat/bootstat.cpp | 14 |
2 files changed, 26 insertions, 20 deletions
diff --git a/bootstat/boot_reason_test.sh b/bootstat/boot_reason_test.sh index f5d789cb6..603d04f67 100755 --- a/bootstat/boot_reason_test.sh +++ b/bootstat/boot_reason_test.sh | |||
@@ -408,29 +408,29 @@ validate_reason() { | |||
408 | tr ' \f\t\r\n' '_____'` | 408 | tr ' \f\t\r\n' '_____'` |
409 | case ${var} in | 409 | case ${var} in |
410 | watchdog | watchdog,?* ) ;; | 410 | watchdog | watchdog,?* ) ;; |
411 | kernel_panic | kernel_panic,?*) ;; | 411 | kernel_panic | kernel_panic,?* ) ;; |
412 | recovery | recovery,?*) ;; | 412 | recovery | recovery,?* ) ;; |
413 | bootloader | bootloader,?*) ;; | 413 | bootloader | bootloader,?* ) ;; |
414 | cold | cold,?*) ;; | 414 | cold | cold,?* ) ;; |
415 | hard | hard,?*) ;; | 415 | hard | hard,?* ) ;; |
416 | warm | warm,?*) ;; | 416 | warm | warm,?* ) ;; |
417 | shutdown | shutdown,?*) ;; | 417 | shutdown | shutdown,?* ) ;; |
418 | reboot,reboot | reboot,reboot,* ) var=${var#reboot,} ; var=${var%,} ;; | 418 | reboot,reboot | reboot,reboot,* ) var=${var#reboot,} ; var=${var%,} ;; |
419 | reboot,cold | reboot,cold,* ) var=${var#reboot,} ; var=${var%,} ;; | 419 | reboot,cold | reboot,cold,* ) var=${var#reboot,} ; var=${var%,} ;; |
420 | reboot,hard | reboot,hard,* ) var=${var#reboot,} ; var=${var%,} ;; | 420 | reboot,hard | reboot,hard,* ) var=${var#reboot,} ; var=${var%,} ;; |
421 | reboot,warm | reboot,warm,* ) var=${var#reboot,} ; var=${var%,} ;; | 421 | reboot,warm | reboot,warm,* ) var=${var#reboot,} ; var=${var%,} ;; |
422 | reboot,recovery | reboot,recovery,* ) var=${var#reboot,} ; var=${var%,} ;; | 422 | reboot,recovery | reboot,recovery,* ) var=${var#reboot,} ; var=${var%,} ;; |
423 | reboot,bootloader | reboot,bootloader,* ) var=${var#reboot,} ; var=${var%,} ;; | 423 | reboot,bootloader | reboot,bootloader,* ) var=${var#reboot,} ; var=${var%,} ;; |
424 | reboot | reboot,?*) ;; | 424 | reboot | reboot,?* ) ;; |
425 | # Aliases and Heuristics | 425 | # Aliases and Heuristics |
426 | *wdog* | *watchdog* ) var="watchdog" ;; | 426 | *wdog* | *watchdog* ) var="watchdog" ;; |
427 | *powerkey* ) var="cold,powerkey" ;; | 427 | *powerkey* | *power_key* | *PowerKey* ) var="cold,powerkey" ;; |
428 | *panic* | *kernel_panic*) var="kernel_panic" ;; | 428 | *panic* | *kernel_panic* ) var="kernel_panic" ;; |
429 | *thermal*) var="shutdown,thermal" ;; | 429 | *thermal* ) var="shutdown,thermal" ;; |
430 | *s3_wakeup*) var="warm,s3_wakeup" ;; | 430 | *s3_wakeup* ) var="warm,s3_wakeup" ;; |
431 | *hw_reset*) var="hard,hw_reset" ;; | 431 | *hw_reset* ) var="hard,hw_reset" ;; |
432 | *bootloader*) var="bootloader" ;; | 432 | *bootloader* ) var="bootloader" ;; |
433 | *) var="reboot" ;; | 433 | * ) var="reboot" ;; |
434 | esac | 434 | esac |
435 | echo ${var} | 435 | echo ${var} |
436 | } | 436 | } |
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index 4ba430ce3..5ca3bd4f6 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <ctime> | 29 | #include <ctime> |
30 | #include <map> | 30 | #include <map> |
31 | #include <memory> | 31 | #include <memory> |
32 | #include <regex> | ||
32 | #include <string> | 33 | #include <string> |
33 | #include <utility> | 34 | #include <utility> |
34 | #include <vector> | 35 | #include <vector> |
@@ -576,10 +577,16 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { | |||
576 | // A series of checks to take some officially unsupported reasons | 577 | // A series of checks to take some officially unsupported reasons |
577 | // reported by the bootloader and find some logical and canonical | 578 | // reported by the bootloader and find some logical and canonical |
578 | // sense. In an ideal world, we would require those bootloaders | 579 | // sense. In an ideal world, we would require those bootloaders |
579 | // to behave and follow our standards. | 580 | // to behave and follow our CTS standards. |
581 | // | ||
582 | // first member is the output | ||
583 | // second member is an unanchored regex for an alias | ||
584 | // | ||
585 | // We match a needle on output. This helps keep the scale of the | ||
586 | // following table smaller. | ||
580 | static const std::vector<std::pair<const std::string, const std::string>> aliasReasons = { | 587 | static const std::vector<std::pair<const std::string, const std::string>> aliasReasons = { |
581 | {"watchdog", "wdog"}, | 588 | {"watchdog", "wdog"}, |
582 | {"cold,powerkey", "powerkey"}, | 589 | {"cold,powerkey", "powerkey|power_key|PowerKey"}, |
583 | {"kernel_panic", "panic"}, | 590 | {"kernel_panic", "panic"}, |
584 | {"shutdown,thermal", "thermal"}, | 591 | {"shutdown,thermal", "thermal"}, |
585 | {"warm,s3_wakeup", "s3_wakeup"}, | 592 | {"warm,s3_wakeup", "s3_wakeup"}, |
@@ -588,13 +595,12 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { | |||
588 | {"bootloader", ""}, | 595 | {"bootloader", ""}, |
589 | }; | 596 | }; |
590 | 597 | ||
591 | // Either the primary or alias is found _somewhere_ in the reason string. | ||
592 | for (auto& s : aliasReasons) { | 598 | for (auto& s : aliasReasons) { |
593 | if (reason.find(s.first) != std::string::npos) { | 599 | if (reason.find(s.first) != std::string::npos) { |
594 | ret = s.first; | 600 | ret = s.first; |
595 | break; | 601 | break; |
596 | } | 602 | } |
597 | if (s.second.size() && (reason.find(s.second) != std::string::npos)) { | 603 | if (s.second.size() && std::regex_search(reason, std::regex(s.second))) { |
598 | ret = s.first; | 604 | ret = s.first; |
599 | break; | 605 | break; |
600 | } | 606 | } |