OSDN Git Service

am ab5971d8: am 1489862e: am 48d0fd99: (-s ours) am ee41b79c: am 7d23e405: am f103317...
[android-x86/frameworks-base.git] / docs / html / tools / help / monkey.jd
1 page.title=UI/Application Exerciser Monkey
2 parent.title=Tools
3 parent.link=index.html
4 @jd:body
5
6 <p>The Monkey is a program that runs on your 
7 <a href="{@docRoot}tools/help/emulator.html">emulator</a> or device and generates pseudo-random
8 streams of user events such as clicks, touches, or gestures, as well as a number of system-level 
9 events.  You can use the Monkey to stress-test applications that you are developing, in a random 
10 yet repeatable manner.</p>
11
12 <a name="overview"></a>
13 <h2>Overview</h2>
14
15 <p>The Monkey is a command-line tool that that you can run on any emulator
16 instance or on a device.  It sends a pseudo-random stream of 
17 user events into the system, which acts as a stress test on the application software you are 
18 developing.</p>
19
20 <p>The Monkey includes a number of options, but they break down into four primary
21 categories:</p>
22
23 <ul>
24   <li>Basic configuration options, such as setting the number of events to attempt.</li>
25   <li>Operational constraints, such as restricting the test to a single package.</li>
26   <li>Event types and frequencies.</li>
27   <li>Debugging options.</li>
28 </ul>
29
30 <p>When the Monkey runs, it generates events and sends them to the system.  It also <i>watches</i>
31 the system under test and looks for three conditions, which it treats specially:</p>
32
33 <ul>
34   <li>If you have constrained the Monkey to run in one or more specific packages, it 
35   watches for attempts to navigate to any other packages, and blocks them.</li>
36   <li>If your application crashes or receives any sort of unhandled exception, the Monkey
37   will stop and report the error.</li>
38   <li>If your application generates an <i>application not responding</i> error, the Monkey
39   will stop and report the error.</li>
40 </ul>
41
42 <p>Depending on the verbosity level you have selected, you will also see reports on the progress
43 of the Monkey and the events being generated.</p>
44
45 <a name="basics"></a>
46 <h2>Basic Use of the Monkey</h2>
47
48 <p>You can launch the Monkey using a command line on your development machine or from a script. 
49 Because the Monkey runs in the emulator/device environment, you must launch it from a shell in 
50 that environment.  You can do this by prefacing <code>adb shell</code> to each command, 
51 or by entering the shell and entering Monkey commands directly.</p>
52 <p>The basic syntax is: </p>
53
54 <pre>$ adb shell monkey [options] &lt;event-count&gt;</pre>
55     
56 <p>With no options specified, the Monkey will launch in a quiet (non-verbose) mode, and will send 
57 events to any (and all) packages installed on your target.  Here is a more typical command line,
58 which will launch your application and send 500 pseudo-random events to it:</p>
59
60 <pre>$ adb shell monkey -p your.package.name -v 500</pre>
61
62 <a name="reference"></a>
63 <h2>Command Options Reference</h2>
64
65 <p>The table below lists all options you can include on the Monkey command line.</p>
66
67 <table>
68 <tr>
69   <th>Category</th>
70   <th>Option</th>
71   <th>Description</th>
72 </tr>
73
74 <tr>
75 <td rowspan="2">General</td>
76 <td><code>--help</code></td>
77 <td>Prints a simple usage guide.</td>
78 </tr>
79
80 <tr>
81 <td><code>-v</code></td>
82 <td>Each -v on the command line will increment the verbosity level.  
83 Level 0 (the default) provides little information beyond startup notification, test completion, and
84 final results.  
85 Level 1 provides more details about the test as it runs, such as individual events being sent to 
86 your activities.  
87 Level 2 provides more detailed setup information such as activities selected or not selected for 
88 testing.</td>
89 </tr>
90
91 <tr>
92 <td rowspan="10">Events</td>
93 <td><code>-s &lt;seed&gt;</code></td>
94 <td>Seed value for pseudo-random number generator.  If you re-run the Monkey with the same seed 
95 value, it will generate the same sequence of events.</td>
96 </tr>
97
98 <tr>
99 <td><code>--throttle &lt;milliseconds&gt;</code></td>
100 <td>Inserts a fixed delay between events.  You can use this option to slow down the Monkey.  
101 If not specified, there is no delay and the events are generated as rapidly as possible.</td>
102 </tr>
103
104 <tr>
105 <td><code>--pct-touch &lt;percent&gt;</code></td>
106 <td>Adjust percentage of touch events.  
107 (Touch events are a down-up event in a single place on the screen.)</td>
108 </tr>
109
110 <tr>
111 <td><code>--pct-motion &lt;percent&gt;</code></td>
112 <td>Adjust percentage of motion events.
113 (Motion events consist of a down event somewhere on the screen, a series of pseudo-random
114 movements, and an up event.)</td>
115 </tr>
116
117 <tr>
118 <td><code>--pct-trackball &lt;percent&gt;</code></td>
119 <td>Adjust percentage of trackball events.
120 (Trackball events consist of one or more random movements, sometimes followed by a click.)</td>
121 </tr>
122
123 <tr>
124 <td><code>--pct-nav &lt;percent&gt;</code></td>
125 <td>Adjust percentage of "basic" navigation events.
126 (Navigation events consist of up/down/left/right, as input from a directional input device.)</td>
127 </tr>
128
129 <tr>
130 <td><code>--pct-majornav &lt;percent&gt;</code></td>
131 <td>Adjust percentage of "major" navigation events.
132 (These are navigation events that will typically cause actions within your UI, such as
133 the center button in a 5-way pad, the back key, or the menu key.)</td>
134 </tr>
135
136 <tr>
137 <td><code>--pct-syskeys &lt;percent&gt;</code></td>
138 <td>Adjust percentage of "system" key events.
139 (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call,
140 End Call, or Volume controls.)</td>
141 </tr>
142
143 <tr>
144 <td><code>--pct-appswitch &lt;percent&gt;</code></td>
145 <td>Adjust percentage of activity launches.  At random intervals, the Monkey will issue a startActivity() call, as a way of maximizing
146 coverage of all activities within your package.</td>
147 </tr>
148
149 <tr>
150 <td><code>--pct-anyevent &lt;percent&gt;</code></td>
151 <td>Adjust percentage of other types of events.  This is a catch-all for all other types of events such as keypresses, other less-used
152 buttons on the device, and so forth.</td>
153 </tr>
154
155 <tr>
156 <td rowspan="2">Constraints</td>
157 <td><code>-p &lt;allowed-package-name&gt;</code></td>
158 <td>If you specify one or more packages this way, the Monkey will <i>only</i> allow the system
159 to visit activities within those packages.  If your application requires access to activities in
160 other packages (e.g. to select a contact) you'll need to specify those packages as well.
161 If you don't specify any packages, the Monkey will allow the system to launch activities
162 in all packages.  To specify multiple packages, use the -p option multiple times &mdash; one -p 
163 option per package.</td>
164 </tr>
165
166 <tr>
167 <td><code>-c &lt;main-category&gt;</code></td>
168 <td>If you specify one or more categories this way, the Monkey will <i>only</i> allow the 
169 system to visit activities that are listed with one of the specified categories.  
170 If you don't specify any categories, the Monkey will select activities listed with the category
171 Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY.  To specify multiple categories, use the -c
172 option multiple times &mdash; one -c option per category.</td>
173 </tr>
174
175 <tr>
176 <td rowspan="8">Debugging</td>
177 <td><code>--dbg-no-events</code></td>
178 <td>When specified, the Monkey will perform the initial launch into a test activity, but
179 will not generate any further events.
180 For best results, combine with -v, one or more package constraints, and a non-zero throttle to keep the Monkey
181 running for 30 seconds or more.  This provides an environment in which you can monitor package
182 transitions invoked by your application.</td>
183 </tr>
184
185 <tr>
186 <td><code>--hprof</code></td>
187 <td>If set, this option will generate profiling reports immediately before and after
188 the Monkey event sequence.
189 This will generate large (~5Mb) files in data/misc, so use with care.  See 
190 <a href="{@docRoot}tools/debugging/debugging-tracing.html" title="traceview">Traceview</a> for more information
191 on trace files.</td>
192 </tr>
193
194 <tr>
195 <td><code>--ignore-crashes</code></td>
196 <td>Normally, the Monkey will stop when the application crashes or experiences any type of 
197 unhandled exception.  If you specify this option, the Monkey will continue to send events to
198 the system, until the count is completed.</td>
199 </tr>
200
201 <tr>
202 <td><code>--ignore-timeouts</code></td>
203 <td>Normally, the Monkey will stop when the application experiences any type of timeout error such
204 as a "Application Not Responding" dialog.  If you specify this option, the Monkey will continue to 
205 send events to the system, until the count is completed.</td>
206 </tr>
207
208 <tr>
209 <td><code>--ignore-security-exceptions</code></td>
210 <td>Normally, the Monkey will stop when the application experiences any type of permissions error,
211 for example if it attempts to launch an activity that requires certain permissions.  If you specify
212 this option, the Monkey will continue to send events to the system, until the count is 
213 completed.</td>
214 </tr>
215
216 <tr>
217 <td><code>--kill-process-after-error</code></td>
218 <td>Normally, when the Monkey stops due to an error, the application that failed will be left
219 running.  When this option is set, it will signal the system to stop the process in which the error
220 occurred.
221 Note, under a normal (successful) completion, the launched process(es) are not stopped, and
222 the device is simply left in the last state after the final event.</td>
223 </tr>
224
225 <tr>
226 <td><code>--monitor-native-crashes</code></td>
227 <td>Watches for and reports crashes occurring in the Android system native code. If --kill-process-after-error is set, the system will stop.</td>
228 </tr>
229
230 <tr>
231 <td><code>--wait-dbg</code></td>
232 <td>Stops the Monkey from executing until a debugger is attached to it.</td>
233 </tr>
234
235 </table>
236
237 <!-- TODO: add a section called "debugging" that covers ways to use it, 
238 need to clear data, use of the seed, etc. -->
239
240 <!-- TODO: add a section that lays down a contract for Monkey output so it can be
241 scripted safely. -->
242