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