Search in sources :

Example 86 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class InstrumentationTest method testLanguageInitializedOrNotAppend.

@Test
public void testLanguageInitializedOrNotAppend() throws Exception {
    Source initSource = Source.create(InstrumentationTestLanguage.ID, "STATEMENT(EXPRESSION, EXPRESSION)");
    setupEngine(initSource, true);
    Instrument instrument = engine.getInstruments().get("testLangInitialized");
    // Events during language initialization phase are prepended and appended:
    TestLangInitialized.initializationEvents = true;
    TestLangInitialized service = instrument.lookup(TestLangInitialized.class);
    run("LOOP(2, STATEMENT())");
    assertEquals("[FunctionRootNode, false, StatementNode, false, ExpressionNode, false, ExpressionNode, false, " + "FunctionRootNode, true, LoopNode, true, StatementNode, true, StatementNode, true, FunctionRootNode, true, StatementNode, true, ExpressionNode, true, ExpressionNode, true]", service.getEnteredNodes());
    engine.close();
    engine = null;
}
Also used : Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 87 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class InstrumentationTest method testInstrumentsWhenForked.

@Test
public void testInstrumentsWhenForked() throws IOException {
    Instrument instrument = engine.getInstruments().get("testIsNodeTaggedWith1");
    assureEnabled(instrument);
    TestIsNodeTaggedWith1 service = instrument.lookup(TestIsNodeTaggedWith1.class);
    assertEquals(1, service.onCreateCalls);
    Source otherLanguageSource = Source.create("testIsNodeTaggedWith1-lang", "STATEMENT(EXPRESSION)");
    run(otherLanguageSource);
    org.graalvm.polyglot.Context forked = newContext();
    assertEquals(1, service.onCreateCalls);
    final Map<String, ? extends Instrument> instruments = forked.getEngine().getInstruments();
    assertSame(instrument, instruments.get("testIsNodeTaggedWith1"));
    assertSame(service, instruments.get("testIsNodeTaggedWith1").lookup(TestIsNodeTaggedWith1.class));
    assertEquals(instruments.size(), engine.getInstruments().size());
    for (String key : instruments.keySet()) {
        assertSame(engine.getInstruments().get(key), instruments.get(key));
    }
    assertEquals(0, service.onDisposeCalls);
    context.close();
    assertEquals(0, service.onDisposeCalls);
    forked.getEngine().close();
    // test if all engines are disposed
    assertEquals(1, service.onDisposeCalls);
    // avoid a second disposal in @After event
    engine = null;
}
Also used : Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 88 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class StatementProfilerExampleTest method testLoopHundreds.

@Test
public void testLoopHundreds() throws IOException {
    Source source = lines(// 1
    "LOOP(100", // 2
    ",STATEMENT(", // 3
    "STATEMENT),", /**/
    "STATEMENT)");
    // 4
    Map<SourceSection, Counter> counters = profiler.getCounters();
    for (int i = 0; i < 10; i++) {
        if (i == 0) {
            Assert.assertTrue(counters.isEmpty());
        } else {
            assertLine(counters, 2, i * 100);
            assertLine(counters, 3, i * 100);
            assertLine(counters, 4, i * 100);
        }
        run(source);
    }
}
Also used : Counter(com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 89 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class DebuggerExampleTest method testStepOut.

@Test
@SuppressWarnings("hiding")
public void testStepOut() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "DEFINE(foo,STATEMENT),", // 3
    "DEFINE(bar", // 4
    ",STATEMENT", // 5
    ",STATEMENT(CALL(foo))", // 6
    ",STATEMENT),", /**/
    "STATEMENT(CALL(bar)))");
    // 7
    final AtomicBoolean allStepped = new AtomicBoolean();
    debugger.installBreakpoint(2, new Callback() {

        @Override
        public void halted(DebuggerController debugger, EventContext haltedAt) {
            assertLineAt(haltedAt, 2);
            debugger.stepOut(new Callback() {

                @Override
                public void halted(DebuggerController debugger, EventContext haltedAt) {
                    assertLineAt(haltedAt, 6);
                    debugger.stepOver(new Callback() {

                        @Override
                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                            throw new AssertionError();
                        }
                    });
                    allStepped.set(true);
                }
            });
        }
    });
    run(source);
    Assert.assertTrue(allStepped.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 90 with Source

use of org.graalvm.polyglot.Source in project graal by oracle.

the class DebuggerExampleTest method testStepInto.

@Test
@SuppressWarnings("hiding")
public void testStepInto() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "DEFINE(foo,STATEMENT),", // 3
    "DEFINE(bar", // 4
    ",STATEMENT", // 5
    ",STATEMENT(CALL(foo))", // 6
    ",STATEMENT),", /**/
    "STATEMENT(CALL(bar)))");
    // 7
    final AtomicBoolean allStepped = new AtomicBoolean();
    debugger.installBreakpoint(7, new Callback() {

        public void halted(DebuggerController debugger, EventContext haltedAt) {
            assertLineAt(haltedAt, 7);
            debugger.stepInto(new Callback() {

                public void halted(DebuggerController debugger, EventContext haltedAt) {
                    assertLineAt(haltedAt, 4);
                    debugger.stepInto(new Callback() {

                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                            assertLineAt(haltedAt, 5);
                            debugger.stepInto(new Callback() {

                                public void halted(DebuggerController debugger, EventContext haltedAt) {
                                    assertLineAt(haltedAt, 2);
                                    debugger.stepInto(new Callback() {

                                        public void halted(DebuggerController debugger, EventContext haltedAt) {
                                            assertLineAt(haltedAt, 6);
                                            debugger.stepInto(new Callback() {

                                                public void halted(DebuggerController debugger, EventContext haltedAt) {
                                                    throw new AssertionError();
                                                }
                                            });
                                            allStepped.set(true);
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }
    });
    run(source);
    Assert.assertTrue(allStepped.get());
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.oracle.truffle.api.instrumentation.test.examples.DebuggerController.Callback) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Aggregations

Source (org.graalvm.polyglot.Source)196 Test (org.junit.Test)165 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)103 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)95 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)51 Value (org.graalvm.polyglot.Value)31 Context (org.graalvm.polyglot.Context)25 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)21 DebugValue (com.oracle.truffle.api.debug.DebugValue)20 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)14 Instrument (org.graalvm.polyglot.Instrument)14 Debugger (com.oracle.truffle.api.debug.Debugger)13 SourceSection (com.oracle.truffle.api.source.SourceSection)12 EventContext (com.oracle.truffle.api.instrumentation.EventContext)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Engine (org.graalvm.polyglot.Engine)9 ArrayList (java.util.ArrayList)8 PolyglotException (org.graalvm.polyglot.PolyglotException)8 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)7 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)7