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