comparison truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/NodeExecCounterTest.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.createExpr13TestCallTarget;
28 import static com.oracle.truffle.tools.test.TestNodes.createExpr13TestRootNode;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.fail;
32
33 import org.junit.Test;
34
27 import com.oracle.truffle.api.CallTarget; 35 import com.oracle.truffle.api.CallTarget;
36 import com.oracle.truffle.api.instrument.Instrumenter;
28 import com.oracle.truffle.api.instrument.Probe; 37 import com.oracle.truffle.api.instrument.Probe;
29 import com.oracle.truffle.api.instrument.StandardSyntaxTag; 38 import com.oracle.truffle.api.instrument.StandardSyntaxTag;
30 import com.oracle.truffle.api.nodes.Node; 39 import com.oracle.truffle.api.nodes.Node;
31 import com.oracle.truffle.api.nodes.RootNode; 40 import com.oracle.truffle.api.nodes.RootNode;
32 import com.oracle.truffle.tools.NodeExecCounter; 41 import com.oracle.truffle.tools.NodeExecCounter;
33 import com.oracle.truffle.tools.NodeExecCounter.NodeExecutionCount; 42 import com.oracle.truffle.tools.NodeExecCounter.NodeExecutionCount;
34 import com.oracle.truffle.tools.test.TestNodes.TestAddNode; 43 import com.oracle.truffle.tools.test.TestNodes.TestAddNode;
35 import com.oracle.truffle.tools.test.TestNodes.TestValueNode; 44 import com.oracle.truffle.tools.test.TestNodes.TestValueNode;
36 import static com.oracle.truffle.tools.test.TestNodes.createExpr13TestCallTarget;
37 import static com.oracle.truffle.tools.test.TestNodes.createExpr13TestRootNode;
38 import static org.junit.Assert.assertEquals;
39 import static org.junit.Assert.assertNotNull;
40 import static org.junit.Assert.fail;
41 import org.junit.Test;
42 45
43 public class NodeExecCounterTest { 46 public class NodeExecCounterTest {
44 47
45 @Test 48 @Test
46 public void testNoExecution() { 49 public void testNoExecution() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
50 final Instrumenter instrumenter = TestNodes.createInstrumenter();
47 final NodeExecCounter tool = new NodeExecCounter(); 51 final NodeExecCounter tool = new NodeExecCounter();
48 assertEquals(tool.getCounts().length, 0); 52 assertEquals(tool.getCounts().length, 0);
49 tool.install(); 53 tool.install(instrumenter);
50 assertEquals(tool.getCounts().length, 0); 54 assertEquals(tool.getCounts().length, 0);
51 tool.setEnabled(false); 55 tool.setEnabled(false);
52 assertEquals(tool.getCounts().length, 0); 56 assertEquals(tool.getCounts().length, 0);
53 tool.setEnabled(true); 57 tool.setEnabled(true);
54 assertEquals(tool.getCounts().length, 0); 58 assertEquals(tool.getCounts().length, 0);
57 tool.dispose(); 61 tool.dispose();
58 assertEquals(tool.getCounts().length, 0); 62 assertEquals(tool.getCounts().length, 0);
59 } 63 }
60 64
61 @Test 65 @Test
62 public void testToolCreatedTooLate() { 66 public void testToolCreatedTooLate() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
63 final CallTarget expr13callTarget = createExpr13TestCallTarget(); 67 final Instrumenter instrumenter = TestNodes.createInstrumenter();
68 final CallTarget expr13callTarget = createExpr13TestCallTarget(instrumenter);
64 final NodeExecCounter tool = new NodeExecCounter(); 69 final NodeExecCounter tool = new NodeExecCounter();
65 tool.install(); 70 tool.install(instrumenter);
66 assertEquals(13, expr13callTarget.call()); 71 assertEquals(13, expr13callTarget.call());
67 assertEquals(tool.getCounts().length, 0); 72 assertEquals(tool.getCounts().length, 0);
68 tool.dispose(); 73 tool.dispose();
69 } 74 }
70 75
71 @Test 76 @Test
72 public void testToolInstalledcTooLate() { 77 public void testToolInstalledcTooLate() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
78 final Instrumenter instrumenter = TestNodes.createInstrumenter();
73 final NodeExecCounter tool = new NodeExecCounter(); 79 final NodeExecCounter tool = new NodeExecCounter();
74 final CallTarget expr13callTarget = createExpr13TestCallTarget(); 80 final CallTarget expr13callTarget = createExpr13TestCallTarget(instrumenter);
75 tool.install(); 81 tool.install(instrumenter);
76 assertEquals(13, expr13callTarget.call()); 82 assertEquals(13, expr13callTarget.call());
77 assertEquals(tool.getCounts().length, 0); 83 assertEquals(tool.getCounts().length, 0);
78 tool.dispose(); 84 tool.dispose();
79 } 85 }
80 86
81 @Test 87 @Test
82 public void testCountingAll() { 88 public void testCountingAll() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
89 final Instrumenter instrumenter = TestNodes.createInstrumenter();
83 final NodeExecCounter tool = new NodeExecCounter(); 90 final NodeExecCounter tool = new NodeExecCounter();
84 tool.install(); 91 tool.install(instrumenter);
85 final CallTarget expr13callTarget = createExpr13TestCallTarget(); 92 final CallTarget expr13callTarget = createExpr13TestCallTarget(instrumenter);
86 93
87 // execute once 94 // execute once
88 assertEquals(13, expr13callTarget.call()); 95 assertEquals(13, expr13callTarget.call());
89 final NodeExecutionCount[] count1 = tool.getCounts(); 96 final NodeExecutionCount[] count1 = tool.getCounts();
90 assertNotNull(count1); 97 assertNotNull(count1);
122 129
123 tool.dispose(); 130 tool.dispose();
124 } 131 }
125 132
126 @Test 133 @Test
127 public void testCountingTagged() { 134 public void testCountingTagged() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
135 final Instrumenter instrumenter = TestNodes.createInstrumenter();
128 final NodeExecCounter tool = new NodeExecCounter(StandardSyntaxTag.STATEMENT); 136 final NodeExecCounter tool = new NodeExecCounter(StandardSyntaxTag.STATEMENT);
129 tool.install(); 137 tool.install(instrumenter);
130 final RootNode expr13rootNode = createExpr13TestRootNode(); 138 final RootNode expr13rootNode = createExpr13TestRootNode(instrumenter);
131 139
132 // Not probed yet. 140 // Not probed yet.
133 assertEquals(13, expr13rootNode.execute(null)); 141 assertEquals(13, expr13rootNode.execute(null));
134 assertEquals(tool.getCounts().length, 0); 142 assertEquals(tool.getCounts().length, 0);
135 143
136 final Node addNode = expr13rootNode.getChildren().iterator().next(); 144 final Node addNode = expr13rootNode.getChildren().iterator().next();
137 final Probe probe = addNode.probe(); 145 final Probe probe = instrumenter.probe(addNode);
138 146
139 // Probed but not tagged yet. 147 // Probed but not tagged yet.
140 assertEquals(13, expr13rootNode.execute(null)); 148 assertEquals(13, expr13rootNode.execute(null));
141 assertEquals(tool.getCounts().length, 0); 149 assertEquals(tool.getCounts().length, 0);
142 150