Search in sources :

Example 31 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class Context method createContext.

@Override
protected Context createContext(TruffleLanguage.Env env) {
    Source initSource = null;
    Boolean runInitAfterExec = null;
    if (envConfig != null) {
        Object envReturner = envConfig.get(ReturnLanguageEnv.KEY);
        if (envReturner != null) {
            ((ReturnLanguageEnv) envReturner).env = env;
        }
        org.graalvm.polyglot.Source initPolyglotSource = (org.graalvm.polyglot.Source) envConfig.get("initSource");
        if (initPolyglotSource != null) {
            initSource = AbstractInstrumentationTest.sourceToImpl(initPolyglotSource);
        }
        runInitAfterExec = (Boolean) envConfig.get("runInitAfterExec");
    }
    return new Context(env, initSource, runInitAfterExec);
}
Also used : TruffleContext(com.oracle.truffle.api.TruffleContext) FunctionsObject(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.FunctionsObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Source(com.oracle.truffle.api.source.Source)

Example 32 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceSectionFilterTest method testSourceIn.

@Test
public void testSourceIn() {
    Source sampleSource1 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Source sampleSource2 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Source sampleSource3 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root1 = createNode(sampleSource1.createSection(0, 23));
    Node root2 = createNode(sampleSource2.createSection(0, 23));
    Node root3 = createNode(sampleSource3.createSection(0, 23));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1).build(), root1, createNode(sampleSource1.createSection(0, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1).build(), null, createNode(sampleSource2.createUnavailableSection())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1).build(), root2, createNode(sampleSource2.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1, sampleSource2).build(), root2, createNode(sampleSource2.createSection(0, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1, sampleSource2).build(), root1, createNode(sampleSource1.createSection(0, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().sourceIs(sampleSource1, sampleSource2).build(), root3, createNode(sampleSource3.createSection(0, 5), tags())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().sourceIs(sampleSource1, sampleSource2).build().toString());
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 33 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceSectionFilterTest method testLineStartIn.

@Test
public void testLineStartIn() {
    Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 23));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(6, 15))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(0, 15))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 15))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(0, 15))));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(6, 15))));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(12, 6))));
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 34 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceSectionFilterTest method testEmpty.

@Test
public void testEmpty() {
    Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 23));
    Node unavailable = createNode(sampleSource.createUnavailableSection());
    SourceSectionFilter filter = SourceSectionFilter.ANY;
    Node sampleSection = createNode(sampleSource.createSection(2));
    Assert.assertTrue(isInstrumentedNode(filter, source()));
    Assert.assertTrue(isInstrumentedNode(filter, unavailable));
    Assert.assertTrue(isInstrumentedNode(filter, sampleSection));
    Assert.assertTrue(isInstrumentedRoot(filter, null));
    Assert.assertTrue(isInstrumentedRoot(filter, unavailable));
    Assert.assertTrue(isInstrumentedRoot(filter, sampleSection));
    Assert.assertTrue(isInstrumented(filter, root, source()));
    Assert.assertTrue(isInstrumented(filter, root, unavailable));
    Assert.assertTrue(isInstrumented(filter, root, sampleSection));
    Class<?> prevTag = null;
    for (Class<?> tag : InstrumentationTestLanguage.TAGS) {
        Assert.assertTrue(isInstrumented(filter, root, source(tag)));
        Assert.assertTrue(isInstrumented(filter, root, unavailable));
        Assert.assertTrue(isInstrumented(filter, root, createNode(sampleSource.createSection(0, 4), tag)));
        if (prevTag != null) {
            Assert.assertTrue(isInstrumented(filter, root, source(tag)));
            Assert.assertTrue(isInstrumented(filter, root, unavailable));
            Assert.assertTrue(isInstrumented(filter, root, createNode(sampleSource.createSection(0, 4), tag, prevTag)));
        }
        prevTag = tag;
    }
    Assert.assertNotNull(filter.toString());
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 35 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceSectionFilterTest method testLineIn.

@Test
public void testLineIn() {
    Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    Node root = createNode(sampleSource.createSection(0, 23));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 1).build(), root, createNode(sampleSource.createSection(6, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(1, 2).build(), root, createNode(sampleSource.createSection(2, 1), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineIn(1, 1).build(), root, createNode(sampleSource.createSection(6, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 2).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 2).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH - 1, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 2).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH - 2, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 2).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 2).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH + 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 2).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH - 2, 5), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 2).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH, 1), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(2, 2).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH - 2, 5), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineIn(1, 1).build(), root, createNode(sampleSource.createUnavailableSection())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIs(1).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(LINE_LENGTH, LINE_LENGTH), tags())));
    Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineIn(IndexRange.byLength(1, 1), IndexRange.between(2, 3), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(LINE_LENGTH, LINE_LENGTH), tags())));
    Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineIn(IndexRange.byLength(1, 1), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(LINE_LENGTH, LINE_LENGTH), tags())));
    Assert.assertNotNull(SourceSectionFilter.newBuilder().lineIn(2, 2).build().toString());
}
Also used : Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Aggregations

Source (com.oracle.truffle.api.source.Source)113 Test (org.junit.Test)65 RootNode (com.oracle.truffle.api.nodes.RootNode)23 File (java.io.File)20 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)16 Node (com.oracle.truffle.api.nodes.Node)16 SourceSection (com.oracle.truffle.api.source.SourceSection)16 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)15 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)11 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CallTarget (com.oracle.truffle.api.CallTarget)5 FileWriter (java.io.FileWriter)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3