use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class InstrumentationTest method testQueryTags1.
/*
* Test behavior of queryTags when used with instruments
*/
@Test
public void testQueryTags1() throws IOException {
Instrument instrument = engine.getInstruments().get("testIsNodeTaggedWith1");
Instrumenter instrumenter = instrument.lookup(Instrumenter.class);
TestIsNodeTaggedWith1.expressionNode = null;
TestIsNodeTaggedWith1.statementNode = null;
Assert.assertTrue(instrumenter.queryTags(new Node() {
}).isEmpty());
run("STATEMENT(EXPRESSION)");
assertTags(instrumenter.queryTags(TestIsNodeTaggedWith1.expressionNode), InstrumentationTestLanguage.EXPRESSION);
assertTags(instrumenter.queryTags(TestIsNodeTaggedWith1.statementNode), InstrumentationTestLanguage.STATEMENT);
try {
instrumenter.queryTags(null);
Assert.fail();
} catch (NullPointerException e) {
}
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class SourceSectionFilterTest method testLineNotIn.
@Test
public void testLineNotIn() {
Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
Node root = createNode(sampleSource.createSection(0, 23));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(6, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(2, 1), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(6, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH - 1, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH - 2, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH + 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH - 2, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH - 2, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createUnavailableSection())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(LINE_LENGTH, LINE_LENGTH), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1), IndexRange.between(2, 3), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(LINE_LENGTH, LINE_LENGTH), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(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());
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class SourceSectionFilterTest method testComplexFilter.
@Test
public void testComplexFilter() {
Source sampleSource1 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType("mime2").build();
Node root = createNode(sampleSource1.createSection(0, 23));
SourceSectionFilter filter = //
SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION, InstrumentationTestLanguage.DEFINE).tagIsNot(InstrumentationTestLanguage.DEFINE, //
InstrumentationTestLanguage.ROOT).indexIn(0, //
3).sourceIs(sampleSource1).sourceSectionEquals(//
sampleSource1.createSection(0, 5)).lineIn(1, 1).lineIs(1).mimeTypeIs("mime1", "mime2").build();
Assert.assertFalse(isInstrumented(filter, root, source()));
Assert.assertTrue(isInstrumentedRoot(filter, null));
Assert.assertFalse(isInstrumentedNode(filter, source()));
Assert.assertFalse(isInstrumented(filter, root, createNode(sampleSource1.createUnavailableSection())));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createUnavailableSection())));
Assert.assertFalse(isInstrumentedNode(filter, createNode(sampleSource1.createUnavailableSection())));
Assert.assertTrue(isInstrumented(filter, root, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.EXPRESSION))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(0, 5))));
Assert.assertTrue(isInstrumentedNode(filter, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.EXPRESSION))));
Assert.assertFalse(isInstrumented(filter, root, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.STATEMENT))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(0, 5))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(10, 5))));
Assert.assertFalse(isInstrumentedNode(filter, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.STATEMENT))));
Assert.assertNotNull(filter.toString());
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class SourceSectionFilterTest method testIndexNotIn.
@Test
public void testIndexNotIn() {
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().indexNotIn(IndexRange.byLength(0, 0)).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(0, 1)).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(0, 4), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(4, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(4, 6), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(10, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(9, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(9, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createUnavailableSection())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.between(0, 5)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.between(0, 5), IndexRange.between(5, 6)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.between(0, 5), IndexRange.between(11, 12)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertNotNull(SourceSectionFilter.newBuilder().indexIn(5, 5).build().toString());
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class SourceSectionFilterTest method testColumnStartIn.
@Test
public void testColumnStartIn() {
Source sampleSource = Source.newBuilder("123456789\n123456789").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
Node root = createNode(sampleSource.createSection(0, 19));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(1, 1))));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(0, 2))));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, 2))));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(0, 2))));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(1, 2))));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().columnStartsIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(2, 1))));
}
Aggregations