development
Revision | 62c4d9bfc5eca4a7bd160e8fb67c0bbc066d9ce8 (tree) |
---|---|
Zeit | 2009-03-28 09:10:47 |
Autor | Evan Millar <> |
Commiter | The Android Open Source Project |
AI 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.
Automated import of CL 143190
@@ -369,7 +369,7 @@ public class Monkey { | ||
369 | 369 | if (mVerbose >= 2) { // check seeding performance |
370 | 370 | System.out.println("// Seeded: " + mSeed); |
371 | 371 | } |
372 | - mEventSource = new MonkeySourceRandom(mSeed, mMainApps); | |
372 | + mEventSource = new MonkeySourceRandom(mSeed, mMainApps, mThrottle); | |
373 | 373 | mEventSource.setVerbose(mVerbose); |
374 | 374 | //set any of the factors that has been set |
375 | 375 | for (int i = 0; i < MonkeySourceRandom.FACTORZ_COUNT; i++) { |
@@ -709,13 +709,6 @@ public class Monkey { | ||
709 | 709 | } |
710 | 710 | } |
711 | 711 | |
712 | - try { | |
713 | - Thread.sleep(mThrottle); | |
714 | - } catch (InterruptedException e1) { | |
715 | - System.out.println("** Monkey interrupted in sleep."); | |
716 | - return i; | |
717 | - } | |
718 | - | |
719 | 712 | // In this debugging mode, we never send any events. This is primarily |
720 | 713 | // here so you can manually test the package or category limits, while manually |
721 | 714 | // exercising the system. |
@@ -730,7 +723,10 @@ public class Monkey { | ||
730 | 723 | |
731 | 724 | MonkeyEvent ev = mEventSource.getNextEvent(); |
732 | 725 | if (ev != null) { |
733 | - i++; | |
726 | + // We don't want to count throttling as an event. | |
727 | + if (!(ev instanceof MonkeyThrottleEvent)) { | |
728 | + i++; | |
729 | + } | |
734 | 730 | int injectCode = ev.injectEvent(mWm, mAm, mVerbose); |
735 | 731 | if (injectCode == MonkeyEvent.INJECT_FAIL) { |
736 | 732 | if (ev instanceof MonkeyKeyEvent) { |
@@ -29,6 +29,7 @@ public abstract class MonkeyEvent { | ||
29 | 29 | public static final int EVENT_TYPE_TRACKBALL = 2; |
30 | 30 | public static final int EVENT_TYPE_ACTIVITY = 3; |
31 | 31 | public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip |
32 | + public static final int EVENT_TYPE_THROTTLE = 5; | |
32 | 33 | |
33 | 34 | public static final int INJECT_SUCCESS = 1; |
34 | 35 | public static final int INJECT_FAIL = 0; |
@@ -171,6 +171,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{ | ||
171 | 171 | private LinkedList<MonkeyEvent> mQ = new LinkedList<MonkeyEvent>(); |
172 | 172 | private Random mRandom; |
173 | 173 | private int mVerbose = 0; |
174 | + private long mThrottle = 0; | |
174 | 175 | |
175 | 176 | private boolean mKeyboardOpen = false; |
176 | 177 |
@@ -185,7 +186,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{ | ||
185 | 186 | return KEY_NAMES[keycode]; |
186 | 187 | } |
187 | 188 | |
188 | - public MonkeySourceRandom(long seed, ArrayList<ComponentName> MainApps) { | |
189 | + public MonkeySourceRandom(long seed, ArrayList<ComponentName> MainApps, long throttle) { | |
189 | 190 | // default values for random distributions |
190 | 191 | // note, these are straight percentages, to match user input (cmd line args) |
191 | 192 | // but they will be converted to 0..1 values before the main loop runs. |
@@ -202,6 +203,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{ | ||
202 | 203 | mRandom = new SecureRandom(); |
203 | 204 | mRandom.setSeed((seed == 0) ? -1 : seed); |
204 | 205 | mMainApps = MainApps; |
206 | + mThrottle = throttle; | |
205 | 207 | } |
206 | 208 | |
207 | 209 | /** |
@@ -334,6 +336,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{ | ||
334 | 336 | downAt, MotionEvent.ACTION_UP, x, y, 0); |
335 | 337 | e.setIntermediateNote(false); |
336 | 338 | mQ.addLast(e); |
339 | + addThrottle(); | |
337 | 340 | } |
338 | 341 | |
339 | 342 | /** |
@@ -384,6 +387,7 @@ public class MonkeySourceRandom implements MonkeyEventSource{ | ||
384 | 387 | e.setIntermediateNote(false); |
385 | 388 | mQ.addLast(e); |
386 | 389 | } |
390 | + addThrottle(); | |
387 | 391 | } |
388 | 392 | |
389 | 393 | /** |
@@ -416,11 +420,13 @@ public class MonkeySourceRandom implements MonkeyEventSource{ | ||
416 | 420 | MonkeyActivityEvent e = new MonkeyActivityEvent(mMainApps.get( |
417 | 421 | mRandom.nextInt(mMainApps.size()))); |
418 | 422 | mQ.addLast(e); |
423 | + addThrottle(); | |
419 | 424 | return; |
420 | 425 | } else if (cls < mFactors[FACTOR_FLIP]) { |
421 | 426 | MonkeyFlipEvent e = new MonkeyFlipEvent(mKeyboardOpen); |
422 | 427 | mKeyboardOpen = !mKeyboardOpen; |
423 | 428 | mQ.addLast(e); |
429 | + addThrottle(); | |
424 | 430 | return; |
425 | 431 | } else { |
426 | 432 | lastKey = 1 + mRandom.nextInt(KeyEvent.getMaxKeyCode() - 1); |
@@ -431,6 +437,8 @@ public class MonkeySourceRandom implements MonkeyEventSource{ | ||
431 | 437 | |
432 | 438 | e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, lastKey); |
433 | 439 | mQ.addLast(e); |
440 | + | |
441 | + addThrottle(); | |
434 | 442 | } |
435 | 443 | |
436 | 444 | public boolean validate() { |
@@ -464,4 +472,8 @@ public class MonkeySourceRandom implements MonkeyEventSource{ | ||
464 | 472 | mQ.removeFirst(); |
465 | 473 | return e; |
466 | 474 | } |
475 | + | |
476 | + private void addThrottle() { | |
477 | + mQ.addLast(new MonkeyThrottleEvent(MonkeyEvent.EVENT_TYPE_THROTTLE, mThrottle)); | |
478 | + } | |
467 | 479 | } |
@@ -0,0 +1,52 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2009 The Android Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | +package com.android.commands.monkey; | |
18 | + | |
19 | +import android.app.IActivityManager; | |
20 | +import android.os.RemoteException; | |
21 | +import android.os.SystemClock; | |
22 | +import android.view.IWindowManager; | |
23 | +import android.view.MotionEvent; | |
24 | + | |
25 | + | |
26 | +/** | |
27 | + * monkey throttle event | |
28 | + */ | |
29 | +public class MonkeyThrottleEvent extends MonkeyEvent { | |
30 | + private long mThrottle; | |
31 | + | |
32 | + public MonkeyThrottleEvent(int type, long throttle) { | |
33 | + super(type); | |
34 | + mThrottle = throttle; | |
35 | + } | |
36 | + | |
37 | + @Override | |
38 | + public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) { | |
39 | + | |
40 | + if (verbose > 1) { | |
41 | + System.out.println("Sleeping for " + mThrottle + " milliseconds"); | |
42 | + } | |
43 | + try { | |
44 | + Thread.sleep(mThrottle); | |
45 | + } catch (InterruptedException e1) { | |
46 | + System.out.println("** Monkey interrupted in sleep."); | |
47 | + return MonkeyEvent.INJECT_FAIL; | |
48 | + } | |
49 | + | |
50 | + return MonkeyEvent.INJECT_SUCCESS; | |
51 | + } | |
52 | +} |