1 <!DOCTYPE html>
  2 <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
  3 <head>
  4   <meta charset="utf-8" />
  5   <meta name="generator" content="pandoc" />
  6   <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
  7   <title>Testing the JDK</title>
  8   <style>
  9     code{white-space: pre-wrap;}
 10     span.smallcaps{font-variant: small-caps;}
 11     div.columns{display: flex; gap: min(4vw, 1.5em);}
 12     div.column{flex: auto; overflow-x: auto;}
 13     div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
 14     ul.task-list{list-style: none;}
 15     ul.task-list li input[type="checkbox"] {
 16       width: 0.8em;
 17       margin: 0 0.8em 0.2em -1.6em;
 18       vertical-align: middle;
 19     }
 20     .display.math{display: block; text-align: center; margin: 0.5rem auto;}
 21   </style>
 22   <link rel="stylesheet" href="../make/data/docs-resources/resources/jdk-default.css" />
 23   <style type="text/css">pre, code, tt { color: #1d6ae5; }</style>
 24   <!--[if lt IE 9]>
 25     <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
 26   <![endif]-->
 27 </head>
 28 <body>
 29 <header id="title-block-header">
 30 <h1 class="title">Testing the JDK</h1>
 31 </header>
 32 <nav id="TOC" role="doc-toc">
 33 <ul>
 34 <li><a href="#overview" id="toc-overview">Overview</a></li>
 35 <li><a href="#running-tests-locally-with-make-test"
 36 id="toc-running-tests-locally-with-make-test">Running tests locally with
 37 <code>make test</code></a>
 38 <ul>
 39 <li><a href="#configuration"
 40 id="toc-configuration">Configuration</a></li>
 41 </ul></li>
 42 <li><a href="#test-selection" id="toc-test-selection">Test selection</a>
 43 <ul>
 44 <li><a href="#common-test-groups" id="toc-common-test-groups">Common
 45 Test Groups</a></li>
 46 <li><a href="#jtreg" id="toc-jtreg">JTReg</a></li>
 47 <li><a href="#gtest" id="toc-gtest">Gtest</a></li>
 48 <li><a href="#microbenchmarks"
 49 id="toc-microbenchmarks">Microbenchmarks</a></li>
 50 <li><a href="#special-tests" id="toc-special-tests">Special
 51 tests</a></li>
 52 </ul></li>
 53 <li><a href="#test-results-and-summary"
 54 id="toc-test-results-and-summary">Test results and summary</a></li>
 55 <li><a href="#test-suite-control" id="toc-test-suite-control">Test suite
 56 control</a>
 57 <ul>
 58 <li><a href="#general-keywords-test_opts"
 59 id="toc-general-keywords-test_opts">General keywords
 60 (TEST_OPTS)</a></li>
 61 <li><a href="#jtreg-keywords" id="toc-jtreg-keywords">JTReg
 62 keywords</a></li>
 63 <li><a href="#gtest-keywords" id="toc-gtest-keywords">Gtest
 64 keywords</a></li>
 65 <li><a href="#microbenchmark-keywords"
 66 id="toc-microbenchmark-keywords">Microbenchmark keywords</a></li>
 67 </ul></li>
 68 <li><a href="#notes-for-specific-tests"
 69 id="toc-notes-for-specific-tests">Notes for Specific Tests</a>
 70 <ul>
 71 <li><a href="#docker-tests" id="toc-docker-tests">Docker Tests</a></li>
 72 <li><a href="#non-us-locale" id="toc-non-us-locale">Non-US
 73 locale</a></li>
 74 <li><a href="#pkcs11-tests" id="toc-pkcs11-tests">PKCS11 Tests</a></li>
 75 <li><a href="#sctp-tests" id="toc-sctp-tests">SCTP Tests</a></li>
 76 <li><a href="#testing-ahead-of-time-optimizations"
 77 id="toc-testing-ahead-of-time-optimizations">Testing Ahead-of-time
 78 Optimizations</a></li>
 79 <li><a href="#testing-with-alternative-security-providers"
 80 id="toc-testing-with-alternative-security-providers">Testing with
 81 alternative security providers</a></li>
 82 <li><a href="#client-ui-tests" id="toc-client-ui-tests">Client UI
 83 Tests</a></li>
 84 </ul></li>
 85 <li><a href="#editing-this-document"
 86 id="toc-editing-this-document">Editing this document</a></li>
 87 </ul>
 88 </nav>
 89 <h2 id="overview">Overview</h2>
 90 <p>The bulk of JDK tests use <a
 91 href="https://openjdk.org/jtreg/">jtreg</a>, a regression test framework
 92 and test runner built for the JDK's specific needs. Other test
 93 frameworks are also used. The different test frameworks can be executed
 94 directly, but there is also a set of make targets intended to simplify
 95 the interface, and figure out how to run your tests for you.</p>
 96 <h2 id="running-tests-locally-with-make-test">Running tests locally with
 97 <code>make test</code></h2>
 98 <p>This is the easiest way to get started. Assuming you've built the JDK
 99 locally, execute:</p>
100 <pre><code>$ make test</code></pre>
101 <p>This will run a default set of tests against the JDK, and present you
102 with the results. <code>make test</code> is part of a family of
103 test-related make targets which simplify running tests, because they
104 invoke the various test frameworks for you. The "make test framework" is
105 simple to start with, but more complex ad-hoc combination of tests is
106 also possible. You can always invoke the test frameworks directly if you
107 want even more control.</p>
108 <p>Some example command-lines:</p>
109 <pre><code>$ make test-tier1
110 $ make test-jdk_lang JTREG=&quot;JOBS=8&quot;
111 $ make test TEST=jdk_lang
112 $ make test-only TEST=&quot;gtest:LogTagSet gtest:LogTagSetDescriptions&quot; GTEST=&quot;REPEAT=-1&quot;
113 $ make test TEST=&quot;hotspot:hotspot_gc&quot; JTREG=&quot;JOBS=1;TIMEOUT_FACTOR=8;JAVA_OPTIONS=-XshowSettings -Xlog:gc+ref=debug&quot;
114 $ make test TEST=&quot;jtreg:test/hotspot:hotspot_gc test/hotspot/jtreg/native_sanity/JniVersion.java&quot;
115 $ make test TEST=&quot;micro:java.lang.reflect&quot; MICRO=&quot;FORK=1;WARMUP_ITER=2&quot;
116 $ make exploded-test TEST=tier2</code></pre>
117 <p>"tier1" and "tier2" refer to tiered testing, see further down. "TEST"
118 is a test selection argument which the make test framework will use to
119 try to find the tests you want. It iterates over the available test
120 frameworks, and if the test isn't present in one, it tries the next one.
121 The main target <code>test</code> uses the jdk-image as the tested
122 product. There is also an alternate target <code>exploded-test</code>
123 that uses the exploded image instead. Not all tests will run
124 successfully on the exploded image, but using this target can greatly
125 improve rebuild times for certain workflows.</p>
126 <p>Previously, <code>make test</code> was used to invoke an old system
127 for running tests, and <code>make run-test</code> was used for the new
128 test framework. For backward compatibility with scripts and muscle
129 memory, <code>run-test</code> and variants like
130 <code>exploded-run-test</code> or <code>run-test-tier1</code> are kept
131 as aliases.</p>
132 <h3 id="configuration">Configuration</h3>
133 <p>To be able to run JTReg tests, <code>configure</code> needs to know
134 where to find the JTReg test framework. If it is not picked up
135 automatically by configure, use the
136 <code>--with-jtreg=&lt;path to jtreg home&gt;</code> option to point to
137 the JTReg framework. Note that this option should point to the JTReg
138 home, i.e. the top directory, containing <code>lib/jtreg.jar</code> etc.
139 (An alternative is to set the <code>JT_HOME</code> environment variable
140 to point to the JTReg home before running <code>configure</code>.)</p>
141 <p>To be able to run microbenchmarks, <code>configure</code> needs to
142 know where to find the JMH dependency. Use
143 <code>--with-jmh=&lt;path to JMH jars&gt;</code> to point to a directory
144 containing the core JMH and transitive dependencies. The recommended
145 dependencies can be retrieved by running
146 <code>sh make/devkit/createJMHBundle.sh</code>, after which
147 <code>--with-jmh=build/jmh/jars</code> should work.</p>
148 <p>When tests fail or timeout, jtreg runs its failure handler to capture
149 necessary data from the system where the test was run. This data can
150 then be used to analyze the test failures. Collecting this data involves
151 running various commands (which are listed in files residing in
152 <code>test/failure_handler/src/share/conf</code>) and some of these
153 commands use <code>sudo</code>. If the system's <code>sudoers</code>
154 file isn't configured to allow running these commands, then it can
155 result in password being prompted during the failure handler execution.
156 Typically, when running locally, collecting this additional data isn't
157 always necessary. To disable running the failure handler, use
158 <code>--enable-jtreg-failure-handler=no</code> when running
159 <code>configure</code>. If, however, you want to let the failure handler
160 to run and don't want to be prompted for sudo password, then you can
161 configure your <code>sudoers</code> file appropriately. Please read the
162 necessary documentation of your operating system to see how to do that;
163 here we only show one possible way of doing that - edit the
164 <code>/etc/sudoers.d/sudoers</code> file to include the following
165 line:</p>
166 <pre><code>johndoe ALL=(ALL) NOPASSWD: /sbin/dmesg</code></pre>
167 <p>This line configures <code>sudo</code> to <em>not</em> prompt for
168 password for the <code>/sbin/dmesg</code> command (this is one of the
169 commands that is listed in the files at
170 <code>test/failure_handler/src/share/conf</code>), for the user
171 <code>johndoe</code>. Here <code>johndoe</code> is the user account
172 under which the jtreg tests are run. Replace the username with a
173 relevant user account of your system.</p>
174 <h2 id="test-selection">Test selection</h2>
175 <p>All functionality is available using the <code>test</code> make
176 target. In this use case, the test or tests to be executed is controlled
177 using the <code>TEST</code> variable. To speed up subsequent test runs
178 with no source code changes, <code>test-only</code> can be used instead,
179 which do not depend on the source and test image build.</p>
180 <p>For some common top-level tests, direct make targets have been
181 generated. This includes all JTReg test groups, the hotspot gtest, and
182 custom tests (if present). This means that <code>make test-tier1</code>
183 is equivalent to <code>make test TEST="tier1"</code>, but the latter is
184 more tab-completion friendly. For more complex test runs, the
185 <code>test TEST="x"</code> solution needs to be used.</p>
186 <p>The test specifications given in <code>TEST</code> is parsed into
187 fully qualified test descriptors, which clearly and unambiguously show
188 which tests will be run. As an example, <code>:tier1</code> will expand
189 to include all subcomponent test directories that define
190 <code>tier1</code>, for example:
191 <code>jtreg:$(TOPDIR)/test/hotspot/jtreg:tier1 jtreg:$(TOPDIR)/test/jdk:tier1 jtreg:$(TOPDIR)/test/langtools:tier1 ...</code>.
192 You can always submit a list of fully qualified test descriptors in the
193 <code>TEST</code> variable if you want to shortcut the parser.</p>
194 <h3 id="common-test-groups">Common Test Groups</h3>
195 <p>Ideally, all tests are run for every change but this may not be
196 practical due to the limited testing resources, the scope of the change,
197 etc.</p>
198 <p>The source tree currently defines a few common test groups in the
199 relevant <code>TEST.groups</code> files. There are test groups that
200 cover a specific component, for example <code>hotspot_gc</code>. It is a
201 good idea to look into <code>TEST.groups</code> files to get a sense
202 what tests are relevant to a particular JDK component.</p>
203 <p>Component-specific tests may miss some unintended consequences of a
204 change, so other tests should also be run. Again, it might be
205 impractical to run all tests, and therefore <em>tiered</em> test groups
206 exist. Tiered test groups are not component-specific, but rather cover
207 the significant parts of the entire JDK.</p>
208 <p>Multiple tiers allow balancing test coverage and testing costs. Lower
209 test tiers are supposed to contain the simpler, quicker and more stable
210 tests. Higher tiers are supposed to contain progressively more thorough,
211 slower, and sometimes less stable tests, or the tests that require
212 special configuration.</p>
213 <p>Contributors are expected to run the tests for the areas that are
214 changed, and the first N tiers they can afford to run, but at least
215 tier1.</p>
216 <p>A brief description of the tiered test groups:</p>
217 <ul>
218 <li><p><code>tier1</code>: This is the most fundamental test tier.
219 Roughly speaking, a failure of a test in this tier has the potential to
220 indicate a problem that would affect many Java programs. Tests in
221 <code>tier1</code> include tests of HotSpot, core APIs in the
222 <code>java.base</code> module, and the <code>javac</code> compiler.
223 Multiple developers run these tests every day. Because of the widespread
224 use, the tests in <code>tier1</code> are carefully selected and
225 optimized to run fast, and to run in the most stable manner. As a
226 guideline, nearly all individual tests in <code>tier1</code> are
227 expected to run to completion in ten seconds or less when run on common
228 configurations used for development. Long-running tests, even of core
229 functionality, should occur in higher tiers or be covered in other kinds
230 of testing. The test failures in <code>tier1</code> are usually followed
231 up on quickly, either with fixes, or adding relevant tests to problem
232 list. GitHub Actions workflows, if enabled, run <code>tier1</code>
233 tests.</p></li>
234 <li><p><code>tier2</code>: This test group covers even more ground.
235 These contain, among other things, tests that either run for too long to
236 be at <code>tier1</code>, or may require special configuration, or tests
237 that are less stable, or cover the broader range of non-core JVM and JDK
238 features/components (for example, XML).</p></li>
239 <li><p><code>tier3</code>: This test group includes more stressful
240 tests, the tests for corner cases not covered by previous tiers, plus
241 the tests that require GUIs. As such, this suite should either be run
242 with low concurrency (<code>TEST_JOBS=1</code>), or without headful
243 tests(<code>JTREG_KEYWORDS=\!headful</code>), or both.</p></li>
244 <li><p><code>tier4</code>: This test group includes every other test not
245 covered by previous tiers. It includes, for example,
246 <code>vmTestbase</code> suites for Hotspot, which run for many hours
247 even on large machines. It also runs GUI tests, so the same
248 <code>TEST_JOBS</code> and <code>JTREG_KEYWORDS</code> caveats
249 apply.</p></li>
250 </ul>
251 <h3 id="jtreg">JTReg</h3>
252 <p>JTReg tests can be selected either by picking a JTReg test group, or
253 a selection of files or directories containing JTReg tests.
254 Documentation can be found at <a
255 href="https://openjdk.org/jtreg/">https://openjdk.org/jtreg/</a>, note
256 especially the extensive <a
257 href="https://openjdk.org/jtreg/faq.html">FAQ</a>.</p>
258 <p>JTReg test groups can be specified either without a test root, e.g.
259 <code>:tier1</code> (or <code>tier1</code>, the initial colon is
260 optional), or with, e.g. <code>hotspot:tier1</code>,
261 <code>test/jdk:jdk_util</code> or
262 <code>$(TOPDIR)/test/hotspot/jtreg:hotspot_all</code>. The test root can
263 be specified either as an absolute path, or a path relative to the JDK
264 top directory, or the <code>test</code> directory. For simplicity, the
265 hotspot JTReg test root, which really is <code>hotspot/jtreg</code> can
266 be abbreviated as just <code>hotspot</code>.</p>
267 <p>When specified without a test root, all matching groups from all test
268 roots will be added. Otherwise, only the group from the specified test
269 root will be added.</p>
270 <p>Individual JTReg tests or directories containing JTReg tests can also
271 be specified, like
272 <code>test/hotspot/jtreg/native_sanity/JniVersion.java</code> or
273 <code>hotspot/jtreg/native_sanity</code>. Just like for test root
274 selection, you can either specify an absolute path (which can even point
275 to JTReg tests outside the source tree), or a path relative to either
276 the JDK top directory or the <code>test</code> directory.
277 <code>hotspot</code> can be used as an alias for
278 <code>hotspot/jtreg</code> here as well.</p>
279 <p>As long as the test groups or test paths can be uniquely resolved,
280 you do not need to enter the <code>jtreg:</code> prefix. If this is not
281 possible, or if you want to use a fully qualified test descriptor, add
282 <code>jtreg:</code>, e.g.
283 <code>jtreg:test/hotspot/jtreg/native_sanity</code>.</p>
284 <h3 id="gtest">Gtest</h3>
285 <p><strong>Note:</strong> To be able to run the Gtest suite, you need to
286 configure your build to be able to find a proper version of the gtest
287 source. For details, see the section <strong>"Running Tests" in the
288 build documentation</strong> (<a
289 href="building.html#running-tests">html</a>, <a
290 href="building.md#running-tests">markdown</a>).</p>
291 <p>Since the Hotspot Gtest suite is so quick, the default is to run all
292 tests. This is specified by just <code>gtest</code>, or as a fully
293 qualified test descriptor <code>gtest:all</code>.</p>
294 <p>If you want, you can single out an individual test or a group of
295 tests, for instance <code>gtest:LogDecorations</code> or
296 <code>gtest:LogDecorations.level_test_vm</code>. This can be
297 particularly useful if you want to run a shaky test repeatedly.</p>
298 <p>For Gtest, there is a separate test suite for each JVM variant. The
299 JVM variant is defined by adding <code>/&lt;variant&gt;</code> to the
300 test descriptor, e.g. <code>gtest:Log/client</code>. If you specify no
301 variant, gtest will run once for each JVM variant present (e.g. server,
302 client). So if you only have the server JVM present, then
303 <code>gtest:all</code> will be equivalent to
304 <code>gtest:all/server</code>.</p>
305 <h3 id="microbenchmarks">Microbenchmarks</h3>
306 <p>Which microbenchmarks to run is selected using a regular expression
307 following the <code>micro:</code> test descriptor, e.g.,
308 <code>micro:java.lang.reflect</code>. This delegates the test selection
309 to JMH, meaning package name, class name and even benchmark method names
310 can be used to select tests.</p>
311 <p>Using special characters like <code>|</code> in the regular
312 expression is possible, but needs to be escaped multiple times:
313 <code>micro:ArrayCopy\\\\\|reflect</code>.</p>
314 <h3 id="special-tests">Special tests</h3>
315 <p>A handful of odd tests that are not covered by any other testing
316 framework are accessible using the <code>special:</code> test
317 descriptor. Currently, this includes <code>failure-handler</code> and
318 <code>make</code>.</p>
319 <ul>
320 <li><p>Failure handler testing is run using
321 <code>special:failure-handler</code> or just
322 <code>failure-handler</code> as test descriptor.</p></li>
323 <li><p>Tests for the build system, including both makefiles and related
324 functionality, is run using <code>special:make</code> or just
325 <code>make</code> as test descriptor. This is equivalent to
326 <code>special:make:all</code>.</p>
327 <p>A specific make test can be run by supplying it as argument, e.g.
328 <code>special:make:idea</code>. As a special syntax, this can also be
329 expressed as <code>make-idea</code>, which allows for command lines as
330 <code>make test-make-idea</code>.</p></li>
331 </ul>
332 <h2 id="test-results-and-summary">Test results and summary</h2>
333 <p>At the end of the test run, a summary of all tests run will be
334 presented. This will have a consistent look, regardless of what test
335 suites were used. This is a sample summary:</p>
336 <pre><code>==============================
337 Test summary
338 ==============================
339    TEST                                          TOTAL  PASS  FAIL ERROR
340 &gt;&gt; jtreg:jdk/test:tier1                           1867  1865     2     0 &lt;&lt;
341    jtreg:langtools/test:tier1                     4711  4711     0     0
342    jtreg:nashorn/test:tier1                        133   133     0     0
343 ==============================
344 TEST FAILURE</code></pre>
345 <p>Tests where the number of TOTAL tests does not equal the number of
346 PASSed tests will be considered a test failure. These are marked with
347 the <code>&gt;&gt; ... &lt;&lt;</code> marker for easy
348 identification.</p>
349 <p>The classification of non-passed tests differs a bit between test
350 suites. In the summary, ERROR is used as a catch-all for tests that
351 neither passed nor are classified as failed by the framework. This might
352 indicate test framework error, timeout or other problems.</p>
353 <p>In case of test failures, <code>make test</code> will exit with a
354 non-zero exit value.</p>
355 <p>All tests have their result stored in
356 <code>build/$BUILD/test-results/$TEST_ID</code>, where TEST_ID is a
357 path-safe conversion from the fully qualified test descriptor, e.g. for
358 <code>jtreg:jdk/test:tier1</code> the TEST_ID is
359 <code>jtreg_jdk_test_tier1</code>. This path is also printed in the log
360 at the end of the test run.</p>
361 <p>Additional work data is stored in
362 <code>build/$BUILD/test-support/$TEST_ID</code>. For some frameworks,
363 this directory might contain information that is useful in determining
364 the cause of a failed test.</p>
365 <h2 id="test-suite-control">Test suite control</h2>
366 <p>It is possible to control various aspects of the test suites using
367 make control variables.</p>
368 <p>These variables use a keyword=value approach to allow multiple values
369 to be set. So, for instance,
370 <code>JTREG="JOBS=1;TIMEOUT_FACTOR=8"</code> will set the JTReg
371 concurrency level to 1 and the timeout factor to 8. This is equivalent
372 to setting <code>JTREG_JOBS=1 JTREG_TIMEOUT_FACTOR=8</code>, but using
373 the keyword format means that the <code>JTREG</code> variable is parsed
374 and verified for correctness, so <code>JTREG="TMIEOUT_FACTOR=8"</code>
375 would give an error, while <code>JTREG_TMIEOUT_FACTOR=8</code> would
376 just pass unnoticed.</p>
377 <p>To separate multiple keyword=value pairs, use <code>;</code>
378 (semicolon). Since the shell normally eats <code>;</code>, the
379 recommended usage is to write the assignment inside quotes, e.g.
380 <code>JTREG="...;..."</code>. This will also make sure spaces are
381 preserved, as in
382 <code>JTREG="JAVA_OPTIONS=-XshowSettings -Xlog:gc+ref=debug"</code>.</p>
383 <p>(Other ways are possible, e.g. using backslash:
384 <code>JTREG=JOBS=1\;TIMEOUT_FACTOR=8</code>. Also, as a special
385 technique, the string <code>%20</code> will be replaced with space for
386 certain options, e.g.
387 <code>JTREG=JAVA_OPTIONS=-XshowSettings%20-Xlog:gc+ref=debug</code>.
388 This can be useful if you have layers of scripts and have trouble
389 getting proper quoting of command line arguments through.)</p>
390 <p>As far as possible, the names of the keywords have been standardized
391 between test suites.</p>
392 <h3 id="general-keywords-test_opts">General keywords (TEST_OPTS)</h3>
393 <p>Some keywords are valid across different test suites. If you want to
394 run tests from multiple test suites, or just don't want to care which
395 test suite specific control variable to use, then you can use the
396 general TEST_OPTS control variable.</p>
397 <p>There are also some keywords that applies globally to the test runner
398 system, not to any specific test suites. These are also available as
399 TEST_OPTS keywords.</p>
400 <h4 id="jobs">JOBS</h4>
401 <p>Currently only applies to JTReg.</p>
402 <h4 id="timeout_factor">TIMEOUT_FACTOR</h4>
403 <p>Currently only applies to <a href="#timeout_factor-1">JTReg
404 -timeoutFactor</a>.</p>
405 <h4 id="java_options">JAVA_OPTIONS</h4>
406 <p>Applies to JTReg, GTest and Micro.</p>
407 <h4 id="vm_options">VM_OPTIONS</h4>
408 <p>Applies to JTReg, GTest and Micro.</p>
409 <h4 id="jcov">JCOV</h4>
410 <p>This keyword applies globally to the test runner system. If set to
411 <code>true</code>, it enables JCov coverage reporting for all tests run.
412 To be useful, the JDK under test must be run with a JDK built with JCov
413 instrumentation
414 (<code>configure --with-jcov=&lt;path to directory containing lib/jcov.jar&gt;</code>,
415 <code>make jcov-image</code>).</p>
416 <p>The simplest way to run tests with JCov coverage report is to use the
417 special target <code>jcov-test</code> instead of <code>test</code>, e.g.
418 <code>make jcov-test TEST=jdk_lang</code>. This will make sure the JCov
419 image is built, and that JCov reporting is enabled.</p>
420 <p>To include JCov coverage for just a subset of all modules, you can
421 use the <code>--with-jcov-modules</code> arguments to
422 <code>configure</code>, e.g.
423 <code>--with-jcov-modules=jdk.compiler,java.desktop</code>.</p>
424 <p>For more fine-grained control, you can pass arbitrary filters to JCov
425 using <code>--with-jcov-filters</code>, and you can specify a specific
426 JDK to instrument using <code>--with-jcov-input-jdk</code>.</p>
427 <p>The JCov report is stored in
428 <code>build/$BUILD/test-results/jcov-output/report</code>.</p>
429 <p>Please note that running with JCov reporting can be very memory
430 intensive.</p>
431 <h4 id="jcov_diff_changeset">JCOV_DIFF_CHANGESET</h4>
432 <p>While collecting code coverage with JCov, it is also possible to find
433 coverage for only recently changed code. JCOV_DIFF_CHANGESET specifies a
434 source revision. A textual report will be generated showing coverage of
435 the diff between the specified revision and the repository tip.</p>
436 <p>The report is stored in
437 <code>build/$BUILD/test-results/jcov-output/diff_coverage_report</code>
438 file.</p>
439 <h4 id="aot_jdk">AOT_JDK</h4>
440 <p>See <a href="#testing-ahead-of-time-optimizations">Testing
441 Ahead-of-time optimizations</a>.</p>
442 <h3 id="jtreg-keywords">JTReg keywords</h3>
443 <h4 id="jobs-1">JOBS</h4>
444 <p>The test concurrency (<code>-concurrency</code>).</p>
445 <p>Defaults to TEST_JOBS (if set by <code>--with-test-jobs=</code>),
446 otherwise it defaults to JOBS, except for Hotspot, where the default is
447 <em>number of CPU cores/2</em>, but never more than <em>memory size in
448 GB/2</em>.</p>
449 <h4 id="timeout_factor-1">TIMEOUT_FACTOR</h4>
450 <p>The <code>TIMEOUT_FACTOR</code> is forwarded to JTReg framework
451 itself (<code>-timeoutFactor</code>). Also, some test cases that
452 programmatically wait a certain amount of time will apply this factor.
453 If we run in forced compilation mode (<code>-Xcomp</code>), the build
454 system will automatically adjust this factor to compensate for less
455 performance. Defaults to 4.</p>
456 <h4 id="failure_handler_timeout">FAILURE_HANDLER_TIMEOUT</h4>
457 <p>Sets the argument <code>-timeoutHandlerTimeout</code> for JTReg. The
458 default value is 0. This is only valid if the failure handler is
459 built.</p>
460 <h4 id="test_thread_factory">TEST_THREAD_FACTORY</h4>
461 <p>Sets the <code>-testThreadFactory</code> for JTReg. It should be the
462 fully qualified classname of a class which implements
463 <code>java.util.concurrent.ThreadFactory</code>. One such implementation
464 class, named Virtual, is currently part of the JDK build in the
465 <code>test/jtreg_test_thread_factory/</code> directory. This class gets
466 compiled during the test image build. The implementation of the Virtual
467 class creates a new virtual thread for executing each test class.</p>
468 <h4 id="jvmti_stress_agent">JVMTI_STRESS_AGENT</h4>
469 <p>Executes JTReg tests with JVM TI stress agent. The stress agent is
470 the part of test library and located in
471 <code>test/lib/jdk/test/lib/jvmti/libJvmtiStressAgent.cpp</code>. The
472 value of this argument is set as JVM TI agent options. This mode uses
473 ProblemList-jvmti-stress-agent.txt as an additional exclude list.</p>
474 <h4 id="test_mode">TEST_MODE</h4>
475 <p>The test mode (<code>agentvm</code> or <code>othervm</code>).</p>
476 <p>Defaults to <code>agentvm</code>.</p>
477 <h4 id="assert">ASSERT</h4>
478 <p>Enable asserts (<code>-ea -esa</code>, or none).</p>
479 <p>Set to <code>true</code> or <code>false</code>. If true, adds
480 <code>-ea -esa</code>. Defaults to true, except for hotspot.</p>
481 <h4 id="verbose">VERBOSE</h4>
482 <p>The verbosity level (<code>-verbose</code>).</p>
483 <p>Defaults to <code>fail,error,summary</code>.</p>
484 <h4 id="retain">RETAIN</h4>
485 <p>What test data to retain (<code>-retain</code>).</p>
486 <p>Defaults to <code>fail,error</code>.</p>
487 <h4 id="max_mem">MAX_MEM</h4>
488 <p>Limit memory consumption (<code>-Xmx</code> and
489 <code>-vmoption:-Xmx</code>, or none).</p>
490 <p>Limit memory consumption for JTReg test framework and VM under test.
491 Set to 0 to disable the limits.</p>
492 <p>Defaults to 512m, except for hotspot, where it defaults to 0 (no
493 limit).</p>
494 <h4 id="max_output">MAX_OUTPUT</h4>
495 <p>Set the property <code>javatest.maxOutputSize</code> for the
496 launcher, to change the default JTReg log limit.</p>
497 <h4 id="keywords">KEYWORDS</h4>
498 <p>JTReg keywords sent to JTReg using <code>-k</code>. Please be careful
499 in making sure that spaces and special characters (like <code>!</code>)
500 are properly quoted. To avoid some issues, the special value
501 <code>%20</code> can be used instead of space.</p>
502 <h4 id="extra_problem_lists">EXTRA_PROBLEM_LISTS</h4>
503 <p>Use additional problem lists file or files, in addition to the
504 default ProblemList.txt located at the JTReg test roots.</p>
505 <p>If multiple file names are specified, they should be separated by
506 space (or, to help avoid quoting issues, the special value
507 <code>%20</code>).</p>
508 <p>The file names should be either absolute, or relative to the JTReg
509 test root of the tests to be run.</p>
510 <h4 id="run_problem_lists">RUN_PROBLEM_LISTS</h4>
511 <p>Use the problem lists to select tests instead of excluding them.</p>
512 <p>Set to <code>true</code> or <code>false</code>. If <code>true</code>,
513 JTReg will use <code>-match:</code> option, otherwise
514 <code>-exclude:</code> will be used. Default is <code>false</code>.</p>
515 <h4 id="options">OPTIONS</h4>
516 <p>Additional options to the JTReg test framework.</p>
517 <p>Use <code>JTREG="OPTIONS=--help all"</code> to see all available
518 JTReg options.</p>
519 <h4 id="java_options-1">JAVA_OPTIONS</h4>
520 <p>Additional Java options for running test classes (sent to JTReg as
521 <code>-javaoption</code>).</p>
522 <h4 id="vm_options-1">VM_OPTIONS</h4>
523 <p>Additional Java options to be used when compiling and running classes
524 (sent to JTReg as <code>-vmoption</code>).</p>
525 <p>This option is only needed in special circumstances. To pass Java
526 options to your test classes, use <code>JAVA_OPTIONS</code>.</p>
527 <h4 id="launcher_options">LAUNCHER_OPTIONS</h4>
528 <p>Additional Java options that are sent to the java launcher that
529 starts the JTReg harness.</p>
530 <h4 id="retry_count">RETRY_COUNT</h4>
531 <p>Retry failed tests up to a set number of times, until they pass. This
532 allows to pass the tests with intermittent failures. Defaults to 0.</p>
533 <h4 id="repeat_count">REPEAT_COUNT</h4>
534 <p>Repeat the tests up to a set number of times, stopping at first
535 failure. This helps to reproduce intermittent test failures. Defaults to
536 0.</p>
537 <h4 id="report">REPORT</h4>
538 <p>Use this report style when reporting test results (sent to JTReg as
539 <code>-report</code>). Defaults to <code>files</code>.</p>
540 <h4 id="manual">MANUAL</h4>
541 <p>Set to <code>true</code> to execute manual tests only.</p>
542 <h3 id="gtest-keywords">Gtest keywords</h3>
543 <h4 id="repeat">REPEAT</h4>
544 <p>The number of times to repeat the tests
545 (<code>--gtest_repeat</code>).</p>
546 <p>Default is 1. Set to -1 to repeat indefinitely. This can be
547 especially useful combined with
548 <code>OPTIONS=--gtest_break_on_failure</code> to reproduce an
549 intermittent problem.</p>
550 <h4 id="options-1">OPTIONS</h4>
551 <p>Additional options to the Gtest test framework.</p>
552 <p>Use <code>GTEST="OPTIONS=--help"</code> to see all available Gtest
553 options.</p>
554 <h3 id="microbenchmark-keywords">Microbenchmark keywords</h3>
555 <h4 id="fork">FORK</h4>
556 <p>Override the number of benchmark forks to spawn. Same as specifying
557 <code>-f &lt;num&gt;</code>.</p>
558 <h4 id="iter">ITER</h4>
559 <p>Number of measurement iterations per fork. Same as specifying
560 <code>-i &lt;num&gt;</code>.</p>
561 <h4 id="time">TIME</h4>
562 <p>Amount of time to spend in each measurement iteration, in seconds.
563 Same as specifying <code>-r &lt;num&gt;</code></p>
564 <h4 id="warmup_iter">WARMUP_ITER</h4>
565 <p>Number of warmup iterations to run before the measurement phase in
566 each fork. Same as specifying <code>-wi &lt;num&gt;</code>.</p>
567 <h4 id="warmup_time">WARMUP_TIME</h4>
568 <p>Amount of time to spend in each warmup iteration. Same as specifying
569 <code>-w &lt;num&gt;</code>.</p>
570 <h4 id="results_format">RESULTS_FORMAT</h4>
571 <p>Specify to have the test run save a log of the values. Accepts the
572 same values as <code>-rff</code>, i.e., <code>text</code>,
573 <code>csv</code>, <code>scsv</code>, <code>json</code>, or
574 <code>latex</code>.</p>
575 <h4 id="test_jdk">TEST_JDK</h4>
576 <p>The path to the JDK that will be used to run the benchmarks.</p>
577 <p>Defaults to <code>build/&lt;CONF-NAME&gt;/jdk</code>.</p>
578 <h4 id="benchmarks_jar">BENCHMARKS_JAR</h4>
579 <p>The path to the JAR containing the benchmarks.</p>
580 <p>Defaults to <code>test/micro/benchmarks.jar</code>.</p>
581 <h4 id="vm_options-2">VM_OPTIONS</h4>
582 <p>Additional VM arguments to provide to forked off VMs. Same as
583 <code>-jvmArgs &lt;args&gt;</code></p>
584 <h4 id="options-2">OPTIONS</h4>
585 <p>Additional arguments to send to JMH.</p>
586 <h2 id="notes-for-specific-tests">Notes for Specific Tests</h2>
587 <h3 id="docker-tests">Docker Tests</h3>
588 <p>Docker tests with default parameters may fail on systems with glibc
589 versions not compatible with the one used in the default docker image
590 (e.g., Oracle Linux 7.6 for x86). For example, they pass on Ubuntu 16.04
591 but fail on Ubuntu 18.04 if run like this on x86:</p>
592 <pre><code>$ make test TEST=&quot;jtreg:test/hotspot/jtreg/containers/docker&quot;</code></pre>
593 <p>To run these tests correctly, additional parameters for the correct
594 docker image are required on Ubuntu 18.04 by using
595 <code>JAVA_OPTIONS</code>.</p>
596 <pre><code>$ make test TEST=&quot;jtreg:test/hotspot/jtreg/containers/docker&quot; \
597     JTREG=&quot;JAVA_OPTIONS=-Djdk.test.docker.image.name=ubuntu
598     -Djdk.test.docker.image.version=latest&quot;</code></pre>
599 <h3 id="non-us-locale">Non-US locale</h3>
600 <p>If your locale is non-US, some tests are likely to fail. To work
601 around this you can set the locale to US. On Unix platforms simply
602 setting <code>LANG="en_US"</code> in the environment before running
603 tests should work. On Windows or macOS, setting
604 <code>JTREG="VM_OPTIONS=-Duser.language=en -Duser.country=US"</code>
605 helps for most, but not all test cases.</p>
606 <p>For example:</p>
607 <pre><code>$ export LANG=&quot;en_US&quot; &amp;&amp; make test TEST=...
608 $ make test JTREG=&quot;VM_OPTIONS=-Duser.language=en -Duser.country=US&quot; TEST=...</code></pre>
609 <h3 id="pkcs11-tests">PKCS11 Tests</h3>
610 <p>It is highly recommended to use the latest NSS version when running
611 PKCS11 tests. Improper NSS version may lead to unexpected failures which
612 are hard to diagnose. For example,
613 sun/security/pkcs11/Secmod/AddTrustedCert.java may fail on Ubuntu 18.04
614 with the default NSS version in the system. To run these tests
615 correctly, the system property
616 <code>jdk.test.lib.artifacts.&lt;NAME&gt;</code> is required on Ubuntu
617 18.04 to specify the alternative NSS lib directory. The
618 <code>&lt;NAME&gt;</code> component should be replaced with the name
619 element of the appropriate <code>@Artifact</code> class. (See
620 <code>test/jdk/sun/security/pkcs11/PKCS11Test.java</code>)</p>
621 <p>For example:</p>
622 <pre><code>$ make test TEST=&quot;jtreg:sun/security/pkcs11/Secmod/AddTrustedCert.java&quot; \
623     JTREG=&quot;JAVA_OPTIONS=-Djdk.test.lib.artifacts.nsslib-linux_aarch64=/path/to/NSS-libs&quot;</code></pre>
624 <p>For more notes about the PKCS11 tests, please refer to
625 test/jdk/sun/security/pkcs11/README.</p>
626 <h3 id="sctp-tests">SCTP Tests</h3>
627 <p>The SCTP tests require the SCTP runtime library, which is often not
628 installed by default in popular Linux distributions. Without this
629 library, the SCTP tests will be skipped. If you want to enable the SCTP
630 tests, you should install the SCTP library before running the tests.</p>
631 <p>For distributions using the .deb packaging format and the apt tool
632 (such as Debian, Ubuntu, etc.), try this:</p>
633 <pre><code>sudo apt install libsctp1
634 sudo modprobe sctp
635 lsmod | grep sctp</code></pre>
636 <p>For distributions using the .rpm packaging format and the dnf tool
637 (such as Fedora, Red Hat, etc.), try this:</p>
638 <pre><code>sudo dnf install -y lksctp-tools
639 sudo modprobe sctp
640 lsmod | grep sctp</code></pre>
641 <h3 id="testing-ahead-of-time-optimizations">Testing Ahead-of-time
642 Optimizations</h3>
643 <p>One way to improve test coverage of ahead-of-time (AOT) optimizations
644 in the JDK is to run existing jtreg test cases in a special "AOT_JDK"
645 mode. Example:</p>
646 <pre><code>$ make test JTREG=&quot;AOT_JDK=onestep&quot; \
647     TEST=open/test/hotspot/jtreg/runtime/invokedynamic</code></pre>
648 <p>In this testing mode, we first perform an AOT training run (see
649 https://openjdk.org/jeps/483) of a special test program (<a
650 href="../test/setup_aot/TestSetupAOT.java">test/setup_aot/TestSetupAOT.java</a>)
651 that accesses about 5,0000 classes in the JDK core libraries.
652 Optimization artifacts for these classes (such as pre-linked lambda
653 expressions, execution profiles, and pre-generated native code) are
654 stored into an AOT cache file, which will be used by all the JVMs
655 launched by the selected jtreg test cases.</p>
656 <p>When the jtreg tests call into the core libraries classes that are in
657 the AOT cache, we will be able to test the AOT optimizations that were
658 used on those classes.</p>
659 <p>Please note that not all existing jtreg test cases can be executed
660 with the AOT_JDK mode. See <a
661 href="../test/hotspot/jtreg/ProblemList-AotJdk.txt">test/hotspot/jtreg/ProblemList-AotJdk.txt</a>
662 and <a
663 href="../test/jdk/ProblemList-AotJdk.txt">test/jdk/ProblemList-AotJdk.txt</a>.</p>
664 <p>Also, test cases that were written specifically to test AOT, such as
665 the tests under <a
666 href="../test/hotspot/jtreg/runtime/cds/">test/hotspot/jtreg/runtime/cds</a>,
667 cannot be executed with the AOT_JDK mode.</p>
668 <p>Valid values for <code>AOT_JDK</code> are <code>onestep</code> and
669 <code>twostep</code>. These control how the AOT cache is generated. See
670 https://openjdk.org/jeps/514 for details. All other values are
671 ignored.</p>
672 <h3 id="testing-with-alternative-security-providers">Testing with
673 alternative security providers</h3>
674 <p>Some security tests use a hardcoded provider for
675 <code>KeyFactory</code>, <code>Cipher</code>,
676 <code>KeyPairGenerator</code>, <code>KeyGenerator</code>,
677 <code>AlgorithmParameterGenerator</code>, <code>KeyAgreement</code>,
678 <code>Mac</code>, <code>MessageDigest</code>, <code>SecureRandom</code>,
679 <code>Signature</code>, <code>AlgorithmParameters</code>,
680 <code>Configuration</code>, <code>Policy</code>, or
681 <code>SecretKeyFactory</code> objects. Specify the
682 <code>-Dtest.provider.name=NAME</code> property to use a different
683 provider for the service(s).</p>
684 <h3 id="client-ui-tests">Client UI Tests</h3>
685 <h4 id="system-key-shortcuts">System key shortcuts</h4>
686 <p>Some Client UI tests use key sequences which may be reserved by the
687 operating system. Usually that causes the test failure. So it is highly
688 recommended to disable system key shortcuts prior testing. The steps to
689 access and disable system key shortcuts for various platforms are
690 provided below.</p>
691 <h5 id="macos">macOS</h5>
692 <p>Choose Apple menu; System Preferences, click Keyboard, then click
693 Shortcuts; select or deselect desired shortcut.</p>
694 <p>For example,
695 test/jdk/javax/swing/TooltipManager/JMenuItemToolTipKeyBindingsTest/JMenuItemToolTipKeyBindingsTest.java
696 fails on macOS because it uses <code>CTRL + F1</code> key sequence to
697 show or hide tooltip message but the key combination is reserved by the
698 operating system. To run the test correctly the default global key
699 shortcut should be disabled using the steps described above, and then
700 deselect "Turn keyboard access on or off" option which is responsible
701 for <code>CTRL + F1</code> combination.</p>
702 <h5 id="linux">Linux</h5>
703 <p>Open the Activities overview and start typing Settings; Choose
704 Settings, click Devices, then click Keyboard; set or override desired
705 shortcut.</p>
706 <h5 id="windows">Windows</h5>
707 <p>Type <code>gpedit</code> in the Search and then click Edit group
708 policy; navigate to User Configuration -&gt; Administrative Templates
709 -&gt; Windows Components -&gt; File Explorer; in the right-side pane
710 look for "Turn off Windows key hotkeys" and double click on it; enable
711 or disable hotkeys.</p>
712 <p>Note: restart is required to make the settings take effect.</p>
713 <h4 id="robot-api">Robot API</h4>
714 <p>Most automated Client UI tests use <code>Robot</code> API to control
715 the UI. Usually, the default operating system settings need to be
716 adjusted for Robot to work correctly. The detailed steps how to access
717 and update these settings for different platforms are provided
718 below.</p>
719 <h5 id="macos-1">macOS</h5>
720 <p><code>Robot</code> is not permitted to control your Mac by default
721 since macOS 10.15. To allow it, choose Apple menu -&gt; System Settings,
722 click Privacy &amp; Security; then click Accessibility and ensure the
723 following apps are allowed to control your computer: <em>Java</em> and
724 <em>Terminal</em>. If the tests are run from an IDE, the IDE should be
725 granted this permission too.</p>
726 <h5 id="windows-1">Windows</h5>
727 <p>On Windows if Cygwin terminal is used to run the tests, there is a
728 delay in focus transfer. Usually it causes automated UI test failure. To
729 disable the delay, type <code>regedit</code> in the Search and then
730 select Registry Editor; navigate to the following key:
731 <code>HKEY_CURRENT_USER\Control Panel\Desktop</code>; make sure the
732 <code>ForegroundLockTimeout</code> value is set to 0.</p>
733 <p>Additional information about Client UI tests configuration for
734 various operating systems can be obtained at <a
735 href="https://wiki.openjdk.org/display/ClientLibs/Automated+client+GUI+testing+system+set+up+requirements">Automated
736 client GUI testing system set up requirements</a></p>
737 <h2 id="editing-this-document">Editing this document</h2>
738 <p>If you want to contribute changes to this document, edit
739 <code>doc/testing.md</code> and then run
740 <code>make update-build-docs</code> to generate the same changes in
741 <code>doc/testing.html</code>.</p>
742 </body>
743 </html>