From e47b2bc8c338a0b137106074952cded1067fc50a Mon Sep 17 00:00:00 2001
From: Igor Ignatyev <iignatyev@openjdk.org>
Date: Wed, 10 Jun 2020 10:47:40 -0700
Subject: [PATCH] 8246387: switch to jtreg 5.1

Reviewed-by: dholmes, erikj
---
 make/conf/jib-profiles.js                     |  4 +-
 .../jtreg/GatherDiagnosticInfoObserver.java   | 27 +-----
 test/hotspot/jtreg/TEST.ROOT                  |  2 +-
 .../condy/staticInit/TestInitException.java   |  7 +-
 test/jaxp/TEST.ROOT                           |  2 +-
 test/jdk/TEST.ROOT                            |  2 +-
 test/langtools/TEST.ROOT                      |  2 +-
 test/lib-test/TEST.ROOT                       |  2 +-
 test/lib/jdk/test/lib/Utils.java              | 86 ++-----------------
 test/lib/jdk/test/lib/cds/CDSTestUtils.java   | 23 ++---
 10 files changed, 23 insertions(+), 134 deletions(-)

diff --git a/make/conf/jib-profiles.js b/make/conf/jib-profiles.js
index 7c883763564..3ec29803ea9 100644
--- a/make/conf/jib-profiles.js
+++ b/make/conf/jib-profiles.js
@@ -1045,10 +1045,10 @@ var getJibProfilesDependencies = function (input, common) {
         jtreg: {
             server: "jpg",
             product: "jtreg",
-            version: "5.0",
+            version: "5.1",
             build_number: "b01",
             checksum_file: "MD5_VALUES",
-            file: "bundles/jtreg_bin-5.0.zip",
+            file: "bundles/jtreg_bin-5.1.zip",
             environment_name: "JT_HOME",
             environment_path: input.get("jtreg", "home_path") + "/bin",
             configure_args: "--with-jtreg=" + input.get("jtreg", "home_path"),
diff --git a/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherDiagnosticInfoObserver.java b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherDiagnosticInfoObserver.java
index 12dd8a42b44..89577e52d05 100644
--- a/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherDiagnosticInfoObserver.java
+++ b/test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherDiagnosticInfoObserver.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -121,29 +121,4 @@ public class GatherDiagnosticInfoObserver implements Harness.Observer {
         compileJdk = rp.getCompileJDK().getAbsoluteFile().toPath();
         testJdk = rp.getTestJDK().getAbsoluteFile().toPath();
     }
-
-    @Override
-    public void startingTest(TestResult tr) {
-        // no-op
-    }
-
-    @Override
-    public void stoppingTestRun() {
-        // no-op
-    }
-
-    @Override
-    public void finishedTesting() {
-        // no-op
-    }
-
-    @Override
-    public void finishedTestRun(boolean allOK) {
-        // no-op
-    }
-
-    @Override
-    public void error(String msg) {
-        // no-op
-    }
 }
diff --git a/test/hotspot/jtreg/TEST.ROOT b/test/hotspot/jtreg/TEST.ROOT
index 7f988e5840d..f1b45bcee2e 100644
--- a/test/hotspot/jtreg/TEST.ROOT
+++ b/test/hotspot/jtreg/TEST.ROOT
@@ -75,7 +75,7 @@ requires.properties= \
     test.vm.gc.nvdimm
 
 # Minimum jtreg version
-requiredVersion=5.0 b1
+requiredVersion=5.1 b1
 
 # Path to libraries in the topmost test directory. This is needed so @library
 # does not need ../../../ notation to reach them
diff --git a/test/hotspot/jtreg/runtime/condy/staticInit/TestInitException.java b/test/hotspot/jtreg/runtime/condy/staticInit/TestInitException.java
index 72b811142fc..ecd945be87f 100644
--- a/test/hotspot/jtreg/runtime/condy/staticInit/TestInitException.java
+++ b/test/hotspot/jtreg/runtime/condy/staticInit/TestInitException.java
@@ -40,13 +40,14 @@ public class TestInitException {
         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("Example");
         OutputAnalyzer oa = new OutputAnalyzer(pb.start());
         // First call stack trace
-        oa.shouldContain("at Example.$jacocoInit(Example.jasm)");
+        // shouldMatch is used to workaround CODETOOLS-7902686
+        oa.shouldMatch("^\tat Example\\.\\$jacocoInit\\(.*Example\\.jasm\\)$");
         oa.shouldContain("Caused by: java.lang.RuntimeException");
         oa.shouldContain("at StaticInit.<clinit>(StaticInit.java:27)");
         // Second call stack trace, with the message
         oa.shouldContain("java.lang.ExceptionInInitializerError: $jacocoData");
-        oa.shouldContain("at Example.foo(Example.jasm)");
-        oa.shouldContain("at Example.main(Example.jasm)");
+        oa.shouldMatch("^\tat Example\\.foo\\(.*Example\\.jasm\\)$");
+        oa.shouldMatch("^\tat Example\\.main\\(.*Example\\.jasm\\)$");
         oa.shouldHaveExitValue(1);
     }
 }
