From fe855b29b57be8f938c9e1fc37dbc10d7cf7f1bb Mon Sep 17 00:00:00 2001 From: Liam Mark Date: Wed, 10 Jul 2013 11:36:12 -0700 Subject: Monkey: Add option to limit run based on launches Add new command line option to set a maximum number of activity launches after which Monkey will stop. Change-Id: I702f3bd1081f3cf1a3383dd90c11da4578856418 --- .../monkey/src/com/android/commands/monkey/Monkey.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmds/monkey/src/com/android/commands/monkey/Monkey.java b/cmds/monkey/src/com/android/commands/monkey/Monkey.java index afedb5c3f..1adfb4d74 100644 --- a/cmds/monkey/src/com/android/commands/monkey/Monkey.java +++ b/cmds/monkey/src/com/android/commands/monkey/Monkey.java @@ -209,6 +209,9 @@ public class Monkey { /** The random number generator **/ Random mRandom = null; + /** Quit after the maximum number of activity launches is reached **/ + long mMaxActivityLaunches = -1; + /** Dropped-event statistics **/ long mDroppedKeyEvents = 0; @@ -847,6 +850,8 @@ public class Monkey { "(in milliseconds)"); } else if (opt.equals("--randomize-script")) { mRandomizeScript = true; + } else if (opt.equals("--max-activity-launches")) { + mMaxActivityLaunches = nextOptionLong("max activity launches"); } else if (opt.equals("--script-log")) { mScriptLog = true; } else if (opt.equals("--bugreport")) { @@ -1073,6 +1078,7 @@ public class Monkey { private int runMonkeyCycles() { int eventCounter = 0; int cycleCounter = 0; + int numActivityLaunches = 0; boolean shouldReportAnrTraces = false; boolean shouldReportDumpsysMemInfo = false; @@ -1169,6 +1175,18 @@ public class Monkey { MonkeyEvent ev = mEventSource.getNextEvent(); if (ev != null) { + if ((mMaxActivityLaunches > -1) && (ev instanceof MonkeyActivityEvent)) { + if (numActivityLaunches >= mMaxActivityLaunches) { + if (mVerbose > 0) { + System.out.println("Exit Monkey," + + " reached max number of activity launches:" + + numActivityLaunches); + return eventCounter; + } + } + numActivityLaunches++; + } + int injectCode = ev.injectEvent(mWm, mAm, mVerbose); if ((mAppSwitchDelay > 0) && (ev instanceof MonkeyActivityEvent)) { -- cgit v1.2.3