andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 1 | # Android Test Instructions |
| 2 | |
| 3 | Device Setup Tests are runnable on physical devices or emulators. See the |
| 4 | instructions below for setting up either a physical device or an emulator. |
| 5 | |
| 6 | [TOC] |
| 7 | |
| 8 | ## Physical Device Setup **ADB Debugging** |
| 9 | |
| 10 | In order to allow the ADB to connect to the device, you must enable USB |
| 11 | debugging: |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 12 | |
| 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". |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 24 | |
| 25 | ### Screen |
| 26 | |
| 27 | You MUST ensure that the screen stays on while testing: `adb shell svc power |
| 28 | stayon usb` Or do this manually on the device: Settings -> Developer options |
| 29 | -> Stay Awake. |
| 30 | |
| 31 | If this option is greyed out, stay awake is probably disabled by policy. In that |
| 32 | case, get another device or log in with a normal, unmanaged account (because the |
| 33 | tests will break in exciting ways if stay awake is off). |
| 34 | |
| 35 | ### Enable Asserts! |
| 36 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 37 | adb shell setprop debug.assert 1 |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 38 | |
| 39 | ### Disable Verify Apps |
| 40 | |
| 41 | You may see a dialog like |
| 42 | [this one](http://www.samsungmobileusa.com/simulators/ATT_GalaxyMega/mobile/screens/06-02_12.jpg), |
| 43 | which states, _Google may regularly check installed apps for potentially harmful |
| 44 | behavior._ 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 | |
| 51 | Use an emulator (i.e. Android Virtual Device, AVD): Enabling Intel's |
| 52 | Virtualizaton support provides the fastest, most reliable emulator configuration |
| 53 | available (i.e. x86 emulator with GPU acceleration and KVM support). |
thestig | f51ad75 | 2015-11-11 18:08:49 | [diff] [blame] | 54 | Remember to build with `target_arch=ia32` for x86. Otherwise installing the APKs |
| 55 | will fail with `INSTALL_FAILED_NO_MATCHING_ABIS`. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 56 | |
| 57 | 1. Enable Intel Virtualization support in the BIOS. |
| 58 | |
| 59 | 2. Set up your environment: |
| 60 | |
| 61 | ```shell |
| 62 | . build/android/envsetup.sh |
| 63 | ``` |
| 64 | |
| 65 | 3. Install emulator deps: |
| 66 | |
| 67 | ```shell |
thestig | f51ad75 | 2015-11-11 18:08:49 | [diff] [blame] | 68 | build/android/install_emulator_deps.py --api-level=23 |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 69 | ``` |
| 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 | |
| 77 | 4. Run the avd.py script. To start up _num_ emulators use -n. For non-x86 use |
| 78 | --abi. |
| 79 | |
| 80 | ```shell |
thestig | f51ad75 | 2015-11-11 18:08:49 | [diff] [blame] | 81 | build/android/avd.py --api-level=23 |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 82 | ``` |
| 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 | |
| 90 | Alternatively, you can create an run your own emulator using the tools provided |
| 91 | by the Android SDK. When doing so, be sure to enable GPU emulation in hardware |
| 92 | settings, since Chromium requires it to render. |
| 93 | |
| 94 | ## Building Tests |
| 95 | |
| 96 | It may not be immediately obvious where your test code gets compiled to, so here |
| 97 | are some general rules: |
| 98 | |
ruuda | b93325b | 2015-11-05 17:17:33 | [diff] [blame] | 99 | * If your test code lives under /base, it will be built as part of the |
| 100 | base_unittests_apk. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 101 | * If your test code lives under /content, it will probably be built as part of |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 102 | 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). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 106 | |
andybons | 22afb31 | 2015-08-31 02:24:51 | [diff] [blame] | 107 | 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. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 111 | |
| 112 | Once you know what to build, just do it like you normally would build anything |
newt | 17e4d24 | 2015-08-27 09:07:26 | [diff] [blame] | 113 | else, e.g.: `ninja -C out/Release chrome_public_test_apk` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 114 | |
| 115 | ## Running Tests |
| 116 | |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 117 | All functional tests are run using `build/android/test_runner.py`, either |
| 118 | directly or via a generated wrapper script in `<output directory>/bin/`. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 119 | Tests are sharded across all attached devices. In order to run tests, call: |
| 120 | `build/android/test_runner.py <test_type> [options]` |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 121 | (or `<generated wrapper script> [options]`). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 122 | For a list of valid test types, see `test_runner.py --help`. For |
| 123 | help on a specific test type, run `test_runner.py <test_type> --help`. |
| 124 | |
| 125 | The commands used by the buildbots are printed in the logs. Look at |
| 126 | http://build.chromium.org/ to duplicate the same test command as a particular |
| 127 | builder. |
| 128 | |
| 129 | If you build in an output directory other than "out", you may have to tell |
| 130 | test\_runner.py where you place it. Say you build your android code in |
| 131 | out\_android, then do `export CHROMIUM_OUT_DIR=out_android` before running the |
rouslan | edd6910 | 2015-09-21 23:54:54 | [diff] [blame] | 132 | command below. You have to do this even if your "out" directory is a symlink |
mlamouri | 0fbd6cd | 2015-10-26 12:08:11 | [diff] [blame] | 133 | pointing to "out_android". You can also use `--output-directory` to point to the |
| 134 | path of your output directory, for example, |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 135 | `--output-directory=out_android/Debug`. (The generated wrapper scripts handle |
| 136 | this automatically.) |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 137 | |
| 138 | ## INSTALL\_FAILED\_CONTAINER\_ERROR or INSTALL\_FAILED\_INSUFFICIENT\_STORAGE |
| 139 | |
| 140 | If you see this error when test\_runner.py is attempting to deploy the test |
| 141 | binaries to the AVD emulator, you may need to resize your userdata partition |
| 142 | with the following commands: |
| 143 | |
| 144 | ```shell |
davve | 7ae32cd | 2015-09-22 06:54:09 | [diff] [blame] | 145 | # Resize userdata partition to be 1G |
thestig | f51ad75 | 2015-11-11 18:08:49 | [diff] [blame] | 146 | resize2fs android_emulator_sdk/sdk/system-images/android-23/x86/userdata.img 1G |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 147 | |
| 148 | # Set filesystem parameter to continue on errors; Android doesn't like some |
| 149 | # things e2fsprogs does. |
thestig | f51ad75 | 2015-11-11 18:08:49 | [diff] [blame] | 150 | tune2fs -e continue android_emulator_sdk/sdk/system-images/android-23/x86/userdata.img |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 151 | ``` |
| 152 | |
| 153 | ## Symbolizing Crashes |
| 154 | |
| 155 | Crash stacks are logged and can be viewed using adb logcat. To symbolize the |
jyasskin | c1c76ff | 2015-12-18 21:39:52 | [diff] [blame] | 156 | traces, define `CHROMIUM_OUTPUT_DIR=$OUTDIR` where `$OUTDIR` is the argument you |
| 157 | pass to `ninja -C`, and pipe the output through |
| 158 | `third_party/android_platform/development/scripts/stack`. If |
| 159 | `$CHROMIUM_OUTPUT_DIR` is unset, the script will search `out/Debug` and |
| 160 | `out/Release`. For example: |
| 161 | |
| 162 | ```shell |
| 163 | # If you build with |
| 164 | ninja -C out/Debug chrome_public_test_apk |
| 165 | # You can run: |
| 166 | adb logcat -d | third_party/android_platform/development/scripts/stack |
| 167 | |
| 168 | # If you build with |
| 169 | ninja -C out/android chrome_public_test_apk |
| 170 | # You can run: |
| 171 | adb logcat -d | CHROMIUM_OUTPUT_DIR=out/android third_party/android_platform/development/scripts/stack |
| 172 | # or |
| 173 | export CHROMIUM_OUTPUT_DIR=out/android |
| 174 | adb logcat -d | third_party/android_platform/development/scripts/stack |
| 175 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 176 | |
mlamouri | 0fbd6cd | 2015-10-26 12:08:11 | [diff] [blame] | 177 | ## JUnit tests |
| 178 | |
| 179 | JUnit tests are Java unittests running on the host instead of the target device. |
| 180 | They are faster to run and therefore are recommended over instrumentation tests |
| 181 | when possible. |
| 182 | |
| 183 | The JUnits tests are usually following the pattern of *target*\_junit\_tests, |
| 184 | for example, `content_junit_tests` and `chrome_junit_tests`. |
| 185 | |
| 186 | When adding a new JUnit test, the associated `BUILD.gn` file must be updated. |
| 187 | For example, adding a test to `chrome_junit_tests` requires to update |
| 188 | `chrome/android/BUILD.gn`. If you are a GYP user, you will not need to do that |
| 189 | step in order to run the test locally but it is still required for GN users to |
| 190 | run the test. |
| 191 | |
| 192 | ```shell |
| 193 | # Build the test suite. |
| 194 | ninja -C out/Release chrome_junit_tests |
| 195 | |
| 196 | # Run the test suite. |
| 197 | build/android/test_runner.py junit -s chrome_junit_tests --release -vvv |
| 198 | |
| 199 | # Run a subset of tests. You might need to pass the package name for some tests. |
| 200 | build/android/test_runner.py junit -s chrome_junit_tests --release -vvv |
| 201 | -f "org.chromium.chrome.browser.media.*" |
| 202 | ``` |
| 203 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 204 | ## Gtests |
| 205 | |
| 206 | ```shell |
| 207 | # Build a test suite |
| 208 | ninja -C out/Release content_unittests_apk |
| 209 | |
| 210 | # Run a test suite |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 211 | out/Release/bin/run_content_unittests [-vv] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 212 | |
| 213 | # Run a subset of tests |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 214 | out/Release/bin/run_content_unittests [-vv] --gtest-filter ByteStreamTest.* |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 215 | ``` |
| 216 | |
| 217 | ## Instrumentation Tests |
| 218 | |
| 219 | In order to run instrumentation tests, you must leave your device screen ON and |
| 220 | UNLOCKED. Otherwise, the test will timeout trying to launch an intent. |
| 221 | Optionally you can disable screen lock under Settings -> Security -> Screen Lock |
| 222 | -> None. |
| 223 | |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 224 | Next, you need to build the app, build your tests, and then run your tests |
| 225 | (which will install the APK under test and the test APK automatically). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 226 | |
| 227 | Examples: |
| 228 | |
| 229 | ContentShell tests: |
| 230 | |
| 231 | ```shell |
| 232 | # Build the code under test |
| 233 | ninja -C out/Release content_shell_apk |
| 234 | |
| 235 | # Build the tests themselves |
| 236 | ninja -C out/Release content_shell_test_apk |
| 237 | |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 238 | # Run the test (will automagically install the APK under test and the test APK) |
| 239 | out/Release/bin/run_content_shell_test_apk [-vv] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 240 | ``` |
| 241 | |
newt | 17e4d24 | 2015-08-27 09:07:26 | [diff] [blame] | 242 | ChromePublic tests: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 243 | |
| 244 | ```shell |
| 245 | # Build the code under test |
newt | 17e4d24 | 2015-08-27 09:07:26 | [diff] [blame] | 246 | ninja -C out/Release chrome_public_apk |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 247 | |
| 248 | # Build the tests themselves |
newt | 17e4d24 | 2015-08-27 09:07:26 | [diff] [blame] | 249 | ninja -C out/Release chrome_public_test_apk |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 250 | |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 251 | # Run the test (will automagically install the APK under test and the test APK) |
| 252 | out/Release/bin/run_chrome_public_test_apk [-vv] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 253 | ``` |
| 254 | |
| 255 | AndroidWebView tests: |
| 256 | |
| 257 | ```shell |
| 258 | ninja -C out/Release android_webview_apk |
| 259 | ninja -C out/Release android_webview_test_apk |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 260 | out/Release/bin/run_android_webview_test_apk [-vv] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 261 | ``` |
| 262 | |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 263 | In order to run a subset of tests, use -f to filter based on test |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 264 | class/method or -A/-E to filter using annotations. |
| 265 | |
| 266 | Filtering examples: |
| 267 | |
| 268 | ```shell |
| 269 | # Run a test suite |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 270 | out/Debug/bin/run_content_shell_test_apk |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 271 | |
| 272 | # Run a specific test class |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 273 | out/Debug/bin/run_content_shell_test_apk -f AddressDetectionTest.* |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 274 | |
| 275 | # Run a specific test method |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 276 | out/Debug/bin/run_content_shell_test_apk -f \ |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 277 | AddressDetectionTest#testAddressLimits |
| 278 | |
| 279 | # Run a subset of tests by size (Smoke, SmallTest, MediumTest, LargeTest, |
| 280 | # EnormousTest) |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 281 | out/Debug/bin/run_content_shell_test_apk -A Smoke |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 282 | |
| 283 | # Run a subset of tests by annotation, such as filtering by Feature |
jbudorick | 9472f11 | 2016-01-27 16:21:56 | [diff] [blame^] | 284 | out/Debug/bin/run_content_shell_test_apk -A Feature=Navigation |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 285 | ``` |
| 286 | |
| 287 | You might want to add stars `*` to each as a regular expression, e.g. |
| 288 | `*`AddressDetectionTest`*` |
| 289 | |
| 290 | ## Running Blink Layout Tests |
| 291 | |
| 292 | See |
| 293 | https://sites.google.com/a/chromium.org/dev/developers/testing/webkit-layout-tests |
| 294 | |
| 295 | ## Running GPU tests |
| 296 | |
| 297 | (e.g. the "Android Debug (Nexus 7)" bot on the chromium.gpu waterfall) |
| 298 | |
| 299 | See http://www.chromium.org/developers/testing/gpu-testing for details. Use |
| 300 | --browser=android-content-shell. Examine the stdio from the test invocation on |
| 301 | the bots to see arguments to pass to src/content/test/gpu/run\_gpu\_test.py. |