Merge "Add the simple script log for the statbility stress test. Add the randomize script option." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
67aad2d8d5
@@ -25,6 +25,7 @@ import android.content.pm.IPackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Debug;
|
||||
import android.os.Environment;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
@@ -34,13 +35,16 @@ import android.os.SystemProperties;
|
||||
import android.view.IWindowManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Writer;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@@ -179,6 +183,10 @@ public class Monkey {
|
||||
/** Device idle time. This is for the scripted monkey. **/
|
||||
long mDeviceSleepTime = 30000;
|
||||
|
||||
boolean mRandomizeScript = false;
|
||||
|
||||
boolean mScriptLog = false;
|
||||
|
||||
/** a filename to the setup script (if any) */
|
||||
private String mSetupFileName = null;
|
||||
|
||||
@@ -369,6 +377,20 @@ public class Monkey {
|
||||
}
|
||||
}
|
||||
|
||||
// Write the numbe of iteration to the log
|
||||
private void writeScriptLog(int count) {
|
||||
// TO DO: Add the script file name to the log.
|
||||
try {
|
||||
Writer output = new BufferedWriter(new FileWriter(new File(
|
||||
Environment.getExternalStorageDirectory(), "scriptlog.txt"), true));
|
||||
output.write("iteration: " + count + " time: "
|
||||
+ MonkeyUtils.toCalendarTime(System.currentTimeMillis()) + "\n");
|
||||
output.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Command-line entry point.
|
||||
*
|
||||
@@ -471,12 +493,14 @@ public class Monkey {
|
||||
mCountEvents = false;
|
||||
} else if (mScriptFileNames != null && mScriptFileNames.size() > 1) {
|
||||
if (mSetupFileName != null) {
|
||||
mEventSource = new MonkeySourceRandomScript(mSetupFileName, mScriptFileNames,
|
||||
mThrottle, mRandomizeThrottle, mRandom, mProfileWaitTime, mDeviceSleepTime);
|
||||
mEventSource = new MonkeySourceRandomScript(mSetupFileName,
|
||||
mScriptFileNames, mThrottle, mRandomizeThrottle, mRandom,
|
||||
mProfileWaitTime, mDeviceSleepTime, mRandomizeScript);
|
||||
mCount++;
|
||||
} else {
|
||||
mEventSource = new MonkeySourceRandomScript(mScriptFileNames, mThrottle,
|
||||
mRandomizeThrottle, mRandom, mProfileWaitTime, mDeviceSleepTime);
|
||||
mEventSource = new MonkeySourceRandomScript(mScriptFileNames,
|
||||
mThrottle, mRandomizeThrottle, mRandom,
|
||||
mProfileWaitTime, mDeviceSleepTime, mRandomizeScript);
|
||||
}
|
||||
mEventSource.setVerbose(mVerbose);
|
||||
mCountEvents = false;
|
||||
@@ -665,6 +689,10 @@ public class Monkey {
|
||||
} else if (opt.equals("--device-sleep-time")) {
|
||||
mDeviceSleepTime = nextOptionLong("Device sleep time" +
|
||||
"(in milliseconds)");
|
||||
} else if (opt.equals("--randomize-script")) {
|
||||
mRandomizeScript = true;
|
||||
} else if (opt.equals("--script-log")) {
|
||||
mScriptLog = true;
|
||||
} else if (opt.equals("-h")) {
|
||||
showUsage();
|
||||
return false;
|
||||
@@ -886,6 +914,7 @@ public class Monkey {
|
||||
|
||||
boolean systemCrashed = false;
|
||||
|
||||
// TO DO : The count should apply to each of the script file.
|
||||
while (!systemCrashed && cycleCounter < mCount) {
|
||||
synchronized (this) {
|
||||
if (mRequestProcRank) {
|
||||
@@ -958,11 +987,13 @@ public class Monkey {
|
||||
eventCounter++;
|
||||
if (mCountEvents) {
|
||||
cycleCounter++;
|
||||
writeScriptLog(cycleCounter);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!mCountEvents) {
|
||||
cycleCounter++;
|
||||
writeScriptLog(cycleCounter);
|
||||
} else {
|
||||
// Event Source has signaled that we have no more events to process
|
||||
break;
|
||||
@@ -1137,7 +1168,10 @@ public class Monkey {
|
||||
usage.append(" [--throttle MILLISEC] [--randomize-throttle]\n");
|
||||
usage.append(" [--profile-wait MILLISEC]\n");
|
||||
usage.append(" [--device-sleep-time MILLISEC]\n");
|
||||
usage.append(" [--randomize-script]\n");
|
||||
usage.append(" [--script-log]\n");
|
||||
usage.append(" COUNT\n");
|
||||
System.err.println(usage.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ public class MonkeySourceRandomScript implements MonkeyEventSource {
|
||||
/** The random number generator */
|
||||
private Random mRandom;
|
||||
|
||||
private boolean mRandomizeScript = false;
|
||||
|
||||
private int mScriptCount = 0;
|
||||
|
||||
/**
|
||||
* Creates a MonkeySourceRandomScript instance with an additional setup script.
|
||||
*
|
||||
@@ -49,7 +53,7 @@ public class MonkeySourceRandomScript implements MonkeyEventSource {
|
||||
*/
|
||||
public MonkeySourceRandomScript(String setupFileName, ArrayList<String> scriptFileNames,
|
||||
long throttle, boolean randomizeThrottle, Random random, long profileWaitTime,
|
||||
long deviceSleepTime) {
|
||||
long deviceSleepTime, boolean randomizeScript) {
|
||||
if (setupFileName != null) {
|
||||
mSetupSource = new MonkeySourceScript(random, setupFileName, throttle,
|
||||
randomizeThrottle, profileWaitTime, deviceSleepTime);
|
||||
@@ -62,6 +66,7 @@ public class MonkeySourceRandomScript implements MonkeyEventSource {
|
||||
}
|
||||
|
||||
mRandom = random;
|
||||
mRandomizeScript = randomizeScript;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,9 +78,10 @@ public class MonkeySourceRandomScript implements MonkeyEventSource {
|
||||
* @param random The random number generator.
|
||||
*/
|
||||
public MonkeySourceRandomScript(ArrayList<String> scriptFileNames, long throttle,
|
||||
boolean randomizeThrottle, Random random, long profileWaitTime, long deviceSleepTime) {
|
||||
boolean randomizeThrottle, Random random, long profileWaitTime, long deviceSleepTime,
|
||||
boolean randomizeScript) {
|
||||
this(null, scriptFileNames, throttle, randomizeThrottle, random, profileWaitTime,
|
||||
deviceSleepTime);
|
||||
deviceSleepTime, randomizeScript);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,8 +97,13 @@ public class MonkeySourceRandomScript implements MonkeyEventSource {
|
||||
int numSources = mScriptSources.size();
|
||||
if (numSources == 1) {
|
||||
mCurrentSource = mScriptSources.get(0);
|
||||
} else if (numSources > 1) {
|
||||
mCurrentSource = mScriptSources.get(mRandom.nextInt(numSources));
|
||||
} else if (numSources > 1 ) {
|
||||
if (mRandomizeScript) {
|
||||
mCurrentSource = mScriptSources.get(mRandom.nextInt(numSources));
|
||||
} else {
|
||||
mCurrentSource = mScriptSources.get(mScriptCount % numSources);
|
||||
mScriptCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user