Skip to content

Commit 743724e

Browse files
committed
8319567: Update java/lang/invoke tests to support vm flags
8319568: Update java/lang/reflect/exeCallerAccessTest/CallerAccessTest.java to accept vm flags 8319672: Several classloader tests ignore VM flags 8319676: A couple of jdk/modules/incubator/ tests ignore VM flags 8319677: Test jdk/internal/misc/VM/RuntimeArguments.java should be marked as flagless Reviewed-by: mdoerr Backport-of: 1588dd934ce4e00a060e329b80f721d894559597
1 parent a266ca0 commit 743724e

16 files changed

+263
-436
lines changed

test/jdk/java/lang/ClassLoader/Assert.java

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2023, 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,19 +24,26 @@
2424
/*
2525
* @test
2626
* @bug 4290640 4785473
27+
* @requires vm.flagless
28+
* @library /test/lib
2729
* @build package1.Class1 package2.Class2 package1.package3.Class3 Assert
2830
* @run main/othervm Assert
2931
* @summary Test the assertion facility
3032
* @author Mike McCloskey
3133
* @key randomness
3234
*/
3335

36+
import jdk.test.lib.process.OutputAnalyzer;
3437
import package1.*;
3538
import package2.*;
3639
import package1.package3.*;
37-
import java.io.*;
40+
41+
import java.util.ArrayList;
42+
import java.util.List;
3843
import java.util.Random;
3944

