36
36
import java .util .List ;
37
37
import java .util .function .Predicate ;
38
38
39
+ import jdk .graal .compiler .test .GraalTest ;
39
40
import jdk .graal .compiler .test .SubprocessUtil ;
40
41
import jdk .graal .compiler .test .SubprocessUtil .Subprocess ;
41
42
42
43
/**
43
44
* Utility class for executing Graal compiler tests in a subprocess. This can be useful for tests
44
45
* 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.
47
49
* <p/>
48
50
* If the test class contains multiple {@code @Test} methods, they will all be executed in the
49
51
* subprocess, except when using one of the methods that take a {@code testSelector} argument. All
59
61
public abstract class SubprocessTest extends GraalCompilerTest {
60
62
61
63
/**
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()}.
68
67
*/
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 );
75
70
}
76
71
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 );
80
82
}
81
83
82
84
private static List <String > filter (List <String > args , Predicate <String > vmArgsFilter ) {
@@ -106,17 +108,36 @@ private static String getRecursionPropName(Class<? extends GraalCompilerTest> te
106
108
return "test." + testClass .getName () + ".subprocess" ;
107
109
}
108
110
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 {
112
133
if (isRecursiveLaunch (testClass )) {
113
134
runnable .run ();
114
135
return null ;
115
136
} else {
116
137
List <String > vmArgs = withoutDebuggerArguments (getVMCommandLine ());
117
138
vmArgs .add (SubprocessUtil .PACKAGE_OPENING_OPTIONS );
118
139
vmArgs .add ("-D" + getRecursionPropName (testClass ) + "=true" );
119
- vmArgs .addAll (Arrays .asList (args ));
140
+ vmArgs .addAll (Arrays .asList (extraVmArgs ));
120
141
if (vmArgsFilter != null ) {
121
142
vmArgs = filter (vmArgs , vmArgsFilter );
122
143
}
@@ -132,13 +153,9 @@ public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>>
132
153
}
133
154
SubprocessUtil .Subprocess proc = java (vmArgs , mainClassAndArgs );
134
155
135
- if (testPredicate != null && !testPredicate .test (proc .output )) {
136
- fail ("Subprocess produced unexpected output:%n%s" , proc .preserveArgfile ());
137
- }
138
156
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 ());
142
159
}
143
160
144
161
// Test passed
@@ -148,5 +165,4 @@ public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>>
148
165
return proc ;
149
166
}
150
167
}
151
-
152
168
}
0 commit comments