Skip to content

Commit

Permalink
[GR-53079] Timeout of BytecodeOSRNodeTest#testFrameTransferWithStatic…
Browse files Browse the repository at this point in the history
…AccessesWithAssertionsDisabled.

PullRequest: graal/17441
  • Loading branch information
tzezula committed Apr 7, 2024
2 parents 3e9ab2b + 3a54864 commit 0a535fd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.test.SubprocessTestUtils;
import com.oracle.truffle.api.test.SubprocessTestUtils.WithSubprocess;
import com.oracle.truffle.runtime.BytecodeOSRMetadata;
import com.oracle.truffle.runtime.OptimizedCallTarget;
import com.oracle.truffle.runtime.OptimizedTruffleRuntime;
Expand All @@ -66,7 +67,7 @@ public class BytecodeOSRNodeTest extends TestWithSynchronousCompiling {

private static final OptimizedTruffleRuntime runtime = (OptimizedTruffleRuntime) Truffle.getRuntime();

@Rule public TestRule timeout = GraalTest.createTimeout(30, TimeUnit.SECONDS);
@Rule public TestRule timeout = SubprocessTestUtils.disableForParentProcess(GraalTest.createTimeout(30, TimeUnit.SECONDS));

private int osrThreshold;

Expand Down Expand Up @@ -191,10 +192,11 @@ public void testMultipleLoopsIncompatibleState() {
* Test that OSR fails if the code cannot be compiled.
*/
@Test
@WithSubprocess
public void testFailedCompilation() throws IOException, InterruptedException {
// Run in a subprocess to prevent graph graal dumps that are enabled by the default mx
// unittest options.
SubprocessTestUtils.executeInSubprocess(BytecodeOSRNodeTest.class, () -> {
SubprocessTestUtils.newBuilder(BytecodeOSRNodeTest.class, () -> {
Context.Builder builder = newContextBuilder().logHandler(new ByteArrayOutputStream());
builder.option("engine.MultiTier", "false");
builder.option("engine.OSR", "true");
Expand All @@ -207,7 +209,7 @@ public void testFailedCompilation() throws IOException, InterruptedException {
Assert.assertEquals(FixedIterationLoop.NORMAL_RESULT, target.call(osrThreshold + 1));
// Compilation should be disabled after a compilation failure.
Assert.assertTrue(osrNode.getGraalOSRMetadata().isDisabled());
});
}).run();
}

/*
Expand Down Expand Up @@ -468,6 +470,7 @@ public void testFrameTransferWithStaticAccesses() {
* enter and exit, and even when assertions are disabled.
*/
@Test
@WithSubprocess
public void testFrameTransferWithStaticAccessesWithAssertionsDisabled() throws Throwable {
// Execute in a subprocess to disable assertion checking for frames.
SubprocessTestUtils.executeInSubprocessWithAssertionsDisabled(BytecodeOSRNodeTest.class,
Expand Down Expand Up @@ -542,6 +545,7 @@ public void testFrameTransferWithUninitializedStaticSlots() {
* Same as above, but with assertion disabled.
*/
@Test
@WithSubprocess
public void testFrameTransferWithUninitializedStaticSlotsWithoutAssertions() throws Throwable {
// Execute in a subprocess to disable assertion checking for frames.
SubprocessTestUtils.executeInSubprocessWithAssertionsDisabled(BytecodeOSRNodeTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.management.LockInfo;
import java.lang.management.MonitorInfo;
import java.lang.management.ThreadInfo;
Expand Down Expand Up @@ -81,6 +85,10 @@

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

/**
* Support for executing Truffle tests in a sub-process with filtered compilation failure options.
Expand Down Expand Up @@ -455,6 +463,67 @@ public void run() throws IOException, InterruptedException {

}

/**
* A marker annotation for test methods that create subprocesses. This annotation is necessary
* for the proper functioning of {@link #disableForParentProcess(TestRule) disabling test rules
* in the parent process}.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface WithSubprocess {
}

/**
* Creates a {@link TestRule} that enables you to disable certain rules for a test method when
* creating a subprocess. One notable use case is for tests employing the {@link Timeout} rule.
* When a test method creates a subprocess, the {@link Timeout} rule must not be enabled in the
* parent process. Otherwise, the parent process may be terminated prematurely before the
* subprocess completes the actual test.
* <p>
* To ensure proper functionality, it's crucial to annotate test methods creating subprocesses
* with {@link WithSubprocess}.
* <p>
* Example usage:
*
* <pre>
* public static class ForkedTest {
*
* &#064;Rule public TestRule timeout = disableForParentProcess(new Timeout(20));
*
* &#064;Test
* &#064;WithSubprocess
* public void test() {
* SubprocessTestUtils.newBuilder(BytecodeOSRNodeTest.class, () -> {
* assertTrue(performTest());
* }).run();
* }
* }
* </pre>
*
* @param base the {@link TestRule} to disable in the parent process.
*/
public static TestRule disableForParentProcess(TestRule base) {
return new DisableForSubprocess(base);
}

private static final class DisableForSubprocess implements TestRule {

private final TestRule rule;

DisableForSubprocess(TestRule rule) {
this.rule = rule;
}

@Override
public Statement apply(Statement base, Description description) {
if (!isSubprocess() && description.getAnnotation(WithSubprocess.class) != null) {
return base;
} else {
return rule.apply(base, description);
}
}
}

// Methods and constants copied from jdk.graal.compiler.test.SubprocessUtil

/**
Expand Down

0 comments on commit 0a535fd

Please sign in to comment.