Skip to content

Commit e596ba6

Browse files
committed
[GR-64329] Run SourceCacheTest#testTraceSourceCacheEviction in a subprocess.
PullRequest: graal/20618
2 parents 4fceea2 + 94c0ab6 commit e596ba6

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/source/SourceCacheTest.java

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import java.util.regex.Matcher;
5555
import java.util.regex.Pattern;
5656

57-
import com.oracle.truffle.api.test.SubprocessTestUtils;
5857
import org.graalvm.nativeimage.ImageInfo;
5958
import org.graalvm.options.OptionCategory;
6059
import org.graalvm.options.OptionDescriptors;
@@ -76,6 +75,7 @@
7675
import com.oracle.truffle.api.frame.VirtualFrame;
7776
import com.oracle.truffle.api.nodes.RootNode;
7877
import com.oracle.truffle.api.test.GCUtils;
78+
import com.oracle.truffle.api.test.SubprocessTestUtils;
7979
import com.oracle.truffle.api.test.common.TestUtils;
8080
import com.oracle.truffle.tck.tests.TruffleTestAssumptions;
8181

@@ -97,33 +97,42 @@ public void testTraceSourceCacheFailure() throws Throwable {
9797
}
9898

9999
@Test
100-
public void testTraceSourceCacheEviction() throws IOException {
100+
public void testTraceSourceCacheEviction() throws IOException, InterruptedException {
101101
TruffleTestAssumptions.assumeWeakEncapsulation(); // Can't control GC in the isolate.
102-
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); Context context = Context.newBuilder().option("engine.TraceSourceCache", "true").out(out).err(out).build()) {
103-
Source auxiliarySource = Source.newBuilder(SourceCacheTestLanguage.ID, "x", "AuxiliarySource").build();
104-
String sourceName = "TestSource";
105-
String[] sourceHash = new String[1];
106-
for (int i = 0; i < 2; i++) {
107-
Source source = Source.newBuilder(SourceCacheTestLanguage.ID, "", sourceName).build();
108-
int sourceHashCode = context.eval(source).asInt();
109-
sourceHash[0] = String.format("0x%08x", sourceHashCode);
110-
WeakReference<Source> souceRef = new WeakReference<>(source);
111-
source = null;
112-
GCUtils.assertGc("Source was not collected", souceRef);
113-
context.eval(auxiliarySource);
114-
}
115-
List<String> logs = new ArrayList<>();
116-
forEachLog(out.toByteArray(), (matcher) -> {
117-
String logType = matcher.group(1);
118-
if ("evict".equals(logType)) {
119-
logs.add(logType);
120-
Assert.assertEquals(sourceHash[0], matcher.group(2));
121-
Assert.assertEquals(sourceName, matcher.group(3));
102+
Runnable runnable = () -> {
103+
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); Context context = Context.newBuilder().option("engine.TraceSourceCache", "true").out(out).err(out).build()) {
104+
Source auxiliarySource = Source.newBuilder(SourceCacheTestLanguage.ID, "x", "AuxiliarySource").build();
105+
String sourceName = "TestSource";
106+
String[] sourceHash = new String[1];
107+
for (int i = 0; i < 2; i++) {
108+
Source source = Source.newBuilder(SourceCacheTestLanguage.ID, "", sourceName).build();
109+
int sourceHashCode = context.eval(source).asInt();
110+
sourceHash[0] = String.format("0x%08x", sourceHashCode);
111+
WeakReference<Source> souceRef = new WeakReference<>(source);
112+
source = null;
113+
GCUtils.assertGc("Source was not collected", souceRef);
114+
context.eval(auxiliarySource);
122115
}
123-
});
124-
// at least one
125-
Assert.assertFalse(logs.isEmpty());
126-
Assert.assertEquals("evict", logs.get(1));
116+
List<String> logs = new ArrayList<>();
117+
forEachLog(out.toByteArray(), (matcher) -> {
118+
String logType = matcher.group(1);
119+
if ("evict".equals(logType)) {
120+
logs.add(logType);
121+
Assert.assertEquals(sourceHash[0], matcher.group(2));
122+
Assert.assertEquals(sourceName, matcher.group(3));
123+
}
124+
});
125+
// at least one
126+
Assert.assertFalse(logs.isEmpty());
127+
Assert.assertEquals("evict", logs.get(1));
128+
} catch (IOException ioe) {
129+
throw new AssertionError(ioe);
130+
}
131+
};
132+
if (ImageInfo.inImageCode()) {
133+
runnable.run();
134+
} else {
135+
SubprocessTestUtils.newBuilder(SourceCacheTest.class, runnable).run();
127136
}
128137
}
129138

0 commit comments

Comments
 (0)