Search in sources :

Example 6 with Context

use of org.graalvm.polyglot.Context in project graal by oracle.

the class LanguageSPIOrderTest method testActivateDuringFinalize.

@Test
public void testActivateDuringFinalize() {
    Context context = Context.create();
    context.initialize(ACTIVATE_DURING_FINALIZE);
    assertNotNull(getOrder(ACTIVATE_DURING_FINALIZE));
    assertEquals(0, getOrder(ACTIVATE_DURING_FINALIZE).createContext);
    assertEquals(1, getOrder(ACTIVATE_DURING_FINALIZE).initializeThread);
    assertEquals(2, getOrder(ACTIVATE_DURING_FINALIZE).initializeContext);
    /*
         * context uses PUBLIC which uses INTERNAL in the finalizeContext methods
         */
    context.close();
    assertEquals(3, getOrder(ACTIVATE_DURING_FINALIZE).finalizeContext);
    assertEquals(4, getOrder(PUBLIC).createContext);
    assertEquals(5, getOrder(INTERNAL).createContext);
    assertEquals(6, getOrder(INTERNAL).initializeThread);
    assertEquals(7, getOrder(INTERNAL).initializeContext);
    assertEquals(8, getOrder(PUBLIC).initializeThread);
    assertEquals(9, getOrder(PUBLIC).initializeContext);
    assertEquals(10, getOrder(PUBLIC).finalizeContext);
    assertEquals(11, getOrder(INTERNAL).finalizeContext);
    assertEquals(12, getOrder(ACTIVATE_DURING_FINALIZE).disposeThread);
    assertEquals(13, getOrder(ACTIVATE_DURING_FINALIZE).disposeContext);
    assertEquals(14, getOrder(PUBLIC).disposeThread);
    assertEquals(15, getOrder(PUBLIC).disposeContext);
    assertEquals(16, getOrder(INTERNAL).disposeThread);
    assertEquals(17, getOrder(INTERNAL).disposeContext);
}
Also used : Context(org.graalvm.polyglot.Context) Test(org.junit.Test)

Example 7 with Context

use of org.graalvm.polyglot.Context in project graal by oracle.

the class LanguageSPIOrderTest method testOrderSimple.

@Test
public void testOrderSimple() {
    Context context = Context.create();
    context.initialize(PUBLIC);
    assertNotNull(getOrder(PUBLIC));
    assertNotNull(getOrder(INTERNAL));
    assertEquals(0, getOrder(PUBLIC).createContext);
    assertEquals(1, getOrder(INTERNAL).createContext);
    assertEquals(2, getOrder(INTERNAL).initializeThread);
    assertEquals(3, getOrder(INTERNAL).initializeContext);
    assertEquals(4, getOrder(PUBLIC).initializeThread);
    assertEquals(5, getOrder(PUBLIC).initializeContext);
    context.close();
    assertEquals(6, getOrder(PUBLIC).finalizeContext);
    assertEquals(7, getOrder(INTERNAL).finalizeContext);
    assertEquals(8, getOrder(PUBLIC).disposeThread);
    assertEquals(9, getOrder(PUBLIC).disposeContext);
    assertEquals(10, getOrder(INTERNAL).disposeThread);
    assertEquals(11, getOrder(INTERNAL).disposeContext);
}
Also used : Context(org.graalvm.polyglot.Context) Test(org.junit.Test)

Example 8 with Context

use of org.graalvm.polyglot.Context in project graal by oracle.

the class LanguageSPIOrderTest method testOrderDependent.

@Test
public void testOrderDependent() {
    Context context = Context.create();
    context.initialize(TRANSITIVE);
    assertNotNull(getOrder(TRANSITIVE));
    assertNotNull(getOrder(DEPENDENT));
    assertNotNull(getOrder(PUBLIC));
    assertNotNull(getOrder(INTERNAL));
    assertEquals(0, getOrder(TRANSITIVE).createContext);
    assertEquals(1, getOrder(TRANSITIVE).initializeThread);
    assertEquals(2, getOrder(TRANSITIVE).initializeContext);
    assertEquals(3, getOrder(DEPENDENT).createContext);
    assertEquals(4, getOrder(DEPENDENT).initializeThread);
    assertEquals(5, getOrder(DEPENDENT).initializeContext);
    assertEquals(6, getOrder(PUBLIC).createContext);
    assertEquals(7, getOrder(INTERNAL).createContext);
    assertEquals(8, getOrder(INTERNAL).initializeThread);
    assertEquals(9, getOrder(INTERNAL).initializeContext);
    assertEquals(10, getOrder(PUBLIC).initializeThread);
    assertEquals(11, getOrder(PUBLIC).initializeContext);
    context.close();
    assertEquals(12, getOrder(TRANSITIVE).finalizeContext);
    assertEquals(13, getOrder(DEPENDENT).finalizeContext);
    assertEquals(14, getOrder(PUBLIC).finalizeContext);
    assertEquals(15, getOrder(INTERNAL).finalizeContext);
    assertEquals(16, getOrder(TRANSITIVE).disposeThread);
    assertEquals(17, getOrder(TRANSITIVE).disposeContext);
    assertEquals(18, getOrder(DEPENDENT).disposeThread);
    assertEquals(19, getOrder(DEPENDENT).disposeContext);
    assertEquals(20, getOrder(PUBLIC).disposeThread);
    assertEquals(21, getOrder(PUBLIC).disposeContext);
    assertEquals(22, getOrder(INTERNAL).disposeThread);
    assertEquals(23, getOrder(INTERNAL).disposeContext);
}
Also used : Context(org.graalvm.polyglot.Context) Test(org.junit.Test)

