Skip to content
Snippets Groups Projects
Commit 21a5f6af authored by Eric Rowe's avatar Eric Rowe
Browse files

Add support for ro.boot.bootreason in parsing

Bug: 25597146
Change-Id: If8617d180fc37eb756e89bb24d7a2e12d9be9533
parent c20ea281
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,8 @@ public class BugreportParser extends AbstractSectionParser {
private static final String DUMPSYS_SECTION_REGEX = "------ DUMPSYS .*";
private static final String NOOP_SECTION_REGEX = "------ .* ------";
private static final String BOOTREASON = "androidboot.bootreason";
private static final String BOOTREASON_PROP = "ro.boot.bootreason";
private static final String BOOTREASON_KERNEL = "androidboot.bootreason";
/**
* Matches: == dumpstate: 2012-04-26 12:13:14
......@@ -225,8 +226,14 @@ public class BugreportParser extends AbstractSectionParser {
lastKmsg = new KernelLogItem();
mBugreport.setLastKmsg(lastKmsg);
}
if (mCommandLine.containsKey(BOOTREASON)) {
String bootreason = mCommandLine.get(BOOTREASON);
String bootreason = null;
if (mBugreport.getSystemProps() != null &&
mBugreport.getSystemProps().containsKey(BOOTREASON_PROP)) {
bootreason = mBugreport.getSystemProps().get(BOOTREASON_PROP);
} else if (mCommandLine.containsKey(BOOTREASON_KERNEL)) {
bootreason = mCommandLine.get(BOOTREASON_KERNEL);
}
if (bootreason != null) {
Matcher m = KernelLogParser.BAD_BOOTREASONS.matcher(bootreason);
if (m.matches()) {
MiscKernelLogItem item = new MiscKernelLogItem();
......
......@@ -17,6 +17,7 @@ package com.android.loganalysis.parser;
import com.android.loganalysis.item.BugreportItem;
import com.android.loganalysis.item.IItem;
import com.android.loganalysis.item.MiscKernelLogItem;
import com.android.loganalysis.util.ArrayUtil;
import junit.framework.TestCase;
......@@ -228,9 +229,9 @@ public class BugreportParserTest extends TestCase {
}
/**
* Test
* Test that a normal boot triggers a normal boot event and no unknown reason.
*/
public void testParse_bootreason_good() {
public void testParse_bootreason_kernel_good() {
List<String> lines = Arrays.asList(
"========================================================",
"== dumpstate: 1999-01-01 02:03:04",
......@@ -245,7 +246,10 @@ public class BugreportParserTest extends TestCase {
assertEquals("NORMAL_REBOOT", bugreport.getLastKmsg().getEvents().get(0).getCategory());
}
public void testParse_bootreason_bad() {
/**
* Test that a kernel reset boot triggers a kernel reset event and no unknown reason.
*/
public void testParse_bootreason_kernel_bad() {
List<String> lines = Arrays.asList(
"========================================================",
"== dumpstate: 1999-01-01 02:03:04",
......@@ -260,12 +264,56 @@ public class BugreportParserTest extends TestCase {
assertEquals("KERNEL_RESET", bugreport.getLastKmsg().getEvents().get(0).getCategory());
}
/**
* Test that a normal boot triggers a normal boot event and no unknown reason.
*/
public void testParse_bootreason_prop_good() {
List<String> lines = Arrays.asList(
"========================================================",
"== dumpstate: 1999-01-01 02:03:04",
"========================================================",
"------ SYSTEM PROPERTIES ------",
"[ro.boot.bootreason]: [reboot]",
"");
BugreportItem bugreport = new BugreportParser().parse(lines);
assertNotNull(bugreport.getLastKmsg());
assertEquals(1, bugreport.getLastKmsg().getEvents().size());
assertEquals("Last boot reason: reboot",
bugreport.getLastKmsg().getEvents().get(0).getStack());
assertEquals("NORMAL_REBOOT", bugreport.getLastKmsg().getEvents().get(0).getCategory());
}
/**
* Test that a kernel reset boot triggers a kernel reset event and no unknown reason.
*/
public void testParse_bootreason_prop_bad() {
List<String> lines = Arrays.asList(
"========================================================",
"== dumpstate: 1999-01-01 02:03:04",
"========================================================",
"------ SYSTEM PROPERTIES ------",
"[ro.boot.bootreason]: [hw_reset]",
"");
BugreportItem bugreport = new BugreportParser().parse(lines);
assertNotNull(bugreport.getLastKmsg());
assertEquals(1, bugreport.getLastKmsg().getEvents().size());
assertEquals("Last boot reason: hw_reset",
bugreport.getLastKmsg().getEvents().get(0).getStack());
assertEquals("KERNEL_RESET", bugreport.getLastKmsg().getEvents().get(0).getCategory());
}
/**
* Test that a kernel panic in the last kmsg and a kernel panic only triggers one kernel reset.
*/
public void testParse_bootreason_duplicate() {
List<String> lines = Arrays.asList(
"========================================================",
"== dumpstate: 1999-01-01 02:03:04",
"========================================================",
"Command line: androidboot.bootreason=hw_reset",
"------ SYSTEM PROPERTIES ------",
"[ro.boot.bootreason]: [hw_reset]",
"",
"------ LAST KMSG (/proc/last_kmsg) ------",
"[ 0.000000] Initializing cgroup subsys cpu",
"[ 16.203491] Kernel panic",
......@@ -430,6 +478,10 @@ public class BugreportParserTest extends TestCase {
assertNull(bugreport.getSystemProps());
assertNull(bugreport.getTop());
assertNotNull(bugreport.getLastKmsg());
List<MiscKernelLogItem> events = bugreport.getLastKmsg().getMiscEvents(
KernelLogParser.KERNEL_RESET);
assertEquals(events.size(), 1);
assertEquals(events.get(0).getStack(), "Unknown reason");
lines = Arrays.asList(
"========================================================",
......@@ -463,6 +515,9 @@ public class BugreportParserTest extends TestCase {
assertNull(bugreport.getSystemProps());
assertNull(bugreport.getTop());
assertNotNull(bugreport.getLastKmsg());
events = bugreport.getLastKmsg().getMiscEvents(KernelLogParser.KERNEL_RESET);
assertEquals(events.size(), 1);
assertEquals(events.get(0).getStack(), "Unknown reason");
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment