use of com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext in project graal by oracle.
the class LanguageSPITest method testCreateContextDuringDispose.
@Test
public void testCreateContextDuringDispose() {
AtomicBoolean contextOnFinalize = new AtomicBoolean(true);
AtomicBoolean contextOnDispose = new AtomicBoolean(false);
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected LanguageContext createContext(Env env) {
return new LanguageContext(env);
}
@Override
protected void finalizeContext(LanguageContext context) {
if (contextOnFinalize.get()) {
context.env.newContextBuilder().build();
}
}
@Override
protected void disposeContext(LanguageContext context) {
if (contextOnDispose.get()) {
context.env.newContextBuilder().build();
}
}
});
Context c = Context.create();
c.initialize(ProxyLanguage.ID);
// Fails on finalize
testFails(() -> {
c.close();
});
contextOnFinalize.set(false);
contextOnDispose.set(true);
// Fails on dispose
testFails(() -> {
c.close();
});
// clean up the context
contextOnDispose.set(false);
c.close();
}
use of com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext in project graal by oracle.
the class LanguageSPITest method testErrorInDisposeLanguage.
@Test
public void testErrorInDisposeLanguage() {
AtomicBoolean fail = new AtomicBoolean(true);
ProxyLanguage.setDelegate(new ProxyLanguage() {
@Override
protected void disposeContext(LanguageContext context) {
if (fail.get()) {
throw new RuntimeException();
}
}
});
Context c = Context.create();
c.initialize(ProxyLanguage.ID);
testFails(() -> {
c.close();
});
testFails(() -> {
c.close();
});
// clean up the context
fail.set(false);
c.close();
}
use of com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext in project graal by oracle.
the class LanguageSPITestLanguage method createContext.
@Override
protected LanguageContext createContext(Env env) {
LanguageSPITest.langContext = new LanguageContext();
LanguageSPITest.langContext.env = env;
LanguageSPITest.langContext.config = env.getConfig();
return LanguageSPITest.langContext;
}
use of com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext in project graal by oracle.
the class LanguageSPITest method testInnerContext.
@Test
public void testInnerContext() {
Context context = Context.create();
Function<Env, Object> f = new Function<Env, Object>() {
public Object apply(Env env) {
LanguageContext outerLangContext = LanguageSPITestLanguage.getContext();
Object config = new Object();
TruffleContext innerContext = env.newContextBuilder().config("config", config).build();
Object p = innerContext.enter();
LanguageContext innerLangContext = LanguageSPITestLanguage.getContext();
try {
try {
innerContext.close();
fail("context could be closed when entered");
} catch (IllegalStateException e) {
}
assertEquals(0, innerLangContext.disposeCalled);
assertEquals(config, innerLangContext.config.get("config"));
assertNotSame(outerLangContext, innerLangContext);
boolean assertions = false;
assert (assertions = true) == true;
if (assertions) {
boolean leaveFailed = false;
try {
innerContext.leave("foo");
} catch (AssertionError e) {
leaveFailed = true;
}
if (!leaveFailed) {
fail("no assertion error for leaving with the wrong object");
}
}
} finally {
innerContext.leave(p);
}
assertSame(outerLangContext, LanguageSPITestLanguage.getContext());
innerContext.close();
try {
innerContext.enter();
fail("cannot be entered after closing");
} catch (IllegalStateException e) {
}
innerContext.close();
assertEquals(1, innerLangContext.disposeCalled);
return null;
}
};
eval(context, f);
// ensure we are not yet closed
eval(context, f);
context.close();
}
use of com.oracle.truffle.api.test.polyglot.LanguageSPITestLanguage.LanguageContext in project graal by oracle.
the class LanguageSPITest method testImplicitClose.
@Test
public void testImplicitClose() {
Engine engine = Engine.create();
langContext = null;
Context c = Context.newBuilder().engine(engine).build();
c.initialize(LanguageSPITestLanguage.ID);
LanguageContext context1 = langContext;
Context.newBuilder().engine(engine).build().initialize(LanguageSPITestLanguage.ID);
LanguageContext context2 = langContext;
c.close();
engine.close();
assertEquals(1, context1.disposeCalled);
assertEquals(1, context2.disposeCalled);
}
Aggregations