Search in sources :

Example 51 with ProxyLanguage

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

the class ContextInterruptCloseCancelOrExitTest method getWaitOnExitLanguage.

private static ProxyLanguage getWaitOnExitLanguage(CountDownLatch signalWaitingStarted, Object waitObject) {
    return new ProxyLanguage() {

        @Override
        protected CallTarget parse(ParsingRequest request) {
            return new RootNode(languageInstance) {

                @Override
                public Object execute(VirtualFrame frame) {
                    LanguageContext languageContext = LanguageContext.get(this);
                    languageContext.getEnv().getContext().closeExited(this, 1);
                    return 0;
                }
            }.getCallTarget();
        }

        @Override
        protected boolean isThreadAccessAllowed(Thread thread, boolean singleThreaded) {
            return true;
        }

        @Override
        protected void exitContext(LanguageContext ctx, ExitMode exitMode, int exitCode) {
            waitIndefinitely();
        }

        @CompilerDirectives.TruffleBoundary
        private void waitIndefinitely() {
            try {
                synchronized (waitObject) {
                    signalWaitingStarted.countDown();
                    waitObject.wait();
                }
            } catch (InterruptedException ie) {
                throw new AssertionError(ie);
            }
        }
    };
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) RootNode(com.oracle.truffle.api.nodes.RootNode) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage)

Example 52 with ProxyLanguage

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

the class ProfilerTest method testNoSourceProfile.

