use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class InstrumentationTest method testLanguageInitializedOnlyAppend.
@Test
public void testLanguageInitializedOnlyAppend() 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 excluded,
// but events from the same nodes used for initialization are appended:
TestLangInitialized.initializationEvents = false;
TestLangInitialized service = instrument.lookup(TestLangInitialized.class);
run("LOOP(2, STATEMENT())");
assertEquals("[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.Instrument in project graal by oracle.
the class InstrumentationTest method testLanguageInitializedOrNot.
@Test
public void testLanguageInitializedOrNot() throws Exception {
Source initSource = Source.create(InstrumentationTestLanguage.ID, "STATEMENT(EXPRESSION, EXPRESSION)");
setupEngine(initSource, false);
Instrument instrument = engine.getInstruments().get("testLangInitialized");
// Events during language initialization phase are included:
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]", service.getEnteredNodes());
engine.close();
engine = null;
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class SourceListenerTest method testExecuteSourceNoRootSection.
@Test
public void testExecuteSourceNoRootSection() throws Exception {
Instrument instrument = engine.getInstruments().get("testLoadExecuteSource");
TestLoadExecuteSource impl = instrument.lookup(TestLoadExecuteSource.class);
impl.attachExecute();
testNoRootSectionImpl(impl);
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class SourceListenerTest method testAllowOnlySourceQueries.
@Test
public void testAllowOnlySourceQueries() throws IOException {
Instrument instrument = engine.getInstruments().get("testAllowOnlySourceQueries");
assureEnabled(instrument);
Source source = lines("");
run(source);
TestAllowOnlySourceQueries impl = instrument.lookup(TestAllowOnlySourceQueries.class);
Assert.assertTrue(impl.success);
}
use of org.graalvm.polyglot.Instrument in project graal by oracle.
the class ThreadsEventsTest method testGetStartedThreads.
@Test
public void testGetStartedThreads() throws Exception {
try {
TestThreadsInstrument.includeStartedThreads = true;
final List<ThreadEvent> events;
try (Context context = Context.newBuilder().allowCreateThread(true).build()) {
context.eval(Source.create(InstrumentationTestLanguage.ID, "ROOT(DEFINE(f1, EXPRESSION), SPAWN(f1), JOIN())"));
Instrument testBlockOnStatementsInstrument = context.getEngine().getInstruments().get("testBlockOnStatementsInstrument");
TestBlockOnStatementsInstrument testBlock = testBlockOnStatementsInstrument.lookup(TestBlockOnStatementsInstrument.class);
CountDownLatch latch = new CountDownLatch(1);
testBlock.runOnBlock = new Runnable() {
@Override
public void run() {
latch.countDown();
}
};
context.eval(Source.create(InstrumentationTestLanguage.ID, "ROOT(DEFINE(foo, STATEMENT), SPAWN(foo))"));
latch.await();
Instrument testThreadsInstrument = context.getEngine().getInstruments().get("testThreadsInstrument");
TestThreadsInstrument test = testThreadsInstrument.lookup(TestThreadsInstrument.class);
events = test.events;
assertEquals(events.toString(), 2, events.size());
assertTrue(events.get(0).isNew);
assertNotNull(events.get(0).context);
assertTrue(events.get(1).isNew);
assertEquals(events.get(0).context, events.get(1).context);
assertNotEquals(events.get(0).thread, events.get(1).thread);
testBlock.blockOnStatements.set(false);
synchronized (testBlock.blockOnStatements) {
testBlock.blockOnStatements.notifyAll();
}
context.eval(Source.create(InstrumentationTestLanguage.ID, "JOIN()"));
assertEquals(3, events.size());
assertFalse(events.get(2).isNew);
assertTrue(events.get(0).thread == events.get(2).thread || events.get(1).thread == events.get(2).thread);
}
assertEquals(4, events.size());
} finally {
TestThreadsInstrument.includeStartedThreads = false;
}
}
Aggregations