diff --git a/test/jaxp/TEST.ROOT b/test/jaxp/TEST.ROOT
index 7348f565c16..1228e05cf03 100644
--- a/test/jaxp/TEST.ROOT
+++ b/test/jaxp/TEST.ROOT
@@ -23,7 +23,7 @@ modules=java.xml
 groups=TEST.groups
 
 # Minimum jtreg version
-requiredVersion=5.0 b1
+requiredVersion=5.1 b1
 
 # Path to libraries in the topmost test directory. This is needed so @library
 # does not need ../../ notation to reach them
diff --git a/test/jdk/TEST.ROOT b/test/jdk/TEST.ROOT
index a1fe0f275bc..948f35b4774 100644
--- a/test/jdk/TEST.ROOT
+++ b/test/jdk/TEST.ROOT
@@ -59,7 +59,7 @@ requires.properties= \
     release.implementor
 
 # Minimum jtreg version
-requiredVersion=5.0 b1
+requiredVersion=5.1 b1
 
 # Path to libraries in the topmost test directory. This is needed so @library
 # does not need ../../ notation to reach them
diff --git a/test/langtools/TEST.ROOT b/test/langtools/TEST.ROOT
index 3f182154cc6..ae86a0030e8 100644
--- a/test/langtools/TEST.ROOT
+++ b/test/langtools/TEST.ROOT
@@ -15,7 +15,7 @@ keys=intermittent randomness
 groups=TEST.groups
 
 # Minimum jtreg version
-requiredVersion=5.0 b1
+requiredVersion=5.1 b1
 
 # Use new module options
 useNewOptions=true
diff --git a/test/lib-test/TEST.ROOT b/test/lib-test/TEST.ROOT
index 4d0f7cd2baa..130e7aa2355 100644
--- a/test/lib-test/TEST.ROOT
+++ b/test/lib-test/TEST.ROOT
@@ -2,7 +2,7 @@
 # It also contains test-suite configuration information.
 
 # Minimum jtreg version
-requiredVersion=5.0 b1
+requiredVersion=5.1 b1
 
 # Path to libraries in the topmost test directory. This is needed so @library
 # does not need ../../ notation to reach them
diff --git a/test/lib/jdk/test/lib/Utils.java b/test/lib/jdk/test/lib/Utils.java
index eb954080d15..05aaeb69cb0 100644
--- a/test/lib/jdk/test/lib/Utils.java
+++ b/test/lib/jdk/test/lib/Utils.java
@@ -113,6 +113,11 @@ public final class Utils {
     public static final String TEST_CLASSES = System.getProperty("test.classes", ".");
 
     /**
+     * Returns the value of 'test.name' system property
+     */
+    public static final String TEST_NAME = System.getProperty("test.name", ".");
+
+   /**
      * Defines property name for seed value.
      */
     public static final String SEED_PROPERTY_NAME = "jdk.test.lib.random.seed";
@@ -824,87 +829,6 @@ public final class Utils {
         }
     }
 
