jdk/test/java/lang/ProcessBuilder/Basic.java
changeset 28671 cb15fc6cc038
parent 27514 b31703bbd2cb
child 28678 5e7636bd2f65
equal deleted inserted replaced
28527:38a80fae1b65 28671:cb15fc6cc038
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
    26  * @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
    27  *      5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
    27  *      5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
    28  *      6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
    28  *      6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
    29  *      4947220 7018606 7034570 4244896 5049299 8003488
    29  *      4947220 7018606 7034570 4244896 5049299 8003488 8054494
    30  * @summary Basic tests for Process and Environment Variable code
    30  * @summary Basic tests for Process and Environment Variable code
    31  * @run main/othervm/timeout=300 Basic
    31  * @run main/othervm/timeout=300 Basic
    32  * @run main/othervm/timeout=300 -Djdk.lang.Process.launchMechanism=fork Basic
    32  * @run main/othervm/timeout=300 -Djdk.lang.Process.launchMechanism=fork Basic
    33  * @author Martin Buchholz
    33  * @author Martin Buchholz
    34  */
    34  */
  2057 
  2057 
  2058                     while (useCountField.getInt(deferred) <= 0) {
  2058                     while (useCountField.getInt(deferred) <= 0) {
  2059                         Thread.yield();
  2059                         Thread.yield();
  2060                     }
  2060                     }
  2061                 } else if (s instanceof BufferedInputStream) {
  2061                 } else if (s instanceof BufferedInputStream) {
  2062                     Field f = Unsafe.class.getDeclaredField("theUnsafe");
  2062                     // Wait until after the s.read occurs in "thread" by
  2063                     f.setAccessible(true);
  2063                     // checking when the input stream monitor is acquired
  2064                     Unsafe unsafe = (Unsafe)f.get(null);
  2064                     // (BufferedInputStream.read is synchronized)
  2065 
  2065                     while (!isLocked(s, 10)) {
  2066                     while (unsafe.tryMonitorEnter(s)) {
  2066                         Thread.sleep(100);
  2067                         unsafe.monitorExit(s);
       
  2068                         Thread.sleep(1);
       
  2069                     }
  2067                     }
  2070                 }
  2068                 }
  2071                 p.destroy();
  2069                 p.destroy();
  2072                 thread.join();
  2070                 thread.join();
  2073             }
  2071             }
  2563         for (Fun f : fs)
  2561         for (Fun f : fs)
  2564             try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
  2562             try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
  2565             catch (Throwable t) {
  2563             catch (Throwable t) {
  2566                 if (k.isAssignableFrom(t.getClass())) pass();
  2564                 if (k.isAssignableFrom(t.getClass())) pass();
  2567                 else unexpected(t);}}
  2565                 else unexpected(t);}}
       
  2566 
       
  2567     static boolean isLocked(final Object monitor, final long millis) throws InterruptedException {
       
  2568         return new Thread() {
       
  2569             volatile boolean unlocked;
       
  2570 
       
  2571             @Override
       
  2572             public void run() {
       
  2573                 synchronized (monitor) { unlocked = true; }
       
  2574             }
       
  2575 
       
  2576             boolean isLocked() throws InterruptedException {
       
  2577                 start();
       
  2578                 join(millis);
       
  2579                 return !unlocked;
       
  2580             }
       
  2581         }.isLocked();
       
  2582     }
  2568 }
  2583 }