Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 1 | # Atest Developer Workflow |
| 2 | |
| 3 | This document explains the practical steps for contributing code to atest. |
| 4 | |
| 5 | ##### Table of Contents |
| 6 | 1. [Identify the code you should work on](#identify-the-code-you-should-work-on) |
| 7 | 2. [Working on the Python Code](#working-on-the-python-code) |
| 8 | 3. [Working on the TradeFed Code](#working-on-the-tradefed-code) |
yangbill | fe4becb | 2020-04-08 11:58:15 +0800 | [diff] [blame] | 9 | 4. [Working on the VTS10-TradeFed Code](#working-on-the-vts10-tradefed-code) |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 10 | 5. [Working on the Robolectric Code](#working-on-the-robolectric-code) |
| 11 | |
| 12 | |
| 13 | ## <a name="what-code">Identify the code you should work on</a> |
| 14 | |
| 15 | Atest is essentially a wrapper around various test runners. Because of |
| 16 | this division, your first step should be to identify the code |
| 17 | involved with your change. This will help determine what tests you write |
| 18 | and run. Note that the wrapper code is written in python, so we'll be |
| 19 | referring to it as the "Python Code". |
| 20 | |
| 21 | ##### The Python Code |
| 22 | |
| 23 | This code defines atest's command line interface. |
| 24 | Its job is to translate user inputs into (1) build targets and (2) |
| 25 | information needed for the test runner to run the test. It then invokes |
| 26 | the appropriate test runner code to run the tests. As the tests |
| 27 | are run it also parses the test runner's output into the output seen by |
| 28 | the user. It uses Test Finder and Test Runner classes to do this work. |
| 29 | If your contribution involves any of this functionality, this is the |
| 30 | code you'll want to work on. |
| 31 | |
| 32 | <p>For more details on how this code works, checkout the following docs: |
| 33 | |
| 34 | - [General Structure](./atest_structure.md) |
| 35 | - [Test Finders](./develop_test_finders.md) |
| 36 | - [Test Runners](./develop_test_runners.md) |
| 37 | |
| 38 | ##### The Test Runner Code |
| 39 | |
| 40 | This is the code that actually runs the test. If your change |
| 41 | involves how the test is actually run, you'll need to work with this |
| 42 | code. |
| 43 | |
| 44 | Each test runner will have a different workflow. Atest currently |
| 45 | supports the following test runners: |
| 46 | - TradeFed |
yangbill | fe4becb | 2020-04-08 11:58:15 +0800 | [diff] [blame] | 47 | - VTS10-TradeFed |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 48 | - Robolectric |
| 49 | |
| 50 | |
| 51 | ## <a name="working-on-the-python-code">Working on the Python Code</a> |
| 52 | |
| 53 | ##### Where does the Python code live? |
| 54 | |
Jim Tang | d8e6bb0 | 2020-12-28 16:46:34 +0800 | [diff] [blame] | 55 | The python code lives here: `tools/asuite/atest/` |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 56 | (path relative to android repo root) |
| 57 | |
| 58 | ##### Writing tests |
| 59 | |
| 60 | Test files go in the same directory as the file being tested. The test |
| 61 | file should have the same name as the file it's testing, except it |
| 62 | should have "_unittests" appended to the name. For example, tests |
| 63 | for the logic in `cli_translator.py` go in the file |
| 64 | `cli_translator_unittests.py` in the same directory. |
| 65 | |
| 66 | |
| 67 | ##### Running tests |
| 68 | |
| 69 | Python tests are just python files executable by the Python interpreter. |
Jim Tang | 5020fe7 | 2021-09-06 15:05:51 +0800 | [diff] [blame] | 70 | You can use atest to run all unit tests via:<br> |
| 71 | |
| 72 | ``` |
| 73 | atest atest_unittests --host |
| 74 | ``` |
| 75 | |
| 76 | Alternatively, it is possible to run ALL the python tests by executing the |
| 77 | python script in the atest root dir:<br> |
| 78 | |
| 79 | ``` |
| 80 | croot <atest_dir> |
| 81 | ./atest_run_unittests.py |
| 82 | ``` |
| 83 | |
| 84 | To directly execute any individual unittest file, you'll need to first add |
| 85 | atest to your PYTHONPATH:<br> |
| 86 | |
| 87 | ```croot <atest_dir> |
| 88 | PYTHONPATH=.:$PYTHONPATH test_finders/module_finder_unittest.py |
| 89 | ``` |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 90 | |
| 91 | All tests should be passing before you submit your change. |
| 92 | |
| 93 | ## <a name="working-on-the-tradefed-code">Working on the TradeFed Code</a> |
| 94 | |
| 95 | ##### Where does the TradeFed code live? |
| 96 | |
| 97 | The TradeFed code lives here: |
| 98 | `tools/tradefederation/core/src/com/android/tradefed/` (path relative |
| 99 | to android repo root). |
| 100 | |
| 101 | The `testtype/suite/AtestRunner.java` is the most important file in |
| 102 | the TradeFed Code. It defines the TradeFed API used |
| 103 | by the Python Code, specifically by |
| 104 | `test_runners/atest_tf_test_runner.py`. This is the file you'll want |
| 105 | to edit if you need to make changes to the TradeFed code. |
| 106 | |
| 107 | |
| 108 | ##### Writing tests |
| 109 | |
| 110 | Tradefed test files live in a parallel `/tests/` file tree here: |
| 111 | `tools/tradefederation/core/tests/src/com/android/tradefed/`. |
| 112 | A test file should have the same name as the file it's testing, |
| 113 | except with the word "Test" appended to the end. <p> |
| 114 | For example, the tests for `tools/tradefederation/core/src/com/android/tradefed/testtype/suite/AtestRunner.java` |
| 115 | can be found in `tools/tradefederation/core/tests/src/com/android/tradefed/testtype/suite/AtestRunnerTest.java`. |
| 116 | |
| 117 | ##### Running tests |
| 118 | |
| 119 | TradeFed itself is used to run the TradeFed unittests so you'll need |
| 120 | to build TradeFed first. See the |
| 121 | [TradeFed README](../../README.md) for information about setting up |
| 122 | TradeFed. <p> |
| 123 | There are so many TradeFed tests that you'll probably want to |
| 124 | first run the test file your code change affected individually. The |
| 125 | command to run an individual test file is:<br> |
| 126 | |
Jim Tang | 5020fe7 | 2021-09-06 15:05:51 +0800 | [diff] [blame] | 127 | ``` |
| 128 | tradefed.sh run host -n --class <fully.qualified.ClassName> |
| 129 | ``` |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 130 | |
| 131 | Thus, to run all the tests in AtestRunnerTest.java, you'd enter: |
| 132 | |
Jim Tang | 5020fe7 | 2021-09-06 15:05:51 +0800 | [diff] [blame] | 133 | ``` |
| 134 | tradefed.sh run host -n --class com.android.tradefed.testtype.suite.AtestRunnerTest |
| 135 | ``` |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 136 | |
Jim Tang | 5020fe7 | 2021-09-06 15:05:51 +0800 | [diff] [blame] | 137 | To run ALL the TradeFed unittests:<br> |
| 138 | ``` |
| 139 | croot tools/tradefederation/core |
| 140 | javatests/run_tradefed_tests.sh |
| 141 | ``` |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 142 | |
| 143 | Before submitting code you should run all the TradeFed tests. |
| 144 | |
yangbill | fe4becb | 2020-04-08 11:58:15 +0800 | [diff] [blame] | 145 | ## <a name="working-on-the-vts10-tradefed-code">Working on the VTS10-TradeFed Code</a> |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 146 | |
Dan Shi | f1a4831 | 2020-04-01 13:00:52 -0700 | [diff] [blame] | 147 | ##### Where does the VTS10-TradeFed code live? |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 148 | |
Dan Shi | f1a4831 | 2020-04-01 13:00:52 -0700 | [diff] [blame] | 149 | The VTS10-Tradefed code lives here: `test/vts/tools/vts-tradefed/` |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 150 | (path relative to android repo root) |
| 151 | |
| 152 | ##### Writing tests |
| 153 | |
Dan Shi | f1a4831 | 2020-04-01 13:00:52 -0700 | [diff] [blame] | 154 | You shouldn't need to edit vts10-tradefed code, so there is no |
| 155 | need to write vts10 tests. Reach out to the vts team |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 156 | if you need information on their unittests. |
| 157 | |
| 158 | ##### Running tests |
| 159 | |
Dan Shi | f1a4831 | 2020-04-01 13:00:52 -0700 | [diff] [blame] | 160 | Again, you shouldn't need to change vts10-tradefed code. |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 161 | |
| 162 | ## <a name="working-on-the-robolectric-code">Working on the Robolectric Code</a> |
| 163 | |
| 164 | ##### Where does the Robolectric code live? |
| 165 | |
Jim Tang | 5020fe7 | 2021-09-06 15:05:51 +0800 | [diff] [blame] | 166 | The Robolectric code lives here: `prebuilts/misc/common/robolectric/4.3.1/` |
Jim Tang | dcbcc17 | 2019-11-25 17:21:28 +0800 | [diff] [blame] | 167 | (path relative to android repo root) |
| 168 | |