7

I use the Monkey to stress-test my app. On https://developer.android.com/studio/test/monkey.html I read:

-s <seed>   Seed value for pseudo-random number generator. If you re-run the Monkey with the same seed value, it will generate the same sequence of events.

But when I ran the Monkey twice with the same seed and then compared the outputs, coordinates of my ACTION_UP and ACTION_DOWN events weren't the same.

Output #1

:Monkey: seed=1470246130093 count=50
:AllowPackage: sample1.com.sample_1
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 7.5%
//   1: 5.0%
//   2: 1.0%
//   3: 7.5%
//   4: 50.0%
//   5: -0.0%
//   6: 12.5%
//   7: 7.5%
//   8: 1.0%
//   9: 1.0%
//   10: 0.5%
//   11: 6.5%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=sample1.com.sample_1/.MainActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=sample1.com.sample_1/.MainActivity } in package sample1.com.sample_1
:Sending rotation degree=2, persist=true
:Sending rotation degree=3, persist=true
:Sending rotation degree=3, persist=true
:Sending rotation degree=0, persist=true
:Sending rotation degree=0, persist=true
:Sending rotation degree=1, persist=false
:Sending rotation degree=2, persist=true
:Sending rotation degree=2, persist=true
:Sending rotation degree=0, persist=true
:Sending Trackball (ACTION_MOVE): 0:(2.0,1.0)
:Sending rotation degree=2, persist=false
:Sending rotation degree=3, persist=true
:Sending rotation degree=0, persist=false
:Sending rotation degree=1, persist=false
:Sending rotation degree=0, persist=true
:Sending Touch (ACTION_DOWN): 0:(1091.0,998.0)
:Sending Touch (ACTION_UP): 0:(1106.5758,994.1529)
:Sending rotation degree=3, persist=false
:Sending Trackball (ACTION_MOVE): 0:(-2.0,3.0)
Events injected: 50
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=241ms (0ms mobile, 0ms wifi, 241ms not connected)
// Monkey finished

Output #2

:Monkey: seed=1470246130093 count=50
:AllowPackage: sample1.com.sample_1
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
//   0: 7.5%
//   1: 5.0%
//   2: 1.0%
//   3: 7.5%
//   4: 50.0%
//   5: -0.0%
//   6: 12.5%
//   7: 7.5%
//   8: 1.0%
//   9: 1.0%
//   10: 0.5%
//   11: 6.5%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=sample1.com.sample_1/.MainActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=sample1.com.sample_1/.MainActivity } in package sample1.com.sample_1
:Sending rotation degree=2, persist=true
:Sending rotation degree=3, persist=true
:Sending rotation degree=3, persist=true
:Sending rotation degree=0, persist=true
:Sending rotation degree=0, persist=true
:Sending rotation degree=1, persist=false
:Sending rotation degree=2, persist=true
:Sending rotation degree=2, persist=true
:Sending rotation degree=0, persist=true
:Sending Trackball (ACTION_MOVE): 0:(2.0,1.0)
:Sending rotation degree=2, persist=false
:Sending rotation degree=3, persist=true
:Sending rotation degree=0, persist=false
:Sending rotation degree=1, persist=false
:Sending rotation degree=0, persist=true
:Sending Touch (ACTION_DOWN): 0:(1635.0,510.0)
:Sending Touch (ACTION_UP): 0:(1650.5758,506.1529)
:Sending rotation degree=3, persist=false
:Sending Trackball (ACTION_MOVE): 0:(-2.0,3.0)
Events injected: 50
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=428ms (0ms mobile, 0ms wifi, 428ms not connected)
// Monkey finished

Why? I expected to see the same events and, hence, the identical outputs

Maksim Dmitriev
  • 5,985
  • 12
  • 73
  • 138
  • checking the source at https://github.com/android/platform_development/blob/1dd320ea93698e38be2bae8f618b76334153cd8c/cmds/monkey/src/com/android/commands/monkey/MonkeySourceRandom.java tells me that it _should_ work... what platform version are you on? – Lovis Aug 29 '16 at 11:22
  • _I expected to see the same events and, hence, the identical outputs_ -- I think you are misreading the docs. `-s` ensures only _same sequence of events_, not the same output. Your logs show same sequence of events. – ozbek Aug 31 '16 at 02:51
  • @ozbek, `:Sending Touch (ACTION_DOWN): 0:(1635.0,510.0)` and `:Sending Touch (ACTION_DOWN): 0:(1091.0,998.0)` are different events. Please copy the outputs and compare them. For example, on https://www.diffchecker.com/ – Maksim Dmitriev Aug 31 '16 at 14:52
  • @MaksimDmitriev, those are same events. Only coordinates differ, but the event is same (`ACTION_DOWN`). – ozbek Sep 01 '16 at 00:05
  • @ozbek, if you're sure, please post an answer with proof, and I'll accept it – Maksim Dmitriev Sep 01 '16 at 08:36
  • I have been able to reproduce runs with the same seed in the past so the events should be exactly the same. I.e., performing a diff on the outputs should not produce differences. Try changing the order of your monkey parameters, at least in older versions the seed is sometimes ignored depending on the order. – 4knahs Jul 24 '17 at 14:23

0 Answers0