blob: 47959e5aa7e6ec29a3b245331eda6885071a0b29 [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:
12 * Before Android 4.1 (Jelly Bean):
13 * Go to "System Settings"
14 * Go to "Developer options"
15 * Check "USB debugging".
16 * Un-check "Verify apps over USB".
17 * On Jelly Bean, developer options are hidden by default. To unhide them:
18 * Go to "About phone"
19 * Tap 10 times on "Build number"
20 * The "Developer options" menu will now be available.
21 * Check "USB debugging".
22 * Un-check "Verify apps over USB".
23
24### Screen
25
26You MUST ensure that the screen stays on while testing: `adb shell svc power
27stayon usb` Or do this manually on the device: Settings -> Developer options
28-> Stay Awake.
29
30If this option is greyed out, stay awake is probably disabled by policy. In that
31case, get another device or log in with a normal, unmanaged account (because the
32tests will break in exciting ways if stay awake is off).
33
34### Enable Asserts!
35
36`adb shell setprop debug.assert 1`
37
38### Disable Verify Apps
39
40You may see a dialog like
41[this one](http://www.samsungmobileusa.com/simulators/ATT_GalaxyMega/mobile/screens/06-02_12.jpg),
42which states, _Google may regularly check installed apps for potentially harmful
43behavior._ This can interfere with the test runner. To disable this dialog, run:
44`adb shell settings put global package_verifier_enable 0`
45
46## Emulator Setup
47
48### Option 1:
49
50Use an emulator (i.e. Android Virtual Device, AVD): Enabling Intel's
51Virtualizaton support provides the fastest, most reliable emulator configuration
52available (i.e. x86 emulator with GPU acceleration and KVM support).
53
541. Enable Intel Virtualization support in the BIOS.
55
562. Set up your environment:
57
58 ```shell
59 . build/android/envsetup.sh
60 ```
61
623. Install emulator deps:
63
64 ```shell
65 build/android/install_emulator_deps.py --api-level=19
66 ```
67
68 This script will download Android SDK and place it a directory called
69 android\_tools in the same parent directory as your chromium checkout. It
70 will also download the system-images for the emulators (i.e. arm and x86).
71 Note that this is a different SDK download than the Android SDK in the
72 chromium source checkout (i.e. src/third\_party/android\_emulator\_sdk).
73
744. Run the avd.py script. To start up _num_ emulators use -n. For non-x86 use
75 --abi.
76
77 ```shell
78 build/android/avd.py --api-level=19
79 ```
80
81 This script will attempt to use GPU emulation, so you must be running the
82 emulators in an environment with hardware rendering available. See
83 `avd.py --help` for more details.
84
85### Option 2:
86
87Alternatively, you can create an run your own emulator using the tools provided
88by the Android SDK. When doing so, be sure to enable GPU emulation in hardware
89settings, since Chromium requires it to render.
90
91## Building Tests
92
93It may not be immediately obvious where your test code gets compiled to, so here
94are some general rules:
95
96* If your test code lives under /content, it will probably be built as part of
97 the content\_shell\_test\_apk * If your test code lives under /chrome (or
98 higher), it will probably be built as part of the chrome\_shell\_test\_apk *
99 (Please fill in more details here if you know them).
100
101 NB: We used to call the chrome\_shell\_test\_apk the
102 chromium\_shell\_test\_apk. There may still be references to this kicking
103 around, but wherever you see chromium\_shell\_test you should replace with
104 chrome\_shell\_test.
105
106Once you know what to build, just do it like you normally would build anything
107else, e.g.: `ninja -C out/Release chrome_shell_test_apk`
108
109## Running Tests
110
111All functional tests are run using `build/android/test_runner.py`.
112Tests are sharded across all attached devices. In order to run tests, call:
113`build/android/test_runner.py <test_type> [options]`
114For a list of valid test types, see `test_runner.py --help`. For
115help on a specific test type, run `test_runner.py <test_type> --help`.
116
117The commands used by the buildbots are printed in the logs. Look at
118http://build.chromium.org/ to duplicate the same test command as a particular
119builder.
120
121If you build in an output directory other than "out", you may have to tell
122test\_runner.py where you place it. Say you build your android code in
123out\_android, then do `export CHROMIUM_OUT_DIR=out_android` before running the
124command below.
125
126## INSTALL\_FAILED\_CONTAINER\_ERROR or INSTALL\_FAILED\_INSUFFICIENT\_STORAGE
127
128If you see this error when test\_runner.py is attempting to deploy the test
129binaries to the AVD emulator, you may need to resize your userdata partition
130with the following commands:
131
132```shell
133# Resize userdata partition to be 1G resize2fs
134android_emulator_sdk/sdk/system-images/android-19/x86/userdata.img 1G
135
136# Set filesystem parameter to continue on errors; Android doesn't like some
137# things e2fsprogs does.
138tune2fs -e continue
139android_emulator_sdk/sdk/system-images/android-19/x86/userdata.img
140```
141
142## Symbolizing Crashes
143
144Crash stacks are logged and can be viewed using adb logcat. To symbolize the
145traces, pipe the output through
146`third_party/android_platform/development/scripts/stack`. If you build in an
147output directory other than "out", pass
148`--chrome-symbols-dir=out_directory/{Debug,Release}/lib` to the script as well.
149
150## Gtests
151
152```shell
153# Build a test suite
154ninja -C out/Release content_unittests_apk
155
156# Run a test suite
157build/android/test_runner.py gtest -s content_unittests --release -vvv
158
159# Run a subset of tests
160build/android/test_runner.py gtest -s content_unittests --release -vvv \
161--gtest-filter ByteStreamTest.*
162```
163
164## Instrumentation Tests
165
166In order to run instrumentation tests, you must leave your device screen ON and
167UNLOCKED. Otherwise, the test will timeout trying to launch an intent.
168Optionally you can disable screen lock under Settings -> Security -> Screen Lock
169-> None.
170
171Next, you need to build the app, build your tests, install the application APK,
172and then run your tests (which will install the test APK automatically).
173
174Examples:
175
176ContentShell tests:
177
178```shell
179# Build the code under test
180ninja -C out/Release content_shell_apk
181
182# Build the tests themselves
183ninja -C out/Release content_shell_test_apk
184
185# Install the code under test
186build/android/adb_install_apk.py out/Release/apks/ContentShell.apk
187
188# Run the test (will automagically install the test APK)
189build/android/test_runner.py instrumentation --test-apk=ContentShellTest \
190--isolate-file-path content/content_shell_test_apk.isolate --release -vv
191```
192
193ChromeShell tests:
194
195```shell
196# Build the code under test
197ninja -C out/Release chrome_shell_apk
198
199# Build the tests themselves
200ninja -C out/Release chrome_shell_test_apk
201
202# Install the code under test
203build/android/adb_install_apk.py out/Release/apks/ChromeShell.apk
204
205# Run the test (will automagically install the test APK)
206build/android/test_runner.py instrumentation --test-apk=ChromeShellTest \
207--isolate-file-path chrome/chrome_shell_test_apk.isolate --release -vv
208```
209
210AndroidWebView tests:
211
212```shell
213ninja -C out/Release android_webview_apk
214ninja -C out/Release android_webview_test_apk
215build/android/adb_install_apk.py out/Release/apks/AndroidWebView.apk \
216build/android/test_runner.py instrumentation --test-apk=AndroidWebViewTest \
217--test_data webview:android_webview/test/data/device_files --release -vvv
218```
219
220Use adb\_install\_apk.py to install the app under test, then run the test
221command. In order to run a subset of tests, use -f to filter based on test
222class/method or -A/-E to filter using annotations.
223
224Filtering examples:
225
226```shell
227# Run a test suite
228build/android/test_runner.py instrumentation --test-apk=ContentShellTest
229
230# Run a specific test class
231build/android/test_runner.py instrumentation --test-apk=ContentShellTest -f \
232AddressDetectionTest
233
234# Run a specific test method
235build/android/test_runner.py instrumentation --test-apk=ContentShellTest -f \
236AddressDetectionTest#testAddressLimits
237
238# Run a subset of tests by size (Smoke, SmallTest, MediumTest, LargeTest,
239# EnormousTest)
240build/android/test_runner.py instrumentation --test-apk=ContentShellTest -A \
241Smoke
242
243# Run a subset of tests by annotation, such as filtering by Feature
244build/android/test_runner.py instrumentation --test-apk=ContentShellTest -A \
245Feature=Navigation
246```
247
248You might want to add stars `*` to each as a regular expression, e.g.
249`*`AddressDetectionTest`*`
250
251## Running Blink Layout Tests
252
253See
254https://sites.google.com/a/chromium.org/dev/developers/testing/webkit-layout-tests
255
256## Running GPU tests
257
258(e.g. the "Android Debug (Nexus 7)" bot on the chromium.gpu waterfall)
259
260See http://www.chromium.org/developers/testing/gpu-testing for details. Use
261--browser=android-content-shell. Examine the stdio from the test invocation on
262the bots to see arguments to pass to src/content/test/gpu/run\_gpu\_test.py.