private PolyglotEngine vm() throws Exception { if (previousVMReference != null) { return previousVMReference; } previousVMReference = prepareVM(); return previousVMReference; }
private TruffleVM vm() throws Exception { if (tckVM == null) { tckVM = prepareVM(); } return tckVM; }
/** * This methods is called before each test is executed. It's purpose is to set a * {@link PolyglotEngine} with your language up, so it is ready for testing. * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source) Execute} any scripts you * need, and prepare global symbols with proper names. The symbols will then be looked up by the * infrastructure (using the names provided by you from methods like {@link #plusInt()}) and * used for internal testing. * * @return initialized Truffle virtual machine * @throws java.lang.Exception thrown when the VM preparation fails * @since 0.8 or earlier */ protected PolyglotEngine prepareVM() throws Exception { return prepareVM(PolyglotEngine.newBuilder()); }
final String countMethod = countInvocations(); PolyglotEngine.Builder builder = PolyglotEngine.newBuilder().executor(Executors.newSingleThreadExecutor()); PolyglotEngine vm2 = prepareVM(builder); try { PolyglotEngine.Value count2 = vm2.findGlobalSymbol(countMethod);
/** * Tests whether execution can be suspended in debugger. * * @since 0.15 */ @Test public void timeOutTest() throws Exception { final ExecWithTimeOut timeOutExecution = new ExecWithTimeOut(); ScheduledExecutorService executor = new MockExecutorService(); timeOutExecution.engine = prepareVM(PolyglotEngine.newBuilder()); PolyglotEngine.Value counting = timeOutExecution.engine.findGlobalSymbol(countUpWhile()); int index = RANDOM.nextInt(50) + 50; CountAndKill obj = new CountAndKill(index, executor); timeOutExecution.executeWithTimeOut(executor, counting, obj); assertEquals("Executed " + index + " times, and counted down to zero", 0, obj.countDown); assertTrue("Last number bigger than requested", index <= obj.lastParameter); assertTrue("All tasks processed", executor.isShutdown()); }
/** @since 0.15 */ @Test public void testRootNodeName() throws Exception { final int[] haltCount = new int[1]; final String name = applyNumbers(); final String[] actualName = new String[1]; final PolyglotEngine engine = prepareVM(PolyglotEngine.newBuilder()); final PolyglotEngine.Value apply = engine.findGlobalSymbol(name); final int value = RANDOM.nextInt(100); final TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); try (DebuggerSession session = Debugger.find(engine).startSession(new SuspendedCallback() { public void onSuspend(SuspendedEvent ev) { actualName[0] = ev.getTopStackFrame().getName(); haltCount[0] = haltCount[0] + 1; } })) { session.suspendNextExecution(); apply.execute(fn).as(Number.class); } assertEquals(1, haltCount[0]); assertEquals(name, actualName[0]); }