45+
import static jdk.test.lib.process.ProcessTools.*;
46+
4047
public class Assert {
4148

4249
private static Class1 testClass1;
@@ -56,7 +63,7 @@ public class Assert {
5663
* off at class load time. Once the class is loaded its assertion status
5764
* does not change.
5865
*/
59-
public static void main(String[] args) throws Exception {
66+
public static void main(String[] args) throws Throwable {
6067

6168
// Switch values: 0=don't touch, 1=off, 2 = on
6269
int[] switches = new int[7];
@@ -77,28 +84,17 @@ public static void main(String[] args) throws Exception {
7784
}
7885

7986
// Spawn new VM and load classes
80-
String command = System.getProperty("java.home") +
81-
File.separator + "bin" + File.separator + "java Assert";
82-
83-
StringBuffer commandString = new StringBuffer(command);
87+
List<String> commands = new ArrayList<>();
88+
commands.add("Assert");
8489
for(int j=0; j<7; j++)
85-
commandString.append(" "+switches[j]);
86-
87-
Process p = null;
88-
p = Runtime.getRuntime().exec(commandString.toString());
89-
90+
commands.add(Integer.toString(switches[j]));
91+
OutputAnalyzer outputAnalyzer = executeCommand(createLimitedTestJavaProcessBuilder(commands));
9092
if (debug) { // See output of test VMs
91-
BufferedReader blah = new BufferedReader(
92-
new InputStreamReader(p.getInputStream()));
93-
String outString = blah.readLine();
94-
while (outString != null) {
95-
System.out.println("from BufferedReader:"+outString);
96-
outString = blah.readLine();
97-
}
93+
outputAnalyzer.asLines()
94+
.stream()
95+
.forEach(s -> System.out.println(s));
9896
}
99-
100-
p.waitFor();
101-
int result = p.exitValue();
97+
int result = outputAnalyzer.getExitValue();
10298
if (debug) { // See which switch configs failed
10399
if (result == 0) {
104100
for(int k=6; k>=0; k--)

test/jdk/java/lang/ClassLoader/GetSystemPackage.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/*
2525
* @test
2626
* @bug 8060130
27+
* @requires vm.flagless
2728
* @library /test/lib
2829
* @build package2.Class2 GetSystemPackage
2930
* @summary Test if getSystemPackage() return consistent values for cases
@@ -41,6 +42,8 @@
4142
import java.util.jar.JarEntry;
4243
import java.util.jar.JarOutputStream;
4344
import java.util.jar.Manifest;
45+
46+
import jdk.test.lib.process.OutputAnalyzer;
4447
import jdk.test.lib.process.ProcessTools;
4548

4649
public class GetSystemPackage {
@@ -118,8 +121,9 @@ private static void buildJar(String name, Manifest man) throws Exception {
118121
private static void runSubProcess(String messageOnError, String ... args)
119122
throws Exception
120123
{
121-
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(args);
122-
int res = pb.directory(tmpFolder).inheritIO().start().waitFor();
124+
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(args)
125+
.directory(tmpFolder);
126+
int res = ProcessTools.executeProcess(pb).getExitValue();
123127
if (res != 0) {
124128
throw new RuntimeException(messageOnError);
125129
}

test/jdk/java/lang/ClassLoader/getResource/GetResource.java

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2023, 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
@@ -40,11 +40,9 @@
4040
import java.nio.file.Paths;
4141
import java.util.ArrayList;
4242
import java.util.List;
43-
import java.util.Map;
4443
import java.util.stream.Collectors;
4544
import java.util.stream.Stream;
4645

47-
import jdk.test.lib.JDKToolFinder;
4846
import static jdk.test.lib.process.ProcessTools.*;
4947

5048
import org.testng.annotations.BeforeTest;
@@ -144,26 +142,14 @@ public void testCurrentDirA(List<String> options, String expected) throws Throwa
144142
private void runTest(Path dir, List<String> options, String expected)
145143
throws Throwable
146144
{
147-
String javapath = JDKToolFinder.getJDKTool("java");
148-
149145
List<String> cmdLine = new ArrayList<>();
150-
cmdLine.add(javapath);
151146
options.forEach(cmdLine::add);
152147

153148
cmdLine.add("GetResource");
154149
cmdLine.add(expected);
155-
156-
System.out.println("Command line: " + cmdLine);
157-
ProcessBuilder pb =
158-
new ProcessBuilder(cmdLine.stream().toArray(String[]::new));
159-
160-
// change working directory
161-
pb.directory(dir.toFile());
162-
163-
// remove CLASSPATH environment variable
164-
Map<String,String> env = pb.environment();
165-
String value = env.remove("CLASSPATH");
166-
150+
ProcessBuilder pb = createTestJavaProcessBuilder(cmdLine);
151+
pb.directory(dir.toFile()); // change working directory
152+
pb.environment().remove("CLASSPATH"); // remove CLASSPATH environment variable
167153
executeCommand(pb).shouldHaveExitValue(0);
168154
}
169155

test/jdk/java/lang/invoke/condy/CondyNestedResolutionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*/
4545
public class CondyNestedResolutionTest {
4646
public static void main(String args[]) throws Throwable {
47-
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder("CondyNestedResolution");
47+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder("CondyNestedResolution");
4848
OutputAnalyzer oa = new OutputAnalyzer(pb.start());
4949
oa.shouldContain("StackOverflowError");
5050
oa.shouldContain("bsm1arg");

test/jdk/java/lang/invoke/findSpecial/FindSpecialTest.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, 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
@@ -37,13 +37,11 @@
3737
import java.nio.file.Path;
3838
import java.nio.file.Paths;
3939

40-
import jdk.test.lib.JDKToolFinder;
41-
import jdk.test.lib.process.ProcessTools;
40+
import static jdk.test.lib.process.ProcessTools.*;
4241

4342
import org.testng.annotations.Test;
4443

4544
public class FindSpecialTest {
46-
static final String JAVA_LAUNCHER = JDKToolFinder.getJDKTool("java");
4745
static final String TEST_CLASSES = System.getProperty("test.classes", ".");
4846
static final String TEST_CLASS_PATH = System.getProperty("test.class.path");
4947
static final String TEST_MAIN_CLASS = "test.FindSpecial";
@@ -59,8 +57,9 @@ public static void callerInUnnamedModule() throws Throwable {
5957
throw new Error(m1 + " not exist");
6058
}
6159
String classpath = m1.toString() + File.pathSeparator + TEST_CLASS_PATH;
62-
ProcessTools.executeCommand(JAVA_LAUNCHER, "-cp", classpath, TEST_MAIN_CLASS)
63-
.shouldHaveExitValue(0);
60+
executeCommand(createTestJavaProcessBuilder("-cp", classpath,
61+
TEST_MAIN_CLASS))
62+
.shouldHaveExitValue(0);
6463
}
6564

6665
/*
@@ -72,10 +71,9 @@ public static void callerInNamedModule() throws Throwable {
7271
if (Files.notExists(modules)) {
7372
throw new Error(modules + " not exist");
7473
}
75-
ProcessTools.executeCommand(JAVA_LAUNCHER,
76-
"-cp", TEST_CLASS_PATH,
77-
"-p", modules.toString(),
78-
"-m", TEST_MODULE + "/" + TEST_MAIN_CLASS)
79-
.shouldHaveExitValue(0);
74+
executeCommand(createTestJavaProcessBuilder("-cp", TEST_CLASS_PATH,
75+
"-p", modules.toString(),
76+
"-m", TEST_MODULE + "/" + TEST_MAIN_CLASS))
77+
.shouldHaveExitValue(0);
8078
}
8179
}

test/jdk/java/lang/invoke/lambda/LUtils.java

-171
This file was deleted.

0 commit comments

Comments
 (0)