Skip to content

Commit 5900c63

Browse files
committed
improved doc and API of SubprocessTest
1 parent e904e09 commit 5900c63

File tree

2 files changed

+49
-33
lines changed

2 files changed

+49
-33
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/SubprocessTest.java

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@
3636
import java.util.List;
3737
import java.util.function.Predicate;
3838

39+
import jdk.graal.compiler.test.GraalTest;
3940
import jdk.graal.compiler.test.SubprocessUtil;
4041
import jdk.graal.compiler.test.SubprocessUtil.Subprocess;
4142

4243
/**
4344
* Utility class for executing Graal compiler tests in a subprocess. This can be useful for tests
4445
* that need special VM arguments or that produce textual output or a special process termination
45-
* status that need to be analyzed. The class to be executed may be the current class or any other
46-
* unit test class.
46+
* status that need to be analyzed. Another use case is a test that behaves very differently when
47+
* run after many other tests (that fill up the heap and pollute profiles). The class to be executed
48+
* may be the current class or any other unit test class.
4749
* <p/>
4850
* If the test class contains multiple {@code @Test} methods, they will all be executed in the
4951
* subprocess, except when using one of the methods that take a {@code testSelector} argument. All
@@ -59,24 +61,24 @@
5961
public abstract class SubprocessTest extends GraalCompilerTest {
6062

6163
/**
62-
* Launches the {@code runnable} in a subprocess, with any extra {@code args} passed as
63-
* arguments to the subprocess VM. Checks that the subprocess terminated successfully, i.e., an
64-
* exit code different from 0 raises an error.
65-
*
66-
* @return Inside the subprocess, returns {@code null}. Outside the subprocess, returns a
67-
* {@link Subprocess} instance describing the process after its successful termination.
64+
* Calls {@link #launchSubprocess(Predicate, boolean, Class, String, Runnable, String...)} with
65+
* the given args, {@code vmArgsFilter=null}, {@code check=true}, {@code testClass=getClass()}
66+
* and {@code testSelector=currentUnitTestName()}.
6867
*/
69-
public SubprocessUtil.Subprocess launchSubprocess(Runnable runnable, String... args) throws InterruptedException, IOException {
70-
return launchSubprocess(null, null, true, getClass(), currentUnitTestName(), runnable, args);
71-
}
72-
73-
public SubprocessUtil.Subprocess launchSubprocess(Predicate<String> vmArgsFilter, Runnable runnable, String... args) throws InterruptedException, IOException {
74-
return launchSubprocess(null, vmArgsFilter, true, getClass(), currentUnitTestName(), runnable, args);
68+
public SubprocessUtil.Subprocess launchSubprocess(Runnable runnable, String... extraVmArgs) throws InterruptedException, IOException {
69+
return launchSubprocess(null, true, getClass(), currentUnitTestName(), runnable, extraVmArgs);
7570
}
7671

77-
public static SubprocessUtil.Subprocess launchSubprocess(Class<? extends GraalCompilerTest> testClass, String testSelector, Runnable runnable, String... args)
78-
throws InterruptedException, IOException {
79-
return launchSubprocess(null, null, true, testClass, testSelector, runnable, args);
72+
/**
73+
* Calls {@link #launchSubprocess(Predicate, boolean, Class, String, Runnable, String...)} with
74+
* the given args, {@code vmArgsFilter=null} and {@code check=true}.
75+
*/
76+
public static SubprocessUtil.Subprocess launchSubprocess(
77+
Class<? extends GraalCompilerTest> testClass,
78+
String testSelector,
79+
Runnable runnable,
80+
String... extraVmArgs) throws InterruptedException, IOException {
81+
return launchSubprocess(null, true, testClass, testSelector, runnable, extraVmArgs);
8082
}
8183

8284
private static List<String> filter(List<String> args, Predicate<String> vmArgsFilter) {
@@ -106,17 +108,36 @@ private static String getRecursionPropName(Class<? extends GraalCompilerTest> te
106108
return "test." + testClass.getName() + ".subprocess";
107109
}
108110

109-
public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>> testPredicate, Predicate<String> vmArgsFilter, boolean expectNormalExit,
110-
Class<? extends GraalCompilerTest> testClass, String testSelector, Runnable runnable, String... args)
111-
throws InterruptedException, IOException {
111+
/**
112+
* Launches {@code runnable} in a subprocess.
113+
*
114+
* @param runnable task to be run in the subprocess
115+
* @param vmArgsFilter filters the VM args to only those matching this predicate
116+
* @param check if true, and the process exits with a non-zero exit code, an AssertionError
117+
* exception will be thrown
118+
* @param testClass the class defining the test
119+
* @param testSelector name of the current test. This is typically provided by
120+
* {@link GraalTest#currentUnitTestName()}. Use {@link #ALL_TESTS} to denote that all
121+
* tests in {@code testClass} are to be run.
122+
* @param extraVmArgs extra VM args to pass to the subprocess
123+
* @return returns {@code null} when run in the subprocess. Outside the subprocess, returns a
124+
* {@link Subprocess} instance describing the process after its successful termination.
125+
*/
126+
public static SubprocessUtil.Subprocess launchSubprocess(
127+
Predicate<String> vmArgsFilter,
128+
boolean check,
129+
Class<? extends GraalCompilerTest> testClass,
130+
String testSelector,
131+
Runnable runnable,
132+
String... extraVmArgs) throws InterruptedException, IOException {
112133
if (isRecursiveLaunch(testClass)) {
113134
runnable.run();
114135
return null;
115136
} else {
116137
List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
117138
vmArgs.add(SubprocessUtil.PACKAGE_OPENING_OPTIONS);
118139
vmArgs.add("-D" + getRecursionPropName(testClass) + "=true");
119-
vmArgs.addAll(Arrays.asList(args));
140+
vmArgs.addAll(Arrays.asList(extraVmArgs));
120141
if (vmArgsFilter != null) {
121142
vmArgs = filter(vmArgs, vmArgsFilter);
122143
}
@@ -132,13 +153,9 @@ public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>>
132153
}
133154
SubprocessUtil.Subprocess proc = java(vmArgs, mainClassAndArgs);
134155

135-
if (testPredicate != null && !testPredicate.test(proc.output)) {
136-
fail("Subprocess produced unexpected output:%n%s", proc.preserveArgfile());
137-
}
138156
int exitCode = proc.exitCode;
139-
if ((exitCode == 0) != expectNormalExit) {
140-
String expectExitCode = expectNormalExit ? "0" : "non-0";
141-
fail("Subprocess produced exit code %d, but expected %s%n%s", exitCode, expectExitCode, proc.preserveArgfile());
157+
if (check && exitCode != 0) {
158+
fail("Subprocess produced non-0 exit code %d%n%s", exitCode, proc.preserveArgfile());
142159
}
143160

144161
// Test passed
@@ -148,5 +165,4 @@ public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>>
148165
return proc;
149166
}
150167
}
151-
152168
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/GraalOnlyIntrinsicsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626

2727
import java.io.IOException;
2828

29-
import jdk.graal.compiler.core.test.SubprocessTest;
29+
import org.junit.Test;
30+
3031
import jdk.graal.compiler.api.test.Graal;
32+
import jdk.graal.compiler.core.test.SubprocessTest;
3133
import jdk.graal.compiler.hotspot.GraalHotSpotVMConfig;
3234
import jdk.graal.compiler.hotspot.HotSpotGraalRuntimeProvider;
3335
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin;
3436
import jdk.graal.compiler.runtime.RuntimeProvider;
35-
import org.junit.Test;
36-
3737
import jdk.vm.ci.aarch64.AArch64;
3838

3939
/**
@@ -70,7 +70,7 @@ public void testUseCharacterCompareIntrinsics() {
7070

7171
@Test
7272
public void assertHotSpotFlags() throws IOException, InterruptedException {
73-
launchSubprocess(s -> !s.contains("UseVectorizedMismatchIntrinsic"), () -> testUseVectorizedMismatchIntrinsic());
74-
launchSubprocess(s -> !s.contains("UseCharacterCompareIntrinsics"), () -> testUseCharacterCompareIntrinsics());
73+
launchSubprocess(s -> !s.contains("UseVectorizedMismatchIntrinsic"), true, getClass(), currentUnitTestName(), () -> testUseVectorizedMismatchIntrinsic());
74+
launchSubprocess(s -> !s.contains("UseCharacterCompareIntrinsics"), true, getClass(), currentUnitTestName(), () -> testUseCharacterCompareIntrinsics());
7575
}
7676
}

0 commit comments

Comments
 (0)