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;
}
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;
}
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);
}
}
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());
}
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());
}
Aggregations