-    // This method is intended to be called from a jtreg test.
-    // It will identify the name of the test by means of stack walking.
-    // It can handle both jtreg tests and a testng tests wrapped inside jtreg tests.
-    // For jtreg tests the name of the test will be searched by stack-walking
-    // until the method main() is found; the class containing that method is the
-    // main test class and will be returned as the name of the test.
-    // Special handling is used for testng tests.
-    @SuppressWarnings("unchecked")
-    public static String getTestName() {
-        String result = null;
-        // If we are using testng, then we should be able to load the "Test" annotation.
-        Class<? extends Annotation> testClassAnnotation, junitTestClassAnnotation;
-
-        try {
-            testClassAnnotation = (Class<? extends Annotation>)Class.forName("org.testng.annotations.Test");
-        } catch (ClassNotFoundException e) {
-            testClassAnnotation = null;
-        }
-
-        // If we are using junit, then we should be able to load the "Test" annotation.
-        try {
-            junitTestClassAnnotation = (Class<? extends Annotation>)Class.forName("org.junit.Test");
-        } catch (ClassNotFoundException e) {
-            junitTestClassAnnotation = null;
-        }
-
-        StackTraceElement[] elms = (new Throwable()).getStackTrace();
-        for (StackTraceElement n: elms) {
-            String className = n.getClassName();
-
-            // If this is a "main" method, then use its class name, but only
-            // if we are not using testng or junit.
-            if (testClassAnnotation == null && junitTestClassAnnotation == null &&
-                "main".equals(n.getMethodName())) {
-                result = className;
-                break;
-            }
-
-            // If this is a testng test, the test will have no "main" method. We can
-            // detect a testng test class by looking for the org.testng.annotations.Test
-            // annotation. If present, then use the name of this class.
-            if (testClassAnnotation != null) {
-                try {
-                    Class<?> c = Class.forName(className);
-                    if (c.isAnnotationPresent(testClassAnnotation)) {
-                        result = className;
-                        break;
-                    }
-                } catch (ClassNotFoundException e) {
-                    throw new RuntimeException("Unexpected exception: " + e, e);
-                }
-            }
-
-            // If this is a junit test, the test will have no "main" method. We can
-            // detect a junit test class by going through all the methods and
-            // check if the method has the org.junit.Test annotation. If present,
-            // then use the name of this class.
-            if (junitTestClassAnnotation != null) {
-                try {
-                    Class<?> c = Class.forName(className);
-                    Method[] methods = c.getMethods();
-                    for (Method method : methods) {
-                        if (method.getName().equals(n.getMethodName()) &&
-                            method.isAnnotationPresent(junitTestClassAnnotation)) {
-                                result = className;
-                                break;
-                        }
-                    }
-                } catch (ClassNotFoundException e) {
-                    throw new RuntimeException("Unexpected exception: " + e, e);
-                }
-            }
-        }
-
-        if (result == null) {
-            throw new RuntimeException("Couldn't find main test class in stack trace");
-        }
-
-        return result;
-    }
-
     /**
      * Creates an empty file in "user.dir" if the property set.
      * <p>
diff --git a/test/lib/jdk/test/lib/cds/CDSTestUtils.java b/test/lib/jdk/test/lib/cds/CDSTestUtils.java
index 8750db37dab..2582833e3b3 100644
--- a/test/lib/jdk/test/lib/cds/CDSTestUtils.java
+++ b/test/lib/jdk/test/lib/cds/CDSTestUtils.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -499,7 +499,7 @@ public class CDSTestUtils {
     // create file containing the specified class list
     public static File makeClassList(String classes[])
         throws Exception {
-        return makeClassList(getTestName() + "-", classes);
+        return makeClassList(testName + "-", classes);
     }
 
     // create file containing the specified class list
@@ -529,18 +529,7 @@ public class CDSTestUtils {
         }
     }
 
-
-    // Optimization for getting a test name.
-    // Test name does not change during execution of the test,
-    // but getTestName() uses stack walking hence it is expensive.
-    // Therefore cache it and reuse it.
-    private static String testName;
-    public static String getTestName() {
-        if (testName == null) {
-            testName = Utils.getTestName();
-        }
-        return testName;
-    }
+    private static String testName = Utils.TEST_NAME.replace('/', '.');
 
     private static final SimpleDateFormat timeStampFormat =
         new SimpleDateFormat("HH'h'mm'm'ss's'SSS");
@@ -549,7 +538,7 @@ public class CDSTestUtils {
 
     // Call this method to start new archive with new unique name
     public static void startNewArchiveName() {
-        defaultArchiveName = getTestName() +
+        defaultArchiveName = testName +
             timeStampFormat.format(new Date()) + ".jsa";
     }
 
@@ -561,7 +550,7 @@ public class CDSTestUtils {
     // ===================== FILE ACCESS convenience methods
     public static File getOutputFile(String name) {
         File dir = new File(System.getProperty("test.classes", "."));
-        return new File(dir, getTestName() + "-" + name);
+        return new File(dir, testName + "-" + name);
     }
 
 
@@ -582,7 +571,7 @@ public class CDSTestUtils {
         long started = System.currentTimeMillis();
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
         String outputFileNamePrefix =
-            getTestName() + "-" + String.format("%04d", getNextLogCounter()) + "-" + logName;
+            testName + "-" + String.format("%04d", getNextLogCounter()) + "-" + logName;
 
         writeFile(getOutputFile(outputFileNamePrefix + ".stdout"), output.getStdout());
         writeFile(getOutputFile(outputFileNamePrefix + ".stderr"), output.getStderr());