comparison truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/LineToProbesMapTest.java @ 22219:1c0f490984d5

Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Wed, 16 Sep 2015 15:36:22 -0700
parents dc83cc1f94f2 3aad794eec0e
children 964e789e17f7
comparison
equal deleted inserted replaced
22160:0599e2df6a9f 22219:1c0f490984d5
22 * or visit www.oracle.com if you need additional information or have any 22 * or visit www.oracle.com if you need additional information or have any
23 * questions. 23 * questions.
24 */ 24 */
25 package com.oracle.truffle.tools.test; 25 package com.oracle.truffle.tools.test;
26 26
27 import static com.oracle.truffle.tools.test.TestNodes.createExpr13TestRootNode;
28 import static com.oracle.truffle.tools.test.TestNodes.expr13Line1;
29 import static com.oracle.truffle.tools.test.TestNodes.expr13Line2;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNull;
32
33 import org.junit.Test;
34
35 import com.oracle.truffle.api.instrument.Instrumenter;
27 import com.oracle.truffle.api.instrument.Probe; 36 import com.oracle.truffle.api.instrument.Probe;
28 import com.oracle.truffle.api.nodes.Node; 37 import com.oracle.truffle.api.nodes.Node;
29 import com.oracle.truffle.api.nodes.RootNode; 38 import com.oracle.truffle.api.nodes.RootNode;
30 import com.oracle.truffle.api.source.LineLocation; 39 import com.oracle.truffle.api.source.LineLocation;
31 import com.oracle.truffle.tools.LineToProbesMap; 40 import com.oracle.truffle.tools.LineToProbesMap;
32 import static com.oracle.truffle.tools.test.TestNodes.createExpr13TestRootNode;
33 import static com.oracle.truffle.tools.test.TestNodes.expr13Line1;
34 import static com.oracle.truffle.tools.test.TestNodes.expr13Line2;
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertNull;
37 import org.junit.Test;
38 41
39 public class LineToProbesMapTest { 42 public class LineToProbesMapTest {
40 43
41 @Test 44 @Test
42 public void testToolCreatedTooLate() { 45 public void testToolCreatedTooLate() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
43 final RootNode expr13rootNode = createExpr13TestRootNode(); 46 final Instrumenter instrumenter = TestNodes.createInstrumenter();
47 final RootNode expr13rootNode = createExpr13TestRootNode(instrumenter);
44 final Node addNode = expr13rootNode.getChildren().iterator().next(); 48 final Node addNode = expr13rootNode.getChildren().iterator().next();
45 final Probe probe = addNode.probe(); 49 final Probe probe = instrumenter.probe(addNode);
46 final LineLocation lineLocation = probe.getProbedSourceSection().getLineLocation(); 50 final LineLocation lineLocation = probe.getProbedSourceSection().getLineLocation();
47 assertEquals(lineLocation, expr13Line2); 51 assertEquals(lineLocation, expr13Line2);
48 52
49 final LineToProbesMap tool = new LineToProbesMap(); 53 final LineToProbesMap tool = new LineToProbesMap();
50 tool.install(); 54 tool.install(instrumenter);
51 55
52 assertNull(tool.findFirstProbe(expr13Line1)); 56 assertNull(tool.findFirstProbe(expr13Line1));
53 assertNull(tool.findFirstProbe(expr13Line2)); 57 assertNull(tool.findFirstProbe(expr13Line2));
54 tool.dispose(); 58 tool.dispose();
55 } 59 }
56 60
57 @Test 61 @Test
58 public void testToolInstalledTooLate() { 62 public void testToolInstalledTooLate() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
63 final Instrumenter instrumenter = TestNodes.createInstrumenter();
59 final LineToProbesMap tool = new LineToProbesMap(); 64 final LineToProbesMap tool = new LineToProbesMap();
60 65
61 final RootNode expr13rootNode = createExpr13TestRootNode(); 66 final RootNode expr13rootNode = createExpr13TestRootNode(instrumenter);
62 final Node addNode = expr13rootNode.getChildren().iterator().next(); 67 final Node addNode = expr13rootNode.getChildren().iterator().next();
63 final Probe probe = addNode.probe(); 68 final Probe probe = instrumenter.probe(addNode);
64 final LineLocation lineLocation = probe.getProbedSourceSection().getLineLocation(); 69 final LineLocation lineLocation = probe.getProbedSourceSection().getLineLocation();
65 assertEquals(lineLocation, expr13Line2); 70 assertEquals(lineLocation, expr13Line2);
66 71
67 tool.install(); 72 tool.install(instrumenter);
68 73
69 assertNull(tool.findFirstProbe(expr13Line1)); 74 assertNull(tool.findFirstProbe(expr13Line1));
70 assertNull(tool.findFirstProbe(expr13Line2)); 75 assertNull(tool.findFirstProbe(expr13Line2));
71 tool.dispose(); 76 tool.dispose();
72 } 77 }
73 78
74 @Test 79 @Test
75 public void testMapping() { 80 public void testMapping() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
81 final Instrumenter instrumenter = TestNodes.createInstrumenter();
76 final LineToProbesMap tool = new LineToProbesMap(); 82 final LineToProbesMap tool = new LineToProbesMap();
77 tool.install(); 83 tool.install(instrumenter);
78 84
79 final RootNode expr13rootNode = createExpr13TestRootNode(); 85 final RootNode expr13rootNode = createExpr13TestRootNode(instrumenter);
80 final Node addNode = expr13rootNode.getChildren().iterator().next(); 86 final Node addNode = expr13rootNode.getChildren().iterator().next();
81 final Probe probe = addNode.probe(); 87 final Probe probe = instrumenter.probe(addNode);
82 final LineLocation lineLocation = probe.getProbedSourceSection().getLineLocation(); 88 final LineLocation lineLocation = probe.getProbedSourceSection().getLineLocation();
83 assertEquals(lineLocation, expr13Line2); 89 assertEquals(lineLocation, expr13Line2);
84 90
85 assertNull(tool.findFirstProbe(expr13Line1)); 91 assertNull(tool.findFirstProbe(expr13Line1));
86 assertEquals(tool.findFirstProbe(expr13Line2), probe); 92 assertEquals(tool.findFirstProbe(expr13Line2), probe);