xref: /aosp_15_r20/tools/asuite/atest/docs/atest_structure.md (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1*c2e18aaaSAndroid Build Coastguard Worker# Atest Developer Guide
2*c2e18aaaSAndroid Build Coastguard Worker
3*c2e18aaaSAndroid Build Coastguard WorkerYou're here because you'd like to contribute to atest. To start off, we'll
4*c2e18aaaSAndroid Build Coastguard Workerexplain how atest is structured and where the major pieces live and what they
5*c2e18aaaSAndroid Build Coastguard Workerdo. If you're more interested in how to use atest, go to the [README](../README.md).
6*c2e18aaaSAndroid Build Coastguard Worker
7*c2e18aaaSAndroid Build Coastguard Worker##### Table of Contents
8*c2e18aaaSAndroid Build Coastguard Worker1. [Overall Structure](#overall-structure)
9*c2e18aaaSAndroid Build Coastguard Worker2. [Major Files and Dirs](#major-files-and-dirs)
10*c2e18aaaSAndroid Build Coastguard Worker3. [Test Finders](#test-finders)
11*c2e18aaaSAndroid Build Coastguard Worker4. [Test Runners](#test-runners)
12*c2e18aaaSAndroid Build Coastguard Worker5. [Constants Override](#constants-override)
13*c2e18aaaSAndroid Build Coastguard Worker
14*c2e18aaaSAndroid Build Coastguard Worker## <a name="overall-structure">Overall Structure</a>
15*c2e18aaaSAndroid Build Coastguard Worker
16*c2e18aaaSAndroid Build Coastguard WorkerAtest is primarily composed of 2 components: [test finders](#test-finders) and
17*c2e18aaaSAndroid Build Coastguard Worker[test runners](#test-runners). At a high level, atest does the following:
18*c2e18aaaSAndroid Build Coastguard Worker1. Parse args and verify environment
19*c2e18aaaSAndroid Build Coastguard Worker2. Find test(s) based on user input
20*c2e18aaaSAndroid Build Coastguard Worker3. Build test dependencies
21*c2e18aaaSAndroid Build Coastguard Worker4. Run test(s)
22*c2e18aaaSAndroid Build Coastguard Worker
23*c2e18aaaSAndroid Build Coastguard WorkerLet's walk through an example run and highlight what happens under the covers.
24*c2e18aaaSAndroid Build Coastguard Worker
25*c2e18aaaSAndroid Build Coastguard Worker> ```# atest hello_world_test```
26*c2e18aaaSAndroid Build Coastguard Worker
27*c2e18aaaSAndroid Build Coastguard WorkerAtest will first check the environment is setup and then load up the
28*c2e18aaaSAndroid Build Coastguard Workermodule-info.json file (and build it if it's not detected or we want to rebuild
29*c2e18aaaSAndroid Build Coastguard Workerit). That is a critical piece that atest depends on. Module-info.json contains a
30*c2e18aaaSAndroid Build Coastguard Workerlist of all modules in the android repo and some relevant info (e.g.
31*c2e18aaaSAndroid Build Coastguard Workercompatibility_suite, auto_gen_config, etc) that is used during the test finding
32*c2e18aaaSAndroid Build Coastguard Workerprocess. We create the results dir for our test runners to dump results in and
33*c2e18aaaSAndroid Build Coastguard Workerproceed to the first juicy part of atest, finding tests.
34*c2e18aaaSAndroid Build Coastguard Worker
35*c2e18aaaSAndroid Build Coastguard WorkerThe tests specified by the user are passed into the ```CLITranslator``` to
36*c2e18aaaSAndroid Build Coastguard Workertransform the user input into a ```TestInfo``` object that contains all of the
37*c2e18aaaSAndroid Build Coastguard Workerrequired and optional bits used to run the test as how the user intended.
38*c2e18aaaSAndroid Build Coastguard WorkerRequired info would be the test name, test dependencies, and the test runner
39*c2e18aaaSAndroid Build Coastguard Workerused to run the test. Optional bits would be additional args for the test and
40*c2e18aaaSAndroid Build Coastguard Workermethod/class filters.
41*c2e18aaaSAndroid Build Coastguard Worker
42*c2e18aaaSAndroid Build Coastguard WorkerOnce ```TestInfo``` objects have been constructed for all the tests passed in
43*c2e18aaaSAndroid Build Coastguard Workerby the user, all of the test dependencies are built. This step can by bypassed
44*c2e18aaaSAndroid Build Coastguard Workerif the user specifies only _-t_ or _-i_.
45*c2e18aaaSAndroid Build Coastguard Worker
46*c2e18aaaSAndroid Build Coastguard WorkerThe final step is to run the tests which is where the test runners do their job.
47*c2e18aaaSAndroid Build Coastguard WorkerAll of the ```TestInfo``` objects get passed into the ```test_runner_handler```
48*c2e18aaaSAndroid Build Coastguard Workerwhich invokes each ```TestInfo``` specified test runner. In this specific case,
49*c2e18aaaSAndroid Build Coastguard Workerthe ```AtestTradefedTestRunner``` is used to kick off ```hello_world_test```.
50*c2e18aaaSAndroid Build Coastguard Worker
51*c2e18aaaSAndroid Build Coastguard WorkerRead on to learn more about the classes mentioned.
52*c2e18aaaSAndroid Build Coastguard Worker
53*c2e18aaaSAndroid Build Coastguard Worker## <a name="major-files-and-dirs">Major Files and Dirs</a>
54*c2e18aaaSAndroid Build Coastguard Worker
55*c2e18aaaSAndroid Build Coastguard WorkerHere is a list of major files and dirs that are important to point out:
56*c2e18aaaSAndroid Build Coastguard Worker* ```atest.py``` - Main entry point.
57*c2e18aaaSAndroid Build Coastguard Worker* ```cli_translator.py``` - Home of ```CLITranslator``` class. Translates the
58*c2e18aaaSAndroid Build Coastguard Worker  user input into something the test runners can understand.
59*c2e18aaaSAndroid Build Coastguard Worker* ```test_finder_handler.py``` - Module that collects all test finders,
60*c2e18aaaSAndroid Build Coastguard Worker  determines which test finder methods to use and returns them for
61*c2e18aaaSAndroid Build Coastguard Worker  ```CLITranslator``` to utilize.
62*c2e18aaaSAndroid Build Coastguard Worker* ```test_finders/``` - Location of test finder classes. More details on test
63*c2e18aaaSAndroid Build Coastguard Worker  finders [below](#test-finders).
64*c2e18aaaSAndroid Build Coastguard Worker* ```test_finders/test_info.py``` - Module that defines ```TestInfo``` class.
65*c2e18aaaSAndroid Build Coastguard Worker* ```test_runner_handler.py``` - Module that collects all test runners and
66*c2e18aaaSAndroid Build Coastguard Worker  contains logic to determine what test runner to use for a particular
67*c2e18aaaSAndroid Build Coastguard Worker  ```TestInfo```.
68*c2e18aaaSAndroid Build Coastguard Worker* ```test_runners/``` - Location of test runner classes. More details on test
69*c2e18aaaSAndroid Build Coastguard Worker  runners [below](#test-runners).
70*c2e18aaaSAndroid Build Coastguard Worker* ```constants_default.py``` - Location of constant defaults. Need to override
71*c2e18aaaSAndroid Build Coastguard Worker  some of these constants for your private repo? [Instructions below](#constants-override).
72*c2e18aaaSAndroid Build Coastguard Worker
73*c2e18aaaSAndroid Build Coastguard Worker## <a name="test-finders">Test Finders</a>
74*c2e18aaaSAndroid Build Coastguard Worker
75*c2e18aaaSAndroid Build Coastguard WorkerTest finders are classes that host find methods. The find methods are called by
76*c2e18aaaSAndroid Build Coastguard Workeratest to find tests in the android repo based on the user's input (path,
77*c2e18aaaSAndroid Build Coastguard Workerfilename, class, etc).  Find methods will also find the corresponding test
78*c2e18aaaSAndroid Build Coastguard Workerdependencies for the supplied test, translating it into a form that a test
79*c2e18aaaSAndroid Build Coastguard Workerrunner can understand, and specifying the test runner.
80*c2e18aaaSAndroid Build Coastguard Worker
81*c2e18aaaSAndroid Build Coastguard WorkerFor more details and instructions on how to create new test finders,
82*c2e18aaaSAndroid Build Coastguard Worker[go here](./develop_test_finders.md)
83*c2e18aaaSAndroid Build Coastguard Worker
84*c2e18aaaSAndroid Build Coastguard Worker## <a name="test-runners">Test Runners</a>
85*c2e18aaaSAndroid Build Coastguard Worker
86*c2e18aaaSAndroid Build Coastguard WorkerTest Runners are classes that execute the tests. They consume a ```TestInfo```
87*c2e18aaaSAndroid Build Coastguard Workerand execute the test as specified.
88*c2e18aaaSAndroid Build Coastguard Worker
89*c2e18aaaSAndroid Build Coastguard WorkerFor more details and instructions on how to create new test runners, [go here](./develop_test_runners.md)
90*c2e18aaaSAndroid Build Coastguard Worker
91*c2e18aaaSAndroid Build Coastguard Worker## <a name="constants-override">Constants Override</a>
92*c2e18aaaSAndroid Build Coastguard Worker
93*c2e18aaaSAndroid Build Coastguard WorkerYou'd like to override some constants but not sure how?  Override them with your
94*c2e18aaaSAndroid Build Coastguard Workerown constants_override.py that lives in your own private repo.
95*c2e18aaaSAndroid Build Coastguard Worker
96*c2e18aaaSAndroid Build Coastguard Worker1. Create new ```constants_override.py``` (or whatever you'd like to name it) in
97*c2e18aaaSAndroid Build Coastguard Worker  your own repo. It can live anywhere but just for example purposes, let's
98*c2e18aaaSAndroid Build Coastguard Worker  specify the path to be ```<private repo>/path/to/constants_override/constants_override.py```.
99*c2e18aaaSAndroid Build Coastguard Worker2. Add a ```vendorsetup.sh``` script in ```//vendor/<somewhere>``` to export the
100*c2e18aaaSAndroid Build Coastguard Worker  path of ```constants_override.py``` base path into ```PYTHONPATH```.
101*c2e18aaaSAndroid Build Coastguard Worker```bash
102*c2e18aaaSAndroid Build Coastguard Worker# This file is executed by build/envsetup.sh
103*c2e18aaaSAndroid Build Coastguard Worker_path_to_constants_override="$(gettop)/path/to/constants_override"
104*c2e18aaaSAndroid Build Coastguard Workerif [[ ! $PYTHONPATH == *${_path_to_constants_override}* ]]; then
105*c2e18aaaSAndroid Build Coastguard Worker  export PYTHONPATH=${_path_to_constants_override}:$PYTHONPATH
106*c2e18aaaSAndroid Build Coastguard Workerfi
107*c2e18aaaSAndroid Build Coastguard Worker```
108*c2e18aaaSAndroid Build Coastguard Worker3. Try-except import ```constants_override``` in ```constants.py```.
109*c2e18aaaSAndroid Build Coastguard Worker```python
110*c2e18aaaSAndroid Build Coastguard Workertry:
111*c2e18aaaSAndroid Build Coastguard Worker    from constants_override import *
112*c2e18aaaSAndroid Build Coastguard Workerexcept ImportError:
113*c2e18aaaSAndroid Build Coastguard Worker    pass
114*c2e18aaaSAndroid Build Coastguard Worker```
115*c2e18aaaSAndroid Build Coastguard Worker4. You're done! To pick up the override, rerun build/envsetup.sh to kick off the
116*c2e18aaaSAndroid Build Coastguard Worker  vendorsetup.sh script.
117