Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/WrapperTest.java @ 16702:2a5ec181dad4
SL: Added instrumentation testing
author | David Piorkowski <david.piorkowski@oracle.com> |
---|---|
date | Tue, 05 Aug 2014 16:34:08 -0700 |
parents | |
children |
rev | line source |
---|---|
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
1 /* |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
4 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
8 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
14 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
18 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
21 * questions. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
22 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.test.instrument; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
24 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
25 import java.util.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
26 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
27 import org.junit.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
28 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.frame.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.instrument.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.nodes.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.source.*; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
34 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
35 /** |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
36 * This test does the following: |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
37 * <ol> |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
38 * <li>Creates a simple add AST</li> |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
39 * <li>Verifies its structure</li> |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
40 * <li>Instruments the add node</li> |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
41 * <li>Attaches a simple probe to the instrumented node</li> |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
42 * <li>Verifies the structure of the instrumented AST</li> |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
43 * <li>Verifies the execution of the instrumented AST</li> |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
44 * </ol> |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
45 * To do these tests, several required classes have been implemented in their most basic form, only |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
46 * implementing the methods necessary for the tests to pass, with stubs elsewhere. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
47 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
48 public class WrapperTest { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
49 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
50 @Test |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
51 public void test() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
52 // Build a tree |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
53 TruffleRuntime runtime = Truffle.getRuntime(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
54 TestChildNode leftChild = new TestChildNode(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
55 TestChildNode rightChild = new TestChildNode(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
56 TestSourceSection sourceSection = new TestSourceSection(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
57 TestAddNode addNode = new TestAddNode(leftChild, rightChild, sourceSection); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
58 TestRootNode rootNode = new TestRootNode(addNode); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
59 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
60 // Have to create a call target before checking parent/child relationships |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
61 CallTarget target = runtime.createCallTarget(rootNode); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
62 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
63 // Check tree structure |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
64 Assert.assertEquals(addNode, leftChild.getParent()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
65 Assert.assertEquals(addNode, rightChild.getParent()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
66 Iterator<Node> iterator = addNode.getChildren().iterator(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
67 Assert.assertEquals(leftChild, iterator.next()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
68 Assert.assertEquals(rightChild, iterator.next()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
69 Assert.assertFalse(iterator.hasNext()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
70 Assert.assertEquals(rootNode, addNode.getParent()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
71 iterator = rootNode.getChildren().iterator(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
72 Assert.assertEquals(addNode, iterator.next()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
73 Assert.assertFalse(iterator.hasNext()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
74 Object result = target.call(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
75 Assert.assertEquals(42, result); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
76 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
77 // Add a wrapper |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
78 TestExecutionContext context = new TestExecutionContext(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
79 TestWrapper wrapper = new TestWrapper(addNode, context); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
80 rootNode = new TestRootNode(wrapper); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
81 target = runtime.createCallTarget(rootNode); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
82 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
83 // Check the new tree structure |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
84 Assert.assertEquals(addNode, leftChild.getParent()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
85 Assert.assertEquals(addNode, rightChild.getParent()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
86 iterator = addNode.getChildren().iterator(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
87 Assert.assertEquals(leftChild, iterator.next()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
88 Assert.assertEquals(rightChild, iterator.next()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
89 Assert.assertFalse(iterator.hasNext()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
90 Assert.assertEquals(wrapper, addNode.getParent()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
91 iterator = wrapper.getChildren().iterator(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
92 Assert.assertEquals(addNode, iterator.next()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
93 Assert.assertFalse(iterator.hasNext()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
94 Assert.assertEquals(rootNode, wrapper.getParent()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
95 iterator = rootNode.getChildren().iterator(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
96 Assert.assertEquals(wrapper, iterator.next()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
97 Assert.assertFalse(iterator.hasNext()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
98 result = target.call(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
99 Assert.assertEquals(42, result); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
100 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
101 // Add an instrument |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
102 wrapper.getProbe().addInstrument(new TestInstrument()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
103 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
104 // Check instrument and result |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
105 result = target.call(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
106 Assert.assertEquals(Counter.numInstrumentEnter, 1); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
107 Assert.assertEquals(Counter.numInstrumentLeave, 1); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
108 Assert.assertEquals(42, result); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
109 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
110 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
111 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
112 private class TestRootNode extends RootNode { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
113 @Child private RootNode child; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
114 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
115 public TestRootNode(RootNode child) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
116 super(null); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
117 this.child = child; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
118 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
119 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
120 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
121 public Object execute(VirtualFrame frame) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
122 return child.execute(frame); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
123 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
124 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
125 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
126 private class TestAddNode extends RootNode { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
127 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
128 @Child private TestChildNode left; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
129 @Child private TestChildNode right; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
130 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
131 public TestAddNode(TestChildNode left, TestChildNode right, TestSourceSection sourceSection) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
132 super(sourceSection); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
133 this.left = left; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
134 this.right = right; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
135 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
136 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
137 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
138 public Object execute(VirtualFrame frame) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
139 return left.execute() + right.execute(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
140 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
141 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
142 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
143 private class TestChildNode extends Node { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
144 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
145 public TestChildNode() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
146 super(null); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
147 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
148 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
149 public int execute() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
150 return 21; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
151 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
152 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
153 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
154 private class TestWrapper extends RootNode implements Wrapper { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
155 @Child private RootNode child; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
156 private Probe probe; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
157 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
158 public TestWrapper(RootNode child, ExecutionContext context) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
159 this.child = insert(child); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
160 this.probe = context.getProbe(child.getSourceSection()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
161 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
162 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
163 public boolean isTaggedAs(SyntaxTag tag) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
164 return false; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
165 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
166 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
167 public Iterable<SyntaxTag> getSyntaxTags() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
168 return null; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
169 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
170 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
171 public Node getChild() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
172 return child; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
173 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
174 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
175 public Probe getProbe() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
176 return probe; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
177 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
178 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
179 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
180 public Object execute(VirtualFrame frame) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
181 probe.enter(child, frame); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
182 Object result; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
183 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
184 try { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
185 result = child.execute(frame); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
186 probe.leave(child, frame, result); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
187 } catch (Exception e) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
188 probe.leaveExceptional(child, frame, e); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
189 throw (e); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
190 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
191 return result; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
192 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
193 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
194 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
195 private class TestSourceSection implements SourceSection { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
196 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
197 public Source getSource() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
198 return null; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
199 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
200 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
201 public int getStartLine() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
202 return 0; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
203 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
204 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
205 public LineLocation getLineLocation() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
206 return null; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
207 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
208 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
209 public int getStartColumn() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
210 return 0; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
211 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
212 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
213 public int getCharIndex() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
214 return 0; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
215 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
216 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
217 public int getCharLength() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
218 return 0; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
219 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
220 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
221 public int getCharEndIndex() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
222 return 0; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
223 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
224 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
225 public String getIdentifier() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
226 return null; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
227 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
228 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
229 public String getCode() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
230 return null; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
231 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
232 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
233 public String getShortDescription() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
234 return null; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
235 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
236 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
237 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
238 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
239 private class TestExecutionContext extends ExecutionContext { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
240 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
241 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
242 public String getLanguageShortName() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
243 return "test"; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
244 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
245 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
246 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
247 protected void setSourceCallback(SourceCallback sourceCallback) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
248 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
249 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
250 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
251 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
252 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
253 private class TestInstrument extends Instrument { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
254 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
255 public void enter(Node astNode, VirtualFrame frame) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
256 Counter.numInstrumentEnter++; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
257 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
258 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
259 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
260 public void leave(Node astNode, VirtualFrame frame, Object result) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
261 Counter.numInstrumentLeave++; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
262 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
263 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
264 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
265 public static class Counter { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
266 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
267 public static int numInstrumentEnter = 0; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
268 public static int numInstrumentLeave = 0; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
269 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
270 } |