8159925: sun/tools/jps/TestJpsJar.java still fails after fix for JDK-8153278
authordsamersoff
Fri, 08 Jul 2016 17:36:34 +0300
changeset 39736 f939432eb32a
parent 39735 8aaca314f0a3
child 39737 4da8463b3d33
8159925: sun/tools/jps/TestJpsJar.java still fails after fix for JDK-8153278 Summary: Check user.dir property Reviewed-by: dcubed, sspitsyn
jdk/test/sun/tools/jps/JpsBase.java
jdk/test/sun/tools/jps/TestJpsJar.java
--- a/jdk/test/sun/tools/jps/JpsBase.java	Thu Jul 07 17:22:04 2016 -0700
+++ b/jdk/test/sun/tools/jps/JpsBase.java	Fri Jul 08 17:36:34 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, 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
@@ -59,7 +59,17 @@
         return JpsBase.class.getName();
     }
 
+    private static boolean userDirSanityCheck(String fullProcessName) {
+        String userDir = System.getProperty("user.dir");
+        if (!fullProcessName.startsWith(userDir)) {
+            System.err.printf("Test skipped. user.dir '%s' is not a prefix of '%s'\n", userDir, fullProcessName);
+            return false;
+        }
+        return true;
+    }
+
     public static void main(String[] args) throws Exception {
+        System.out.printf("INFO: user.dir:  '%s''\n", System.getProperty("user.dir"));
         long pid = ProcessTools.getProcessId();
 
         List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
@@ -85,8 +95,12 @@
                     // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
                     isFull = true;
                     String fullProcessName = getFullProcessName();
-                    pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
-                    output.shouldMatch(pattern);
+                    // Skip the test if user.dir is not a prefix of the current path
+                    // It's possible if the test is run from symlinked dir or windows alias drive
+                    if (userDirSanityCheck(fullProcessName)) {
+                        pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
+                        output.shouldMatch(pattern);
+                    }
                     break;
                 case m:
                     // If '-m' is specified output should contain the arguments passed to the main method:
--- a/jdk/test/sun/tools/jps/TestJpsJar.java	Thu Jul 07 17:22:04 2016 -0700
+++ b/jdk/test/sun/tools/jps/TestJpsJar.java	Fri Jul 08 17:36:34 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, 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
@@ -52,6 +52,7 @@
         cmd.addAll(JpsHelper.getVmArgs());
         cmd.add("-Dtest.jdk=" + testJdk);
         cmd.add("-Dtest.src=" + testSrc);
+        cmd.add("-Duser.dir=" + System.getProperty("user.dir"));
         cmd.add("-jar");
         cmd.add(jar.getAbsolutePath());
         cmd.add("monkey");