use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class LanguageSPITest method testContextCloseInsideFromSameThreadCancelExecution.
@Test
public void testContextCloseInsideFromSameThreadCancelExecution() {
Engine engine = Engine.create();
langContext = null;
Context context = Context.newBuilder(LanguageSPITestLanguage.ID).engine(engine).build();
eval(context, new Function<Env, Object>() {
public Object apply(Env t) {
context.close(true);
return null;
}
});
engine.close();
assertEquals(1, langContext.disposeCalled);
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class LanguageSPITest method testLookupHostDisabled.
@Test
public void testLookupHostDisabled() {
Context context = Context.newBuilder().allowHostAccess(false).build();
try {
eval(context, new Function<Env, Object>() {
public Object apply(Env t) {
return t.lookupHostSymbol("java.util.HashMap");
}
});
fail();
} catch (PolyglotException e) {
assertTrue(!e.isInternalError());
}
context.close();
}
use of com.oracle.truffle.api.TruffleLanguage.Env 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.TruffleLanguage.Env in project graal by oracle.
the class MultiThreadedLanguageTest method testAsssertionIfThreadStillActive.
@Test
public void testAsssertionIfThreadStillActive() throws InterruptedException {
MultiThreadedLanguage.isThreadAccessAllowed = (req) -> {
return true;
};
Engine engine = Engine.create();
Context context = Context.newBuilder().allowCreateThread(true).engine(engine).build();
Semaphore wait = new Semaphore(0);
Thread returnThread = eval(context, new Function<Env, Object>() {
public Object apply(Env env) {
Semaphore waitForEnter = new Semaphore(0);
Thread t = env.createThread(() -> {
try {
waitForEnter.release();
wait.acquire();
} catch (InterruptedException e) {
}
});
t.start();
try {
waitForEnter.acquire();
} catch (InterruptedException e) {
}
return t;
}
}).asHostObject();
try {
engine.close();
Assert.fail();
} catch (PolyglotException e) {
assertTrue(e.isInternalError());
assertTrue(e.getMessage().contains("The language did not complete all polyglot threads but should have"));
}
wait.release(1);
returnThread.join();
engine.close();
}
use of com.oracle.truffle.api.TruffleLanguage.Env in project graal by oracle.
the class VirtualizedFileSystemTest method testReadUsingChannel.
@Test
public void testReadUsingChannel() {
final Context ctx = cfg.getContext();
final Path path = cfg.getPath();
final boolean canRead = cfg.canRead();
languageAction = (Env env) -> {
final TruffleFile root = cfg.needsURI() ? env.getTruffleFile(path.toUri()) : env.getTruffleFile(path.toString());
try {
final TruffleFile file = root.resolve(FOLDER_EXISTING).resolve(FILE_EXISTING);
final String content = new String(file.readAllBytes(), StandardCharsets.UTF_8);
Assert.assertTrue(cfg.formatErrorMessage("Expected SecurityException"), canRead);
Assert.assertEquals(cfg.formatErrorMessage("Expected file content"), FILE_EXISTING_CONTENT, content);
} catch (SecurityException se) {
Assert.assertFalse(cfg.formatErrorMessage("Unexpected SecurityException"), canRead);
} catch (IOException ioe) {
throw new AssertionError(cfg.formatErrorMessage(ioe.getMessage()), ioe);
}
};
ctx.eval(LANGAUGE_ID, "");
}
Aggregations