Search in sources :

Example 61 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class LegacyTruffleExceptionTest method testPolyglotStackTrace.

@Test
public void testPolyglotStackTrace() {
    setupEnv(Context.create(), new ProxyLanguage() {

        @Override
        protected CallTarget parse(TruffleLanguage.ParsingRequest request) throws Exception {
            ThrowNode throwNode = new ThrowNode((n) -> {
                return new LegacyCatchableException("Test exception", n);
            });
            return new TestRootNode(languageInstance, "test", null, throwNode).getCallTarget();
        }
    });
    assertFails(() -> context.eval(ProxyLanguage.ID, "Test"), PolyglotException.class, (pe) -> {
        TruffleExceptionTest.verifyStackTrace(pe, "<proxyLanguage> test", "(org.graalvm.sdk/)?org.graalvm.polyglot.Context.eval");
    });
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Node(com.oracle.truffle.api.nodes.Node) BeforeClass(org.junit.BeforeClass) ExportLibrary(com.oracle.truffle.api.library.ExportLibrary) PolyglotException(org.graalvm.polyglot.PolyglotException) ThrowNode(com.oracle.truffle.api.test.TruffleExceptionTest.ThrowNode) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) Test(org.junit.Test) CallTarget(com.oracle.truffle.api.CallTarget) BlockNode(com.oracle.truffle.api.test.TruffleExceptionTest.BlockNode) AbstractPolyglotTest(com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest) TestRootNode(com.oracle.truffle.api.test.TruffleExceptionTest.TestRootNode) ExceptionType(com.oracle.truffle.api.interop.ExceptionType) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) ExportMessage(com.oracle.truffle.api.library.ExportMessage) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleExceptionTest.createContext(com.oracle.truffle.api.test.TruffleExceptionTest.createContext) Context(org.graalvm.polyglot.Context) Assert(org.junit.Assert) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) TruffleTestAssumptions(com.oracle.truffle.tck.tests.TruffleTestAssumptions) TruffleExceptionTest.createAST(com.oracle.truffle.api.test.TruffleExceptionTest.createAST) Before(org.junit.Before) CallTarget(com.oracle.truffle.api.CallTarget) ThrowNode(com.oracle.truffle.api.test.TruffleExceptionTest.ThrowNode) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) TestRootNode(com.oracle.truffle.api.test.TruffleExceptionTest.TestRootNode) PolyglotException(org.graalvm.polyglot.PolyglotException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test) AbstractPolyglotTest(com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest)

Example 62 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class ManualSamplingTest method setup.

@Before
public void setup() {
    enterContext = false;
    enteredSample = new Semaphore(0);
    leaveSample = new Semaphore(0);
    setupEnv(Context.newBuilder().build(), new ProxyLanguage() {

        @Override
        protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
            return true;
        }
    });
    context.eval(InstrumentationTestLanguage.ID, "DEFINE(sample, ROOT)");
    instrumentEnv.getInstrumenter().attachExecutionEventListener(SourceSectionFilter.newBuilder().rootNameIs((s) -> s.equals("sample")).tagIs(RootTag.class).build(), new ExecutionEventListener() {

        public void onEnter(EventContext c, VirtualFrame frame) {
            enteredSample.release(1);
            TruffleSafepoint.setBlockedThreadInterruptible(c.getInstrumentedNode(), Semaphore::acquire, leaveSample);
        }

        public void onReturnValue(EventContext c, VirtualFrame frame, Object result) {
        }

        public void onReturnExceptional(EventContext c, VirtualFrame frame, Throwable exception) {
        }
    });
    sampler = CPUSampler.find(context.getEngine());
    sampler.setFilter(DEFAULT_FILTER);
}
Also used : PolyglotException(org.graalvm.polyglot.PolyglotException) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) ArrayList(java.util.ArrayList) InstrumentationTestLanguage(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) EventContext(com.oracle.truffle.api.instrumentation.EventContext) Map(java.util.Map) After(org.junit.After) BiConsumer(java.util.function.BiConsumer) Assert.fail(org.junit.Assert.fail) StackTraceEntry(com.oracle.truffle.tools.profiler.StackTraceEntry) Before(org.junit.Before) RootTag(com.oracle.truffle.api.instrumentation.StandardTags.RootTag) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Semaphore(java.util.concurrent.Semaphore) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TimeUnit(java.util.concurrent.TimeUnit) AbstractPolyglotTest(com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest) List(java.util.List) ReflectionUtils(com.oracle.truffle.api.test.ReflectionUtils) Assert.assertFalse(org.junit.Assert.assertFalse) Engine(org.graalvm.polyglot.Engine) Entry(java.util.Map.Entry) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler) Context(org.graalvm.polyglot.Context) ExecutionEventListener(com.oracle.truffle.api.instrumentation.ExecutionEventListener) StatementTag(com.oracle.truffle.api.instrumentation.StandardTags.StatementTag) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) Assert.assertEquals(org.junit.Assert.assertEquals) EventContext(com.oracle.truffle.api.instrumentation.EventContext) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Semaphore(java.util.concurrent.Semaphore) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) ExecutionEventListener(com.oracle.truffle.api.instrumentation.ExecutionEventListener) Before(org.junit.Before)