@Test
public void testNoSourceProfile() throws InterruptedException, IOException, ExecutionException {
    ProxyLanguage.setDelegate(new TestNoSourceLanguage());
    InspectorTester tester = InspectorTester.start(false);
    Source source = Source.newBuilder(ProxyLanguage.ID, "1", "NoSourceProfile").build();
    tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
    assertEquals("{\"result\":{},\"id\":1}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":2,\"method\":\"Profiler.enable\"}");
    assertEquals("{\"result\":{},\"id\":2}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":3,\"method\":\"Profiler.setSamplingInterval\",\"params\":{\"interval\":1000}}");
    assertEquals("{\"result\":{},\"id\":3}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":4,\"method\":\"Profiler.start\"}");
    assertEquals("{\"result\":{},\"id\":4}", tester.getMessages(true).trim());
    tester.eval(source).get();
    tester.sendMessage("{\"id\":5,\"method\":\"Profiler.stop\"}");
    JSONObject json = new JSONObject(tester.getMessages(true).trim());
    assertNotNull(json);
    assertEquals(json.getInt("id"), 5);
    JSONObject jsonResult = json.getJSONObject("result");
    assertNotNull(jsonResult);
    JSONObject jsonProfile = jsonResult.getJSONObject("profile");
    assertNotNull(jsonProfile);
    tester.sendMessage("{\"id\":6,\"method\":\"Profiler.disable\"}");
    assertEquals("{\"result\":{},\"id\":6}", tester.getMessages(true).trim());
    ProxyLanguage.setDelegate(new ProxyLanguage());
    tester.finish();
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Source(org.graalvm.polyglot.Source) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 53 with ProxyLanguage

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

the class ProfilerTest method testNoSourceCoverage.

@Test
public void testNoSourceCoverage() throws InterruptedException, IOException, ExecutionException {
    ProxyLanguage.setDelegate(new TestNoSourceLanguage());
    InspectorTester tester = InspectorTester.start(false);
    Source source = Source.newBuilder(ProxyLanguage.ID, "1", "NoSourceProfile").build();
    tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
    assertEquals("{\"result\":{},\"id\":1}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":2,\"method\":\"Profiler.enable\"}");
    assertEquals("{\"result\":{},\"id\":2}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":3,\"method\":\"Profiler.startPreciseCoverage\"}");
    assertEquals("{\"result\":{},\"id\":3}", tester.getMessages(true).trim());
    tester.eval(source).get();
    tester.sendMessage("{\"id\":5,\"method\":\"Profiler.takePreciseCoverage\"}");
    // No results in case of no source section
    assertEquals("{\"result\":{\"result\":[]},\"id\":5}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":7,\"method\":\"Profiler.stopPreciseCoverage\"}");
    assertEquals("{\"result\":{},\"id\":7}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":6,\"method\":\"Profiler.disable\"}");
    assertEquals("{\"result\":{},\"id\":6}", tester.getMessages(true).trim());
    ProxyLanguage.setDelegate(new ProxyLanguage());
    tester.finish();
}
Also used : Source(org.graalvm.polyglot.Source) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 54 with ProxyLanguage

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

the class NotReadableValuesTest method testNotReadableVariables.

// @formatter:off   The default formatting makes unnecessarily big indents and illogical line breaks
@Test
public void testNotReadableVariables() throws Exception {
    InspectorTester tester = InspectorTester.start(true);
    tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
    tester.sendMessage("{\"id\":2,\"method\":\"Debugger.enable\"}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":1}\n" + "{\"result\":{},\"id\":2}\n"));
    tester.sendMessage("{\"id\":3,\"method\":\"Runtime.runIfWaitingForDebugger\"}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":3}\n" + "{\"method\":\"Runtime.executionContextCreated\",\"params\":{\"context\":{\"origin\":\"\",\"name\":\"test\",\"id\":1}}}\n"));
    ProxyLanguage.setDelegate(new NotReadableValuesLanguage());
    Source source = Source.newBuilder(ProxyLanguage.ID, "1", "ReadWithSideEffects.test").build();
    String sourceURI = InspectorTester.getStringURI(source.getURI());
    tester.eval(source);
    assertNotNull(tester.receiveMessages("{\"method\":\"Debugger.scriptParsed\"", "}\n"));
    assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[]," + "\"callFrames\":[{\"callFrameId\":\"0\",\"functionName\":\"TestRootNode\"," + "\"scopeChain\":[{\"name\":\"TestRootNode\",\"type\":\"local\",\"object\":{\"description\":\"TestRootNode\",\"type\":\"object\",\"objectId\":\"1\"}}," + "{\"name\":\"top\",\"type\":\"global\",\"object\":{\"description\":\"top\",\"type\":\"object\",\"objectId\":\"2\"}}]," + "\"this\":null," + "\"functionLocation\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"location\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"url\":\"" + sourceURI + "\"" + "}]}}\n"));
    // Ask for global variables
    tester.sendMessage("{\"id\":10,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"2\"}}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true,\"name\":\"object\"," + "\"value\":{\"description\":\"Object VariablesObject\",\"className\":\"Object\",\"type\":\"object\",\"objectId\":\"3\"},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"array\"," + "\"value\":{\"subtype\":\"array\",\"description\":\"Object ArrayValue\",\"className\":\"Object\",\"type\":\"object\",\"objectId\":\"4\"},\"configurable\":true,\"writable\":false}]," + "\"internalProperties\":[]},\"id\":10}\n"));
    // Ask for variable properties
    tester.sendMessage("{\"id\":20,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"3\"}}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true,\"name\":\"object\"," + "\"value\":{\"description\":\"Object VariablesObject\",\"className\":\"Object\",\"type\":\"object\",\"objectId\":\"5\"},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"array\"," + "\"value\":{\"subtype\":\"array\",\"description\":\"Object ArrayValue\",\"className\":\"Object\",\"type\":\"object\",\"objectId\":\"6\"},\"configurable\":true,\"writable\":false}]," + "\"internalProperties\":[]},\"id\":20}\n"));
    // Ask for array elements
    tester.sendMessage("{\"id\":30,\"method\":\"Runtime.getProperties\",\"params\":{\"objectId\":\"4\"}}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{\"result\":[{\"isOwn\":true,\"enumerable\":true,\"name\":\"0\",\"value\":{\"description\":\"6\",\"type\":\"number\",\"value\":6},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"1\",\"value\":{\"description\":\"5\",\"type\":\"number\",\"value\":5},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"4\",\"value\":{\"description\":\"2\",\"type\":\"number\",\"value\":2},\"configurable\":true,\"writable\":false}," + "{\"isOwn\":true,\"enumerable\":true,\"name\":\"5\",\"value\":{\"description\":\"1\",\"type\":\"number\",\"value\":1},\"configurable\":true,\"writable\":false}]," + "\"internalProperties\":[]},\"id\":30}\n"));
    tester.sendMessage("{\"id\":100,\"method\":\"Debugger.resume\"}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":100}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
    // Reset the delegate so that we can GC the tested Engine
    ProxyLanguage.setDelegate(new ProxyLanguage());
    tester.finish();
}
Also used : Source(org.graalvm.polyglot.Source) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 55 with ProxyLanguage

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

