< prev index next >

test/jdk/java/lang/ProcessBuilder/Basic.java

Print this page

  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
  27  *      5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
  28  *      6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
  29  *      4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464
  30  *      8067796 8224905 8263729 8265173 8272600 8231297 8282219 8285517
  31  *      8352533
  32  * @key intermittent
  33  * @summary Basic tests for Process and Environment Variable code
  34  * @modules java.base/java.lang:open
  35  *          java.base/java.io:open
  36  * @requires !vm.musl
  37  * @requires vm.flagless
  38  * @library /test/lib
  39  * @run main/othervm/native/timeout=360 Basic
  40  * @run main/othervm/native/timeout=360 -Djdk.lang.Process.launchMechanism=fork Basic
  41  * @author Martin Buchholz
  42  */
  43 
  44 /*
  45  * @test
  46  * @modules java.base/java.lang:open
  47  *          java.base/java.io:open
  48  *          java.base/jdk.internal.misc
  49  * @requires (os.family == "linux" & !vm.musl)
  50  * @library /test/lib
  51  * @run main/othervm/timeout=300 -Djdk.lang.Process.launchMechanism=posix_spawn Basic

 760         @Override
 761         public OutputStream getOutputStream() {
 762             return p.getOutputStream();
 763         }
 764 
 765         @Override
 766         public InputStream getInputStream() {
 767             return p.getInputStream();
 768         }
 769 
 770         @Override
 771         public InputStream getErrorStream() {
 772             return p.getErrorStream();
 773         }
 774     }
 775 
 776     private static boolean matches(String str, String regex) {
 777         return Pattern.compile(regex).matcher(str).find();
 778     }
 779 
 780     private static String matchAndExtract(String str, String regex) {
 781         Matcher matcher = Pattern.compile(regex).matcher(str);
 782         if (matcher.find()) {
 783             return matcher.group();
 784         } else {
 785             return "";
 786         }
 787     }
 788 
 789     /* Only used for Mac OS X --
 790      * Mac OS X (may) add the variable __CF_USER_TEXT_ENCODING to an empty
 791      * environment. The environment variable JAVA_MAIN_CLASS_<pid> may also
 792      * be set in Mac OS X.
 793      * Remove them both from the list of env variables
 794      */
 795     private static String removeMacExpectedVars(String vars) {
 796         // Check for __CF_USER_TEXT_ENCODING
 797         String cleanedVars = vars.replace("__CF_USER_TEXT_ENCODING="
 798                                             +cfUserTextEncoding+",","");
 799         // Check for JAVA_MAIN_CLASS_<pid>
 800         String javaMainClassStr
 801                 = matchAndExtract(cleanedVars,
 802                                     "JAVA_MAIN_CLASS_\\d+=Basic.JavaChild,");
 803         return cleanedVars.replace(javaMainClassStr,"");


 804     }
 805 
 806     /* Only used for AIX --
 807      * AIX adds the variable AIXTHREAD_GUARDPAGES=0 to the environment.
 808      * Remove it from the list of env variables
 809      */
 810     private static String removeAixExpectedVars(String vars) {
 811         return vars.replace("AIXTHREAD_GUARDPAGES=0,", "");
 812     }
 813 
 814     private static String sortByLinesWindowsly(String text) {
 815         String[] lines = text.split("\n");
 816         Arrays.sort(lines, new WindowsComparator());
 817         StringBuilder sb = new StringBuilder();
 818         for (String line : lines)
 819             sb.append(line).append("\n");
 820         return sb.toString();
 821     }
 822 
 823     private static void checkMapSanity(Map<String,String> map) {

  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
  27  *      5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
  28  *      6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
  29  *      4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464
  30  *      8067796 8224905 8263729 8265173 8272600 8231297 8282219 8285517
  31  *      8352533 8368192
  32  * @key intermittent
  33  * @summary Basic tests for Process and Environment Variable code
  34  * @modules java.base/java.lang:open
  35  *          java.base/java.io:open
  36  * @requires !vm.musl
  37  * @requires vm.flagless
  38  * @library /test/lib
  39  * @run main/othervm/native/timeout=360 Basic
  40  * @run main/othervm/native/timeout=360 -Djdk.lang.Process.launchMechanism=fork Basic
  41  * @author Martin Buchholz
  42  */
  43 
  44 /*
  45  * @test
  46  * @modules java.base/java.lang:open
  47  *          java.base/java.io:open
  48  *          java.base/jdk.internal.misc
  49  * @requires (os.family == "linux" & !vm.musl)
  50  * @library /test/lib
  51  * @run main/othervm/timeout=300 -Djdk.lang.Process.launchMechanism=posix_spawn Basic

 760         @Override
 761         public OutputStream getOutputStream() {
 762             return p.getOutputStream();
 763         }
 764 
 765         @Override
 766         public InputStream getInputStream() {
 767             return p.getInputStream();
 768         }
 769 
 770         @Override
 771         public InputStream getErrorStream() {
 772             return p.getErrorStream();
 773         }
 774     }
 775 
 776     private static boolean matches(String str, String regex) {
 777         return Pattern.compile(regex).matcher(str).find();
 778     }
 779 
 780     // Return the string with the matching regex removed
 781     private static String matchAndRemove(String str, String regex) {
 782         return Pattern.compile(regex)
 783                 .matcher(str)
 784                 .replaceAll("");


 785     }
 786 
 787     /* Only used for Mac OS X --
 788      * Mac OS X (may) add the variables: __CF_USER_TEXT_ENCODING, JAVA_MAIN_CLASS_<pid>,
 789      * and TMPDIR.
 790      * Remove them from the list of env variables

 791      */
 792     private static String removeMacExpectedVars(String vars) {
 793         // Check for __CF_USER_TEXT_ENCODING
 794         String cleanedVars = matchAndRemove(vars,
 795                 "__CF_USER_TEXT_ENCODING=" + cfUserTextEncoding + ",");
 796         // Check for JAVA_MAIN_CLASS_<pid>
 797         cleanedVars = matchAndRemove(cleanedVars,
 798                 "JAVA_MAIN_CLASS_\\d+=Basic.JavaChild,");
 799         // Check and remove TMPDIR
 800         cleanedVars = matchAndRemove(cleanedVars,
 801                 "TMPDIR=[^,]*,");
 802         return cleanedVars;
 803     }
 804 
 805     /* Only used for AIX --
 806      * AIX adds the variable AIXTHREAD_GUARDPAGES=0 to the environment.
 807      * Remove it from the list of env variables
 808      */
 809     private static String removeAixExpectedVars(String vars) {
 810         return vars.replace("AIXTHREAD_GUARDPAGES=0,", "");
 811     }
 812 
 813     private static String sortByLinesWindowsly(String text) {
 814         String[] lines = text.split("\n");
 815         Arrays.sort(lines, new WindowsComparator());
 816         StringBuilder sb = new StringBuilder();
 817         for (String line : lines)
 818             sb.append(line).append("\n");
 819         return sb.toString();
 820     }
 821 
 822     private static void checkMapSanity(Map<String,String> map) {
< prev index next >