1*9c5db199SXin Li# test\_droid: Quick Primer 2*9c5db199SXin Li 3*9c5db199SXin Li## References 4*9c5db199SXin Li 5*9c5db199SXin Li[Autotest Best Practices](best-practices.md) 6*9c5db199SXin Li 7*9c5db199SXin Li[test\_that Basic Usage](test-that.md) 8*9c5db199SXin Li 9*9c5db199SXin Li## Objective 10*9c5db199SXin LiThis document contains instructions for Brillo/Android developers interested in 11*9c5db199SXin Lirunning automated integration tests at their desk. 12*9c5db199SXin Li 13*9c5db199SXin Li## Usage 14*9c5db199SXin LiThe autotest repository, the `test_droid` tool, and all tests are checked out 15*9c5db199SXin Liin both AOSP and internal Android trees at external/autotest. You need a copy 16*9c5db199SXin Liof the autotest source code and an `adb` binary in your PATH to run tests. 17*9c5db199SXin Li 18*9c5db199SXin Li### Running tests against a single local device under test 19*9c5db199SXin LiOnce you have a local copy of the autotest source, you can easily run tests 20*9c5db199SXin Liagainst a DUT connected directly to your workstation via a USB cable. Please 21*9c5db199SXin Linote your first time running `test_droid` it will download and install a number 22*9c5db199SXin Liof required packages locally into your autotest checkout. 23*9c5db199SXin Li 24*9c5db199SXin LiRun site\_utils/test\_droid.py from your autotest checkout to launch a test 25*9c5db199SXin Liagainst a given DUT: 26*9c5db199SXin Li 27*9c5db199SXin Li``` 28*9c5db199SXin Li $ ./site_utils/test_droid.py <Test Name> 29*9c5db199SXin Li``` 30*9c5db199SXin Li 31*9c5db199SXin LiFor example, to run the brillo\_WhitelistedGtests test: 32*9c5db199SXin Li 33*9c5db199SXin Li``` 34*9c5db199SXin Li $ ./site_utils/test_droid.py brillo_WhitelistedGtests 35*9c5db199SXin Li``` 36*9c5db199SXin Li 37*9c5db199SXin Li`test_droid` can run multiple tests at once: 38*9c5db199SXin Li 39*9c5db199SXin Li``` 40*9c5db199SXin Li $ ./site_utils/test_droid.py brillo_WhitelistedGtests brillo_KernelVersionTest 41*9c5db199SXin Li``` 42*9c5db199SXin Li 43*9c5db199SXin LiAs well as test suites: 44*9c5db199SXin Li 45*9c5db199SXin Li``` 46*9c5db199SXin Li $ ./site_utils/test_droid.py suite:brillo-bvt 47*9c5db199SXin Li``` 48*9c5db199SXin Li 49*9c5db199SXin Li#### Selecting a specific device 50*9c5db199SXin LiIf you have more than one device connected, you'll have to specify its serial 51*9c5db199SXin Linumber. First, look it up: 52*9c5db199SXin Li 53*9c5db199SXin Li``` 54*9c5db199SXin Li $ adb devices 55*9c5db199SXin Li* daemon started successfully * 56*9c5db199SXin LiList of devices attached 57*9c5db199SXin Li7d52318 device 58*9c5db199SXin Li``` 59*9c5db199SXin Li 60*9c5db199SXin LiThen use it when running: 61*9c5db199SXin Li 62*9c5db199SXin Li``` 63*9c5db199SXin Li $ ./site_utils/test_droid.py -s 7d52318 brillo_WhitelistedGtests 64*9c5db199SXin Li``` 65*9c5db199SXin Li 66*9c5db199SXin Li### Running tests that require multiple devices under test 67*9c5db199SXin LiAutotest now supports the concept of testbeds, which are multiple devices being 68*9c5db199SXin Licontrolled by a single test. `test_droid` supports running these tests 69*9c5db199SXin Liby specifying a comma separated list of serials as the test device: 70*9c5db199SXin Li 71*9c5db199SXin Li``` 72*9c5db199SXin Li $ adb devices 73*9c5db199SXin LiList of devices attached 74*9c5db199SXin Liemulator-5554 device 75*9c5db199SXin Li7d52318 device 76*9c5db199SXin Li 77*9c5db199SXin Li $ ./site_utils/test_droid.py -s emulator-5554,7d52318 testbed_DummyTest 78*9c5db199SXin Li``` 79*9c5db199SXin Li 80*9c5db199SXin Li### Running tests against a remote device under test 81*9c5db199SXin Li`test_droid` can run tests against devices connected to a remote server. This 82*9c5db199SXin Lirequires passwordless SSH access from the workstation to the remote server. 83*9c5db199SXin LiIf no username is specified, `test_droid` will try the root and adb users. 84*9c5db199SXin LiIf using the adb user, make sure it has passwordless sudo 85*9c5db199SXin Lirights to run the adb and fastboot commands. You can specify a 86*9c5db199SXin Lidifferent user in the remote host name (the same passwordless requirement 87*9c5db199SXin Liapplies). 88*9c5db199SXin Li 89*9c5db199SXin LiThe easiest way to set this up is to use the 90*9c5db199SXin Li[ChromeOS testing keys](https://www.chromium.org/chromium-os/testing/autotest-developer-faq/ssh-test-keys-setup). 91*9c5db199SXin LiAdd to your SSH config an entry that looks like the following: 92*9c5db199SXin Li 93*9c5db199SXin Li``` 94*9c5db199SXin LiHostName <Remote Server IP or Hostname> 95*9c5db199SXin Li Port 9222 96*9c5db199SXin Li User root 97*9c5db199SXin Li CheckHostIP no 98*9c5db199SXin Li StrictHostKeyChecking no 99*9c5db199SXin Li IdentityFile ~/.ssh/testing_rsa 100*9c5db199SXin Li Protocol 2 101*9c5db199SXin Li``` 102*9c5db199SXin Li 103*9c5db199SXin LiTo run the test: 104*9c5db199SXin Li 105*9c5db199SXin Li``` 106*9c5db199SXin Li $ ./site_utils/test_droid.py \ 107*9c5db199SXin Li -r <Remote Server IP or Hostname> \ 108*9c5db199SXin Li <Test Name> 109*9c5db199SXin Li 110*9c5db199SXin Li $ ./site_utils/test_droid.py \ 111*9c5db199SXin Li -r <User>@<Remote Server IP or Hostname> \ 112*9c5db199SXin Li <Test Name> 113*9c5db199SXin Li 114*9c5db199SXin Li $ ./site_utils/test_droid.py -r 100.96.48.119 suite:brillo-bvt 115*9c5db199SXin Li``` 116*9c5db199SXin Li 117*9c5db199SXin Li### Advanced: Uploading Commits for Review 118*9c5db199SXin LiCurrently Autotest in AOSP is read-only, so you cannot use repo upload to 119*9c5db199SXin Liupload code changes. If you do edit or add a new test, make a commit and upload 120*9c5db199SXin Liit to https://chromium-review.googlesource.com. 121*9c5db199SXin Li 122*9c5db199SXin LiDue to the way Android does its automerging, the AOSP mirror of Autotest cannot 123*9c5db199SXin Libe uploaded directly back to the Chromium upstream because the upstream does not 124*9c5db199SXin Licontain the merge commits. It will also reject the automerge committer ID. 125*9c5db199SXin LiTo work around this, if you need to upload a commit to Autotest, you first have 126*9c5db199SXin Lito fetch and check out the upstream branch before making your changes: 127*9c5db199SXin Li 128*9c5db199SXin Li``` 129*9c5db199SXin Li $ git remote add -t master cros \ 130*9c5db199SXin Li https://chromium.googlesource.com/chromiumos/third_party/autotest 131*9c5db199SXin Li $ git fetch cros 132*9c5db199SXin Li $ git checkout cros/master 133*9c5db199SXin Li $ git checkout -b <local branch name> 134*9c5db199SXin Li $ git branch --set-upstream-to=cros/master 135*9c5db199SXin Li``` 136*9c5db199SXin Li 137*9c5db199SXin LiBe sure to run pylint on every file you touch: 138*9c5db199SXin Li 139*9c5db199SXin Li``` 140*9c5db199SXin Li $ ./utils/run_pylint.py <file name> 141*9c5db199SXin Li``` 142*9c5db199SXin Li 143*9c5db199SXin LiRun autotest unittests (which usually requires external packages): 144*9c5db199SXin Li 145*9c5db199SXin Li``` 146*9c5db199SXin Li $ utils/build_externals.py # install any missing os packages with apt-get 147*9c5db199SXin Li $ utils/unittest_suite.py 148*9c5db199SXin Li``` 149*9c5db199SXin Li 150*9c5db199SXin LiThen upload your commit for review: 151*9c5db199SXin Li 152*9c5db199SXin Li``` 153*9c5db199SXin Li $ git push cros <local branch name>:refs/for/master 154*9c5db199SXin Li``` 155*9c5db199SXin Li 156*9c5db199SXin Li## Limitations 157*9c5db199SXin Li 158*9c5db199SXin LiTesting on Brillo/Android (and `test_droid` by extension) is currently limited 159*9c5db199SXin Lito server-side tests, which run on an autotest server and control a 160*9c5db199SXin LiBrillo/Android DUT (device under test) via remote command execution. In the 161*9c5db199SXin Licontext of `test_droid`, the test logic is running on your development machine, 162*9c5db199SXin Liand controlling devices with commands executed via `adb`. 163*9c5db199SXin Li 164*9c5db199SXin Li`test_droid` does not support the autoupdate end-to-end test. For instructions 165*9c5db199SXin Lion how to run this test please refer to the Running Brillo/Android Autoupdate 166*9c5db199SXin LiEnd-to-End Test doc. 167