Search in sources :

Example 1 with TestDebugNoContentLanguage

use of com.oracle.truffle.api.debug.test.TestDebugNoContentLanguage in project graal by oracle.

the class RelativeSourceInspectDebugTest method testNonExistingSourcePath.

@Test
public void testNonExistingSourcePath() throws Exception {
    TestDebugNoContentLanguage language = new TestDebugNoContentLanguage("relative/path", true, true);
    ProxyLanguage.setDelegate(language);
    Source source = Source.create(ProxyLanguage.ID, "relative source1\nVarA");
    InspectorTester tester = InspectorTester.start(true, false, false);
    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\"}");
    String resolvedPath = new File("relative/path").toPath().toAbsolutePath().toUri().toString();
    // @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.eval(source);
    assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":3,\"scriptId\":\"0\",\"endColumn\":0,\"startColumn\":0,\"startLine\":0,\"length\":168,\"executionContextId\":1,\"url\":\"" + resolvedPath + "\",\"hash\":\"ea519706da04092af2f9afd9f84696c2fe44bc91\"}}\n"));
    // Suspend at the beginning of the script:
    assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[]," + "\"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\":\"" + resolvedPath + "\"}]}}\n"));
    tester.sendMessage("{\"id\":1,\"method\":\"Debugger.resume\"}");
    assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":1}\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 : TestDebugNoContentLanguage(com.oracle.truffle.api.debug.test.TestDebugNoContentLanguage) File(java.io.File) Source(org.graalvm.polyglot.Source) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) Test(org.junit.Test)

Example 2 with TestDebugNoContentLanguage

use of com.oracle.truffle.api.debug.test.TestDebugNoContentLanguage 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)

Example 3 with TestDebugNoContentLanguage

use of com.oracle.truffle.api.debug.test.TestDebugNoContentLanguage in project graal by oracle.

the class RelativeSourceInspectDebugTest method testSourcePath.

