xref: /aosp_15_r20/external/autotest/autotest_lib/docs/test-that.md (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1*9c5db199SXin Li## Introduction
2*9c5db199SXin Li
3*9c5db199SXin Li`test_that` is the supported mechanism to run autotests against ChromeOS
4*9c5db199SXin Lidevices at your desk.  `test_that` replaces an older script, `run_remote_tests`.
5*9c5db199SXin Li
6*9c5db199SXin LiFeatures for testing a local device:
7*9c5db199SXin Li  - CTRL+C kills `test_that` and all its autoserv children. Orphaned processes
8*9c5db199SXin Li    are no longer left behind.
9*9c5db199SXin Li  - Tests that require binary autotest dependencies will just work, because
10*9c5db199SXin Li    test_that always runs from the sysroot location.
11*9c5db199SXin Li  - Running emerge after python-only test changes is no longer necessary.
12*9c5db199SXin Li    test_that uses autotest_quickmerge to copy your python changes to the
13*9c5db199SXin Li    sysroot.
14*9c5db199SXin Li  - Tests are generally specified to `test_that` by the NAME field of their
15*9c5db199SXin Li    control file. Matching tests by filename is supported using f:[file
16*9c5db199SXin Li    pattern]
17*9c5db199SXin Li
18*9c5db199SXin LiIn addition to running tests against local device, `test_that` can be used to
19*9c5db199SXin Lilaunch jobs in the ChromeOS Hardware Lab (or against a local Autotest instance
20*9c5db199SXin Lior a Moblab). This feature is only supported for infrastructure-produced builds
21*9c5db199SXin Lithat were uploaded to google storage.
22*9c5db199SXin Li
23*9c5db199SXin Li### Example uses (inside the chroot)
24*9c5db199SXin Li
25*9c5db199SXin LiRun the test(s) named stub\_Pass:
26*9c5db199SXin Li
27*9c5db199SXin Li```
28*9c5db199SXin Li$ test_that -b ${board} ${host} stub_Pass
29*9c5db199SXin Li```
30*9c5db199SXin Li
31*9c5db199SXin LiRun the test(s) named stub\_Pass.suspend:
32*9c5db199SXin Li
33*9c5db199SXin Li```
34*9c5db199SXin Li$ test_that -b ${board} ${host} stub_Pass.suspend
35*9c5db199SXin Li```
36*9c5db199SXin Li
37*9c5db199SXin LiRun the bvt-inline suite against dut:
38*9c5db199SXin Li
39*9c5db199SXin Li```
40*9c5db199SXin Li$ test_that -b ${board} ${host} suite:bvt-inline
41*9c5db199SXin Li```
42*9c5db199SXin Li
43*9c5db199SXin LiRun all tests whose names match the regular expression `^login_.*$`. Note that
44*9c5db199SXin Lieven though these tests have binary dependencies, there is no longer a need to
45*9c5db199SXin Lispecify extra flags.
46*9c5db199SXin Li
47*9c5db199SXin Li```
48*9c5db199SXin Li$ test_that -b ${board} ${host} e:login_.*
49*9c5db199SXin Li```
50*9c5db199SXin Li
51*9c5db199SXin LiRun all tests whose control file filename matches the regular expression
52*9c5db199SXin Li`^.*control.stub$`:
53*9c5db199SXin Li
54*9c5db199SXin Li```
55*9c5db199SXin Li$ test_that -b ${board} ${host} f:.*control.stub
56*9c5db199SXin Li```
57*9c5db199SXin Li
58*9c5db199SXin Li### Running jobs in the lab
59*9c5db199SXin Li
60*9c5db199SXin Li`test_that` now allows you to run jobs in the test lab. The usage is similar to
61*9c5db199SXin Lirunning tests against a specified host. The keyword :lab: is used as
62*9c5db199SXin Litest\_that's REMOTE argument, and the -i/--build argument is required, and takes
63*9c5db199SXin Lia trybot, paladin, or canary build number. To learn how to build a trybot image
64*9c5db199SXin Liwith a new test that you're iterating on, see "dynamic suite" codelab or the
65*9c5db199SXin Li[Chromium OS Remote
66*9c5db199SXin LiTrybots](https://sites.google.com/a/chromium.org/dev/chromium-os/build/using-remote-trybots)
67*9c5db199SXin Liguide.
68*9c5db199SXin Li
69*9c5db199SXin LiFor instance:
70*9c5db199SXin Li
71*9c5db199SXin Li```
72*9c5db199SXin Li$ test_that -b lumpy -i lumpy-paladin/R38-6009.0.0-rc4 :lab: stub_Pass
73*9c5db199SXin Li```
74*9c5db199SXin Li
75*9c5db199SXin LiThis will kick off a suite in the lab that consists of just 1 job, stub\_Pass,
76*9c5db199SXin Lito run in this case on board lumpy using the image
77*9c5db199SXin Lilumpy-paladin/R38-6009.0.0-rc4. The lab's scheduler will take responsibility
78*9c5db199SXin Lifor finding a suitable set of hosts, provisioning them to the correct image,
79*9c5db199SXin Liand running the tests. `test_that` will return after the suite finishes running,
80*9c5db199SXin Liwith a suite run report.
81*9c5db199SXin Li
82*9c5db199SXin LiYou can specify multiple tests or test-matching expressions in the same way as
83*9c5db199SXin Libefore:
84*9c5db199SXin Li
85*9c5db199SXin Li```
86*9c5db199SXin Li$ test_that -b lumpy -i ${latest_image} :lab: stub_Pass dummy_Fail
87*9c5db199SXin Li$ test_that -b lumpy -i ${latest_image} :lab: e:login_.*
88*9c5db199SXin Li```
89*9c5db199SXin Li
90*9c5db199SXin LiKicking off a run in the lab should be useful whenever you need to run a
91*9c5db199SXin Liparticular test on a board or image that you do not have readily available
92*9c5db199SXin Lilocally.For occasional runs of ad-hoc suites in the lab, this will also avoid
93*9c5db199SXin Lithe need to create a suite control file and wait for it to end up in an image.
94*9c5db199SXin Li
95*9c5db199SXin LiYou can also kick off a suite, for example with:
96*9c5db199SXin Li
97*9c5db199SXin Li```
98*9c5db199SXin Litest_that -b peach_pit :lab: suite:pyauto_perf -i 'peach_pit-release/R32-4763.0.0'
99*9c5db199SXin Li```
100*9c5db199SXin Li
101*9c5db199SXin LiThat told me that my job ID was 5196037. I could follow along by going to
102*9c5db199SXin Lihttp://cautotest/afe/#tab_id=view_job&object_id=5195962.
103*9c5db199SXin Li
104*9c5db199SXin LiThings to note about running in the lab:
105*9c5db199SXin Li
106*9c5db199SXin Li - This feature will only work on builds that produced autotest test artifacts.
107*9c5db199SXin Li   If your build doesn't have such artifacts, you will see a
108*9c5db199SXin Li   [confusing error](https://crbug.com/354556). The easiest way today to
109*9c5db199SXin Li   guarantee that hwtest artifacts are produced is to make sure that your tryjob
110*9c5db199SXin Li   is launched with the --hwtest flag. Once [this bug](https://crbug.com/299838)
111*9c5db199SXin Li   is fixed that will no longer be the case.
112*9c5db199SXin Li - By default, jobs will be scheduled in the `suites` machine pool. That can be
113*9c5db199SXin Li   overridden with the `-p` flag.
114*9c5db199SXin Li - This will only work with images newer than Sept 20, 2013 (specifically, builds
115*9c5db199SXin Li   that contain Ifa73d7de7aac9c6efebd5f559708623804ad3691).
116*9c5db199SXin Li
117*9c5db199SXin Li
118*9c5db199SXin Li### Running jobs against a local Autotest setup or MobLab
119*9c5db199SXin Li
120*9c5db199SXin Li`test_that` allows you to run jobs against a local Autotest setup or a
121*9c5db199SXin LiMobLab instance. This usage is similar to running tests in the lab. The argument
122*9c5db199SXin Li--web allows you to specify the web address of the Autotest instance you want to
123*9c5db199SXin Lirun tests within.
124*9c5db199SXin Li
125*9c5db199SXin LiFor instance:
126*9c5db199SXin Li```
127*9c5db199SXin Li$ test_that -b lumpy -i lumpy-paladin/R38-6009.0.0-rc4 --web 100.96.51.136 :lab:
128*9c5db199SXin Listub_Pass
129*9c5db199SXin Li```
130*9c5db199SXin Li
131*9c5db199SXin LiThis will kick off the stub_Pass test on a lumpy device on the Autotest
132*9c5db199SXin Liinstance located at 100.96.51.136
133