From 7dcd1ea28aa85748b0b01d05277158c21829110f Mon Sep 17 00:00:00 2001 From: Netta Peterbursky Date: Mon, 18 Dec 2017 11:07:59 -0800 Subject: [PATCH] Print out CRASH info when monkey encounters tombstone. Bug: 68762010 Test: Run monkey + manually add tombstone Change-Id: I8c819ad42d1dd09b98a575a8a761041dded3d7ba --- .../com/android/commands/monkey/Monkey.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java index 3b1e39b46..6cf9cecc9 100644 --- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java +++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java @@ -44,6 +44,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.ArrayList; import java.util.HashSet; @@ -51,6 +54,8 @@ import java.util.Iterator; import java.util.List; import java.util.Random; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Application that injects random key events and other actions into the system. @@ -240,6 +245,10 @@ public class Monkey { private static final String TOMBSTONE_PREFIX = "tombstone_"; + /** Example: "pid: 5379, tid: 8345, name: RenderThread >>> com.google.android.gms.ui <<<" */ + private static final Pattern TOMBSTONE_PROCESS_PATTERN = + Pattern.compile("^pid: (\\d+).*\\>\\>\\> (.*) \\<\\<\\<$"); + private HashSet mTombstones = null; float[] mFactors = new float[MonkeySourceRandom.FACTORZ_COUNT]; @@ -1293,6 +1302,7 @@ public class Monkey { newStones.add(f.lastModified()); if (mTombstones == null || !mTombstones.contains(f.lastModified())) { result = true; + printNativeCrashFromTombstone(Paths.get(TOMBSTONES_PATH.getPath(), t)); Logger.out.println("** New tombstone found: " + f.getAbsolutePath() + ", size: " + f.length()); } @@ -1305,6 +1315,24 @@ public class Monkey { return result; } + private void printNativeCrashFromTombstone(Path path) { + try { + List lines = Files.readAllLines(path); + for (String line : lines) { + final Matcher matcher = TOMBSTONE_PROCESS_PATTERN.matcher(line); + if (!matcher.matches()) + continue; + final String pid = matcher.group(1); + final String process = matcher.group(2); + Logger.out.println("// CRASH: " + process + " (pid " + pid + ")"); + return; + } + Logger.err.println("Process not found in tombstone file."); + } catch (IOException e) { + Logger.err.println("Failed to read tombstone file: " + e.toString()); + } + } + /** * Return the next command line option. This has a number of special cases * which closely, but not exactly, follow the POSIX command line options