blob: 88d1f295718ad0a445dfaad7b52a355d6ca6b8b8 [file] [log] [blame] [view]
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -07001This file explains how to use gem5's updated testing infrastructure. Running
2tests before submitting a patch is *incredibly important* so unexpected bugs
3don't creep into gem5.
4
5gem5's testing infrastructure has the following goals:
6 * Simple for *all* users to run
7 * Fast execution in the simple case
8 * High coverage of gem5 code
9
Bobby R. Brucec3a4fb02019-10-04 13:25:44 -070010# Running unit tests
11
12gem5 comes with unit tests, created using the Google Test framework. These can
13be built through SCons.
14
15To build and run all the unit tests:
16
17```shell
18scons build/NULL/unittests.opt
19```
20
21All unit tests should be run prior to posting a patch to
22https://gem5-review.googlesource.com
23
24To compile and run just one set of tests (e.g. those declared within
25`src/base/bitunion.test.cc`):
26
27```shell
28scons build/NULL/base/bitunion.test.opt
29./build/NULL/base/bitunion.test.opt
30```
31
32To list the available test functions from a test file:
33
34```shell
35./build/NULL/base/bitunion.test.opt --gtest_list_tests
36```
37
38To run a specific test function (e.g., BitUnionData.NormalBitfield):
39
40```shell
41./build/NULL/base/bitunion.test.opt --gtest_filter=BitUnionData.NormalBitfield
42```
43
44# Running system-level tests
45
46Within the `tests` directory we have system-level tests. These tests run
47the gem5 framework against various hardware configurations, with different
48ISAs, then verify the simulations execute correctly. These should be seen as
49high-level, coarse-grained tests to compliment the unit-tests.
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -070050
51Below is the most common way the tests are run. This will run all of the
52"quick" tests for X86, ARM, and RISC-V. These tests make up our best-supported
53platforms and use cases. When running these tests, you will likely want to us
54the option `-j <CPUs>` where `CPUs` is as large as you can make it.
55Additionally, it is often a good idea to run longer tests (e.g., linux boot)
56before submitting your patch.
57
58```shell
59cd tests
60./main.py run
61```
62
Bobby R. Brucec3a4fb02019-10-04 13:25:44 -070063The above is the *minumum* you should run before posting a patch to
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -070064https://gem5-review.googlesource.com
65
Giacomo Travaglini7ed22b32021-01-29 22:19:13 +000066## Running tests from multiple directories
67
68The command line above will walk the directory tree starting from the cwd
69(tests), and it will run every test it encounters in its path. It is possible
70to specify multiple root directories by providing several positional
71arguments:
72
73```shell
74./main.py run <directory1> <directory2> [...]
75```
76
77This will load every test in directory1 and directory2 (and their
78subdirectories).
79
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -070080## Specifying a subset of tests to run
81
82You can use the tag query interface to specify the exact tests you want to run.
83For instance, if you want to run only with `gem5.opt`, you can use
84
85```shell
86./main.py run --variant opt
87```
88
89Or, if you want to just run X86 tests with the `gem5.opt` binary:
90
91```shell
92./main.py run --length quick --variant opt --isa X86
93```
94
95
96To view all of the available tags, use
97
98```shell
99./main.py list --all-tags
100```
101
102The output is split into tag *types* (e.g., isa, variant, length) and the
103tags for each type are listed after the type name.
104
105You can specify "or" between tags within the same type by using the tag flag
106multiple times. For instance, to run everything that is tagged "opt" or "fast"
107use
108
109```shell
110./main.py run --variant opt --variant fast
111```
112
113You can also specify "and" between different types of tags by specifying more
114than one type on the command line. For instance, this will only run tests with
115both the "X86" and "opt" tags.
116
117```shell
118./main.py run --isa X86 --variant opt
119```
120
121## Running tests in batch
122
123The testing infrastructure provides the two needed methods to run tests in
124batch. First, you can list all of the tests based on the same tags as above in
125a machine-readable format by passing the `-q` flag. This will list all of the
126*suites* that match the given tag(s).
127
128```shell
129./main.py list -q --suites
130SuiteUID:tests/gem5/hello_se/test_hello_se.py:testhello64-static-X86-opt
131SuiteUID:tests/gem5/hello_se/test_hello_se.py:testhello64-dynamic-X86-opt
132SuiteUID:tests/gem5/hello_se/test_hello_se.py:testhello32-static-X86-opt
133SuiteUID:tests/gem5/hello_se/test_hello_se.py:testhello64-static-ARM-opt
134SuiteUID:tests/gem5/hello_se/test_hello_se.py:testhello32-static-ARM-opt
135SuiteUID:tests/gem5/m5_util/test_exit.py:m5_exit_test-X86-opt
136SuiteUID:tests/gem5/test_build/test_build.py:build-X86-opt
137SuiteUID:tests/gem5/test_build/test_build.py:build-RISCV-opt
138SuiteUID:tests/gem5/test_build/test_build.py:build-ARM-opt
139```
140
141Next, you can run a single *suite* from the command line by passing the option
142`--uid`. For instance,
143
144```shell
145./main.py run --skip-build \
146 --uid SuiteUID:tests/gem5/m5_util/test_exit.py:m5_exit_test-X86-opt
147```
148
149With this method, you can only run a *single* suite at a time. If you want to
150run more than one uid, you must call `./main.py` multiple times.
151
152Currently, you must specify `--skip-build` if you want to run a single suite or
153run in batch mode. Otherwise, you will build gem5 for all architectures.
154
155## Rerunning failed tests
156
157While developing software a common practice is to run tests, make a change, and
158assert that the tests still pass. If tests fail you'll likely want to
159rerun and fix those specific tests without running redundant ones. The testing
160infrastructure allows you to rerun tests which failed in the last execution by
161using the `rerun` command.
162
163```shell
164./main.py run
165#
166# Some tests fail...
167#
168
169# Rerun only the failed test suites (not the ones which passed).
170./main.py rerun
171```
172
Bobby R. Brucec3a4fb02019-10-04 13:25:44 -0700173## If something goes wrong
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -0700174
175The first step is to turn up the verbosity of the output using `-v`. This will
176allow you to see what tests are running and why a test is failing.
177
178If a test fails, the temporary directory where the gem5 output was saved is kept
179and the path to the directory is printed in the terminal.
180
181## Debugging the testing infrastructure
182
183Every command takes an option for the verbosity. `-v`, `-vv`, `-vvv` will
184increase the verbosity level. If something isn't working correctly, you can
185start here.
186
187Most of the code for the testing infrastructure is in ext/testlib. This code
188contains the base code for tests, suites, fixtures, etc. The code in tests/gem5
189is *gem5-specific* code. For the most part, the code in tests/gem5 extends the
190structures in ext/testlib.
191
192## Common errors
193
194You may see a number of lines of output during test discovery that look like
195the following:
196
197```shell
198 Tried to load tests from ... but failed with an exception.
199 Tried to load tests from ... but failed with an exception.
200 ...
201```
202
203The testing library searches all python files in the `tests/` directory. The
204test library executes each python file it finds searching for tests. It's okay
205if the file causes an exception. This means there are no tests in that file
206(e.g., it's not a new-style test).
207
208
Bobby R. Brucec3a4fb02019-10-04 13:25:44 -0700209## Binary test applications
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -0700210
Giacomo Travaglini75548f02020-01-16 10:01:08 +0000211The code for some test binaries that are run in the gem5 guest during
212testing can be found in `tests/test-progs`.
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -0700213There's one directory per test application.
214The source code is under the `source` directory.
215
216You may have a `bin` directory as well.
217The `bin` directory is automatically created when running the test case that
Giacomo Travaglini75548f02020-01-16 10:01:08 +0000218uses the test binary.
219This is not the case when a test is run via the --bin-path option.
220In that scenario a bin directory will be created in the selected path
221rather than in `tests/test-progs`.
222The binary is downloaded from the gem5 servers the first
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -0700223time it is referenced by a test.
224
Giacomo Travaglini75548f02020-01-16 10:01:08 +0000225Some other tests (like Linux-boot) don't have sources inside gem5 and
226are simply downloaded from gem5 servers.
227
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -0700228## Updating the test binaries
229
230The test infrastructure should check with the gem5 servers to ensure you have
231the latest binaries. However, if you believe your binaries are out of date,
232simply delete the `bin` directory and they will be re-downloaded to your local
233machine.
234
235## Building (new-style) test binaries
236
237In each `src/` directory under `tests/test-progs`, there is a Makefile.
238This Makefile downloads a docker image and builds the test binary for some ISA
239(e.g., Makefile.x86 builds the binary for x86). Additionally, if you run `make
240upload` it will upload the binaries to the gem5 server, if you have access to
241modify the binaries. *If you need to modify the binaries for updating a test or
242adding a new test and you don't have access to the gem5 server, contact a
243maintainer (see MAINTAINERS).*
244
245
Bobby R. Brucec3a4fb02019-10-04 13:25:44 -0700246## Running Tests in Parallel
Jason Lowe-Powerbbb53022017-09-21 14:29:43 -0700247
248Whimsy has support for parallel testing baked in. This system supports
249running multiple suites at the same time on the same computer. To run
250suites in parallel, supply the `-t <number-tests>` flag to the run command.
251
252For example, to run up to three test suites at the same time::
253
254 ./main.py run --skip-build -t 3
255