Android Stress Test-monkey

Source: Internet
Author: User
Tags root access

first, what is Monkey

Monkey is an Android platform for the next command-line automated test tool that can be run in the emulator or in the actual device. It sends pseudo-random user event streams (such as key input, touch input, gesture input, etc.) to the system, enabling stress testing of the application under development. Monkey includes many options, which are broadly divided into four categories:

    • Basic configuration options, such as setting the number of events attempted
    • Run constraint options, such as setting test only for a single package
    • Event Type and frequency
    • Debugging options

When the monkey is running, it generates events and sends them to the system. At the same time, the monkey also monitors the system under test, with special treatment for the following three cases (stop conditions):

    • If Monkey is qualified to run on one or several specific packages, it will monitor and block attempts to move to other packages.
    • If the application crashes or receives any runaway exceptions, the monkey will stop and error.
    • If the application produces an error that the application does not respond to (anr:application not responding), Monkey will stop and make a mistake.

According to the different levels of feedback you have selected, you can also see their execution process reports and generated events in Monkey

Second, test preparation

Monkey test must first enter the Android device adb Shell (Android SDK Environment configuration is not described here, there are many online) steps are as follows:

1. Enter the terminal

2. USB connection phone, enter adb shell command

3. After entering the phone, enter the corresponding monkey command to test

Third, Mon Basic command format for key

The basic syntax is as follows:

1, $ adb shell monkey [options]

ADB shell monkey–p Package –v test times

If you do not specify Options,monkey will start in a no-feedback mode and send events to all packages installed in the target environment.

The following is a more typical command-line example that starts the Com.android.email package and sends 500 pseudo-random events to it: $ adb shell monkey-p com.sankuai.xxx-v 500

2. Perform a single apk:

Monkey–p <options>-C <options>-S <seed> < limit statements >--throttle <milliseconds>-v execution times > c:\m Onkey_test.txt

3. Execute APK Collection:

Monkey–pkg-blacklist-file/data/blacklist.txt-c <options>-S <seed> < restriction statements >--throttle < Milliseconds>-V executions > C:\blacklist_test.txt//Do not blacklist applications

Or

Monkey–pkg-whitelist-file/data/whitelist.txt-c <options>-S <seed> < restriction statements >--throttle < Milliseconds>-V executions > C:\whitelist_test.txt/Whitelist Apps

iv. Test Log Acquisition

With monkey test, in order to facilitate the analysis of the problem, you can add "|logcat-v time" after the command Monkey command, so that you can test the side of the print log (remember to save the log text with the terminal) for example:

adb shell monkey–p com.android.email–v 20000|logcat-v Time

But this combination after the monkey test is complete, logcat is still executing, and the test needs to be noted

If the test monkey encounters crash or ANR (the program is forced to quit or not respond), you need to provide traces.txt while fetching the log,

The steps are as follows:{ adb pull/data/anr/traces.txt.}

1. The beta version requires root access

2. Enter the DATA/ANR directory below

3. Copy the Traces.txt file to the TF card and copy it to the software analysis for eg. Trace View

Five, save monkey log and cell phone log to SDcard

First, enter the ADB shell in CMD or terminal

Second, the implementation of monkey, such as

Monkey-p com.android.email--throttle--ignore-crashes--ignore-timeouts--ignore-security-exceptions-- Ignore-native-crashes--monitor-native-crashes-v-v-v >/mnt/sdcard/monkey.txt & logcat-v Time >/MNT/SDCA Rd/logcat.txt

Note: If you do not want to generate a Logcat file, remove the red flag (& logcat-v time >/mnt/sdcard/logcat.txt)

Third, the terminal to open the storage log address, such as

Cd/users/wuxiao/documents

Four, drag the log to the computer, such as

ADB pull/mnt/sdcard/monkey.txt

six, manual stop Monkey

ADB shell PS (lookup process PID)

adb shell kill pid (Kill process)

seven, Monkey command parameter introduction

category Parameters meaning Notes

Basic

--help Help information
-v command line each-V will increase the level of feedback information
  • Level 0 (default) provides less information than startup prompts, test completion, and final results. eg: adb shell monkey -p com.sankuai.xxx–v 100
  • Level 1 provides more detailed testing information, Events that are sent to activity individually. Eg: adb shell monkey -p com.sankuai.xxx–v-v
  • Level 2 provides more detailed setup information, Activity that is selected or not selected in the test.  eg: adb shell monkey -p com.sankuai.xxx–v–v–v

 

 

 

