Search in sources :

Example 1 with ProxyInstrument

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);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) ProxyInstrument(com.oracle.truffle.api.test.polyglot.ProxyInstrument) DebuggerTags(com.oracle.truffle.api.debug.DebuggerTags) IOException(java.io.IOException) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 2 with ProxyInstrument

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);
}
Also used : ProxyInstrument(com.oracle.truffle.api.test.polyglot.ProxyInstrument) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags)

Example 3 with ProxyInstrument

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");
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) EventContext(com.oracle.truffle.api.instrumentation.EventContext) Context(org.graalvm.polyglot.Context) ExecutionEventNodeFactory(com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory) ProxyInstrument(com.oracle.truffle.api.test.polyglot.ProxyInstrument) ExpressionTag(com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode) PolyglotException(org.graalvm.polyglot.PolyglotException) Test(org.junit.Test)

Example 4 with ProxyInstrument

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();
    }
}
Also used : ProxyInstrument(com.oracle.truffle.api.test.polyglot.ProxyInstrument) PolyglotException(org.graalvm.polyglot.PolyglotException) Test(org.junit.Test) AbstractPolyglotTest(com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest)

Example 5 with ProxyInstrument

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);
    }
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) EventContext(com.oracle.truffle.api.instrumentation.EventContext) Context(org.graalvm.polyglot.Context) ExecutionEventNodeFactory(com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory) ProxyInstrument(com.oracle.truffle.api.test.polyglot.ProxyInstrument) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode) PolyglotException(org.graalvm.polyglot.PolyglotException) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) Test(org.junit.Test)

Aggregations

ProxyInstrument (com.oracle.truffle.api.test.polyglot.ProxyInstrument)5 PolyglotException (org.graalvm.polyglot.PolyglotException)3 Test (org.junit.Test)3 EventContext (com.oracle.truffle.api.instrumentation.EventContext)2 ExecutionEventNode (com.oracle.truffle.api.instrumentation.ExecutionEventNode)2 ExecutionEventNodeFactory (com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory)2 StandardTags (com.oracle.truffle.api.instrumentation.StandardTags)2 Context (org.graalvm.polyglot.Context)2 CallTarget (com.oracle.truffle.api.CallTarget)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 DebuggerTags (com.oracle.truffle.api.debug.DebuggerTags)1 ExpressionTag (com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 AbstractPolyglotTest (com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest)1 IOException (java.io.IOException)1