Merge "bootstat: add support for regex in aliasReasons and powerkeys"

This commit is contained in:
Treehugger Robot 2018-03-16 22:44:57 +00:00 committed by Gerrit Code Review
commit f4be06450a
2 changed files with 26 additions and 20 deletions

View File

@ -408,29 +408,29 @@ validate_reason() {
tr ' \f\t\r\n' '_____'`
case ${var} in
watchdog | watchdog,?* ) ;;
kernel_panic | kernel_panic,?*) ;;
recovery | recovery,?*) ;;
bootloader | bootloader,?*) ;;
cold | cold,?*) ;;
hard | hard,?*) ;;
warm | warm,?*) ;;
shutdown | shutdown,?*) ;;
kernel_panic | kernel_panic,?* ) ;;
recovery | recovery,?* ) ;;
bootloader | bootloader,?* ) ;;
cold | cold,?* ) ;;
hard | hard,?* ) ;;
warm | warm,?* ) ;;
shutdown | shutdown,?* ) ;;
reboot,reboot | reboot,reboot,* ) var=${var#reboot,} ; var=${var%,} ;;
reboot,cold | reboot,cold,* ) var=${var#reboot,} ; var=${var%,} ;;
reboot,hard | reboot,hard,* ) var=${var#reboot,} ; var=${var%,} ;;
reboot,warm | reboot,warm,* ) var=${var#reboot,} ; var=${var%,} ;;
reboot,recovery | reboot,recovery,* ) var=${var#reboot,} ; var=${var%,} ;;
reboot,bootloader | reboot,bootloader,* ) var=${var#reboot,} ; var=${var%,} ;;
reboot | reboot,?*) ;;
reboot | reboot,?* ) ;;
# Aliases and Heuristics
*wdog* | *watchdog* ) var="watchdog" ;;
*powerkey* ) var="cold,powerkey" ;;
*panic* | *kernel_panic*) var="kernel_panic" ;;
*thermal*) var="shutdown,thermal" ;;
*s3_wakeup*) var="warm,s3_wakeup" ;;
*hw_reset*) var="hard,hw_reset" ;;
*bootloader*) var="bootloader" ;;
*) var="reboot" ;;
*wdog* | *watchdog* ) var="watchdog" ;;
*powerkey* | *power_key* | *PowerKey* ) var="cold,powerkey" ;;
*panic* | *kernel_panic* ) var="kernel_panic" ;;
*thermal* ) var="shutdown,thermal" ;;
*s3_wakeup* ) var="warm,s3_wakeup" ;;
*hw_reset* ) var="hard,hw_reset" ;;
*bootloader* ) var="bootloader" ;;
* ) var="reboot" ;;
esac
echo ${var}
}

View File

@ -29,6 +29,7 @@
#include <ctime>
#include <map>
#include <memory>
#include <regex>
#include <string>
#include <utility>
#include <vector>
@ -576,10 +577,16 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
// A series of checks to take some officially unsupported reasons
// reported by the bootloader and find some logical and canonical
// sense. In an ideal world, we would require those bootloaders
// to behave and follow our standards.
// to behave and follow our CTS standards.
//
// first member is the output
// second member is an unanchored regex for an alias
//
// We match a needle on output. This helps keep the scale of the
// following table smaller.
static const std::vector<std::pair<const std::string, const std::string>> aliasReasons = {
{"watchdog", "wdog"},
{"cold,powerkey", "powerkey"},
{"cold,powerkey", "powerkey|power_key|PowerKey"},
{"kernel_panic", "panic"},
{"shutdown,thermal", "thermal"},
{"warm,s3_wakeup", "s3_wakeup"},
@ -588,13 +595,12 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
{"bootloader", ""},
};
// Either the primary or alias is found _somewhere_ in the reason string.
for (auto& s : aliasReasons) {
if (reason.find(s.first) != std::string::npos) {
ret = s.first;
break;
}
if (s.second.size() && (reason.find(s.second) != std::string::npos)) {
if (s.second.size() && std::regex_search(reason, std::regex(s.second))) {
ret = s.first;
break;
}