Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7902789

When using a relative path in -jdk,the library specified by @library ${java.home}/ will be invalid

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • jtreg5.2
    • jtreg5.1
    • tools
    • None

      $ rm -rf JT*; jtreg -jdk:../../../../../../jdk1.8.0_212/ -va sun/tools/jconsole/WorkerDeadlockTest.java
      STDOUT:
      STDERR:
      /home/hedongbo/myprojects/openJDK/jdk8u-dev/jdk/test/sun/tools/jconsole/WorkerDeadlockTest.java:33: error: package sun.tools.jconsole does not exist
      import sun.tools.jconsole.Worker;
                               ^
      /home/hedongbo/myprojects/openJDK/jdk8u-dev/jdk/test/sun/tools/jconsole/WorkerDeadlockTest.java:42: error: cannot find symbol
                  Worker worker = new Worker("worker-" + i);
                  ^
        symbol: class Worker
        location: class WorkerDeadlockTest
      /home/hedongbo/myprojects/openJDK/jdk8u-dev/jdk/test/sun/tools/jconsole/WorkerDeadlockTest.java:42: error: cannot find symbol
                  Worker worker = new Worker("worker-" + i);
                                      ^
        symbol: class Worker
        location: class WorkerDeadlockTest
      3 errors

      TEST RESULT: Failed. Compilation failed: Compilation failed
      --------------------------------------------------
      Test results: failed: 1

      $ rm -rf JT*; jtreg -jdk:/home/hedongbo/software/jdk1.8.0_212 sun/tools/jconsole/WorkerDeadlockTest.java
      Directory "JTwork" not found: creating
      Directory "JTreport" not found: creating
      Test results: passed: 1

      $ cat sun/tools/jconsole/WorkerDeadlockTest.java
      /**
       * @test
       * @bug 8236872
       * @summary The test tries to catch a deadlock by creating a new worker,
       * starting it, adding an empty job and immediately stopping it.
       * @library ${java.home}/lib/jconsole.jar
       * @run main WorkerDeadlockTest
       */
      import sun.tools.jconsole.Worker;
      public class WorkerDeadlockTest {
          private static final int REPEAT_NUMBER = 1000;
          public static void main(String[] args) {
              for (int i = 1; i < REPEAT_NUMBER; i++) {
                  Worker worker = new Worker("worker-" + i);
                  worker.start();
                  worker.add(() -> { });
                  worker.stopWorker();
                  System.out.println("Worker " + i + " was successfully stopped");
              }
          }
      }

      The reason for the error is that the working directory of jtreg is JTwork/scratch, which causes the relative path to fail.

      As can be seen from Locations.java:262, jtreg hopes to get the absolute path of the library, so it is recommended to modify the code as follows:
      diff -r ff9fdaab4344 src/share/classes/com/sun/javatest/regtest/config/Locations.java
      --- a/src/share/classes/com/sun/javatest/regtest/config/Locations.java Tue Sep 15 15:23:52 2020 -0700
      +++ b/src/share/classes/com/sun/javatest/regtest/config/Locations.java Sat Oct 17 02:38:18 2020 +0800
      @@ -253,7 +253,7 @@
                       String name = lib.substring(2, end);
                       File dir = null;
                       if (name.equals("java.home")) {
      - dir = testJDK.getFile();
      + dir = testJDK.getAbsoluteFile();
                       } else if (name.equals("jtreg.home")) {
                           dir = jtpath.asList().get(0).getParentFile().getParentFile();
                       }

            jjg Jonathan Gibbons
            dongbohe Dongbo He
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: