Search in sources :

Example 1 with SuspendAnchor

use of com.oracle.truffle.api.debug.SuspendAnchor in project graal by oracle.

the class BreakpointTest method testBreakpointsAtSamePlaceHitCorrectly.

@Test
public void testBreakpointsAtSamePlaceHitCorrectly() {
    Source testSource = testSource("ROOT(\n" + "  LOOP(4,\n" + "    STATEMENT\n" + "  )\n" + ")\n");
    String conditionTrue = "ROOT(PRINT(OUT, CT), CONSTANT(true))";
    String conditionFalse = "ROOT(PRINT(OUT, CF), CONSTANT(false))";
    boolean isBefore = true;
    String prefix = "";
    do {
        SuspendAnchor anchor = isBefore ? SuspendAnchor.BEFORE : SuspendAnchor.AFTER;
        try (DebuggerSession session = startSession()) {
            Breakpoint breakpoint1 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).suspendAnchor(anchor).build());
            Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).suspendAnchor(anchor).build());
            breakpoint1.setCondition(conditionFalse);
            breakpoint2.setCondition(conditionTrue);
            startEval(testSource);
            final String out1 = prefix + ((isBefore) ? "CFCT" : "CTCF");
            expectSuspended((SuspendedEvent event) -> {
                assertEquals(1, event.getBreakpoints().size());
                Breakpoint hit = event.getBreakpoints().get(0);
                assertSame(breakpoint2, hit);
                assertEquals(out1, getOutput());
            });
            final String out2 = out1 + ((isBefore) ? "CFCT" : "CTCF");
            expectSuspended((SuspendedEvent event) -> {
                assertEquals(1, event.getBreakpoints().size());
                Breakpoint hit = event.getBreakpoints().get(0);
                assertSame(breakpoint2, hit);
                breakpoint1.setCondition(conditionTrue);
                breakpoint2.setCondition(conditionFalse);
                assertEquals(out2, getOutput());
            });
            final String out3 = out2 + ((isBefore) ? "CTCF" : "CFCT");
            expectSuspended((SuspendedEvent event) -> {
                assertEquals(1, event.getBreakpoints().size());
                Breakpoint hit = event.getBreakpoints().get(0);
                assertSame(breakpoint1, hit);
                breakpoint1.setCondition(null);
                breakpoint2.setCondition(null);
                assertEquals(out3, getOutput());
            });
            expectSuspended((SuspendedEvent event) -> {
                assertEquals(2, event.getBreakpoints().size());
            });
            expectDone();
            prefix += out3;
            assertEquals(out3, getOutput());
            assertEquals(2, breakpoint1.getHitCount());
            assertEquals(3, breakpoint2.getHitCount());
        }
    } while (!(isBefore = !isBefore));
}
Also used : SuspendAnchor(com.oracle.truffle.api.debug.SuspendAnchor) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Aggregations

Breakpoint (com.oracle.truffle.api.debug.Breakpoint)1 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)1 SuspendAnchor (com.oracle.truffle.api.debug.SuspendAnchor)1 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)1 Source (org.graalvm.polyglot.Source)1 Test (org.junit.Test)1