8

I'm using monkey command to do some stress testing on my app. But i want to test it more with respect to screen orientations to detect and capture some heapupdates while changing orientations. I searched all over android official site about monkey commands/arguments which will do screen orientations while running on any app/activity. But no luck and thought of asking professionals like you.

If idea on this, please let me know.

msk
  • 135
  • 2
  • 13

3 Answers3

10

Monkey has a number of undocumented options, including --pct-rotation. Add that switch to your command and watch your screen rotate like it's possessed by demons:

Up to (including) adb version 1.0.31:

adb shell monkey -p com.example.app -v --pct-rotation=70 500

Since adb version 1.0.32:

adb shell monkey -p com.example.app -v --pct-rotation 70 500

Look in the processOptions() method of the monkey command to see all of the supported options: https://android.googlesource.com/platform/development.git/+/master/cmds/monkey/src/com/android/commands/monkey/Monkey.java

Look at the constructor for the MonkeySourceRandom class to see the default percentages for all of the event types. These are the current values in the master branch at the time of this post. Note that the default for rotation is 0:

    // default values for random distributions
    // 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.
    mFactors[FACTOR_TOUCH] = 15.0f;
    mFactors[FACTOR_MOTION] = 10.0f;
    mFactors[FACTOR_TRACKBALL] = 15.0f;
    // Adjust the values if we want to enable rotation by default.
    mFactors[FACTOR_ROTATION] = 0.0f;
    mFactors[FACTOR_NAV] = 25.0f;
    mFactors[FACTOR_MAJORNAV] = 15.0f;
    mFactors[FACTOR_SYSOPS] = 2.0f;
    mFactors[FACTOR_APPSWITCH] = 2.0f;
    mFactors[FACTOR_FLIP] = 1.0f;
    mFactors[FACTOR_ANYTHING] = 13.0f;
    mFactors[FACTOR_PINCHZOOM] = 2.0f;

https://android.googlesource.com/platform/development.git/+/master/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java

fklappan
  • 3,259
  • 2
  • 17
  • 18
chuckbjones
  • 374
  • 2
  • 7
  • 5
    `--pct-rotation=70` should actually be `--pct-rotation 70`, at least since adb version 1.0.32. – Tadej Jul 10 '15 at 12:00
2

The Test Monkey uses random input. It will change the screen orientation, but there is no guarantee that it will do so on any given test run.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yes, there is no way to make sure it will pickup the orientation or not. I wanted to know that whether is it possible to do with exiting monkey tool or not else any other way to do that? – msk Oct 13 '12 at 19:40
  • @user1031345: The Test Monkey *only* uses random input. What you want, by definition, is not random. – CommonsWare Oct 13 '12 at 19:43
  • I knew that monkey is random.. All i want is to figure it out on screen orientation changes along with random inputs.. – msk Oct 14 '12 at 05:09
  • Are you sure? I did 100000 inputs and zero were rotations. – Mgamerz Apr 18 '14 at 04:05
  • @Mgamerz: It's possible they changed the behavior recently, but it most certainly would rotate the screen historically. – CommonsWare Apr 18 '14 at 10:58
1

Although there is no guarantee that Monkey will change orientation during a given run, you can reach your desired outcome by figuring out a SEED that will cause monkey to change orientation and re-using that SEED in future runs.

# monkey -h
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
              ...
              [-s SEED] [-v [-v] ...]
              ...
slowpoison
  • 586
  • 3
  • 20