AI 143341: am: CL 143190 am: CL 142951 Change the way we handle monkey throttling. We now will only sleep after complete down/[move]/up sequences. This avoids unwanted long pressing. We will need to add code to explicitly long press at some point.

Original author: emillar
  Merged from: //branches/cupcake/...
  Original author: android-build
  Merged from: //branches/donutburger/...

Automated import of CL 143341
This commit is contained in:
Evan Millar
2009-03-27 18:51:49 -07:00
committed by The Android Open Source Project
parent 66c0d68c53
commit 84426e4d3f
4 changed files with 71 additions and 10 deletions

View File

@@ -369,7 +369,7 @@ public class Monkey {
if (mVerbose >= 2) { // check seeding performance if (mVerbose >= 2) { // check seeding performance
System.out.println("// Seeded: " + mSeed); System.out.println("// Seeded: " + mSeed);
} }
mEventSource = new MonkeySourceRandom(mSeed, mMainApps); mEventSource = new MonkeySourceRandom(mSeed, mMainApps, mThrottle);
mEventSource.setVerbose(mVerbose); mEventSource.setVerbose(mVerbose);
//set any of the factors that has been set //set any of the factors that has been set
for (int i = 0; i < MonkeySourceRandom.FACTORZ_COUNT; i++) { for (int i = 0; i < MonkeySourceRandom.FACTORZ_COUNT; i++) {
@@ -709,13 +709,6 @@ public class Monkey {
} }
} }
try {
Thread.sleep(mThrottle);
} catch (InterruptedException e1) {
System.out.println("** Monkey interrupted in sleep.");
return i;
}
// In this debugging mode, we never send any events. This is primarily // In this debugging mode, we never send any events. This is primarily
// here so you can manually test the package or category limits, while manually // here so you can manually test the package or category limits, while manually
// exercising the system. // exercising the system.
@@ -730,7 +723,10 @@ public class Monkey {
MonkeyEvent ev = mEventSource.getNextEvent(); MonkeyEvent ev = mEventSource.getNextEvent();
if (ev != null) { if (ev != null) {
i++; // We don't want to count throttling as an event.
if (!(ev instanceof MonkeyThrottleEvent)) {
i++;
}
int injectCode = ev.injectEvent(mWm, mAm, mVerbose); int injectCode = ev.injectEvent(mWm, mAm, mVerbose);
if (injectCode == MonkeyEvent.INJECT_FAIL) { if (injectCode == MonkeyEvent.INJECT_FAIL) {
if (ev instanceof MonkeyKeyEvent) { if (ev instanceof MonkeyKeyEvent) {

View File

@@ -29,6 +29,7 @@ public abstract class MonkeyEvent {
public static final int EVENT_TYPE_TRACKBALL = 2; public static final int EVENT_TYPE_TRACKBALL = 2;
public static final int EVENT_TYPE_ACTIVITY = 3; public static final int EVENT_TYPE_ACTIVITY = 3;
public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip
public static final int EVENT_TYPE_THROTTLE = 5;
public static final int INJECT_SUCCESS = 1; public static final int INJECT_SUCCESS = 1;
public static final int INJECT_FAIL = 0; public static final int INJECT_FAIL = 0;

View File

@@ -171,6 +171,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
private LinkedList<MonkeyEvent> mQ = new LinkedList<MonkeyEvent>(); private LinkedList<MonkeyEvent> mQ = new LinkedList<MonkeyEvent>();
private Random mRandom; private Random mRandom;
private int mVerbose = 0; private int mVerbose = 0;
private long mThrottle = 0;
private boolean mKeyboardOpen = false; private boolean mKeyboardOpen = false;
@@ -185,7 +186,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
return KEY_NAMES[keycode]; return KEY_NAMES[keycode];
} }
public MonkeySourceRandom(long seed, ArrayList<ComponentName> MainApps) { public MonkeySourceRandom(long seed, ArrayList<ComponentName> MainApps, long throttle) {
// default values for random distributions // default values for random distributions
// note, these are straight percentages, to match user input (cmd line args) // note, these are straight percentages, to match user input (cmd line args)
// but they will be converted to 0..1 values before the main loop runs. // but they will be converted to 0..1 values before the main loop runs.
@@ -202,6 +203,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
mRandom = new SecureRandom(); mRandom = new SecureRandom();
mRandom.setSeed((seed == 0) ? -1 : seed); mRandom.setSeed((seed == 0) ? -1 : seed);
mMainApps = MainApps; mMainApps = MainApps;
mThrottle = throttle;
} }
/** /**
@@ -334,6 +336,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
downAt, MotionEvent.ACTION_UP, x, y, 0); downAt, MotionEvent.ACTION_UP, x, y, 0);
e.setIntermediateNote(false); e.setIntermediateNote(false);
mQ.addLast(e); mQ.addLast(e);
addThrottle();
} }
/** /**
@@ -384,6 +387,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{
e.setIntermediateNote(false); e.setIntermediateNote(false);
mQ.addLast(e); mQ.addLast(e);
} }
addThrottle();
} }
/** /**
@@ -416,11 +420,13 @@ public class MonkeySourceRandom implements MonkeyEventSource{
MonkeyActivityEvent e = new MonkeyActivityEvent(mMainApps.get( MonkeyActivityEvent e = new MonkeyActivityEvent(mMainApps.get(
mRandom.nextInt(mMainApps.size()))); mRandom.nextInt(mMainApps.size())));
mQ.addLast(e); mQ.addLast(e);
addThrottle();
return; return;
} else if (cls < mFactors[FACTOR_FLIP]) { } else if (cls < mFactors[FACTOR_FLIP]) {
MonkeyFlipEvent e = new MonkeyFlipEvent(mKeyboardOpen); MonkeyFlipEvent e = new MonkeyFlipEvent(mKeyboardOpen);
mKeyboardOpen = !mKeyboardOpen; mKeyboardOpen = !mKeyboardOpen;
mQ.addLast(e); mQ.addLast(e);
addThrottle();
return; return;
} else { } else {
lastKey = 1 + mRandom.nextInt(KeyEvent.getMaxKeyCode() - 1); lastKey = 1 + mRandom.nextInt(KeyEvent.getMaxKeyCode() - 1);
@@ -431,6 +437,8 @@ public class MonkeySourceRandom implements MonkeyEventSource{
e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, lastKey); e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, lastKey);
mQ.addLast(e); mQ.addLast(e);
addThrottle();
} }
public boolean validate() { public boolean validate() {
@@ -464,4 +472,8 @@ public class MonkeySourceRandom implements MonkeyEventSource{
mQ.removeFirst(); mQ.removeFirst();
return e; return e;
} }
private void addThrottle() {
mQ.addLast(new MonkeyThrottleEvent(MonkeyEvent.EVENT_TYPE_THROTTLE, mThrottle));
}
} }

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.commands.monkey;
import android.app.IActivityManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.view.IWindowManager;
import android.view.MotionEvent;
/**
* monkey throttle event
*/
public class MonkeyThrottleEvent extends MonkeyEvent {
private long mThrottle;
public MonkeyThrottleEvent(int type, long throttle) {
super(type);
mThrottle = throttle;
}
@Override
public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
if (verbose > 1) {
System.out.println("Sleeping for " + mThrottle + " milliseconds");
}
try {
Thread.sleep(mThrottle);
} catch (InterruptedException e1) {
System.out.println("** Monkey interrupted in sleep.");
return MonkeyEvent.INJECT_FAIL;
}
return MonkeyEvent.INJECT_SUCCESS;
}
}