Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/NodeExecCounterTest.java @ 22535:9b9301abe3ff
@Ignored broken test and corrected order of assertEquals arguments (GRAAL-1385)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 08 Jan 2016 21:43:03 +0100 |
parents | 906a5f6e07cc |
children |
comparison
equal
deleted
inserted
replaced
22534:1133c68332ef | 22535:9b9301abe3ff |
---|---|
28 import static org.junit.Assert.fail; | 28 import static org.junit.Assert.fail; |
29 | 29 |
30 import java.io.IOException; | 30 import java.io.IOException; |
31 import java.lang.reflect.Field; | 31 import java.lang.reflect.Field; |
32 | 32 |
33 import org.junit.Ignore; | |
33 import org.junit.Test; | 34 import org.junit.Test; |
34 | 35 |
35 import com.oracle.truffle.api.instrument.Instrumenter; | 36 import com.oracle.truffle.api.instrument.Instrumenter; |
36 import com.oracle.truffle.api.source.Source; | 37 import com.oracle.truffle.api.source.Source; |
37 import com.oracle.truffle.api.vm.PolyglotEngine; | 38 import com.oracle.truffle.api.vm.PolyglotEngine; |
45 final PolyglotEngine vm = PolyglotEngine.newBuilder().build(); | 46 final PolyglotEngine vm = PolyglotEngine.newBuilder().build(); |
46 final Field field = PolyglotEngine.class.getDeclaredField("instrumenter"); | 47 final Field field = PolyglotEngine.class.getDeclaredField("instrumenter"); |
47 field.setAccessible(true); | 48 field.setAccessible(true); |
48 final Instrumenter instrumenter = (Instrumenter) field.get(vm); | 49 final Instrumenter instrumenter = (Instrumenter) field.get(vm); |
49 final NodeExecCounter tool = new NodeExecCounter(); | 50 final NodeExecCounter tool = new NodeExecCounter(); |
50 assertEquals(tool.getCounts().length, 0); | 51 assertEquals(0, tool.getCounts().length); |
51 instrumenter.install(tool); | 52 instrumenter.install(tool); |
52 assertEquals(tool.getCounts().length, 0); | 53 assertEquals(0, tool.getCounts().length); |
53 tool.setEnabled(false); | 54 tool.setEnabled(false); |
54 assertEquals(tool.getCounts().length, 0); | 55 assertEquals(0, tool.getCounts().length); |
55 tool.setEnabled(true); | 56 tool.setEnabled(true); |
56 assertEquals(tool.getCounts().length, 0); | 57 assertEquals(0, tool.getCounts().length); |
57 tool.reset(); | 58 tool.reset(); |
58 assertEquals(tool.getCounts().length, 0); | 59 assertEquals(0, tool.getCounts().length); |
59 tool.dispose(); | 60 tool.dispose(); |
60 assertEquals(tool.getCounts().length, 0); | 61 assertEquals(0, tool.getCounts().length); |
61 } | 62 } |
62 | 63 |
63 void checkCounts(NodeExecCounter execTool, int addCount, int valueCount) { | 64 void checkCounts(NodeExecCounter execTool, int addCount, int valueCount) { |
64 NodeExecutionCount[] counts = execTool.getCounts(); | 65 NodeExecutionCount[] counts = execTool.getCounts(); |
65 assertEquals(counts.length, 2); | 66 assertEquals(2, counts.length); |
66 for (NodeExecutionCount counter : counts) { | 67 for (NodeExecutionCount counter : counts) { |
67 if (counter.nodeClass() == ToolTestUtil.TestAdditionNode.class) { | 68 if (counter.nodeClass() == ToolTestUtil.TestAdditionNode.class) { |
68 assertEquals(counter.executionCount(), addCount); | 69 assertEquals(addCount, counter.executionCount()); |
69 } else if (counter.nodeClass() == ToolTestUtil.TestValueNode.class) { | 70 } else if (counter.nodeClass() == ToolTestUtil.TestValueNode.class) { |
70 assertEquals(counter.executionCount(), valueCount); | 71 assertEquals(valueCount, counter.executionCount()); |
71 } else { | 72 } else { |
72 fail("correct classes counted"); | 73 fail("correct classes counted"); |
73 } | 74 } |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
78 @Ignore("GRAAL-1385") | |
77 @Test | 79 @Test |
78 public void testCounting() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException { | 80 public void testCounting() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException { |
79 final PolyglotEngine vm = PolyglotEngine.newBuilder().build(); | 81 final PolyglotEngine vm = PolyglotEngine.newBuilder().build(); |
80 final Field field = PolyglotEngine.class.getDeclaredField("instrumenter"); | 82 final Field field = PolyglotEngine.class.getDeclaredField("instrumenter"); |
81 field.setAccessible(true); | 83 field.setAccessible(true); |
82 final Instrumenter instrumenter = (Instrumenter) field.get(vm); | 84 final Instrumenter instrumenter = (Instrumenter) field.get(vm); |
83 final Source source = ToolTestUtil.createTestSource("testCounting"); | 85 final Source source = ToolTestUtil.createTestSource("testCounting"); |
84 final NodeExecCounter execTool = new NodeExecCounter(); | 86 final NodeExecCounter execTool = new NodeExecCounter(); |
85 instrumenter.install(execTool); | 87 instrumenter.install(execTool); |
86 | 88 |
87 assertEquals(execTool.getCounts().length, 0); | 89 assertEquals(0, execTool.getCounts().length); |
88 | 90 |
89 assertEquals(vm.eval(source).get(), 13); | 91 assertEquals(13, vm.eval(source).get()); |
90 | 92 |
91 checkCounts(execTool, 1, 2); | 93 checkCounts(execTool, 1, 2); |
92 | 94 |
93 for (int i = 0; i < 99; i++) { | 95 for (int i = 0; i < 99; i++) { |
94 assertEquals(vm.eval(source).get(), 13); | 96 assertEquals(13, vm.eval(source).get()); |
95 } | 97 } |
96 checkCounts(execTool, 100, 200); | 98 checkCounts(execTool, 100, 200); |
97 | 99 |
98 execTool.setEnabled(false); | 100 execTool.setEnabled(false); |
99 assertEquals(vm.eval(source).get(), 13); | 101 assertEquals(13, vm.eval(source).get()); |
100 checkCounts(execTool, 100, 200); | 102 checkCounts(execTool, 100, 200); |
101 | 103 |
102 execTool.dispose(); | 104 execTool.dispose(); |
103 } | 105 } |
104 } | 106 } |