Event  

-S&NBSP;
  • pseudo-random number generator seed value
  • if you run monkey again with the same seed value, it will generate the same sequence of events
  • Monkey Test 1:adb shell monkey -p com.sankuai.xxx –s 10  100
  • Monkey Test 2:adb shell monkey -p com.sankuai.xxx –s 10 100 The effect of the
  • two test is the same, because the simulated sequence of user actions (a sequence of operations consisting of each operation in a certain order) is the same. The
  • sequence of operations is randomly generated, but as long as we specify the same seed value, we can guarantee that the random sequence of operations generated by the two Tests is exactly the same, so this sequence of operations is pseudo-random
--throttle
  • Inserts a fixed delay between events. This option slows down the execution speed of the monkey.
  • If you do not specify this option monkey will not be delayed and events will be produced as soon as possible
  • Used to specify the delay between user actions (that is, events), in milliseconds
ADB shell monkey-p com.sankuai.xxx–throttle 3000 100

Adjustment percentage

-pct+{-Event Name}

--pct-touch Adjust the percentage of touch events Touch event is a down-up event that occurs in a single location on the screen
--pct-motion Adjust the percentage of action events An action event consists of a down event, a series of pseudo-random events, and an up event somewhere on the screen
--pct-trackball Adjust the percentage of track events A trajectory event consists of one or several random movements, sometimes accompanied by a click
--pct-nav Adjust the percentage of the basic navigation event Navigation events consist of up/down/left/right from the direction input device
--pct-majornav

Adjust the percentage of the primary navigation event

These navigation events usually trigger actions in the graphical interface, such as: 5-way keyboard, rewind button, menu key
--pct-syskeys Adjust the percentage of the System key event These keys are usually reserved for use by the system, such as home, back, Start call, End call, and volume control keys
--pct-appswitch Adjust the percentage of startup activity In a random interval, monkey will execute a startactivity () call as a way to maximally cover all activity in the package
--pct-anyevent Adjust the percentage of other types of events It includes all other types of events, such as keystrokes, other infrequently used device buttons, and so on.

Constraint restrictions

-P
  • If you specify one or several packages with this parameter, monkey will only allow the system to start the activity in those packages.
  • If your application also needs to access activity in other packages (such as choosing to take a contact), those packages also need to be specified at this time
  • If you do not specify any packages, monkey will allow the system to start the activity in all packages
  • To specify multiple packages, multiple-p options are required, and each-p option can only be used for one package
-C
  • If you specify one or more categories with this parameter, monkey will only allow the system to start activity that is listed by a category in these categories
  • If you do not specify any categories, MONKEY will select the Activity:Intent.CATEGORY_LAUNCHER or Intent.category_monkey listed in the following categories
To specify multiple categories, you need to use multiple-c options, and each-c option can only be used for one category

Debugging






--dbg-no-events

Set this option, monkey will perform the initial boot, enter into a test activity, and no further events will be generated

For best results, combine it with-V, one or several package constraints, and a non-0 value that keeps monkey running for 30 seconds or longer, providing an environment to monitor conversions between packages called by the application
--hprof Set this option to generate the profiling report immediately before and after the monkey event sequence This will generate a large file (~5MB) in the Data/misc, so use it with care
--ignore-crashes
  • Typically, monkey stops running when an application crashes or any runaway exception occurs
  • If this option is set, Monkey will continue to send events to the system until the count is complete
--ignore-timeouts
  • Typically, monkey stops running when an application has any time-out errors, such as the application not responding dialog box
  • If this option is set, Monkey will continue to send events to the system until the count is complete
--ignore-security-exceptions
  • Typically, when an application has a licensing error (such as initiating an activity that requires some license), Monkey will stop running
  • If this option is set, Monkey will continue to send events to the system until the count is complete
--kill-process-after-error
  • Typically, when Monkey is stopped due to an error, the application that went wrong will continue to be in a running state
  • When this option is set, the system will be notified of the process of stopping the error.
The normal (successful) end, and does not stop the process from starting, the device simply remains in the final state after the end event
--monitor-native-crashes
  • Monitor and report crash events for native code in Android systems
  • If--kill-process-after-error is set, the system will stop running
--wait-dbg

Stop monkey in execution until there is a debugger connected to it

Android Stress Test-monkey

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.