Merge "1) add the bugreport option which allow the scripted monkey to capature the bugrepor and save it to the sdcard wherenever there is a ANR, java crash and native crash. 2) Add a new option in the scripted monkey which can enter a string through the shell command input text <string>" into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
9bfa6f90b8
@@ -124,6 +124,21 @@ public class Monkey {
|
|||||||
*/
|
*/
|
||||||
private boolean mRequestDumpsysMemInfo = false;
|
private boolean mRequestDumpsysMemInfo = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is set by the ActivityController thread to request a
|
||||||
|
* bugreport after ANR
|
||||||
|
*/
|
||||||
|
private boolean mRequestAnrBugreport = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is set by the ActivityController thread to request a
|
||||||
|
* bugreport after java application crash
|
||||||
|
*/
|
||||||
|
private boolean mRequestAppCrashBugreport = false;
|
||||||
|
|
||||||
|
/** Failure process name */
|
||||||
|
private String mReportProcessName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is set by the ActivityController thread to request a "procrank"
|
* This is set by the ActivityController thread to request a "procrank"
|
||||||
*/
|
*/
|
||||||
@@ -187,6 +202,9 @@ public class Monkey {
|
|||||||
|
|
||||||
boolean mScriptLog = false;
|
boolean mScriptLog = false;
|
||||||
|
|
||||||
|
/** Capture bugreprot whenever there is a crash. **/
|
||||||
|
private boolean mRequestBugreport = false;
|
||||||
|
|
||||||
/** a filename to the setup script (if any) */
|
/** a filename to the setup script (if any) */
|
||||||
private String mSetupFileName = null;
|
private String mSetupFileName = null;
|
||||||
|
|
||||||
@@ -281,11 +299,16 @@ public class Monkey {
|
|||||||
System.err.println("// " + stackTrace.replace("\n", "\n// "));
|
System.err.println("// " + stackTrace.replace("\n", "\n// "));
|
||||||
StrictMode.setThreadPolicy(savedPolicy);
|
StrictMode.setThreadPolicy(savedPolicy);
|
||||||
|
|
||||||
if (!mIgnoreCrashes) {
|
if (!mIgnoreCrashes || mRequestBugreport) {
|
||||||
synchronized (Monkey.this) {
|
synchronized (Monkey.this) {
|
||||||
mAbort = true;
|
if (!mIgnoreCrashes) {
|
||||||
|
mAbort = true;
|
||||||
|
}
|
||||||
|
if (mRequestBugreport){
|
||||||
|
mRequestAppCrashBugreport = true;
|
||||||
|
mReportProcessName = processName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !mKillProcessAfterError;
|
return !mKillProcessAfterError;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -300,10 +323,15 @@ public class Monkey {
|
|||||||
System.err.println("// NOT RESPONDING: " + processName + " (pid " + pid + ")");
|
System.err.println("// NOT RESPONDING: " + processName + " (pid " + pid + ")");
|
||||||
System.err.println(processStats);
|
System.err.println(processStats);
|
||||||
StrictMode.setThreadPolicy(savedPolicy);
|
StrictMode.setThreadPolicy(savedPolicy);
|
||||||
|
|
||||||
synchronized (Monkey.this) {
|
synchronized (Monkey.this) {
|
||||||
mRequestAnrTraces = true;
|
mRequestAnrTraces = true;
|
||||||
mRequestDumpsysMemInfo = true;
|
mRequestDumpsysMemInfo = true;
|
||||||
mRequestProcRank = true;
|
mRequestProcRank = true;
|
||||||
|
if (mRequestBugreport){
|
||||||
|
mRequestAnrBugreport = true;
|
||||||
|
mReportProcessName = processName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!mIgnoreTimeouts) {
|
if (!mIgnoreTimeouts) {
|
||||||
synchronized (Monkey.this) {
|
synchronized (Monkey.this) {
|
||||||
@@ -359,22 +387,38 @@ public class Monkey {
|
|||||||
private void commandLineReport(String reportName, String command) {
|
private void commandLineReport(String reportName, String command) {
|
||||||
System.err.println(reportName + ":");
|
System.err.println(reportName + ":");
|
||||||
Runtime rt = Runtime.getRuntime();
|
Runtime rt = Runtime.getRuntime();
|
||||||
|
Writer logOutput = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Process must be fully qualified here because android.os.Process
|
// Process must be fully qualified here because android.os.Process
|
||||||
// is used elsewhere
|
// is used elsewhere
|
||||||
java.lang.Process p = Runtime.getRuntime().exec(command);
|
java.lang.Process p = Runtime.getRuntime().exec(command);
|
||||||
|
|
||||||
|
if (mRequestBugreport) {
|
||||||
|
logOutput =
|
||||||
|
new BufferedWriter(new FileWriter(new File(Environment
|
||||||
|
.getExternalStorageDirectory(), reportName), true));
|
||||||
|
}
|
||||||
// pipe everything from process stdout -> System.err
|
// pipe everything from process stdout -> System.err
|
||||||
InputStream inStream = p.getInputStream();
|
InputStream inStream = p.getInputStream();
|
||||||
InputStreamReader inReader = new InputStreamReader(inStream);
|
InputStreamReader inReader = new InputStreamReader(inStream);
|
||||||
BufferedReader inBuffer = new BufferedReader(inReader);
|
BufferedReader inBuffer = new BufferedReader(inReader);
|
||||||
String s;
|
String s;
|
||||||
while ((s = inBuffer.readLine()) != null) {
|
while ((s = inBuffer.readLine()) != null) {
|
||||||
System.err.println(s);
|
if (mRequestBugreport) {
|
||||||
|
logOutput.write(s);
|
||||||
|
logOutput.write("\n");
|
||||||
|
} else {
|
||||||
|
System.err.println(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = p.waitFor();
|
int status = p.waitFor();
|
||||||
System.err.println("// " + reportName + " status was " + status);
|
System.err.println("// " + reportName + " status was " + status);
|
||||||
|
|
||||||
|
if (logOutput != null) {
|
||||||
|
logOutput.close();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("// Exception from " + reportName + ":");
|
System.err.println("// Exception from " + reportName + ":");
|
||||||
System.err.println(e.toString());
|
System.err.println(e.toString());
|
||||||
@@ -395,6 +439,13 @@ public class Monkey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the bugreport to the sdcard.
|
||||||
|
private void getBugreport(String reportName) {
|
||||||
|
reportName += MonkeyUtils.toCalendarTime(System.currentTimeMillis());
|
||||||
|
String bugreportName = reportName.replaceAll("[ ,:]", "_");
|
||||||
|
commandLineReport(bugreportName + ".txt", "bugreport");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command-line entry point.
|
* Command-line entry point.
|
||||||
*
|
*
|
||||||
@@ -557,6 +608,15 @@ public class Monkey {
|
|||||||
reportAnrTraces();
|
reportAnrTraces();
|
||||||
mRequestAnrTraces = false;
|
mRequestAnrTraces = false;
|
||||||
}
|
}
|
||||||
|
if (mRequestAnrBugreport){
|
||||||
|
System.out.println("Print the anr report");
|
||||||
|
getBugreport("anr_" + mReportProcessName + "_");
|
||||||
|
mRequestAnrBugreport = false;
|
||||||
|
}
|
||||||
|
if (mRequestAppCrashBugreport){
|
||||||
|
getBugreport("app_crash" + mReportProcessName + "_");
|
||||||
|
mRequestAnrBugreport = false;
|
||||||
|
}
|
||||||
if (mRequestDumpsysMemInfo) {
|
if (mRequestDumpsysMemInfo) {
|
||||||
reportDumpsysMemInfo();
|
reportDumpsysMemInfo();
|
||||||
mRequestDumpsysMemInfo = false;
|
mRequestDumpsysMemInfo = false;
|
||||||
@@ -697,9 +757,11 @@ public class Monkey {
|
|||||||
mDeviceSleepTime = nextOptionLong("Device sleep time" +
|
mDeviceSleepTime = nextOptionLong("Device sleep time" +
|
||||||
"(in milliseconds)");
|
"(in milliseconds)");
|
||||||
} else if (opt.equals("--randomize-script")) {
|
} else if (opt.equals("--randomize-script")) {
|
||||||
mRandomizeScript = true;
|
mRandomizeScript = true;
|
||||||
} else if (opt.equals("--script-log")) {
|
} else if (opt.equals("--script-log")) {
|
||||||
mScriptLog = true;
|
mScriptLog = true;
|
||||||
|
} else if (opt.equals("--bugreport")) {
|
||||||
|
mRequestBugreport = true;
|
||||||
} else if (opt.equals("-h")) {
|
} else if (opt.equals("-h")) {
|
||||||
showUsage();
|
showUsage();
|
||||||
return false;
|
return false;
|
||||||
@@ -932,6 +994,14 @@ public class Monkey {
|
|||||||
reportAnrTraces();
|
reportAnrTraces();
|
||||||
mRequestAnrTraces = false;
|
mRequestAnrTraces = false;
|
||||||
}
|
}
|
||||||
|
if (mRequestAnrBugreport){
|
||||||
|
getBugreport("anr_" + mReportProcessName + "_");
|
||||||
|
mRequestAnrBugreport = false;
|
||||||
|
}
|
||||||
|
if (mRequestAppCrashBugreport){
|
||||||
|
getBugreport("app_crash" + mReportProcessName + "_");
|
||||||
|
mRequestAnrBugreport = false;
|
||||||
|
}
|
||||||
if (mRequestDumpsysMemInfo) {
|
if (mRequestDumpsysMemInfo) {
|
||||||
reportDumpsysMemInfo();
|
reportDumpsysMemInfo();
|
||||||
mRequestDumpsysMemInfo = false;
|
mRequestDumpsysMemInfo = false;
|
||||||
@@ -941,6 +1011,9 @@ public class Monkey {
|
|||||||
// the watcher (ignore the error)
|
// the watcher (ignore the error)
|
||||||
if (checkNativeCrashes() && (eventCounter > 0)) {
|
if (checkNativeCrashes() && (eventCounter > 0)) {
|
||||||
System.out.println("** New native crash detected.");
|
System.out.println("** New native crash detected.");
|
||||||
|
if (mRequestBugreport) {
|
||||||
|
getBugreport("native_crash_");
|
||||||
|
}
|
||||||
mAbort = mAbort || !mIgnoreNativeCrashes || mKillProcessAfterError;
|
mAbort = mAbort || !mIgnoreNativeCrashes || mKillProcessAfterError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1177,6 +1250,7 @@ public class Monkey {
|
|||||||
usage.append(" [--device-sleep-time MILLISEC]\n");
|
usage.append(" [--device-sleep-time MILLISEC]\n");
|
||||||
usage.append(" [--randomize-script]\n");
|
usage.append(" [--randomize-script]\n");
|
||||||
usage.append(" [--script-log]\n");
|
usage.append(" [--script-log]\n");
|
||||||
|
usage.append(" [--bugreport]\n");
|
||||||
usage.append(" COUNT\n");
|
usage.append(" COUNT\n");
|
||||||
System.err.println(usage.toString());
|
System.err.println(usage.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
|
|
||||||
private static final String EVENT_KEYWORD_DEVICE_WAKEUP = "DeviceWakeUp";
|
private static final String EVENT_KEYWORD_DEVICE_WAKEUP = "DeviceWakeUp";
|
||||||
|
|
||||||
|
private static final String EVENT_KEYWORD_INPUT_STRING = "DispatchString";
|
||||||
|
|
||||||
// a line at the end of the header
|
// a line at the end of the header
|
||||||
private static final String STARTING_DATA_LINE = "start data >>";
|
private static final String STARTING_DATA_LINE = "start data >>";
|
||||||
|
|
||||||
@@ -439,6 +441,16 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
|||||||
MonkeyCommandEvent e = new MonkeyCommandEvent(cmd);
|
MonkeyCommandEvent e = new MonkeyCommandEvent(cmd);
|
||||||
mQ.addLast(e);
|
mQ.addLast(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Input the string through the shell command
|
||||||
|
if (s.indexOf(EVENT_KEYWORD_INPUT_STRING) >= 0 && args.length == 1) {
|
||||||
|
String input = args[0];
|
||||||
|
String cmd = "input text " + input;
|
||||||
|
MonkeyCommandEvent e = new MonkeyCommandEvent(cmd);
|
||||||
|
mQ.addLast(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user