blob: 616a970b63b5ce8dc664a719643d69010987f6d3 [file] [log] [blame] [view]
andybons3322f762015-08-24 21:37:091# Android Test Instructions
2
3Device Setup Tests are runnable on physical devices or emulators. See the
4instructions below for setting up either a physical device or an emulator.
5
6[TOC]
7
8## Physical Device Setup **ADB Debugging**
9
10In order to allow the ADB to connect to the device, you must enable USB
11debugging:
andybons22afb312015-08-31 02:24:5112
13* Before Android 4.1 (Jelly Bean):
14 * Go to "System Settings"
15 * Go to "Developer options"
16 * Check "USB debugging".
17 * Un-check "Verify apps over USB".
18* On Jelly Bean, developer options are hidden by default. To unhide them:
19 * Go to "About phone"
20 * Tap 10 times on "Build number"
21 * The "Developer options" menu will now be available.
22 * Check "USB debugging".
23 * Un-check "Verify apps over USB".
andybons3322f762015-08-24 21:37:0924
25### Screen
26
27You MUST ensure that the screen stays on while testing: `adb shell svc power
28stayon usb` Or do this manually on the device: Settings -> Developer options
29-> Stay Awake.
30
31If this option is greyed out, stay awake is probably disabled by policy. In that
32case, get another device or log in with a normal, unmanaged account (because the
33tests will break in exciting ways if stay awake is off).
34
35### Enable Asserts!
36
andybons22afb312015-08-31 02:24:5137 adb shell setprop debug.assert 1
andybons3322f762015-08-24 21:37:0938
39### Disable Verify Apps
40
41You may see a dialog like
42[this one](http://www.samsungmobileusa.com/simulators/ATT_GalaxyMega/mobile/screens/06-02_12.jpg),
43which states, _Google may regularly check installed apps for potentially harmful
44behavior._ This can interfere with the test runner. To disable this dialog, run:
45`adb shell settings put global package_verifier_enable 0`
46
47## Emulator Setup
48
49### Option 1:
50
51Use an emulator (i.e. Android Virtual Device, AVD): Enabling Intel's
52Virtualizaton support provides the fastest, most reliable emulator configuration
53available (i.e. x86 emulator with GPU acceleration and KVM support).
thestigf51ad752015-11-11 18:08:4954Remember to build with `target_arch=ia32` for x86. Otherwise installing the APKs
55will fail with `INSTALL_FAILED_NO_MATCHING_ABIS`.
andybons3322f762015-08-24 21:37:0956
571. Enable Intel Virtualization support in the BIOS.
58
592. Set up your environment:
60
61 ```shell
62 . build/android/envsetup.sh
63 ```
64
653. Install emulator deps:
66
67 ```shell
thestigf51ad752015-11-11 18:08:4968 build/android/install_emulator_deps.py --api-level=23
andybons3322f762015-08-24 21:37:0969 ```
70
71 This script will download Android SDK and place it a directory called
72 android\_tools in the same parent directory as your chromium checkout. It
73 will also download the system-images for the emulators (i.e. arm and x86).
74 Note that this is a different SDK download than the Android SDK in the
75 chromium source checkout (i.e. src/third\_party/android\_emulator\_sdk).
76
774. Run the avd.py script. To start up _num_ emulators use -n. For non-x86 use
78 --abi.
79
80 ```shell
thestigf51ad752015-11-11 18:08:4981 build/android/avd.py --api-level=23
andybons3322f762015-08-24 21:37:0982 ```
83
84 This script will attempt to use GPU emulation, so you must be running the
85 emulators in an environment with hardware rendering available. See
86 `avd.py --help` for more details.
87
88### Option 2:
89
90Alternatively, you can create an run your own emulator using the tools provided
91by the Android SDK. When doing so, be sure to enable GPU emulation in hardware
92settings, since Chromium requires it to render.
93
94## Building Tests
95
96It may not be immediately obvious where your test code gets compiled to, so here
97are some general rules:
98
ruudab93325b2015-11-05 17:17:3399* If your test code lives under /base, it will be built as part of the
100 base_unittests_apk.
andybons3322f762015-08-24 21:37:09101* If your test code lives under /content, it will probably be built as part of
andybons22afb312015-08-31 02:24:51102 the content_shell_test_apk
103* If your test code lives under /chrome (or higher), it will probably be built
104 as part of the chrome_public_test_apk
105* (Please fill in more details here if you know them).
andybons3322f762015-08-24 21:37:09106
andybons22afb312015-08-31 02:24:51107 NB: We used to call the chrome_public_test_apk the
108 chromium_shell_test_apk. There may still be references to this kicking
109 around, but wherever you see chromium_shell_test you should replace with
110 chrome_public_test.
andybons3322f762015-08-24 21:37:09111
112Once you know what to build, just do it like you normally would build anything
newt17e4d242015-08-27 09:07:26113else, e.g.: `ninja -C out/Release chrome_public_test_apk`
andybons3322f762015-08-24 21:37:09114
115## Running Tests
116
117All functional tests are run using `build/android/test_runner.py`.
118Tests are sharded across all attached devices. In order to run tests, call:
119`build/android/test_runner.py <test_type> [options]`
120For a list of valid test types, see `test_runner.py --help`. For
121help on a specific test type, run `test_runner.py <test_type> --help`.
122
123The commands used by the buildbots are printed in the logs. Look at
124http://build.chromium.org/ to duplicate the same test command as a particular
125builder.
126
127If you build in an output directory other than "out", you may have to tell
128test\_runner.py where you place it. Say you build your android code in
129out\_android, then do `export CHROMIUM_OUT_DIR=out_android` before running the
rouslanedd69102015-09-21 23:54:54130command below. You have to do this even if your "out" directory is a symlink
mlamouri0fbd6cd2015-10-26 12:08:11131pointing to "out_android". You can also use `--output-directory` to point to the
132path of your output directory, for example,
133`--output-directory=out_android/Debug`.
andybons3322f762015-08-24 21:37:09134
135## INSTALL\_FAILED\_CONTAINER\_ERROR or INSTALL\_FAILED\_INSUFFICIENT\_STORAGE
136
137If you see this error when test\_runner.py is attempting to deploy the test
138binaries to the AVD emulator, you may need to resize your userdata partition
139with the following commands:
140
141```shell
davve7ae32cd2015-09-22 06:54:09142# Resize userdata partition to be 1G
thestigf51ad752015-11-11 18:08:49143resize2fs android_emulator_sdk/sdk/system-images/android-23/x86/userdata.img 1G
andybons3322f762015-08-24 21:37:09144
145# Set filesystem parameter to continue on errors; Android doesn't like some
146# things e2fsprogs does.
thestigf51ad752015-11-11 18:08:49147tune2fs -e continue android_emulator_sdk/sdk/system-images/android-23/x86/userdata.img
andybons3322f762015-08-24 21:37:09148```
149
150## Symbolizing Crashes
151
152Crash stacks are logged and can be viewed using adb logcat. To symbolize the
jyasskinc1c76ff2015-12-18 21:39:52153traces, define `CHROMIUM_OUTPUT_DIR=$OUTDIR` where `$OUTDIR` is the argument you
154pass to `ninja -C`, and pipe the output through
155`third_party/android_platform/development/scripts/stack`. If
156`$CHROMIUM_OUTPUT_DIR` is unset, the script will search `out/Debug` and
157`out/Release`. For example:
158
159```shell
160# If you build with
161ninja -C out/Debug chrome_public_test_apk
162# You can run:
163adb logcat -d | third_party/android_platform/development/scripts/stack
164
165# If you build with
166ninja -C out/android chrome_public_test_apk
167# You can run:
168adb logcat -d | CHROMIUM_OUTPUT_DIR=out/android third_party/android_platform/development/scripts/stack
169# or
170export CHROMIUM_OUTPUT_DIR=out/android
171adb logcat -d | third_party/android_platform/development/scripts/stack
172```
andybons3322f762015-08-24 21:37:09173
mlamouri0fbd6cd2015-10-26 12:08:11174## JUnit tests
175
176JUnit tests are Java unittests running on the host instead of the target device.
177They are faster to run and therefore are recommended over instrumentation tests
178when possible.
179
180The JUnits tests are usually following the pattern of *target*\_junit\_tests,
181for example, `content_junit_tests` and `chrome_junit_tests`.
182
183When adding a new JUnit test, the associated `BUILD.gn` file must be updated.
184For example, adding a test to `chrome_junit_tests` requires to update
185`chrome/android/BUILD.gn`. If you are a GYP user, you will not need to do that
186step in order to run the test locally but it is still required for GN users to
187run the test.
188
189```shell
190# Build the test suite.
191ninja -C out/Release chrome_junit_tests
192
193# Run the test suite.
194build/android/test_runner.py junit -s chrome_junit_tests --release -vvv
195
196# Run a subset of tests. You might need to pass the package name for some tests.
197build/android/test_runner.py junit -s chrome_junit_tests --release -vvv
198-f "org.chromium.chrome.browser.media.*"
199```
200
andybons3322f762015-08-24 21:37:09201## Gtests
202
203```shell
204# Build a test suite
205ninja -C out/Release content_unittests_apk
206
207# Run a test suite
208build/android/test_runner.py gtest -s content_unittests --release -vvv
209
210# Run a subset of tests
211build/android/test_runner.py gtest -s content_unittests --release -vvv \
212--gtest-filter ByteStreamTest.*
213```
214
215## Instrumentation Tests
216
217In order to run instrumentation tests, you must leave your device screen ON and
218UNLOCKED. Otherwise, the test will timeout trying to launch an intent.
219Optionally you can disable screen lock under Settings -> Security -> Screen Lock
220-> None.
221
222Next, you need to build the app, build your tests, install the application APK,
223and then run your tests (which will install the test APK automatically).
224
225Examples:
226
227ContentShell tests:
228
229```shell
230# Build the code under test
231ninja -C out/Release content_shell_apk
232
233# Build the tests themselves
234ninja -C out/Release content_shell_test_apk
235
236# Install the code under test
237build/android/adb_install_apk.py out/Release/apks/ContentShell.apk
238
239# Run the test (will automagically install the test APK)
240build/android/test_runner.py instrumentation --test-apk=ContentShellTest \
241--isolate-file-path content/content_shell_test_apk.isolate --release -vv
242```
243
newt17e4d242015-08-27 09:07:26244ChromePublic tests:
andybons3322f762015-08-24 21:37:09245
246```shell
247# Build the code under test
newt17e4d242015-08-27 09:07:26248ninja -C out/Release chrome_public_apk
andybons3322f762015-08-24 21:37:09249
250# Build the tests themselves
newt17e4d242015-08-27 09:07:26251ninja -C out/Release chrome_public_test_apk
andybons3322f762015-08-24 21:37:09252
253# Install the code under test
newt17e4d242015-08-27 09:07:26254build/android/adb_install_apk.py out/Release/apks/ChromePublic.apk
andybons3322f762015-08-24 21:37:09255
256# Run the test (will automagically install the test APK)
newt17e4d242015-08-27 09:07:26257build/android/test_runner.py instrumentation --test-apk=ChromePublicTest \
258--isolate-file-path chrome/chrome_public_test_apk.isolate --release -vv
andybons3322f762015-08-24 21:37:09259```
260
261AndroidWebView tests:
262
263```shell
264ninja -C out/Release android_webview_apk
265ninja -C out/Release android_webview_test_apk
266build/android/adb_install_apk.py out/Release/apks/AndroidWebView.apk \
267build/android/test_runner.py instrumentation --test-apk=AndroidWebViewTest \
268--test_data webview:android_webview/test/data/device_files --release -vvv
269```
270
271Use adb\_install\_apk.py to install the app under test, then run the test
272command. In order to run a subset of tests, use -f to filter based on test
273class/method or -A/-E to filter using annotations.
274
275Filtering examples:
276
277```shell
278# Run a test suite
279build/android/test_runner.py instrumentation --test-apk=ContentShellTest
280
281# Run a specific test class
282build/android/test_runner.py instrumentation --test-apk=ContentShellTest -f \
283AddressDetectionTest
284
285# Run a specific test method
286build/android/test_runner.py instrumentation --test-apk=ContentShellTest -f \
287AddressDetectionTest#testAddressLimits
288
289# Run a subset of tests by size (Smoke, SmallTest, MediumTest, LargeTest,
290# EnormousTest)
291build/android/test_runner.py instrumentation --test-apk=ContentShellTest -A \
292Smoke
293
294# Run a subset of tests by annotation, such as filtering by Feature
295build/android/test_runner.py instrumentation --test-apk=ContentShellTest -A \
296Feature=Navigation
297```
298
299You might want to add stars `*` to each as a regular expression, e.g.
300`*`AddressDetectionTest`*`
301
302## Running Blink Layout Tests
303
304See
305https://sites.google.com/a/chromium.org/dev/developers/testing/webkit-layout-tests
306
307## Running GPU tests
308
309(e.g. the "Android Debug (Nexus 7)" bot on the chromium.gpu waterfall)
310
311See http://www.chromium.org/developers/testing/gpu-testing for details. Use
312--browser=android-content-shell. Examine the stdio from the test invocation on
313the bots to see arguments to pass to src/content/test/gpu/run\_gpu\_test.py.