Example 63 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class ProxyLanguageEnvTest method before.

@Before
public void before() {
    context = Context.newBuilder().allowAllAccess(true).build();
    ProxyLanguage.setDelegate(new ProxyLanguage() {

        @Override
        protected LanguageContext createContext(Env contextEnv) {
            env = contextEnv;
            return super.createContext(contextEnv);
        }
    });
    context.initialize(ProxyLanguage.ID);
    context.enter();
    assertNotNull(env);
}
Also used : Env(com.oracle.truffle.api.TruffleLanguage.Env) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Before(org.junit.Before)

Example 64 with ProxyLanguage

use of com.oracle.truffle.api.test.polyglot.ProxyLanguage in project graal by oracle.

the class NodeAssertionsTest method testView.

@Test
@SuppressWarnings("hiding")
public void testView() {
    try (Context context = Context.create()) {
        ProxyLanguage language = new ProxyLanguage();
        ProxyLanguage.setDelegate(language);
        context.initialize(ProxyLanguage.ID);
        context.enter();
        Frame frame = Truffle.getRuntime().createMaterializedFrame(new Object[] {});
        TestAssertsNode n = new TestAssertsNode(ProxyLanguage.get(null), frame.getFrameDescriptor());
        NodeLibrary l = createLibrary(NodeLibrary.class, n);
        n.getView = (f, x) -> x;
        assertFails(() -> l.getView(n, null, true), AssertionError.class);
        assertFails(() -> l.getView(n, null, new Object()), AssertionError.class);
        assertFails(() -> l.getView(n, frame, true), AssertionError.class);
        assertFails(() -> l.getView(n, frame, new Object()), AssertionError.class);
        NodeDefaultsTest.ProxyLanguageValue pv = new NodeDefaultsTest.ProxyLanguageValue();
        assertSame(pv, l.getView(n, frame, pv));
        assertFails(() -> l.getView(n, null, pv), AssertionError.class);
        assertFails(() -> l.getView(new TestAssertsNode(ProxyLanguage.get(null), null), frame, pv), AssertionError.class);
        assertFails(() -> l.getView(new TestAssertsNode(null, frame.getFrameDescriptor()), frame, pv), AssertionError.class);
    }
}
Also used : Context(org.graalvm.polyglot.Context) NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Frame(com.oracle.truffle.api.frame.Frame) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Aggregations

ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)64 Test (org.junit.Test)47 CallTarget (com.oracle.truffle.api.CallTarget)32 AbstractPolyglotTest (com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest)28 PolyglotException (org.graalvm.polyglot.PolyglotException)26 RootNode (com.oracle.truffle.api.nodes.RootNode)21 Source (org.graalvm.polyglot.Source)21 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)20 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)20 Context (org.graalvm.polyglot.Context)17 TruffleContext (com.oracle.truffle.api.TruffleContext)16 Before (org.junit.Before)16 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)14 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)13 CountDownLatch (java.util.concurrent.CountDownLatch)11 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)10 ArrayList (java.util.ArrayList)10 ExecutionException (java.util.concurrent.ExecutionException)10 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)9 ExecutorService (java.util.concurrent.ExecutorService)9