github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/docs/running_tests.md (about) 1 # Tast: Running Tests (go/tast-running) 2 3 [TOC] 4 5 ## Basic syntax 6 7 Tests can be executed within a ChromeOS chroot using the `tast` executable's 8 `run` command: 9 10 ```shell 11 tast run <target> <test-pattern> <test-pattern> ... 12 ``` 13 14 To run private tests (e.g. `crosint` test bundle), use 15 `-buildbundle=<bundle-name>`. 16 17 ## Specifying where to run tests 18 19 The first positional argument supplied to the `run` subcommand specifies the 20 "target", i.e. the device where the test will be run, also known as the 21 device-under-test or DUT. In the case of local tests, the test code will run 22 directly on the DUT. For remote tests, the test code will run on the host 23 machine but connect to the DUT. Expressions like `root@10.0.0.1:22`, 24 `root@localhost`, and `10.0.0.2` are supported. The root user is used by 25 default, as tests frequently require root access to the DUT. 26 27 By default, the standard `testing_rsa` key from `chromite/ssh_keys` will be used 28 to establish an SSH connection with the device. The `keyfile` flag can be 29 supplied to specify a different private key: 30 31 ```shell 32 tast run -keyfile=$HOME/.ssh/id_rsa ... 33 ``` 34 35 ## Specifying which tests to run 36 37 Any additional positional arguments describe which tests should be executed: 38 39 * If no arguments are supplied, all tests are selected. 40 * If a single argument surrounded by parentheses is supplied, it is 41 interpreted as a boolean expression consisting of test attributes. 42 For example, the expression 43 `(("dep:chrome" || "dep:android") && !informational)` matches all tests with 44 a `dep:chrome` or `dep:android` attribute but not an `informational` 45 attribute. Attributes that don't consist of a letter or underscore followed 46 by letters, digits, and underscores must be double-quoted. '*' characters in 47 quoted strings are interpreted as wildcards. 48 See [go.chromium.org/tast/core/internal/expr] for details about expression syntax. 49 * Otherwise, the argument(s) are interpreted as wildcard patterns matching 50 test names. For example, `ui.*` matches all tests with names prefixed by 51 `ui.`. Multiple patterns can be supplied: passing `example.Pass` and 52 `example.Fail` selects those two tests. 53 * It's invalid to mix attribute expressions and wildcard patterns. To use a 54 wildcard to match against the test name you can use the `"name:ui.*"` 55 expression instead. 56 57 See the [Test Attributes] document for more information about attributes. 58 59 Tests may be skipped if they list [software dependencies] that aren't provided 60 by the DUT. This behavior can be controlled via the `tast` command's 61 `-checktestdeps` flag. 62 63 [go.chromium.org/tast/core/internal/expr]: https://godoc.org/chromium.googlesource.com/chromiumos/platform/tast.git/src/go.chromium.org/tast/core/internal/expr 64 [Test Attributes]: test_attributes.md 65 [software dependencies]: test_dependencies.md 66 67 ## Controlling whether tests are rebuilt 68 69 When the `-build` flag is true (the default), `tast run` rebuilds the `cros` 70 test bundle and pushes it to the DUT as 71 `/usr/local/share/tast/bundles_pushed/cros`. This permits faster compilation and 72 deployment when writing new tests than the normal `emerge`/`cros deploy` cycle 73 can provide. 74 75 The name of the bundle to build, push, and run can be specified via the 76 `-buildbundle` flag. If the bundle's source code is outside of the [tast-tests 77 repository], you will need to specify the repository's path using the 78 `-buildtestdir` flag. 79 80 To rebuild a test bundle, the `tast` command needs its dependencies' source code 81 to be available. This code is automatically checked out to `/usr/lib/gopath` 82 when building packages for the host system, as described in the [Go in Chromium 83 OS] document. The `tast` command will automatically inform you when the bundle's 84 dependencies need to be manually emerged. 85 86 To skip rebuilding a bundle and instead run all builtin bundles within the 87 `/usr/local/share/tast/bundles` directory on the DUT (for local tests) and 88 `/usr/share/tast/bundles` on the host system (for remote tests), pass 89 `-build=false`. The default builtin `cros` local bundle should be present on 90 all `test` system images (non-`test` system images are not supposed by Tast). 91 92 [tast-tests repository]: https://chromium.googlesource.com/chromiumos/platform/tast-tests/ 93 [Go in ChromiumOS]: https://www.chromium.org/chromium-os/developer-guide/go-in-chromium-os 94 95 ## Running tests with Servo 96 97 Some tests use servo, a physical device that connects to both the host machine 98 and the DUT. These tests all specify `servo` as a [runtime variable], so they 99 must be run with that variable specifying the servo host and servo port. 100 101 If you can run Tast without [port forwarding], please use following syntax. 102 103 ```shell 104 tast run -var=servo=<servo-host>:<servo-port> <target> <test-pattern> 105 ``` 106 107 If you need run Tast with [port forwarding], please use following syntax. 108 109 ```shell 110 tast run -var=servo=localhost:<servo-port>:ssh:<servo_localhost_port> localhost:<DUT_localhost_port> <test-pattern> 111 ``` 112 113 In order for a test to interact with the servo, the servo host must be running 114 an instance of `servod` (servo daemon) on the appropriate port. When Tast is 115 run through the Tauto wrapper via `test_that`, Tauto takes care of initiating 116 and closing `servod`. However, when Tast is run through `tast run`, it does not 117 initiate `servod`; the user must initiate `servod` from the servo host: 118 119 ```shell 120 ssh <servo-host> 121 servod --board=<board> --model=<model> --port=<servo-port> --serialname=<servo-serial> 122 ``` 123 124 In automated testing in the ChromeOS lab, Tast tests can reach a working Servo 125 device via `servo` runtime variable if they are scheduled with Autotest control 126 files declaring a Servo dependency. Control files for mainline tests declare it, 127 but other control files may not. See [crrev.com/c/2790771] for an example to add 128 a dependency declaration. 129 130 [runtime variable]: writing_tests.md#runtime-variables 131 [crrev.com/c/2790771]: https://crrev.com/c/2790771 132 [port forwarding]: running_tests.md#Option-2_Use-SSH-port-forwarding 133 134 135 ## Interpreting test results 136 137 As each test runs, its output is streamed to the `tast` executable. Overall 138 information about the current state of the test run is logged to stdout by 139 default. The top-level (i.e. `tast -verbose run ...`) `-verbose` flag can be 140 supplied to log additional information to the console, including all messages 141 written by tests. 142 143 By default, test results are written to a subdirectory under 144 `/tmp/tast/results`, but an alternate directory can be supplied via the `run` 145 command's `-resultsdir` flag. If the default directory is used, a symlink will 146 also be created to it at `/tmp/tast/results/latest`. 147 148 Various files and directories are created within the results directory: 149 150 * `crashes/` - [Breakpad] minidump files with information about crashes that 151 occured during testing. 152 * `full.txt` - All output from the run, including messages logged by 153 individual tests. 154 * `results.json` - Machine-parseable test results, supplied as a 155 JSON-marshaled array of [run.TestResult] structs. 156 * `run_error.txt` - Error message describing the reason why the run was 157 aborted (e.g. SSH connection to DUT was lost). Only written when a global 158 error occurs. 159 * `streamed_results.jsonl` - Streamed machine-parseable test results, supplied 160 as a [JSONL] array of [run.TestResult] structs. Provides partial results if 161 the `tast` process is interrupted before `results.json` is written. 162 * `system_logs/` - Diff of `/var/log` on the DUT before and after testing. 163 * `unified/` - Unified log collected from system logs. 164 * `unified.log` - Human-readable system log messages. 165 * `unified.export.gz` - gzip-compressed logs with full metadata from 166 croslog's export mode which is similler to `journalctl -o export`. 167 * `tests/<test-name>/` - Per-test subdirectories, containing test logs and 168 other output files. 169 * `log.txt` - Log of messages and errors reported by the test. 170 * (optional) `results-chart.json` - Machine-parseable performance 171 metrics produced by the [perf] package. 172 * `...` - Other [output files] from the test. 173 * `timing.json` - Machine-parsable JSON-marshaled timing information about the 174 test run produced by the [timing] package. 175 176 [Breakpad]: https://github.com/google/breakpad/ 177 [run.TestResult]: https://godoc.org/chromium.googlesource.com/chromiumos/platform/tast.git/src/go.chromium.org/tast/core/cmd/tast/internal/run#TestResult 178 [JSONL]: http://jsonlines.org/ 179 [output files]: writing_tests.md#Output-files 180 [perf]: https://godoc.org/chromium.googlesource.com/chromiumos/platform/tast-tests.git/src/go.chromium.org/tast-tests/cros/common/perf 181 [timing]: https://godoc.org/chromium.googlesource.com/chromiumos/platform/tast.git/src/go.chromium.org/tast/core/timing 182 183 ## Reset the device owner of the DUT after test run 184 185 Tast resets the device owner of the DUT before test run, and after the test run, 186 the device owner remains to be testuser. To reset that, run the following on the 187 DUT: 188 189 ```shell 190 stop ui 191 rm -rf /var/lib/devicesettings '/home/chronos/Local State' 192 start ui 193 ``` 194 ## Googlers Only: Running tests on a leased DUT from the lab 195 196 ### Option 1: Use corp-ssh-helper-helper 197 198 In a window outside the chroot do, 199 200 * Run gcert once a day. 201 * Install [corp-ssh-helper-helper] and start the corp-ssh-helper-helper server process. 202 203 In another window inside chroot: 204 205 ```shell 206 tast run <target> <test> 207 ``` 208 209 [corp-ssh-helper-helper]: https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/dev/contrib/corp-ssh-helper-helper/README.md 210 211 ### Option 2: Use SSH port forwarding 212 213 In a window outside the chroot do, 214 215 * Run gcert once a day. 216 * Use [SSH Watcher] to port-forward a ssh connection to your device. 217 * Use [SSH Watcher] to port-forward a ssh connection to labstation if you need 218 to use servo. 219 220 221 Any port is fine as long as it is not used by other applications. Leave the SSH Watcher session(s) on. 222 223 In another window inside chroot: 224 225 ```shell 226 tast run localhost:<port> <test> 227 ``` 228 229 Specific example: 230 231 ``` 232 DUT_HOSTNAME=chromeos6-row18-rack18-host17 233 SERVO_HOSTNAME=chromeos6-row18-rack18-labstation4 234 SERVO_PORT=9972 235 LOCAL_SERVO_SSH_PORT=2003 236 LOCAL_DUT_SSH_PORT=2005 237 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/testing_rsa -l root ${SERVO_HOSTNAME?} "start servod PORT=${SERVO_PORT?}" 238 go run ~/chromiumos/src/platform/dev/contrib/sshwatcher/sshwatcher.go ${SERVO_HOSTNAME?} ${LOCAL_SERVO_SSH_PORT?} ${DUT_HOSTNAME?} ${LOCAL_DUT_SSH_PORT?} 239 240 <new window> 241 cd ~/chromiumos ; cros_sdk --no-ns-pid 242 SERVO_PORT=9972 243 LOCAL_SERVO_SSH_PORT=2003 244 LOCAL_DUT_SSH_PORT=2005 245 246 tast run --var=servo=localhost:${SERVO_PORT?}:ssh:${LOCAL_SERVO_SSH_PORT?} localhost:${LOCAL_DUT_SSH_PORT?} firmware.Fixture.normal 247 ``` 248 249 [SSH Watcher]: https://chromium.googlesource.com/chromiumos/platform/dev-util/+/HEAD/contrib/sshwatcher/README.md 250 251 ## Running tests attached to a debugger 252 See [Tast Debugger](debugger.md)