Skip to content

Commit 2c98339

Browse files
tkrodriguezdougxc
authored andcommitted
SubprocessTest should only run the current unit test in the subprocess
1 parent e2a660b commit 2c98339

File tree

7 files changed

+55
-56
lines changed

7 files changed

+55
-56
lines changed

compiler/src/jdk.graal.compiler.hotspot.jdk21.test/src/jdk/graal/compiler/hotspot/jdk21/test/PreviewEnabledTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public void testBody() {
5757

5858
@Test
5959
public void testInSubprocess() throws IOException, InterruptedException {
60-
SubprocessTest.launchSubprocess(getClass(), this::testBody, "--enable-preview");
60+
SubprocessTest.launchSubprocess(getClass(), currentUnitTestName(), this::testBody, "--enable-preview");
6161
}
6262
}

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

+8-19
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,20 @@ public abstract class SubprocessTest extends GraalCompilerTest {
6767
* {@link Subprocess} instance describing the process after its successful termination.
6868
*/
6969
public SubprocessUtil.Subprocess launchSubprocess(Runnable runnable, String... args) throws InterruptedException, IOException {
70-
return launchSubprocess(null, null, true, getClass(), null, runnable, args);
71-
}
72-
73-
/**
74-
* Like {@link #launchSubprocess(Runnable, String...)}, but with an extra {@code testSelector}
75-
* to specify a specific test method to execute in the test class.
76-
*/
77-
public SubprocessUtil.Subprocess launchSubprocess(String testSelector, Runnable runnable, String... args) throws InterruptedException, IOException {
78-
return launchSubprocess(null, null, true, getClass(), testSelector, runnable, args);
70+
return launchSubprocess(null, null, true, getClass(), currentUnitTestName(), runnable, args);
7971
}
8072

8173
public SubprocessUtil.Subprocess launchSubprocess(Predicate<String> vmArgsFilter, Runnable runnable, String... args) throws InterruptedException, IOException {
82-
return launchSubprocess(null, vmArgsFilter, true, getClass(), null, runnable, args);
74+
return launchSubprocess(null, vmArgsFilter, true, getClass(), currentUnitTestName(), runnable, args);
8375
}
8476

85-
public static SubprocessUtil.Subprocess launchSubprocess(Class<? extends GraalCompilerTest> testClass, Runnable runnable, String... args) throws InterruptedException, IOException {
86-
return launchSubprocess(null, null, true, testClass, null, runnable, args);
77+
public SubprocessUtil.Subprocess launchSubprocess(Class<? extends GraalCompilerTest> testClass, Runnable runnable, String... args) throws InterruptedException, IOException {
78+
return launchSubprocess(null, null, true, testClass, currentUnitTestName(), runnable, args);
8779
}
8880

89-
public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>> testPredicate, Predicate<String> vmArgsFilter, boolean expectNormalExit,
90-
Class<? extends GraalCompilerTest> testClass, Runnable runnable, String... args)
81+
public static SubprocessUtil.Subprocess launchSubprocess(Class<? extends GraalCompilerTest> testClass, String testSelector, Runnable runnable, String... args)
9182
throws InterruptedException, IOException {
92-
return launchSubprocess(testPredicate, vmArgsFilter, expectNormalExit, testClass, null, runnable, args);
83+
return launchSubprocess(null, null, true, testClass, testSelector, runnable, args);
9384
}
9485

9586
private static List<String> filter(List<String> args, Predicate<String> vmArgsFilter) {
@@ -131,10 +122,8 @@ public static SubprocessUtil.Subprocess launchSubprocess(Predicate<List<String>>
131122

132123
List<String> mainClassAndArgs = new LinkedList<>();
133124
mainClassAndArgs.add("com.oracle.mxtool.junit.MxJUnitWrapper");
134-
String testName = testClass.getName();
135-
if (testSelector != null) {
136-
testName += "#" + testSelector;
137-
}
125+
assert testSelector != null : "must pass the name of the current unit test";
126+
String testName = testClass.getName() + "#" + testSelector;
138127
mainClassAndArgs.add(testName);
139128
boolean junitVerbose = getProcessCommandLine().contains("-JUnitVerbose");
140129
if (junitVerbose) {

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/ea/ReadEliminationCodeEmissionTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static int accessVolatile1Snippet(A a) {
6060

6161
@Test
6262
public void accessVolatile1() {
63-
runTest("accessVolatile1", new A(12));
63+
runTest(currentUnitTestName(), new A(12));
6464
}
6565

6666
public void runTest(String baseName, Object... args) {
@@ -120,7 +120,7 @@ public void runTest(String baseName, Object... args) {
120120
"-Dgraal.Dump=:5"};
121121
}
122122
try {
123-
subprocess = launchSubprocess(baseName, run, vmArgs);
123+
subprocess = launchSubprocess(run, vmArgs);
124124
} catch (InterruptedException | IOException e) {
125125
throw new RuntimeException(e);
126126
}

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

+23-22
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static Object fieldReadBarrierSnippet(TestObject t) {
9292

9393
@Test
9494
public void fieldReadBarrier() {
95-
runTest("fieldReadBarrier", new TestObject());
95+
runTest(new TestObject());
9696
}
9797

9898
public static void fieldWriteBarrierSnippet(TestObject t, Object value) {
@@ -101,7 +101,7 @@ public static void fieldWriteBarrierSnippet(TestObject t, Object value) {
101101

102102
@Test
103103
public void fieldWriteBarrier() {
104-
runTest("fieldWriteBarrier", new TestObject(), "string");
104+
runTest(new TestObject(), "string");
105105
}
106106

107107
public static void volatileFieldWriteBarrierSnippet(TestObject t, Object value) {
@@ -110,7 +110,7 @@ public static void volatileFieldWriteBarrierSnippet(TestObject t, Object value)
110110

111111
@Test
112112
public void volatileFieldWriteBarrier() {
113-
runTest("volatileFieldWriteBarrier", new TestObject(), "string");
113+
runTest(new TestObject(), "string");
114114
}
115115

116116
public static void arrayWriteBarrierSnippet(Object[] t, Object value) {
@@ -119,7 +119,7 @@ public static void arrayWriteBarrierSnippet(Object[] t, Object value) {
119119

120120
@Test
121121
public void arrayWriteBarrier() {
122-
runTest("arrayWriteBarrier", new Object[1], "string");
122+
runTest(new Object[1], "string");
123123
}
124124

125125
public static void volatileArrayWriteBarrierSnippet(Object[] t, Object value) {
@@ -131,7 +131,7 @@ public static void volatileArrayWriteBarrierSnippet(Object[] t, Object value) {
131131

132132
@Test
133133
public void volatileArrayWriteBarrier() {
134-
runTest("volatileArrayWriteBarrier", new Object[1], "string");
134+
runTest(new Object[1], "string");
135135
}
136136

137137
public static void fieldWriteNullBarrierSnippet(TestObject t) {
@@ -140,7 +140,7 @@ public static void fieldWriteNullBarrierSnippet(TestObject t) {
140140

141141
@Test
142142
public void fieldWriteNullBarrier() {
143-
runTest("fieldWriteNullBarrier", new TestObject());
143+
runTest(new TestObject());
144144
}
145145

146146
public static void volatileFieldWriteNullBarrierSnippet(TestObject t) {
@@ -149,7 +149,7 @@ public static void volatileFieldWriteNullBarrierSnippet(TestObject t) {
149149

150150
@Test
151151
public void volatileFieldWriteNullBarrier() {
152-
runTest("volatileFieldWriteNullBarrier", new TestObject());
152+
runTest(new TestObject());
153153
}
154154

155155
public static void arrayWriteNullBarrierSnippet(Object[] t) {
@@ -158,7 +158,7 @@ public static void arrayWriteNullBarrierSnippet(Object[] t) {
158158

159159
@Test
160160
public void arrayWriteNullBarrier() {
161-
runTest("arrayWriteNullBarrier", new Object[]{new Object[1]});
161+
runTest(new Object[]{new Object[1]});
162162
}
163163

164164
public static Object valueCompareAndSwapBarrierSnippet(TestObject t1, Object value) {
@@ -174,7 +174,7 @@ public void valueCompareAndSwapBarrier() {
174174
assertTrue(graph.getNodes().filter(ValueCompareAndSwapNode.class).isNotEmpty(), "expected ValueCompareAndSwapNode");
175175
return true;
176176
};
177-
runTest("valueCompareAndSwapBarrier", nodePredicate, supply(TestObject::new), "string");
177+
runTest(nodePredicate, supply(TestObject::new), "string");
178178
}
179179

180180
public static boolean logicCompareAndSwapBarrierSnippet(TestObject t1, Object value) {
@@ -190,7 +190,7 @@ public void logicCompareAndSwapBarrier() {
190190
assertTrue(graph.getNodes().filter(LogicCompareAndSwapNode.class).isNotEmpty(), "expected LogicCompareAndSwapNode");
191191
return true;
192192
};
193-
runTest("logicCompareAndSwapBarrier", nodePredicate, supply(TestObject::new), "string");
193+
runTest(nodePredicate, supply(TestObject::new), "string");
194194
}
195195

196196
public static Object getAndSetBarrierSnippet(TestObject t1, Object value) {
@@ -206,7 +206,7 @@ public void getAndSetBarrier() {
206206
assertTrue(graph.getNodes().filter(LoweredAtomicReadAndWriteNode.class).isNotEmpty(), "expected LoweredAtomicReadAndWriteNode");
207207
return true;
208208
};
209-
runTest("getAndSetBarrier", nodePredicate, supply(TestObject::new), "string");
209+
runTest(nodePredicate, supply(TestObject::new), "string");
210210
}
211211

212212
public static boolean phantomRefersToBarrierSnippet(PhantomReference<Object> phantom, Object value) {
@@ -216,7 +216,7 @@ public static boolean phantomRefersToBarrierSnippet(PhantomReference<Object> pha
216216
@Test
217217
public void phantomRefersToBarrier() {
218218
ReferenceQueue<Object> queue = new ReferenceQueue<>();
219-
runTest("phantomRefersToBarrier", new PhantomReference<>("string", queue), "string");
219+
runTest(new PhantomReference<>("string", queue), "string");
220220
}
221221

222222
public static boolean weakRefersToBarrierSnippet(WeakReference<Object> weak, Object value) {
@@ -225,7 +225,7 @@ public static boolean weakRefersToBarrierSnippet(WeakReference<Object> weak, Obj
225225

226226
@Test
227227
public void weakRefersToBarrier() {
228-
runTest("weakRefersToBarrier", new WeakReference<>("string"), "string");
228+
runTest(new WeakReference<>("string"), "string");
229229
}
230230

231231
public static Object referenceGetBarrierSnippet(WeakReference<Object> weak) {
@@ -234,7 +234,7 @@ public static Object referenceGetBarrierSnippet(WeakReference<Object> weak) {
234234

235235
@Test
236236
public void referenceGetBarrier() {
237-
runTest("referenceGetBarrier", new WeakReference<>("string"));
237+
runTest(new WeakReference<>("string"));
238238
}
239239

240240
public static TestObject objectAllocationBarrierSnippet() {
@@ -243,7 +243,7 @@ public static TestObject objectAllocationBarrierSnippet() {
243243

244244
@Test
245245
public void objectAllocationBarrier() {
246-
runTest("objectAllocationBarrier");
246+
runTest();
247247
}
248248

249249
public static String stringAllocationBarrierSnippet() {
@@ -252,7 +252,7 @@ public static String stringAllocationBarrierSnippet() {
252252

253253
@Test
254254
public void stringAllocationBarrier() {
255-
runTest("stringAllocationBarrier");
255+
runTest();
256256
}
257257

258258
private static TestObject obj6 = new TestObject(6);
@@ -265,7 +265,7 @@ public static Object testuuvCAESnippet() {
265265

266266
@Test
267267
public void testuuvCAE() {
268-
runTest("testuuvCAE");
268+
runTest();
269269
}
270270

271271
public static Object threadHandleBarrierSnippet() {
@@ -274,7 +274,7 @@ public static Object threadHandleBarrierSnippet() {
274274

275275
@Test
276276
public void threadHandleBarrier() {
277-
runTest("threadHandleBarrier");
277+
runTest();
278278
}
279279

280280
@Override
@@ -286,11 +286,12 @@ protected void checkLowTierGraph(StructuredGraph graph) {
286286

287287
Predicate<StructuredGraph> graphPredicate;
288288

289-
public void runTest(String baseName, Object... args) {
290-
runTest(baseName, null, args);
289+
public void runTest(Object... args) {
290+
runTest(null, args);
291291
}
292292

293-
public void runTest(String baseName, Predicate<StructuredGraph> predicate, Object... args) {
293+
public void runTest(Predicate<StructuredGraph> predicate, Object... args) {
294+
String baseName = currentUnitTestName();
294295
String snippetName = baseName + "Snippet";
295296
String methodSpec = getClass().getName() + "::" + snippetName;
296297
Method m = getMethod(snippetName);
@@ -350,7 +351,7 @@ public void runTest(String baseName, Predicate<StructuredGraph> predicate, Objec
350351
"-XX:LogFile=" + logName};
351352
}
352353
try {
353-
subprocess = launchSubprocess(baseName, run, vmArgs);
354+
subprocess = launchSubprocess(run, vmArgs);
354355
} catch (InterruptedException | IOException e) {
355356
throw new RuntimeException(e);
356357
}

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
import java.util.Collections;
3030
import java.util.List;
3131

32-
import org.junit.Rule;
3332
import org.junit.Test;
34-
import org.junit.rules.TestName;
3533

3634
import jdk.graal.compiler.core.test.SubprocessTest;
3735
import jdk.internal.vm.annotation.Contended;
@@ -53,8 +51,6 @@ public static void testSnippet() {
5351
}
5452
}
5553

56-
@Rule public TestName currentTest = new TestName();
57-
5854
public void runSubprocessTest(String... args) throws IOException, InterruptedException {
5955
List<String> newArgs = new ArrayList<>();
6056
Collections.addAll(newArgs, args);
@@ -63,13 +59,13 @@ public void runSubprocessTest(String... args) throws IOException, InterruptedExc
6359
newArgs.remove("-XX:+UseG1GC");
6460
newArgs.remove("-XX:+UseParallelGC");
6561

66-
launchSubprocess(currentTest.getMethodName(), () -> {
62+
launchSubprocess(() -> {
6763
test("testSnippet");
6864
}, newArgs.toArray(new String[0]));
6965

7066
// Test without assertions as well
7167
newArgs.add("-da");
72-
launchSubprocess(currentTest.getMethodName(), () -> {
68+
launchSubprocess(() -> {
7369
test("testSnippet");
7470
}, newArgs.toArray(new String[0]));
7571
}

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@
3030
import java.lang.reflect.Constructor;
3131
import java.util.List;
3232

33+
import org.junit.Assert;
34+
import org.junit.Test;
35+
import org.objectweb.asm.ClassWriter;
36+
import org.objectweb.asm.FieldVisitor;
37+
import org.objectweb.asm.MethodVisitor;
38+
3339
import com.oracle.truffle.api.impl.asm.Opcodes;
40+
3441
import jdk.graal.compiler.core.test.SubprocessTest;
3542
import jdk.graal.compiler.nodes.StructuredGraph;
3643
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
@@ -40,11 +47,6 @@
4047
import jdk.graal.compiler.test.AddExports;
4148
import jdk.internal.vm.annotation.Stable;
4249
import jdk.vm.ci.meta.ResolvedJavaMethod;
43-
import org.junit.Assert;
44-
import org.junit.Test;
45-
import org.objectweb.asm.ClassWriter;
46-
import org.objectweb.asm.FieldVisitor;
47-
import org.objectweb.asm.MethodVisitor;
4850

4951
/**
5052
* Assert that a barrier is inserted at the end of a constructor that writes to Stable fields or if
@@ -89,7 +91,7 @@ public void checkAlwaysSafeConstructors() throws NoSuchMethodException {
8991

9092
@Test
9193
public void runCheckStableWriteConstructors() throws IOException, InterruptedException {
92-
launchSubprocess("runCheckStableWriteConstructors", this::checkStableWriteConstructors, "--add-opens=java.base/java.lang=ALL-UNNAMED");
94+
launchSubprocess(this::checkStableWriteConstructors, "--add-opens=java.base/java.lang=ALL-UNNAMED");
9395
}
9496

9597
private void checkStableWriteConstructors() {

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/test/GraalTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
import org.junit.After;
4848
import org.junit.Assert;
4949
import org.junit.AssumptionViolatedException;
50+
import org.junit.Rule;
5051
import org.junit.internal.ComparisonCriteria;
5152
import org.junit.internal.ExactComparisonCriteria;
5253
import org.junit.rules.DisableOnDebug;
54+
import org.junit.rules.TestName;
5355
import org.junit.rules.TestRule;
5456
import org.junit.rules.Timeout;
5557

@@ -72,6 +74,15 @@ public class GraalTest {
7274

7375
public static final Unsafe UNSAFE = Unsafe.getUnsafe();
7476

77+
@Rule public TestName currentUnitTestName = new TestName();
78+
79+
/**
80+
* Returns the name of the current unit test being run.
81+
*/
82+
public String currentUnitTestName() {
83+
return currentUnitTestName.getMethodName();
84+
}
85+
7586
protected Method getMethod(String methodName) {
7687
return getMethod(getClass(), methodName);
7788
}

0 commit comments

Comments
 (0)