blob: 6524177a06f464799ad856f750720ca9a943baf6 [file] [log] [blame] [view]
andybons3322f762015-08-24 21:37:091# Android Test Instructions
2
andybons3322f762015-08-24 21:37:093[TOC]
4
jbudorick25c17382016-08-03 18:53:075## Device Setup
6
7### Physical Device Setup
8
9#### ADB Debugging
andybons3322f762015-08-24 21:37:0910
11In order to allow the ADB to connect to the device, you must enable USB
12debugging:
andybons22afb312015-08-31 02:24:5113
14* Before Android 4.1 (Jelly Bean):
15 * Go to "System Settings"
16 * Go to "Developer options"
17 * Check "USB debugging".
18 * Un-check "Verify apps over USB".
jbudorick25c17382016-08-03 18:53:0719* On Jelly Bean and above, developer options are hidden by default. To unhide them:
andybons22afb312015-08-31 02:24:5120 * Go to "About phone"
21 * Tap 10 times on "Build number"
22 * The "Developer options" menu will now be available.
23 * Check "USB debugging".
24 * Un-check "Verify apps over USB".
andybons3322f762015-08-24 21:37:0925
jbudorick25c17382016-08-03 18:53:0726#### Screen
andybons3322f762015-08-24 21:37:0927
28You MUST ensure that the screen stays on while testing: `adb shell svc power
29stayon usb` Or do this manually on the device: Settings -> Developer options
30-> Stay Awake.
31
32If this option is greyed out, stay awake is probably disabled by policy. In that
33case, get another device or log in with a normal, unmanaged account (because the
34tests will break in exciting ways if stay awake is off).
35
jbudorick25c17382016-08-03 18:53:0736#### Enable Asserts
andybons3322f762015-08-24 21:37:0937
andybons22afb312015-08-31 02:24:5138 adb shell setprop debug.assert 1
andybons3322f762015-08-24 21:37:0939
jbudorick25c17382016-08-03 18:53:0740#### Disable Verify Apps
andybons3322f762015-08-24 21:37:0941
42You may see a dialog like
43[this one](http://www.samsungmobileusa.com/simulators/ATT_GalaxyMega/mobile/screens/06-02_12.jpg),
44which states, _Google may regularly check installed apps for potentially harmful
45behavior._ This can interfere with the test runner. To disable this dialog, run:
46`adb shell settings put global package_verifier_enable 0`
47
jbudorick25c17382016-08-03 18:53:0748### Emulator Setup
andybons3322f762015-08-24 21:37:0949
jbudorick25c17382016-08-03 18:53:0750#### Option 1
andybons3322f762015-08-24 21:37:0951
52Use an emulator (i.e. Android Virtual Device, AVD): Enabling Intel's
53Virtualizaton support provides the fastest, most reliable emulator configuration
54available (i.e. x86 emulator with GPU acceleration and KVM support).
thestigf51ad752015-11-11 18:08:4955Remember to build with `target_arch=ia32` for x86. Otherwise installing the APKs
56will fail with `INSTALL_FAILED_NO_MATCHING_ABIS`.
andybons3322f762015-08-24 21:37:0957
581. Enable Intel Virtualization support in the BIOS.
59
602. Set up your environment:
61
62 ```shell
63 . build/android/envsetup.sh
64 ```
65
663. Install emulator deps:
67
68 ```shell
thestigf51ad752015-11-11 18:08:4969 build/android/install_emulator_deps.py --api-level=23
andybons3322f762015-08-24 21:37:0970 ```
71
72 This script will download Android SDK and place it a directory called
73 android\_tools in the same parent directory as your chromium checkout. It
74 will also download the system-images for the emulators (i.e. arm and x86).
75 Note that this is a different SDK download than the Android SDK in the
jbudorick25c17382016-08-03 18:53:0776 chromium source checkout (i.e. `src/third_party/android_emulator_sdk`).
andybons3322f762015-08-24 21:37:0977
784. Run the avd.py script. To start up _num_ emulators use -n. For non-x86 use
79 --abi.
80
81 ```shell
thestigf51ad752015-11-11 18:08:4982 build/android/avd.py --api-level=23
andybons3322f762015-08-24 21:37:0983 ```
84
85 This script will attempt to use GPU emulation, so you must be running the
86 emulators in an environment with hardware rendering available. See
87 `avd.py --help` for more details.
88
jbudorick25c17382016-08-03 18:53:0789#### Option 2
andybons3322f762015-08-24 21:37:0990
jbudorick25c17382016-08-03 18:53:0791Alternatively, you can create and run your own emulator using the tools provided
andybons3322f762015-08-24 21:37:0992by the Android SDK. When doing so, be sure to enable GPU emulation in hardware
93settings, since Chromium requires it to render.
94
95## Building Tests
96
jbudorick25c17382016-08-03 18:53:0797If you're adding a new test file, you'll need to explicitly add it to a gn
98target. If you're adding a test to an existing file, you won't to make gn
99changes, but you may be interested in where your test winds up. In either case,
100here are some guidelines for where a test belongs:
andybons3322f762015-08-24 21:37:09101
jbudorick25c17382016-08-03 18:53:07102### C++
andybons3322f762015-08-24 21:37:09103
jbudorick25c17382016-08-03 18:53:07104C++ test files typically belong in `<top-level directory>_unittests` (e.g.
105`base_unittests` for `//base`). There are a few exceptions -- browser tests are
106typically their own target (e.g. `content_browsertests` for `//content`, or
107`browser_tests` for `//chrome`), and some unit test suites are broken at the
108second directory rather than the top-level one.
109
110### Java
111
112Java test files vary a bit more widely than their C++ counterparts:
113
114 - Instrumentation test files -- i.e., tests that will run on a device --
115typically belong in either `<top-level directory>_javatests` or
116`<top-level directory>_test_java`. Regardless, they'll wind up getting packaged
117into one of a few test APKs:
118 - `android_webview_test_apk` for anything in `//android_webview`
119 - `content_shell_test_apk` for anything in `//content` or below
120 - `chrome_public_test_apk` for most things in `//chrome`
121 - `chrome_sync_shell_test_apk` in a few exceptional cases
122 - JUnit or Robolectric test files -- i.e., tests that will run on the host --
123typically belong in `<top-level directory>_junit_tests` (e.g. `base_junit_tests`
124for `//base`), though here again there are cases (particularly in
125`//components`) where suites are split at the second directory rather than the
126top-level one.
andybons3322f762015-08-24 21:37:09127
128Once you know what to build, just do it like you normally would build anything
newt17e4d242015-08-27 09:07:26129else, e.g.: `ninja -C out/Release chrome_public_test_apk`
andybons3322f762015-08-24 21:37:09130
131## Running Tests
132
jbudorick25c17382016-08-03 18:53:07133All functional tests should be runnable via the wrapper scripts generated at
134build time:
135
136```sh
137<output directory>/bin/run_<target_name> [options]
138```
139
140Note that tests are sharded across all attached devices unless explicitly told
141to do otherwise by `-d/--device`.
andybons3322f762015-08-24 21:37:09142
143The commands used by the buildbots are printed in the logs. Look at
144http://build.chromium.org/ to duplicate the same test command as a particular
145builder.
146
jbudorick25c17382016-08-03 18:53:07147### INSTALL\_FAILED\_CONTAINER\_ERROR or INSTALL\_FAILED\_INSUFFICIENT\_STORAGE
andybons3322f762015-08-24 21:37:09148
jbudorick25c17382016-08-03 18:53:07149If you see this error when the test runner is attempting to deploy the test
andybons3322f762015-08-24 21:37:09150binaries to the AVD emulator, you may need to resize your userdata partition
151with the following commands:
152
153```shell
davve7ae32cd2015-09-22 06:54:09154# Resize userdata partition to be 1G
thestigf51ad752015-11-11 18:08:49155resize2fs android_emulator_sdk/sdk/system-images/android-23/x86/userdata.img 1G
andybons3322f762015-08-24 21:37:09156
157# Set filesystem parameter to continue on errors; Android doesn't like some
158# things e2fsprogs does.
thestigf51ad752015-11-11 18:08:49159tune2fs -e continue android_emulator_sdk/sdk/system-images/android-23/x86/userdata.img
andybons3322f762015-08-24 21:37:09160```
161
162## Symbolizing Crashes
163
164Crash stacks are logged and can be viewed using adb logcat. To symbolize the
jyasskinc1c76ff2015-12-18 21:39:52165traces, define `CHROMIUM_OUTPUT_DIR=$OUTDIR` where `$OUTDIR` is the argument you
166pass to `ninja -C`, and pipe the output through
167`third_party/android_platform/development/scripts/stack`. If
168`$CHROMIUM_OUTPUT_DIR` is unset, the script will search `out/Debug` and
169`out/Release`. For example:
170
171```shell
172# If you build with
173ninja -C out/Debug chrome_public_test_apk
174# You can run:
175adb logcat -d | third_party/android_platform/development/scripts/stack
176
177# If you build with
178ninja -C out/android chrome_public_test_apk
179# You can run:
180adb logcat -d | CHROMIUM_OUTPUT_DIR=out/android third_party/android_platform/development/scripts/stack
181# or
182export CHROMIUM_OUTPUT_DIR=out/android
183adb logcat -d | third_party/android_platform/development/scripts/stack
184```
andybons3322f762015-08-24 21:37:09185
mlamouri0fbd6cd2015-10-26 12:08:11186## JUnit tests
187
188JUnit tests are Java unittests running on the host instead of the target device.
189They are faster to run and therefore are recommended over instrumentation tests
190when possible.
191
192The JUnits tests are usually following the pattern of *target*\_junit\_tests,
193for example, `content_junit_tests` and `chrome_junit_tests`.
194
195When adding a new JUnit test, the associated `BUILD.gn` file must be updated.
196For example, adding a test to `chrome_junit_tests` requires to update
197`chrome/android/BUILD.gn`. If you are a GYP user, you will not need to do that
198step in order to run the test locally but it is still required for GN users to
199run the test.
200
201```shell
202# Build the test suite.
203ninja -C out/Release chrome_junit_tests
204
205# Run the test suite.
206build/android/test_runner.py junit -s chrome_junit_tests --release -vvv
207
208# Run a subset of tests. You might need to pass the package name for some tests.
209build/android/test_runner.py junit -s chrome_junit_tests --release -vvv
210-f "org.chromium.chrome.browser.media.*"
211```
212
andybons3322f762015-08-24 21:37:09213## Gtests
214
215```shell
216# Build a test suite
jbudorick25c17382016-08-03 18:53:07217ninja -C out/Release content_unittests
andybons3322f762015-08-24 21:37:09218
219# Run a test suite
jbudorick9472f112016-01-27 16:21:56220out/Release/bin/run_content_unittests [-vv]
andybons3322f762015-08-24 21:37:09221
222# Run a subset of tests
jbudorick9472f112016-01-27 16:21:56223out/Release/bin/run_content_unittests [-vv] --gtest-filter ByteStreamTest.*
andybons3322f762015-08-24 21:37:09224```
225
226## Instrumentation Tests
227
228In order to run instrumentation tests, you must leave your device screen ON and
229UNLOCKED. Otherwise, the test will timeout trying to launch an intent.
230Optionally you can disable screen lock under Settings -> Security -> Screen Lock
231-> None.
232
jbudorick9472f112016-01-27 16:21:56233Next, you need to build the app, build your tests, and then run your tests
234(which will install the APK under test and the test APK automatically).
andybons3322f762015-08-24 21:37:09235
236Examples:
237
238ContentShell tests:
239
240```shell
241# Build the code under test
242ninja -C out/Release content_shell_apk
243
244# Build the tests themselves
245ninja -C out/Release content_shell_test_apk
246
jbudorick9472f112016-01-27 16:21:56247# Run the test (will automagically install the APK under test and the test APK)
248out/Release/bin/run_content_shell_test_apk [-vv]
andybons3322f762015-08-24 21:37:09249```
250
newt17e4d242015-08-27 09:07:26251ChromePublic tests:
andybons3322f762015-08-24 21:37:09252
253```shell
254# Build the code under test
newt17e4d242015-08-27 09:07:26255ninja -C out/Release chrome_public_apk
andybons3322f762015-08-24 21:37:09256
257# Build the tests themselves
newt17e4d242015-08-27 09:07:26258ninja -C out/Release chrome_public_test_apk
andybons3322f762015-08-24 21:37:09259
jbudorick9472f112016-01-27 16:21:56260# Run the test (will automagically install the APK under test and the test APK)
261out/Release/bin/run_chrome_public_test_apk [-vv]
andybons3322f762015-08-24 21:37:09262```
263
264AndroidWebView tests:
265
266```shell
267ninja -C out/Release android_webview_apk
268ninja -C out/Release android_webview_test_apk
jbudorick9472f112016-01-27 16:21:56269out/Release/bin/run_android_webview_test_apk [-vv]
andybons3322f762015-08-24 21:37:09270```
271
jbudorick9472f112016-01-27 16:21:56272In order to run a subset of tests, use -f to filter based on test
andybons3322f762015-08-24 21:37:09273class/method or -A/-E to filter using annotations.
274
275Filtering examples:
276
277```shell
278# Run a test suite
jbudorick9472f112016-01-27 16:21:56279out/Debug/bin/run_content_shell_test_apk
andybons3322f762015-08-24 21:37:09280
281# Run a specific test class
jbudorick9472f112016-01-27 16:21:56282out/Debug/bin/run_content_shell_test_apk -f AddressDetectionTest.*
andybons3322f762015-08-24 21:37:09283
284# Run a specific test method
jbudorick9472f112016-01-27 16:21:56285out/Debug/bin/run_content_shell_test_apk -f \
andybons3322f762015-08-24 21:37:09286AddressDetectionTest#testAddressLimits
287
288# Run a subset of tests by size (Smoke, SmallTest, MediumTest, LargeTest,
289# EnormousTest)
jbudorick9472f112016-01-27 16:21:56290out/Debug/bin/run_content_shell_test_apk -A Smoke
andybons3322f762015-08-24 21:37:09291
292# Run a subset of tests by annotation, such as filtering by Feature
jbudorick9472f112016-01-27 16:21:56293out/Debug/bin/run_content_shell_test_apk -A Feature=Navigation
andybons3322f762015-08-24 21:37:09294```
295
296You might want to add stars `*` to each as a regular expression, e.g.
297`*`AddressDetectionTest`*`
298
299## Running Blink Layout Tests
300
301See
302https://sites.google.com/a/chromium.org/dev/developers/testing/webkit-layout-tests
303
304## Running GPU tests
305
306(e.g. the "Android Debug (Nexus 7)" bot on the chromium.gpu waterfall)
307
308See http://www.chromium.org/developers/testing/gpu-testing for details. Use
jbudorick25c17382016-08-03 18:53:07309`--browser=android-content-shell`. Examine the stdio from the test invocation on
310the bots to see arguments to pass to `src/content/test/gpu/run_gpu_test.py`.