Skip to content

Commit

Permalink
8319651: Several network tests ignore vm flags when start java process
Browse files Browse the repository at this point in the history
Backport-of: 9538f5d317972bbb82f7f2575819d35d2a5f8b91
  • Loading branch information
GoeLin committed Mar 25, 2024
1 parent 2836734 commit 1dfda33
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 96 deletions.
23 changes: 8 additions & 15 deletions test/jdk/java/net/InetAddress/ptr/Lookup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2024, 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
Expand Down Expand Up @@ -41,18 +41,15 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.Collectors;

import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

public class Lookup {
private static final String HOST = "icann.org";
private static final String SKIP = "SKIP";
private static final String CLASS_PATH = System.getProperty(
"test.class.path");

public static void main(String args[]) throws IOException {
String addr = null;
Expand Down Expand Up @@ -135,20 +132,16 @@ public static void main(String args[]) throws IOException {
}

static String lookupWithIPv4Prefer() throws IOException {
String java = JDKToolFinder.getTestJDKTool("java");
String testClz = Lookup.class.getName();
List<String> cmd = List.of(java, "-Djava.net.preferIPv4Stack=true",
"-cp", CLASS_PATH, testClz);
System.out.println("Executing: " + cmd);
return new OutputAnalyzer(new ProcessBuilder(cmd).start()).getOutput();
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
"-Djava.net.preferIPv4Stack=true", testClz);
return new OutputAnalyzer(pb.start()).getOutput();
}

static String reverseWithIPv4Prefer(String addr) throws IOException {
String java = JDKToolFinder.getTestJDKTool("java");
String testClz = Lookup.class.getName();
List<String> cmd = List.of(java, "-Djava.net.preferIPv4Stack=true",
"-cp", CLASS_PATH, testClz, "reverse", addr);
System.out.println("Executing: " + cmd);
return new OutputAnalyzer(new ProcessBuilder(cmd).start()).getOutput();
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
"-Djava.net.preferIPv4Stack=true", testClz, "reverse", addr);
return new OutputAnalyzer(pb.start()).getOutput();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2024, 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
Expand Down Expand Up @@ -31,7 +31,8 @@
* can cause fd leak.
* This test may fail intermittently if foreign processes will
* try to establish connection to the test server socket.
* @requires (os.family != "windows")
* @requires os.family != "windows"
* @requires vm.flagless
* @library /test/lib
* @build jdk.test.lib.Utils
* jdk.test.lib.Asserts
Expand Down
12 changes: 5 additions & 7 deletions test/jdk/java/net/ServerSocket/AcceptInheritHandle.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, 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
Expand Down Expand Up @@ -34,10 +34,12 @@
import java.nio.channels.ServerSocketChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import jdk.test.lib.net.IPSupport;
import jdk.test.lib.process.ProcessTools;

public class AcceptInheritHandle {

Expand Down Expand Up @@ -95,16 +97,12 @@ static void test(ServerSocketProducer ssp, String... jvmArgs) throws Exception {
System.out.println("\nStarting test for " + ssp.name());

List<String> commands = new ArrayList<>();
commands.add(JAVA);
for (String arg : jvmArgs)
commands.add(arg);
commands.add("-cp");
commands.add(CLASSPATH);
Collections.addAll(commands, jvmArgs);
commands.add("AcceptInheritHandle");
commands.add(ssp.name());

System.out.println("Executing: "+ commands);
ProcessBuilder pb = new ProcessBuilder(commands);
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(commands);
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
Process serverProcess = pb.start();
DataInputStream dis = new DataInputStream(serverProcess.getInputStream());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024, 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
Expand Down Expand Up @@ -36,7 +36,6 @@
* @run main/othervm TestDriver
*/

import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.ProcessTools;

import java.io.IOException;
Expand All @@ -53,33 +52,33 @@ public static void main(String[] args)
throws Throwable {

Path userDir = Paths.get(System.getProperty("user.dir"));
String java = JDKToolFinder.getTestJDKTool("java");
String basename = userDir.getFileName().toString();
setup(userDir);
ProcessBuilder[] tests = new ProcessBuilder[]{
new ProcessBuilder(
java, TEST_NAME, "./" + ARCHIVE_NAME
ProcessTools.createTestJavaProcessBuilder(
TEST_NAME,
"./" + ARCHIVE_NAME
),
new ProcessBuilder(
java, "-cp", ".",
ProcessTools.createTestJavaProcessBuilder(
"-cp", ".",
"-Djava.security.policy=file:./policy",
"-Djava.security.manager",
TEST_NAME, "./" + ARCHIVE_NAME
),
new ProcessBuilder(
java, "-cp", ".",
ProcessTools.createTestJavaProcessBuilder(
"-cp", ".",
"-Djava.security.policy=file:./policy",
"-Djava.security.manager",
TEST_NAME, "./" + ARCHIVE_NAME
),
new ProcessBuilder(
java, "-cp", "..",
ProcessTools.createTestJavaProcessBuilder(
"-cp", "..",
"-Djava.security.policy=file:../policy",
"-Djava.security.manager",
TEST_NAME, "../" + ARCHIVE_NAME
).directory(userDir.resolve("tmp").toFile()),
new ProcessBuilder(
java, "-cp", basename,
ProcessTools.createTestJavaProcessBuilder(
"-cp", basename,
"-Djava.security.policy=file:" + basename + "/policy",
"-Djava.security.manager",
TEST_NAME, basename + "/" + ARCHIVE_NAME
Expand Down
21 changes: 11 additions & 10 deletions test/jdk/java/net/URLClassLoader/sealing/CheckSealedTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024, 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
Expand Down Expand Up @@ -46,6 +46,8 @@
import java.util.List;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static jdk.test.lib.process.ProcessTools.createTestJavaProcessBuilder;
import static jdk.test.lib.process.ProcessTools.executeCommand;

public class CheckSealedTest {
private static final String ARCHIVE_NAME = "b.jar";
Expand All @@ -55,31 +57,30 @@ public static void main(String[] args)

String baseDir = System.getProperty("user.dir") + File.separator;
String javac = JDKToolFinder.getTestJDKTool("javac");
String java = JDKToolFinder.getTestJDKTool("java");

setup(baseDir);
String srcDir = System.getProperty("test.src");
String cp = srcDir + File.separator + "a" + File.pathSeparator
+ srcDir + File.separator + "b.jar" + File.pathSeparator
+ ".";

// Compile
ProcessTools.executeCommand(javac, "-cp", cp, "-d", ".",
srcDir + File.separator + TEST_NAME + ".java");

List<String[]> allCMDs = List.of(
// Compile command
new String[]{
javac, "-cp", cp, "-d", ".",
srcDir + File.separator + TEST_NAME + ".java"
},
// Run test the first time
new String[]{
java, "-cp", cp, TEST_NAME, "1"
"-cp", cp, TEST_NAME, "1"
},
// Run test the second time
new String[]{
java, "-cp", cp, TEST_NAME, "2"
"-cp", cp, TEST_NAME, "2"
}
);

for (String[] cmd : allCMDs) {
ProcessTools.executeCommand(cmd)
executeCommand(createTestJavaProcessBuilder(cmd))
.outputTo(System.out)
.errorTo(System.out)
.shouldHaveExitValue(0);
Expand Down
3 changes: 2 additions & 1 deletion test/jdk/java/net/URLConnection/6212146/TestDriver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024, 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
Expand Down Expand Up @@ -27,6 +27,7 @@
* @summary URLConnection.connect() fails on JAR Entry it creates
* file handler leak
* @library /test/lib
* @requires vm.flagless
* @build jdk.test.lib.Utils
* jdk.test.lib.Asserts
* jdk.test.lib.JDKToolFinder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, 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
Expand All @@ -21,6 +21,8 @@
* questions.
*/

import jdk.test.lib.process.ProcessTools;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
Expand Down Expand Up @@ -56,6 +58,7 @@
/*
* @test
* @bug 8064925
* @library /test/lib
* @summary Basic test for ContentHandler. Ensures discovery paths for content
* handlers follow a particular order.
*/
Expand Down Expand Up @@ -268,14 +271,10 @@ private static Result java(Map<String, String> properties,
Collection<Path> classpath,
String classname, String... args) {

String java = getJDKTool("java");

List<String> commands = new ArrayList<>();
commands.add(java);
commands.addAll(properties.entrySet()
List<String> commands = properties.entrySet()
.stream()
.map(e -> "-D" + e.getKey() + "=" + e.getValue())
.collect(Collectors.toList()));
.collect(Collectors.toList());

String cp = classpath.stream()
.map(Path::toString)
Expand All @@ -285,7 +284,7 @@ private static Result java(Map<String, String> properties,
commands.add(classname);
commands.addAll(Arrays.asList(args));

return run(new ProcessBuilder(commands));
return run(ProcessTools.createTestJavaProcessBuilder(commands));
}

private static Result run(ProcessBuilder b) {
Expand Down
7 changes: 3 additions & 4 deletions test/jdk/java/net/httpclient/security/Driver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, 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
Expand Down Expand Up @@ -56,6 +56,7 @@
import java.util.List;
import java.util.stream.Collectors;
import jdk.test.lib.Utils;
import jdk.test.lib.process.ProcessTools;

/**
* Driver for tests
Expand Down Expand Up @@ -126,12 +127,10 @@ public static void runtest(String policy, String testnum, String addProp) throws
String testClassPath = System.getProperty("test.class.path", "?");
String testClasses = System.getProperty("test.classes", "?");
String sep = System.getProperty("file.separator", "?");
String javaCmd = testJdk + sep + "bin" + sep + "java";
int retval = 10; // 10 is special exit code denoting a bind error
// in which case, we retry
while (retval == 10) {
List<String> cmd = new ArrayList<>();
cmd.add(javaCmd);
cmd.add("-ea");
cmd.add("-esa");
cmd.add("-Dtest.jdk=" + testJdk);
Expand All @@ -150,7 +149,7 @@ public static void runtest(String policy, String testnum, String addProp) throws
cmd.add("Security");
cmd.add(testnum);

ProcessBuilder processBuilder = new ProcessBuilder(cmd)
ProcessBuilder processBuilder = ProcessTools.createTestJavaProcessBuilder(cmd)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectErrorStream(true);

Expand Down
12 changes: 5 additions & 7 deletions test/jdk/java/net/spi/URLStreamHandlerProvider/Basic.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, 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
Expand Down Expand Up @@ -45,6 +45,8 @@
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;

import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
import jdk.test.lib.JDKToolFinder;
import static java.lang.String.format;
Expand Down Expand Up @@ -234,12 +236,8 @@ static void quickFail(Result r) {

static Result java(List<String> sysProps, Collection<Path> classpath,
String classname, String arg) {
String java = getJDKTool("java");

List<String> commands = new ArrayList<>();
commands.add(java);
for (String prop : sysProps)
commands.add(prop);
List<String> commands = new ArrayList<>(sysProps);

String cp = classpath.stream()
.map(Path::toString)
Expand All @@ -249,7 +247,7 @@ static Result java(List<String> sysProps, Collection<Path> classpath,
commands.add(classname);
commands.add(arg);

return run(new ProcessBuilder(commands));
return run(ProcessTools.createTestJavaProcessBuilder(commands));
}

static Result run(ProcessBuilder pb) {
Expand Down
Loading

1 comment on commit 1dfda33

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.