Skip to content

Commit 4bbc29c

Browse files
committed
8319678: Several tests from corelibs areas ignore VM flags
Backport-of: 2e3682a7f2983cd58b9564253dc698760faba4b8
1 parent add7934 commit 4bbc29c

File tree

6 files changed

+103
-105
lines changed

6 files changed

+103
-105
lines changed

test/jdk/java/lang/Thread/UncaughtExceptionsTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,15 +23,13 @@
2323

2424
import java.util.stream.Stream;
2525

26+
import static java.lang.System.err;
27+
import static java.lang.System.out;
2628
import jdk.test.lib.process.OutputAnalyzer;
2729
import jdk.test.lib.process.ProcessTools;
28-
import org.junit.jupiter.api.Test;
2930
import org.junit.jupiter.params.ParameterizedTest;
30-
import org.junit.jupiter.params.provider.MethodSource;
3131
import org.junit.jupiter.params.provider.Arguments;
32-
33-
import static java.lang.System.err;
34-
import static java.lang.System.out;
32+
import org.junit.jupiter.params.provider.MethodSource;
3533

3634
/*
3735
* @test
@@ -85,7 +83,7 @@ private static Stream<Arguments> testCases() {
8583
@MethodSource("testCases")
8684
void test(String className, int exitValue, String stdOutMatch, String stdErrMatch) throws Throwable {
8785
String cmd = "UncaughtExitSimulator$" + className;
88-
ProcessBuilder processBuilder = ProcessTools.createLimitedTestJavaProcessBuilder(cmd);
86+
ProcessBuilder processBuilder = ProcessTools.createTestJavaProcessBuilder(cmd);
8987
OutputAnalyzer outputAnalyzer = ProcessTools.executeCommand(processBuilder);
9088
outputAnalyzer.shouldHaveExitValue(exitValue);
9189
outputAnalyzer.stderrShouldMatch(stdErrMatch);

test/jdk/java/lang/annotation/LoaderLeakTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,7 +55,7 @@ public void testWithReadingAnnotations() throws Throwable {
5555
}
5656

5757
private void runJavaProcessExpectSuccessExitCode(String ... command) throws Throwable {
58-
var processBuilder = ProcessTools.createLimitedTestJavaProcessBuilder(command)
58+
var processBuilder = ProcessTools.createTestJavaProcessBuilder(command)
5959
.directory(Paths.get(Utils.TEST_CLASSES).toFile());
6060
ProcessTools.executeCommand(processBuilder).shouldHaveExitValue(0);
6161
}

test/jdk/java/rmi/reliability/benchmark/bench/rmi/Main.java

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,13 +25,13 @@
2525
* @test
2626
* @summary The RMI benchmark test. This java class is used to run the test
2727
* under JTREG.
28-
* @library ../../../../testlibrary ../../
28+
* @library ../../../../testlibrary ../../ /test/lib
2929
* @modules java.desktop
3030
* java.rmi/sun.rmi.registry
3131
* java.rmi/sun.rmi.server
3232
* java.rmi/sun.rmi.transport
3333
* java.rmi/sun.rmi.transport.tcp
34-
* @build TestLibrary bench.BenchInfo bench.HtmlReporter bench.Util
34+
* @build TestLibrary bench.BenchInfo bench.HtmlReporter bench.Util jdk.test.lib.process.ProcessTools
3535
* bench.Benchmark bench.Reporter bench.XmlReporter bench.ConfigFormatException
3636
* bench.Harness bench.TextReporter bench.rmi.BenchServer
3737
* bench.rmi.DoubleArrayCalls bench.rmi.LongCalls bench.rmi.ShortCalls
@@ -51,19 +51,12 @@
5151

5252
package bench.rmi;
5353

54-
import bench.ConfigFormatException;
55-
import bench.Harness;
56-
import bench.HtmlReporter;
57-
import bench.Reporter;
58-
import bench.TextReporter;
59-
import bench.XmlReporter;
60-
import static bench.rmi.Main.OutputFormat.*;
6154
import java.io.File;
6255
import java.io.FileInputStream;
6356
import java.io.FileNotFoundException;
6457
import java.io.FileOutputStream;
65-
import java.io.InputStream;
6658
import java.io.IOException;
59+
import java.io.InputStream;
6760
import java.io.OutputStream;
6861
import java.io.PrintStream;
6962
import java.rmi.AlreadyBoundException;
@@ -77,6 +70,18 @@
7770
import java.util.Timer;
7871
import java.util.TimerTask;
7972

73+
import bench.ConfigFormatException;
74+
import bench.Harness;
75+
import bench.HtmlReporter;
76+
import bench.Reporter;
77+
import bench.TextReporter;
78+
import bench.XmlReporter;
79+
import static bench.rmi.Main.OutputFormat.HTML;
80+
import static bench.rmi.Main.OutputFormat.TEXT;
81+
import static bench.rmi.Main.OutputFormat.XML;
82+
import jdk.test.lib.process.OutputAnalyzer;
83+
import jdk.test.lib.process.ProcessTools;
84+
8085
/**
8186
* RMI/Serialization benchmark tests.
8287
*/
@@ -234,13 +239,6 @@ public static void main(String[] args) {
234239
//Setup for client mode, server will fork client process
235240
//after its initiation.
236241
List<String> clientProcessStr = new ArrayList<>();
237-
clientProcessStr.add(System.getProperty("test.jdk") +
238-
File.separator + "bin" + File.separator + "java");
239-
String classpath = System.getProperty("java.class.path");
240-
if (classpath != null) {
241-
clientProcessStr.add("-cp");
242-
clientProcessStr.add(classpath);
243-
}
244242
clientProcessStr.add("-Djava.security.policy=" + TEST_SRC_PATH + "policy.all");
245243
clientProcessStr.add("-Djava.security.manager=allow");
246244
clientProcessStr.add("-Dtest.src=" + TEST_SRC_PATH);
@@ -276,20 +274,13 @@ public static void main(String[] args) {
276274
}
277275

278276
try {
279-
Process client = new ProcessBuilder(clientProcessStr).
280-
inheritIO().start();
281-
try {
282-
client.waitFor();
283-
int exitValue = client.exitValue();
284-
if (0 != exitValue) {
285-
die("Error: error happened in client process, exitValue = " + exitValue);
286-
}
287-
} finally {
288-
client.destroyForcibly();
289-
}
277+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(clientProcessStr);
278+
OutputAnalyzer outputAnalyzer = ProcessTools.executeProcess(pb);
279+
System.out.println(outputAnalyzer.getOutput());
280+
outputAnalyzer.shouldHaveExitValue(0);
290281
} catch (IOException ex) {
291282
die("Error: Unable start client process, ex=" + ex.getMessage());
292-
} catch (InterruptedException ex) {
283+
} catch (Exception ex) {
293284
die("Error: Error happening to client process, ex=" + ex.getMessage());
294285
}
295286
break;

test/jdk/java/time/nontestng/java/time/chrono/HijrahConfigTest.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,8 @@
2424
import java.nio.file.Files;
2525
import java.nio.file.Path;
2626

27+
import jdk.test.lib.process.OutputAnalyzer;
28+
import jdk.test.lib.process.ProcessTools;
2729
import tests.Helper;
2830
import tests.JImageGenerator;
2931

@@ -32,12 +34,12 @@
3234
* @summary Tests whether a custom Hijrah configuration properties file works correctly
3335
* @bug 8187987
3436
* @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
35-
* @library /tools/lib
37+
* @library /tools/lib /test/lib
3638
* @modules java.base/jdk.internal.jimage
3739
* jdk.jdeps/com.sun.tools.classfile
3840
* jdk.jlink/jdk.tools.jimage
3941
* jdk.compiler
40-
* @build HijrahConfigCheck tests.*
42+
* @build HijrahConfigCheck tests.* jdk.test.lib.compiler.CompilerUtils jdk.test.lib.process.ProcessTools
4143
* @run main/othervm -Xmx1g HijrahConfigTest
4244
*/
4345
public class HijrahConfigTest {
@@ -66,13 +68,7 @@ public static void main(String[] args) throws Exception {
6668

6769
// Run tests
6870
Path launcher = outputPath.resolve("bin").resolve("java");
69-
ProcessBuilder builder = new ProcessBuilder(
70-
launcher.toAbsolutePath().toString(), "-ea", "-esa", "HijrahConfigCheck");
71-
Process p = builder.inheritIO().start();
72-
p.waitFor();
73-
int exitValue = p.exitValue();
74-
if (exitValue != 0) {
75-
throw new RuntimeException("HijrahConfigTest failed. Exit value: " + exitValue);
76-
}
71+
OutputAnalyzer analyzer = ProcessTools.executeCommand(launcher.toAbsolutePath().toString(), "-ea", "-esa", "HijrahConfigCheck");
72+
analyzer.shouldHaveExitValue(0);
7773
}
7874
}

test/jdk/javax/naming/spi/providers/InitialContextTest.java

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,30 +21,48 @@
2121
* questions.
2222
*/
2323

24-
import javax.naming.Context;
25-
import java.io.*;
24+
import java.io.BufferedReader;
25+
import java.io.BufferedWriter;
26+
import java.io.File;
27+
import java.io.FileReader;
28+
import java.io.FileWriter;
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
import java.io.InputStreamReader;
32+
import java.io.Reader;
33+
import java.io.SequenceInputStream;
34+
import java.io.StringWriter;
35+
import java.io.Writer;
2636
import java.nio.file.Files;
2737
import java.nio.file.Path;
2838
import java.nio.file.Paths;
29-
import java.util.*;
39+
import java.util.ArrayList;
3040
import java.util.Collection;
3141
import java.util.Collections;
42+
import java.util.Iterator;
3243
import java.util.List;
44+
import java.util.Map;
3345
import java.util.function.Function;
3446
import java.util.stream.Collectors;
3547
import java.util.stream.Stream;
3648

37-
import static java.lang.String.format;
49+
import javax.naming.Context;
50+
3851
import static java.util.Arrays.asList;
3952
import static java.util.Collections.singleton;
4053
import static java.util.Collections.singletonMap;
54+
import jdk.test.lib.process.OutputAnalyzer;
55+
import jdk.test.lib.process.ProcessTools;
4156

4257
/*
4358
* @test
4459
* @bug 8044627
4560
* @summary Examines different ways JNDI providers can hook up themselves and
4661
* become available. Each case mimics the most straightforward way of
4762
* executing scenarios.
63+
* @library /test/lib
64+
* @build jdk.test.lib.process.ProcessTools
65+
* @run main InitialContextTest
4866
*/
4967
public class InitialContextTest {
5068

@@ -243,9 +261,13 @@ private static boolean verifyOutput(String output, String fqn) {
243261

244262
private static void jar(Path jarName, Path jarRoot) {
245263
String jar = getJDKTool("jar");
246-
ProcessBuilder p = new ProcessBuilder(jar, "cf", jarName.toString(),
247-
"-C", jarRoot.toString(), ".");
248-
quickFail(run(p));
264+
String [] commands = {jar, "cf", jarName.toString(),"-C", jarRoot.toString(), "."};
265+
try {
266+
OutputAnalyzer outputAnalyzer = ProcessTools.executeCommand(commands);
267+
outputAnalyzer.shouldHaveExitValue(0);
268+
} catch (Exception ex) {
269+
throw new RuntimeException(ex);
270+
}
249271
}
250272

251273
private static void javac(Path compilationOutput, Path... sourceFiles) {
@@ -256,22 +278,18 @@ private static void javac(Path compilationOutput, Path... sourceFiles) {
256278
commands.addAll(paths.stream()
257279
.map(Path::toString)
258280
.collect(Collectors.toList()));
259-
quickFail(run(new ProcessBuilder(commands)));
260-
}
261-
262-
private static void quickFail(Result r) {
263-
if (r.exitValue != 0)
264-
throw new RuntimeException(r.output);
281+
try {
282+
OutputAnalyzer outputAnalyzer = ProcessTools.executeCommand(commands.toArray(new String[commands.size()]));
283+
outputAnalyzer.shouldHaveExitValue(0);
284+
} catch (Exception ex) {
285+
throw new RuntimeException(ex);
286+
}
265287
}
266288

267289
private static Result java(Map<String, String> properties,
268290
Collection<Path> classpath,
269291
String classname) {
270-
271-
String java = getJDKTool("java");
272-
273292
List<String> commands = new ArrayList<>();
274-
commands.add(java);
275293
commands.addAll(properties.entrySet()
276294
.stream()
277295
.map(e -> "-D" + e.getKey() + "=" + e.getValue())
@@ -283,35 +301,14 @@ private static Result java(Map<String, String> properties,
283301
commands.add("-cp");
284302
commands.add(cp);
285303
commands.add(classname);
304+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(commands);
286305

287-
return run(new ProcessBuilder(commands));
288-
}
289-
290-
private static Result run(ProcessBuilder b) {
291-
Process p = null;
292-
try {
293-
p = b.start();
294-
} catch (IOException e) {
295-
throw new RuntimeException(
296-
format("Couldn't start process '%s'", b.command()), e);
297-
}
298-
299-
String output;
300306
try {
301-
output = toString(p.getInputStream(), p.getErrorStream());
302-
} catch (IOException e) {
303-
throw new RuntimeException(
304-
format("Couldn't read process output '%s'", b.command()), e);
305-
}
306-
307-
try {
308-
p.waitFor();
309-
} catch (InterruptedException e) {
310-
throw new RuntimeException(
311-
format("Process hasn't finished '%s'", b.command()), e);
307+
OutputAnalyzer outputAnalyzer = ProcessTools.executeProcess(pb);
308+
return new Result(outputAnalyzer.getExitValue(), outputAnalyzer.getOutput());
309+
} catch (Exception ex) {
310+
throw new RuntimeException(ex);
312311
}
313-
314-
return new Result(p.exitValue(), output);
315312
}
316313

317314
private static String getJDKTool(String name) {

0 commit comments

Comments
 (0)