JDK-8292316 : Tests should not rely on specific JAR file names (jpackage)
  • Type: Sub-task
  • Component: tools
  • Sub-Component: jpackage
  • Affected Version: 17,18,19,20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-08-13
  • Updated: 2023-09-19
  • Resolved: 2022-08-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17 JDK 20
17.0.10-oracleFixed 20 b12Fixed
Related Reports
Blocks :  
Relates :  
Description
There are tests that rely on specific JAR file names being present at run-time, which they don't control, as they are normally provided by jtreg's binary image. Examples for such JAR files names are:

- junit.jar
- hamcrest.jar
- testng.jar

These tests expect those specific JAR files being present in:

- jtreg's lib directory
- the value returned by System.getProperty("java.class.path")

Here is one such test in question:

https://github.com/openjdk/jdk/blob/master/test/jdk/tools/jpackage/junit/junit.java

There may be more under "test/jdk/tools/jpackage"
Comments
Fix request [17u] I backport this as it is needed by jtreg 7 No risk, only a test change. Clean backport except for one Test not in 17. Tests pass. SAP nighlty testing passed
17-06-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/1460 Date: 2023-06-16 15:22:34 +0000
16-06-2023

Changeset: 45c3e898 Author: Alexey Semenyuk <asemenyuk@openjdk.org> Date: 2022-08-22 15:42:27 +0000 URL: https://git.openjdk.org/jdk/commit/45c3e898ed538545921395372fe507e9111401e1
22-08-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/9944 Date: 2022-08-19 15:41:47 +0000
19-08-2022

Dropping both "helper" files and replacing them with direct jtreg directives looks very good. Happy to review and double-check a PR with updated unit tests, which would supersede https://github.com/openjdk/jdk/commit/60c018e802b6a8a50cf58d4ea0a667bbe3fcbadc with a more future-proof variant.
19-08-2022

The following test declaration in each unit test allows to drop junit.java and run_junit.sh: /* * @test * @modules jdk.jpackage * @compile --patch-module jdk.jpackage=${test.src} --add-reads jdk.jpackage=ALL-UNNAMED --add-exports jdk.jpackage/jdk.jpackage.internal=ALL-UNNAMED PathGroupTest.java * @run junit/othervm --patch-module jdk.jpackage=${test.classes} --add-reads jdk.jpackage=ALL-UNNAMED --add-exports jdk.jpackage/jdk.jpackage.internal=ALL-UNNAMED jdk.jpackage.internal.PathGroupTest */ Does it look good?
19-08-2022

Good question! I'll give it a try and get back with the results.
17-08-2022

Why are those tests run by a shell script in the first place? Shouldn't each test have one or more jtreg test directives? Like: /* * @test * @modules jdk.jpackage * ... * @run junit PlatformVersionTest */
17-08-2022

Nor do I -- even tried `@library ${jtreg.home}/lib/*.jar` Note that passing `@library ${jtreg.home}/lib/junit-platform-console-standalone-1.8.2.jar` does work, but then the test would still rely on a specific JAR file name. [~jjg] do you have an idea how to fix this, perhaps without enhancing jtreg (and release jtreg 7.1)?
17-08-2022

Are there jtreg variables not used in run_junit.sh: --- "${COMPILEJAVA}/bin/javac" ${TESTTOOLVMOPTS} ${TESTJAVACOPTS} \ "${common_args[@]}" -d "${TESTCLASSES}" "${sources[@]}" --- ? This command line is based on what is documented at https://openjdk.org/jtreg/vmoptions.html#run When run_junit.sh was created I didn't find an alternative to adding junit classes on javac and java command lines in run_junit.sh but use @library in junit.java.
15-08-2022

In this case the idea is to configure the classpath in the shell file, using variables provided by jtreg and remove the `@library ...` directive from the Java compilation unit.
15-08-2022

test/jdk/tools/jpackage/junit/junit.java is the only place in jpackage test suite referencing specific jars by name. https://github.com/openjdk/jdk/blob/master/test/jdk/tools/jpackage/junit/junit.java works together with https://github.com/openjdk/jdk/blob/master/test/jdk/tools/jpackage/junit/run_junit.sh run_junit.sh script compiles all .java sources (which a junit tests) in https://github.com/openjdk/jdk/tree/master/test/jdk/tools/jpackage/junit/jdk/jpackage/internal directory and runs them. [~cstein] what is the right way to run junit tests with jtreg?
15-08-2022