testing.md revision 2679:5a380daa50ba
1% Testing OpenJDK
2
3## Using the run-test framework
4
5This new way of running tests is developer-centric. It assumes that you have
6built a jdk locally and want to test it. Running common test targets is simple,
7and more complex ad-hoc combination of tests is possible. The user interface is
8forgiving, and clearly report errors it cannot resolve.
9
10The main target "run-test" uses the jdk-image as the tested product. There is
11also an alternate target "exploded-run-test" that uses the exploded image
12instead. Not all tests will run successfully on the exploded image, but using
13this target can greatly improve rebuild times for certain workflows.
14
15Some example command-lines:
16
17    $ make run-test-tier1
18    $ make run-test-jdk_lang JTREG="JOBS=8"
19    $ make run-test TEST=jdk_lang
20    $ make run-test-only TEST="gtest:LogTagSet gtest:LogTagSetDescriptions" GTEST="REPEAT=-1"
21    $ make run-test TEST="hotspot/test:hotspot_gc" JTREG="JOBS=1;TIMEOUT=8;VM_OTIONS=-XshowSettings -Xlog:gc+ref=debug"
22    $ make run-test TEST="jtreg:hotspot/test:hotspot_gc hotspot/test/native_sanity/JniVersion.java"
23    $ make exploded-run-test TEST=hotspot_tier1
24
25### Configuration
26
27To be able to run JTReg tests, `configure` needs to know where to find the
28JTReg test framework. If it is not picked up automatically by configure, use
29the `--with-jtreg=<path to jtreg home>` option to point to the JTReg framework.
30Note that this option should point to the JTReg home, i.e. the top directory,
31containing `lib/jtreg.jar` etc. (An alternative is to set the `JT_HOME`
32environment variable to point to the JTReg home before running `configure`.)
33
34## Test selection
35
36All functionality is available using the run-test make target. In this use
37case, the test or tests to be executed is controlled using the `TEST` variable.
38To speed up subsequent test runs with no source code changes, run-test-only can
39be used instead, which do not depend on the source and test image build.
40
41For some common top-level tests, direct make targets have been generated. This
42includes all JTReg test groups, the hotspot gtest, and custom tests (if
43present). This means that `make run-test-tier1` is equivalent to `make run-test
44TEST="tier1"`, but the latter is more tab-completion friendly. For more complex
45test runs, the `run-test TEST="x"` solution needs to be used.
46
47The test specifications given in `TEST` is parsed into fully qualified test
48descriptors, which clearly and unambigously show which tests will be run. As an
49example, `:tier1` will expand to `jtreg:jdk/test:tier1
50jtreg:langtools/test:tier1 jtreg:nashorn/test:tier1 jtreg:jaxp/test:tier1`. You
51can always submit a list of fully qualified test descriptors in the `TEST`
52variable if you want to shortcut the parser.
53
54### JTReg
55
56JTReg test groups can be specified either without a test root, e.g. `:tier1`
57(or `tier1`, the initial colon is optional), or with, e.g.
58`hotspot/test:tier1`, `jdk/test:jdk_util`.
59
60When specified without a test root, all matching groups from all tests roots
61will be added. Otherwise, only the group from the specified test root will be
62added.
63
64Individual JTReg tests or directories containing JTReg tests can also be
65specified, like `hotspot/test/native_sanity/JniVersion.java` or
66`hotspot/test/native_sanity`. You can also specify an absolute path, to point
67to a JTReg test outside the source tree.
68
69As long as the test groups or test paths can be uniquely resolved, you do not
70need to enter the `jtreg:` prefix. If this is not possible, or if you want to
71use a fully qualified test descriptor, add `jtreg:`, e.g.
72`jtreg:hotspot/test/native_sanity`.
73
74### Gtest
75
76Since the Hotspot Gtest suite is so quick, the default is to run all tests.
77This is specified by just `gtest`, or as a fully qualified test descriptor
78`gtest:all`.
79
80If you want, you can single out an individual test or a group of tests, for
81instance `gtest:LogDecorations` or `gtest:LogDecorations.level_test_vm`. This
82can be particularly useful if you want to run a shaky test repeatedly.
83
84## Test results and summary
85
86At the end of the test run, a summary of all tests run will be presented. This
87will have a consistent look, regardless of what test suites were used. This is
88a sample summary:
89
90    ==============================
91    Test summary
92    ==============================
93       TEST                                          TOTAL  PASS  FAIL ERROR
94    >> jtreg:jdk/test:tier1                           1867  1865     2     0 <<
95       jtreg:langtools/test:tier1                     4711  4711     0     0
96       jtreg:nashorn/test:tier1                        133   133     0     0
97    ==============================
98    TEST FAILURE
99
100Tests where the number of TOTAL tests does not equal the number of PASSed tests
101will be considered a test failure. These are marked with the `>> ... <<` marker
102for easy identification.
103
104The classification of non-passed tests differs a bit between test suites. In
105the summary, ERROR is used as a catch-all for tests that neither passed nor are
106classified as failed by the framework. This might indicate test framework
107error, timeout or other problems.
108
109In case of test failures, `make run-test` will exit with a non-zero exit value.
110
111All tests have their result stored in `build/$BUILD/test-results/$TEST_ID`,
112where TEST_ID is a path-safe conversion from the fully qualified test
113descriptor, e.g. for `jtreg:jdk/test:tier1` the TEST_ID is
114`jtreg_jdk_test_tier1`. This path is also printed in the log at the end of the
115test run.
116
117Additional work data is stored in `build/$BUILD/test-support/$TEST_ID`. For
118some frameworks, this directory might contain information that is useful in
119determining the cause of a failed test.
120
121## Test suite control
122
123It is possible to control various aspects of the test suites using make control
124variables.
125
126These variables use a keyword=value approach to allow multiple values to be
127set. So, for instance, `JTREG="JOBS=1;TIMEOUT=8"` will set the JTReg
128concurrency level to 1 and the timeout factor to 8. This is equivalent to
129setting `JTREG_JOBS=1 JTREG_TIMEOUT=8`, but using the keyword format means that
130the `JTREG` variable is parsed and verified for correctness, so
131`JTREG="TMIEOUT=8"` would give an error, while `JTREG_TMIEOUT=8` would just
132pass unnoticed.
133
134To separate multiple keyword=value pairs, use `;` (semicolon). Since the shell
135normally eats `;`, the recommended usage is to write the assignment inside
136qoutes, e.g. `JTREG="...;..."`. This will also make sure spaces are preserved,
137as in `JTREG="VM_OTIONS=-XshowSettings -Xlog:gc+ref=debug"`.
138
139(Other ways are possible, e.g. using backslash: `JTREG=JOBS=1\;TIMEOUT=8`.
140Also, as a special technique, the string `%20` will be replaced with space for
141certain options, e.g. `JTREG=VM_OTIONS=-XshowSettings%20-Xlog:gc+ref=debug`.
142This can be useful if you have layers of scripts and have trouble getting
143proper quoting of command line arguments through.)
144
145As far as possible, the names of the keywords have been standardized between
146test suites.
147
148### JTReg keywords
149
150#### JOBS
151The test concurrency (`-concurrency`).
152
153Defaults to TEST_JOBS (if set by `--with-test-jobs=`), otherwise it defaults to
154JOBS, except for Hotspot, where the default is *number of CPU cores/2*, but
155never more than 12.
156
157#### TIMEOUT
158The timeout factor (`-timeoutFactor`).
159
160Defaults to 4.
161
162#### TEST_MODE
163The test mode (`-agentvm`, `-samevm` or `-othervm`).
164
165Defaults to `-agentvm`.
166
167#### ASSERT
168Enable asserts (`-ea -esa`, or none).
169
170Set to `true` or `false`. If true, adds `-ea -esa`. Defaults to true, except
171for hotspot.
172
173#### VERBOSE
174The verbosity level (`-verbose`).
175
176Defaults to `fail,error,summary`.
177
178#### RETAIN
179What test data to retain (`-retain`).
180
181Defaults to `fail,error`.
182
183#### MAX_MEM
184Limit memory consumption (`-Xmx` and `-vmoption:-Xmx`, or none).
185
186Limit memory consumption for JTReg test framework and VM under test. Set to 0
187to disable the limits.
188
189Defaults to 512m, except for hotspot, where it defaults to 0 (no limit).
190
191#### OPTIONS
192Additional options to the JTReg test framework.
193
194Use `JTREG="OPTIONS=--help all"` to see all available JTReg options.
195
196#### JAVA_OPTIONS
197Additional Java options to JTReg (`-javaoption`).
198
199#### VM_OPTIONS
200Additional VM options to JTReg (`-vmoption`).
201
202### Gtest keywords
203
204#### REPEAT
205The number of times to repeat the tests (`--gtest_repeat`).
206
207Default is 1. Set to -1 to repeat indefinitely. This can be especially useful
208combined with `OPTIONS=--gtest_break_on_failure` to reproduce an intermittent
209problem.
210
211#### OPTIONS
212Additional options to the Gtest test framework.
213
214Use `GTEST="OPTIONS=--help"` to see all available Gtest options.
215
216---
217# Override some definitions in the global css file that are not optimal for
218# this document.
219header-includes:
220 - '<style type="text/css">pre, code, tt { color: #1d6ae5; }</style>'
221---
222