@Test
public void testSourcePath() throws Exception {
    // Using 3 source path elements and 3 sources to verify that
    // the correct final source path is built.
    final int numSources = 3;
    URI[] sourcePathURI = new URI[numSources];
    String[] sourceContent = new String[numSources];
    String[] relativePath = new String[numSources];
    URI[] resolvedURI = new URI[numSources];
    String[] hashes = new String[] { "fdfc3c86f176a91df464039fffffffffffffffff", "fdfc3c86f176a91df1786babffffffffffffffff", "fdfc3c86f176a91dee8cd3b7ffffffffffffffff" };
    // Create a file source-path
    sourceContent[0] = "relative source1\nVarA";
    relativePath[0] = "relative/test1.file";
    Path testSourcePath1 = Files.createTempDirectory("testPath").toRealPath();
    sourcePathURI[0] = testSourcePath1.toUri();
    Files.createDirectory(testSourcePath1.resolve("relative"));
    Path filePath1 = testSourcePath1.resolve(relativePath[0]);
    Files.write(filePath1, sourceContent[0].getBytes());
    resolvedURI[0] = filePath1.toUri();
    // Create a zip source-path with root matching the zip root
    sourceContent[1] = "relative source2\nVarB";
    relativePath[1] = "relative/test2.file";
    File zip2 = File.createTempFile("TestZip", ".zip");
    zip2.deleteOnExit();
    try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zip2))) {
        ZipEntry e = new ZipEntry(relativePath[1]);
        out.putNextEntry(e);
        byte[] data = sourceContent[1].getBytes();
        out.write(data, 0, data.length);
        out.closeEntry();
    }
    try (FileSystem fs = FileSystems.newFileSystem(zip2.toPath(), (ClassLoader) null)) {
        Path spInZip = fs.getPath("/");
        sourcePathURI[1] = spInZip.toUri();
        resolvedURI[1] = fs.getPath(relativePath[1]).toUri();
    }
    // Create a zip source-path with root under the zip root
    sourceContent[2] = "relative source3\nVarC";
    relativePath[2] = "relative/test3.file";
    String folderInZip3 = "src/main";
    File zip3 = File.createTempFile("TestZip", ".zip");
    zip3.deleteOnExit();
    try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zip3))) {
        ZipEntry e = new ZipEntry(folderInZip3 + "/" + relativePath[2]);
        out.putNextEntry(e);
        byte[] data = sourceContent[2].getBytes();
        out.write(data, 0, data.length);
        out.closeEntry();
    }
    try (FileSystem fs = FileSystems.newFileSystem(zip3.toPath(), (ClassLoader) null)) {
        Path spInZip = fs.getPath(folderInZip3);
        sourcePathURI[2] = spInZip.toUri();
        resolvedURI[2] = fs.getPath(folderInZip3, relativePath[2]).toUri();
    }
    InspectorTester tester = InspectorTester.start(true, false, false, Arrays.asList(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"));
    long cid = tester.getContextId();
    int cmdId = 1;
    int objId = 1;
    for (int i = 0; i < numSources; i++) {
        TestDebugNoContentLanguage language = new TestDebugNoContentLanguage(relativePath[i], true, true);
        ProxyLanguage.setDelegate(language);
        Source source = Source.create(ProxyLanguage.ID, sourceContent[i]);
        String funcName = source.getCharacters(1).toString();
        funcName = funcName.substring(0, funcName.indexOf(' '));
        tester.eval(source);
        // Suspend at the beginning of the script:
        assertTrue(tester.compareReceivedMessages("{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":1,\"scriptId\":\"" + i + "\",\"endColumn\":4,\"startColumn\":0,\"startLine\":0,\"length\":21,\"executionContextId\":" + cid + ",\"url\":\"" + resolvedURI[i] + "\",\"hash\":\"" + hashes[i] + "\"}}\n" + "{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[]," + "\"callFrames\":[{\"callFrameId\":\"0\",\"functionName\":\"" + funcName + "\"," + "\"scopeChain\":[{\"name\":\"" + funcName + "\",\"type\":\"local\",\"object\":{\"description\":\"" + funcName + "\",\"type\":\"object\",\"objectId\":\"" + objId + "\"}}]," + "\"this\":null," + "\"functionLocation\":{\"scriptId\":\"" + i + "\",\"columnNumber\":0,\"lineNumber\":0}," + "\"location\":{\"scriptId\":\"" + i + "\",\"columnNumber\":0,\"lineNumber\":0}," + "\"url\":\"" + resolvedURI[i] + "\"}]}}\n"));
        objId++;
        tester.sendMessage("{\"id\":" + cmdId + ",\"method\":\"Debugger.getScriptSource\",\"params\":{\"scriptId\":\"" + i + "\"}}");
        assertTrue(tester.compareReceivedMessages("{\"result\":{\"scriptSource\":\"" + sourceContent[i].replace("\n", "\\n") + "\"},\"id\":" + cmdId + "}\n"));
        cmdId++;
        tester.sendMessage("{\"id\":" + cmdId + ",\"method\":\"Debugger.resume\"}");
        assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":" + cmdId + "}\n" + "{\"method\":\"Debugger.resumed\"}\n"));
        cmdId++;
        tester.sendMessage("{\"id\":" + cmdId + ",\"method\":\"Debugger.pause\"}");
        assertTrue(tester.compareReceivedMessages("{\"result\":{},\"id\":" + cmdId + "}\n"));
        cmdId++;
    }
    // @formatter:on
    // CheckStyle: resume line length check
    // 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) ZipEntry(java.util.zip.ZipEntry) URI(java.net.URI) Source(org.graalvm.polyglot.Source) ProxyLanguage(com.oracle.truffle.api.test.polyglot.ProxyLanguage) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) FileSystem(java.nio.file.FileSystem) File(java.io.File) Test(org.junit.Test)

Aggregations

TestDebugNoContentLanguage (com.oracle.truffle.api.debug.test.TestDebugNoContentLanguage)3 ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)3 Source (org.graalvm.polyglot.Source)3 Test (org.junit.Test)3 File (java.io.File)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 FileOutputStream (java.io.FileOutputStream)1 FileSystem (java.nio.file.FileSystem)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1