§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 tests
  • all - 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
2
3
4
5
6
7
8
9
10
11
12
13
/*
* @test
* @run main RetainDemo
*/
import java.nio.file.*;

public class RetainDemo {
public static void main(String[] args) throws Exception {
Path p = Path.of("retain-demo.txt"); // relative => goes into jtreg scratch dir
Files.writeString(p, "hello\n");
System.out.println("Wrote: " + p.toAbsolutePath());
}
}

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.