the class RelativeSourceInspectDebugTest method testBreakpoints.

@Test
public void testBreakpoints() throws Exception {
    Path testSourcePath = Files.createTempDirectory("testPath").toRealPath();
    String relativePath = "relative/test1.file";
    String sourceContent = "relative source1\nVarA";
    URI sourcePathURI = testSourcePath.toUri();
    Files.createDirectory(testSourcePath.resolve("relative"));
    Path filePath = testSourcePath.resolve(relativePath);
    Files.write(filePath, sourceContent.getBytes());
    String fileURI = filePath.toUri().toString();
    TestDebugNoContentLanguage language = new TestDebugNoContentLanguage(relativePath, true, true);
    ProxyLanguage.setDelegate(language);
    Source source = Source.create(ProxyLanguage.ID, "relative source1\nVarA");
    InspectorTester tester = InspectorTester.start(false, false, false, Collections.singletonList(sourcePathURI));
    tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}");
    assertEquals("{\"result\":{},\"id\":1}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":2,\"method\":\"Debugger.enable\"}");
    assertEquals("{\"result\":{},\"id\":2}", tester.getMessages(true).trim());
    tester.sendMessage("{\"id\":3,\"method\":\"Runtime.runIfWaitingForDebugger\"}");
    // @formatter:off   The default formatting makes unnecessarily big indents and illogical line breaks
    // CheckStyle: stop line length check
    assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":3}\n" + "{\"method\":\"Runtime.executionContextCreated\",\"params\":{\"context\":{\"origin\":\"\",\"name\":\"test\",\"id\":1}}}\n"));
    tester.sendMessage("{\"id\":4,\"method\":\"Debugger.setBreakpointByUrl\",\"params\":{\"lineNumber\":0,\"url\":\"" + fileURI + "\",\"columnNumber\":0,\"condition\":\"\"}}");
    assertEquals("{\"result\":{\"breakpointId\":\"1\",\"locations\":[]},\"id\":4}", tester.getMessages(true).trim());
    tester.eval(source);
    assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":1,\"scriptId\":\"0\",\"endColumn\":4,\"startColumn\":0,\"startLine\":0,\"length\":" + sourceContent.length() + ",\"executionContextId\":1,\"url\":\"" + fileURI + "\",\"hash\":\"fdfc3c86f176a91df464039fffffffffffffffff\"}}\n"));
    // Suspend at the beginning of the script:
    assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[\"1\"]," + "\"callFrames\":[{\"callFrameId\":\"0\",\"functionName\":\"relative\"," + "\"scopeChain\":[{\"name\":\"relative\",\"type\":\"local\",\"object\":{\"description\":\"relative\",\"type\":\"object\",\"objectId\":\"1\"}}]," + "\"this\":null," + "\"functionLocation\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"location\":{\"scriptId\":\"0\",\"columnNumber\":0,\"lineNumber\":0}," + "\"url\":\"" + fileURI + "\"}]}}\n"));
    tester.sendMessage("{\"id\":5,\"method\":\"Debugger.resume\"}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":5}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
    // @formatter:on
    // CheckStyle: resume line length check
    language = null;
    // Reset the delegate so that we can GC the tested Engine
    ProxyLanguage.setDelegate(new ProxyLanguage());
    tester.finish();
}
Also used : Path(java.nio.file.Path) TestDebugNoContentLanguage(com.oracle.truffle.api.debug.test.TestDebugNoContentLanguage) URI(java.net.URI) Source(org.graalvm.polyglot.Source) 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