use of com.oracle.truffle.api.test.polyglot.ProxyInstrument in project graal by oracle.
the class NodeLibrarySLCompilerTest method doInstrument.
private void doInstrument(Engine engine) {
ProxyInstrument instrument = new ProxyInstrument();
ProxyInstrument.setDelegate(instrument);
instrument.setOnCreate((env) -> {
env.getInstrumenter().attachExecutionEventFactory(SourceSectionFilter.newBuilder().tagIs(DebuggerTags.AlwaysHalt.class).build(), context -> new SumVarsExecNode(context.getInstrumentedNode()));
try {
CallTarget langSumTarget = env.parse(Source.newBuilder("sl", "function test(x, y) {z = 0; z = x + y; return z;}", "sumLang.sl").build());
RootNode langSum = ((RootCallTarget) langSumTarget).getRootNode();
CallTarget instrSumTarget = env.parse(Source.newBuilder("sl", "function test(x, y) {z = 0; debugger; return z;}", "sumInstr.sl").build());
RootNode instrSum = ((RootCallTarget) instrSumTarget).getRootNode();
assertPartialEvalEquals(langSum, instrSum, new Object[] { 1, 2 });
} catch (IOException e) {
throw new IllegalStateException(e);
}
});
engine.getInstruments().get(ProxyInstrument.ID).lookup(ProxyInstrument.Initialize.class);
}
use of com.oracle.truffle.api.test.polyglot.ProxyInstrument in project graal by oracle.
the class NodeLibraryCompilerTest method doInstrument.
private static void doInstrument(Engine engine) {
ProxyInstrument instrument = new ProxyInstrument();
ProxyInstrument.setDelegate(instrument);
instrument.setOnCreate((env) -> {
env.getInstrumenter().attachExecutionEventFactory(SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build(), context -> new ReadVarExecNode(context));
});
engine.getInstruments().get(ProxyInstrument.ID).lookup(ProxyInstrument.Initialize.class);
}
use of com.oracle.truffle.api.test.polyglot.ProxyInstrument in project graal by oracle.
the class TagsTest method testUndeclaredTagsLanguage.
@Test
public void testUndeclaredTagsLanguage() {
ProxyInstrument instrument = new ProxyInstrument();
ProxyInstrument.setDelegate(instrument);
instrument.setOnCreate((env) -> {
env.getInstrumenter().attachExecutionEventFactory(SourceSectionFilter.ANY, new ExecutionEventNodeFactory() {
@Override
public ExecutionEventNode create(EventContext context) {
try {
context.hasTag(MyTagWithIdentifier.class);
Assert.fail();
} catch (AssertionError err) {
String message = err.getMessage();
assertUndeclaredTagMessage(message, MyTagWithIdentifier.class);
}
return null;
}
});
});
Context context = Context.create();
context.getEngine().getInstruments().get(ProxyInstrument.ID).lookup(ProxyInstrument.Initialize.class);
try {
context.eval(UndeclaredTagsLanguage.ID, "E");
Assert.fail();
} catch (PolyglotException ex) {
String message = ex.getMessage();
assertUndeclaredTagMessage(message, StandardTags.ExpressionTag.class);
}
context.eval(UndeclaredTagsLanguage.ID, "M");
}
use of com.oracle.truffle.api.test.polyglot.ProxyInstrument in project graal by oracle.
the class InternalErrorPropagationTest method testInstrumentCreateException.
@Test
public void testInstrumentCreateException() {
TestContextListener listener = new TestContextListener();
ProxyInstrument instrument = new TestProxyInstrument(listener);
TestEventListener triggerFailure = new TestEventListener();
setupEnv(Context.create(ProxyLanguage.ID), instrument);
try {
listener.onContextCreated = triggerFailure;
setupEnv(Context.create(ProxyLanguage.ID), instrument);
Assert.fail();
} catch (PolyglotException e) {
Assert.assertTrue(e.isInternalError());
}
try {
listener.onContextCreated = null;
listener.onLanguageContextCreated = triggerFailure;
setupEnv(Context.create(ProxyLanguage.ID), instrument);
Assert.fail();
} catch (PolyglotException e) {
Assert.assertTrue(e.isInternalError());
}
try {
listener.onLanguageContextCreated = null;
listener.onLanguageContextInitialized = triggerFailure;
setupEnv(Context.create(ProxyLanguage.ID), instrument);
Assert.fail();
} catch (PolyglotException e) {
Assert.assertTrue(e.isInternalError());
}
listener.onLanguageContextInitialized = null;
setupEnv(Context.create(ProxyLanguage.ID), instrument);
try {
listener.onLanguageContextFinalized = triggerFailure;
context.close();
Assert.fail();
} catch (PolyglotException e) {
Assert.assertTrue(e.isInternalError());
listener.onLanguageContextFinalized = null;
context.close();
}
listener.onLanguageContextFinalized = null;
setupEnv(Context.create(ProxyLanguage.ID), instrument);
try {
listener.onLanguageContextDisposed = triggerFailure;
context.close();
Assert.fail();
} catch (PolyglotException e) {
Assert.assertTrue(e.isInternalError());
listener.onLanguageContextDisposed = null;
context.close();
}
listener.onLanguageContextDisposed = null;
setupEnv(Context.create(ProxyLanguage.ID), instrument);
try {
listener.onContextClosed = triggerFailure;
context.close();
Assert.fail();
} catch (PolyglotException e) {
Assert.assertTrue(e.isInternalError());
listener.onContextClosed = null;
context.close();
}
}
use of com.oracle.truffle.api.test.polyglot.ProxyInstrument in project graal by oracle.
the class TagsTest method testRWVariableTags.
@Test
public void testRWVariableTags() {
ProxyInstrument instrument = new ProxyInstrument();
ProxyInstrument.setDelegate(instrument);
instrument.setOnCreate((env) -> {
env.getInstrumenter().attachExecutionEventFactory(SourceSectionFilter.newBuilder().tagIs(StandardTags.ReadVariableTag.class, StandardTags.WriteVariableTag.class).build(), new ExecutionEventNodeFactory() {
@Override
public ExecutionEventNode create(EventContext context) {
assert context.getNodeObject() != null;
return null;
}
});
});
Context context = Context.create();
context.getEngine().getInstruments().get(ProxyInstrument.ID).lookup(ProxyInstrument.Initialize.class);
context.eval(RWVariableLanguage.ID, "R a");
context.eval(RWVariableLanguage.ID, "W a");
context.eval(RWVariableLanguage.ID, "R string");
context.eval(RWVariableLanguage.ID, "WSstring");
context.eval(RWVariableLanguage.ID, "R a,b,c");
context.eval(RWVariableLanguage.ID, "WSa,b,c");
try {
context.eval(RWVariableLanguage.ID, "BadR a");
Assert.fail();
} catch (PolyglotException ex) {
String message = ex.getMessage();
Assert.assertTrue(message, message.indexOf(StandardTags.ReadVariableTag.NAME) > 0);
}
try {
context.eval(RWVariableLanguage.ID, "BadW a");
Assert.fail();
} catch (PolyglotException ex) {
String message = ex.getMessage();
Assert.assertTrue(message, message.indexOf(StandardTags.WriteVariableTag.NAME) > 0);
}
try {
context.eval(RWVariableLanguage.ID, "R null");
Assert.fail();
} catch (PolyglotException ex) {
String message = ex.getMessage();
Assert.assertTrue(message, message.indexOf("String") > 0);
}
}
Aggregations