OpenJDK Trivia: jtreg Retains Logs for Successful Tests
§JTREG_RETAIN
JTREG_RETAIN controls whether per-test scratch artifacts are kept after a test run.
fail,error(the default) - keep artifacts only for failing or erroring testsall- keep artifacts for every test, including passing ones
Using all is useful for debugging but increases disk usage.
§Example
Create a tiny jtreg test that writes a file using a relative path (for example, retain-demo.txt). Because the path is relative, the file is created in the test’s scratch directory established by the jtreg harness.
test/jdk/RetainDemo.java:
1 | /* |
Run the test via make CONF=debug test TEST="jtreg:test/jdk/RetainDemo.java" <placeholder-for-JTREG_RETAIN> and compare two runs:
- With
JTREG_RETAIN=fail,error: the test passes, so the harness removes the scratch directory after completion. - With
JTREG_RETAIN=all: the test passes, but the work directory (and the file written) remains.
With JTREG_RETAIN=all, the generated file appears as
build/linux-x64-debug/test-support/jtreg_test_jdk_RetainDemo_java/RetainDemo/retain-demo.txt
Exact subdirectories vary, but the key point is that retain=all retains temp files (e.g. logs) after a successful run.