Example 9 with Context

use of org.graalvm.polyglot.Context in project graal by oracle.

the class LanguageSPIOrderTest method testActivateDuringDispose.

@Test
public void testActivateDuringDispose() {
    Context context = Context.create();
    context.initialize(ACTIVATE_DURING_DISPOSE);
    assertNotNull(getOrder(ACTIVATE_DURING_DISPOSE));
    assertEquals(0, getOrder(ACTIVATE_DURING_DISPOSE).createContext);
    assertEquals(1, getOrder(ACTIVATE_DURING_DISPOSE).initializeThread);
    assertEquals(2, getOrder(ACTIVATE_DURING_DISPOSE).initializeContext);
    context.close();
    assertEquals(3, getOrder(ACTIVATE_DURING_DISPOSE).finalizeContext);
    assertEquals(4, getOrder(ACTIVATE_DURING_DISPOSE).disposeThread);
    assertEquals(5, getOrder(ACTIVATE_DURING_DISPOSE).disposeContext);
}
Also used : Context(org.graalvm.polyglot.Context) Test(org.junit.Test)

Example 10 with Context

use of org.graalvm.polyglot.Context in project graal by oracle.

the class LanguageSPITest method testIsHostAccessAllowed.

@Test
public void testIsHostAccessAllowed() {
    Context context = Context.newBuilder().allowHostAccess(false).build();
    assertTrue(!eval(context, env -> env.isHostLookupAllowed()).asBoolean());
    context.close();
    context = Context.newBuilder().allowHostAccess(true).build();
    assertTrue(eval(context, env -> env.isHostLookupAllowed()).asBoolean());
    context.close();
}
Also used : Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) TruffleContext(com.oracle.truffle.api.TruffleContext) Arrays(java.util.Arrays) OptionKey(org.graalvm.options.OptionKey) Assert.assertNotSame(org.junit.Assert.assertNotSame) Env(com.oracle.truffle.api.TruffleLanguage.Env) TimeoutException(java.util.concurrent.TimeoutException) KeyInfo(com.oracle.truffle.api.interop.KeyInfo) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) RootNode(com.oracle.truffle.api.nodes.RootNode) Assert.fail(org.junit.Assert.fail) Value(org.graalvm.polyglot.Value) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) CallTarget(com.oracle.truffle.api.CallTarget) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Source(com.oracle.truffle.api.source.Source) Message(com.oracle.truffle.api.interop.Message) TruffleException(com.oracle.truffle.api.TruffleException) Assert.assertFalse(org.junit.Assert.assertFalse) Context(org.graalvm.polyglot.Context) LanguageContext(com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext) PolyglotException(org.graalvm.polyglot.PolyglotException) RootCallTarget(com.oracle.truffle.api.RootCallTarget) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ForeignAccess(com.oracle.truffle.api.interop.ForeignAccess) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) HashSet(java.util.HashSet) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) SourceSection(com.oracle.truffle.api.source.SourceSection) OptionDescriptor(org.graalvm.options.OptionDescriptor) ExecutorService(java.util.concurrent.ExecutorService) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Node(com.oracle.truffle.api.nodes.Node) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) OptionDescriptors(org.graalvm.options.OptionDescriptors) TruffleContext(com.oracle.truffle.api.TruffleContext) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Assert.assertNull(org.junit.Assert.assertNull) Engine(org.graalvm.polyglot.Engine) Truffle(com.oracle.truffle.api.Truffle) Assert(org.junit.Assert) Scope(com.oracle.truffle.api.Scope) Assert.assertEquals(org.junit.Assert.assertEquals) Test(org.junit.Test)

Aggregations

Context (org.graalvm.polyglot.Context)185 Test (org.junit.Test)148 Value (org.graalvm.polyglot.Value)58 TruffleContext (com.oracle.truffle.api.TruffleContext)56 Env (com.oracle.truffle.api.TruffleLanguage.Env)41 LanguageContext (com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext)37 Engine (org.graalvm.polyglot.Engine)32 ArrayList (java.util.ArrayList)29 PolyglotException (org.graalvm.polyglot.PolyglotException)24 Source (org.graalvm.polyglot.Source)22 Path (java.nio.file.Path)21 TruffleFile (com.oracle.truffle.api.TruffleFile)20 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)20 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)19 CEntryPointContext (org.graalvm.nativeimage.c.function.CEntryPointContext)19 LanguageContext (com.oracle.truffle.api.test.polyglot.ContextAPITestLanguage.LanguageContext)17 IOException (java.io.IOException)14 Debugger (com.oracle.truffle.api.debug.Debugger)13 EventContext (com.oracle.truffle.api.instrumentation.EventContext)13 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)12