Merge changes Ia1c401b8,I571fb7da,I47999569

am: c2cdaf1840

Change-Id: Ic6e12a40e75f0a68400f803e53987aff4590c7bc
This commit is contained in:
Mark Salyzyn 2017-10-27 00:46:52 +00:00 committed by android-build-merger
commit 511e05f893
2 changed files with 35 additions and 16 deletions

View file

@ -873,17 +873,30 @@ Its Just So Hard reboot test:
- NB: should report reboot,its_just_so_hard - NB: should report reboot,its_just_so_hard
- NB: expect log \"... I bootstat: Unknown boot reason: reboot,its_just_so_hard\"" ] - NB: expect log \"... I bootstat: Unknown boot reason: reboot,its_just_so_hard\"" ]
test_Its_Just_So_Hard_reboot() { test_Its_Just_So_Hard_reboot() {
duration_test if isDebuggable; then # see below
duration_test
else
duration_test `expr ${DURATION_DEFAULT} + ${DURATION_DEFAULT}`
fi
adb shell 'reboot "Its Just So Hard"' adb shell 'reboot "Its Just So Hard"'
wait_for_screen wait_for_screen
EXPECT_PROPERTY sys.boot.reason reboot,its_just_so_hard EXPECT_PROPERTY sys.boot.reason reboot,its_just_so_hard
EXPECT_PROPERTY persist.sys.boot.reason "reboot,Its Just So Hard" EXPECT_PROPERTY persist.sys.boot.reason "reboot,Its Just So Hard"
adb shell su root setprop persist.sys.boot.reason reboot,its_just_so_hard # Do not leave this test with an illegal value in persist.sys.boot.reason
if checkDebugBuild; then save_ret=${?} # hold on to error code from above two lines
flag="" if isDebuggable; then # can do this easy, or we can do this hard.
adb shell su root setprop persist.sys.boot.reason reboot,its_just_so_hard
( exit ${save_ret} ) # because one can not just do ?=${save_ret}
else else
flag="--allow_failure" report_bootstat_logs reboot,its_just_so_hard # report what we have so far
# user build mitigation
adb shell reboot its_just_so_hard
wait_for_screen
( exit ${save_ret} ) # because one can not just do ?=${save_ret}
EXPECT_PROPERTY sys.boot.reason reboot,its_just_so_hard
fi fi
# Ensure persist.sys.boot.reason now valid, failure here acts as a signal
# that we could choke up following tests. For example test_properties.
EXPECT_PROPERTY persist.sys.boot.reason reboot,its_just_so_hard ${flag} EXPECT_PROPERTY persist.sys.boot.reason reboot,its_just_so_hard ${flag}
report_bootstat_logs reboot,its_just_so_hard report_bootstat_logs reboot,its_just_so_hard
} }

View file

@ -225,6 +225,8 @@ const std::map<std::string, int32_t> kBootReasonMap = {
{"reboot,longkey", 85}, {"reboot,longkey", 85},
{"reboot,2sec", 86}, {"reboot,2sec", 86},
{"shutdown,thermal,battery", 87}, {"shutdown,thermal,battery", 87},
{"reboot,its_just_so_hard", 88}, // produced by boot_reason_test
{"reboot,Its Just So Hard", 89}, // produced by boot_reason_test
}; };
// Converts a string value representing the reason the system booted to an // Converts a string value representing the reason the system booted to an
@ -351,10 +353,18 @@ bool addKernelPanicSubReason(const std::string& console, std::string& ret) {
char tounderline(char c) { char tounderline(char c) {
return ::isblank(c) ? '_' : c; return ::isblank(c) ? '_' : c;
} }
char toprintable(char c) { char toprintable(char c) {
return ::isprint(c) ? c : '?'; return ::isprint(c) ? c : '?';
} }
// Cleanup boot_reason regarding acceptable character set
void transformReason(std::string& reason) {
std::transform(reason.begin(), reason.end(), reason.begin(), ::tolower);
std::transform(reason.begin(), reason.end(), reason.begin(), tounderline);
std::transform(reason.begin(), reason.end(), reason.begin(), toprintable);
}
const char system_reboot_reason_property[] = "sys.boot.reason"; const char system_reboot_reason_property[] = "sys.boot.reason";
const char last_reboot_reason_property[] = LAST_REBOOT_REASON_PROPERTY; const char last_reboot_reason_property[] = LAST_REBOOT_REASON_PROPERTY;
const char bootloader_reboot_reason_property[] = "ro.boot.bootreason"; const char bootloader_reboot_reason_property[] = "ro.boot.bootreason";
@ -368,10 +378,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
// If sys.boot.reason == ro.boot.bootreason, let's re-evaluate // If sys.boot.reason == ro.boot.bootreason, let's re-evaluate
if (reason == ret) ret = ""; if (reason == ret) ret = "";
// Cleanup boot_reason regarding acceptable character set transformReason(reason);
std::transform(reason.begin(), reason.end(), reason.begin(), ::tolower);
std::transform(reason.begin(), reason.end(), reason.begin(), tounderline);
std::transform(reason.begin(), reason.end(), reason.begin(), toprintable);
// Is the current system boot reason sys.boot.reason valid? // Is the current system boot reason sys.boot.reason valid?
if (!isKnownRebootReason(ret)) ret = ""; if (!isKnownRebootReason(ret)) ret = "";
@ -460,18 +467,20 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
pos += strlen(cmd); pos += strlen(cmd);
std::string subReason(content.substr(pos, max_reason_length)); std::string subReason(content.substr(pos, max_reason_length));
for (pos = 0; pos < subReason.length(); ++pos) { for (pos = 0; pos < subReason.length(); ++pos) {
char c = tounderline(subReason[pos]); char c = subReason[pos];
if (!::isprint(c) || (c == '\'')) { if (!::isprint(c) || (c == '\'')) {
subReason.erase(pos); subReason.erase(pos);
break; break;
} }
subReason[pos] = ::tolower(c);
} }
transformReason(subReason);
if (subReason != "") { // Will not land "reboot" as that is too blunt. if (subReason != "") { // Will not land "reboot" as that is too blunt.
if (isKernelRebootReason(subReason)) { if (isKernelRebootReason(subReason)) {
ret = "reboot," + subReason; // User space can't talk kernel reasons. ret = "reboot," + subReason; // User space can't talk kernel reasons.
} else { } else if (isKnownRebootReason(subReason)) {
ret = subReason; ret = subReason;
} else {
ret = "reboot," + subReason; // legitimize unknown reasons
} }
} }
} }
@ -563,10 +572,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
// Content buffer no longer will have console data. Beware if more // Content buffer no longer will have console data. Beware if more
// checks added below, that depend on parsing console content. // checks added below, that depend on parsing console content.
content = GetProperty(last_reboot_reason_property); content = GetProperty(last_reboot_reason_property);
// Cleanup last_boot_reason regarding acceptable character set transformReason(content);
std::transform(content.begin(), content.end(), content.begin(), ::tolower);
std::transform(content.begin(), content.end(), content.begin(), tounderline);
std::transform(content.begin(), content.end(), content.begin(), toprintable);
// Anything in last is better than 'super-blunt' reboot or shutdown. // Anything in last is better than 'super-blunt' reboot or shutdown.
if ((ret == "") || (ret == "reboot") || (ret == "shutdown") || !isBluntRebootReason(content)) { if ((ret == "") || (ret == "reboot") || (ret == "shutdown") || !isBluntRebootReason(content)) {