7018606: (process) test/java/lang/ProcessBuilder/Basic.java failing intermittently (win)
authormichaelm
Thu, 03 Mar 2011 15:34:09 +0000
changeset 8561 ca8d6ccdd9dc
parent 8560 f2abd715d39b
child 8562 72c0c44969c1
child 8564 d99f879a35ab
child 8566 e2df5f8fa082
7018606: (process) test/java/lang/ProcessBuilder/Basic.java failing intermittently (win) Reviewed-by: alanb
jdk/test/java/lang/ProcessBuilder/Basic.java
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java	Wed Mar 02 16:56:07 2011 +0000
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java	Thu Mar 03 15:34:09 2011 +0000
@@ -26,7 +26,7 @@
  * @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
  *      5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
  *      6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
- *      4947220
+ *      4947220 7018606
  * @summary Basic tests for Process and Environment Variable code
  * @run main/othervm/timeout=300 Basic
  * @author Martin Buchholz
@@ -47,6 +47,9 @@
 
 public class Basic {
 
+    /* used for Windows only */
+    static final String systemRoot = System.getenv("SystemRoot");
+
     private static String commandOutput(Reader r) throws Throwable {
         StringBuilder sb = new StringBuilder();
         int c;
@@ -1073,7 +1076,11 @@
         try {
             ProcessBuilder pb = new ProcessBuilder();
             pb.environment().clear();
-            equal(getenvInChild(pb), "");
+            String expected = Windows.is() ? "SystemRoot="+systemRoot+",": "";
+            if (Windows.is()) {
+                pb.environment().put("SystemRoot", systemRoot);
+            }
+            equal(getenvInChild(pb), expected);
         } catch (Throwable t) { unexpected(t); }
 
         //----------------------------------------------------------------
@@ -1561,13 +1568,21 @@
             List<String> childArgs = new ArrayList<String>(javaChildArgs);
             childArgs.add("System.getenv()");
             String[] cmdp = childArgs.toArray(new String[childArgs.size()]);
-            String[] envp = {"=ExitValue=3", "=C:=\\"};
+            String[] envp;
+            String[] envpWin = {"=ExitValue=3", "=C:=\\", "SystemRoot="+systemRoot};
+            String[] envpOth = {"=ExitValue=3", "=C:=\\"};
+            if (Windows.is()) {
+                envp = envpWin;
+            } else {
+                envp = envpOth;
+            }
             Process p = Runtime.getRuntime().exec(cmdp, envp);
-            String expected = Windows.is() ? "=C:=\\,=ExitValue=3," : "=C:=\\,";
+            String expected = Windows.is() ? "=C:=\\,SystemRoot="+systemRoot+",=ExitValue=3," : "=C:=\\,";
             equal(commandOutput(p), expected);
             if (Windows.is()) {
                 ProcessBuilder pb = new ProcessBuilder(childArgs);
                 pb.environment().clear();
+                pb.environment().put("SystemRoot", systemRoot);
                 pb.environment().put("=ExitValue", "3");
                 pb.environment().put("=C:", "\\");
                 equal(commandOutput(pb), expected);
@@ -1591,10 +1606,18 @@
             List<String> childArgs = new ArrayList<String>(javaChildArgs);
             childArgs.add("System.getenv()");
             String[] cmdp = childArgs.toArray(new String[childArgs.size()]);
-            String[] envp = {"LC_ALL=C\u0000\u0000", // Yuck!
+            String[] envpWin = {"SystemRoot="+systemRoot, "LC_ALL=C\u0000\u0000", // Yuck!
+                             "FO\u0000=B\u0000R"};
+            String[] envpOth = {"LC_ALL=C\u0000\u0000", // Yuck!
                              "FO\u0000=B\u0000R"};
+            String[] envp;
+            if (Windows.is()) {
+                envp = envpWin;
+            } else {
+                envp = envpOth;
+            }
             Process p = Runtime.getRuntime().exec(cmdp, envp);
-            check(commandOutput(p).equals("LC_ALL=C,"),
+            check(commandOutput(p).equals(Windows.is() ? "SystemRoot="+systemRoot+",LC_ALL=C," : "LC_ALL=C,"),
                   "Incorrect handling of envstrings containing NULs");
         } catch (Throwable t) { unexpected(t); }
 
@@ -2144,6 +2167,7 @@
     static void equal(Object x, Object y) {
         if (x == null ? y == null : x.equals(y)) pass();
         else fail(x + " not equal to " + y);}
+
     public static void main(String[] args) throws Throwable {
         try {realMain(args);} catch (Throwable t) {unexpected(t);}
         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);