Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/tools/CoverageTrackerTest.java @ 18988:cca166aa28c0
Truffle/Tools: unit tests for new framework and tool instances
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 27 Jan 2015 20:27:25 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
18987:ac114ad31cdd | 18988:cca166aa28c0 |
---|---|
1 /* | |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.test.tools; | |
24 | |
25 import static com.oracle.truffle.api.test.tools.TestNodes.*; | |
26 import static org.junit.Assert.*; | |
27 | |
28 import org.junit.*; | |
29 | |
30 import com.oracle.truffle.api.instrument.*; | |
31 import com.oracle.truffle.api.nodes.*; | |
32 import com.oracle.truffle.api.tools.*; | |
33 | |
34 public class CoverageTrackerTest { | |
35 | |
36 @Test | |
37 public void testNoExecution() { | |
38 final CoverageTracker tool = new CoverageTracker(); | |
39 assertEquals(tool.getCounts().entrySet().size(), 0); | |
40 tool.install(); | |
41 assertEquals(tool.getCounts().entrySet().size(), 0); | |
42 tool.setEnabled(false); | |
43 assertEquals(tool.getCounts().entrySet().size(), 0); | |
44 tool.setEnabled(true); | |
45 assertEquals(tool.getCounts().entrySet().size(), 0); | |
46 tool.reset(); | |
47 assertEquals(tool.getCounts().entrySet().size(), 0); | |
48 tool.dispose(); | |
49 assertEquals(tool.getCounts().entrySet().size(), 0); | |
50 } | |
51 | |
52 @Test | |
53 public void testToolCreatedTooLate() { | |
54 final RootNode expr13rootNode = createExpr13TestRootNode(); | |
55 final CoverageTracker tool = new CoverageTracker(); | |
56 tool.install(); | |
57 assertEquals(13, expr13rootNode.execute(null)); | |
58 assertTrue(tool.getCounts().isEmpty()); | |
59 tool.dispose(); | |
60 } | |
61 | |
62 @Test | |
63 public void testToolInstalledcTooLate() { | |
64 final CoverageTracker tool = new CoverageTracker(); | |
65 final RootNode expr13rootNode = createExpr13TestRootNode(); | |
66 tool.install(); | |
67 assertEquals(13, expr13rootNode.execute(null)); | |
68 assertTrue(tool.getCounts().isEmpty()); | |
69 tool.dispose(); | |
70 } | |
71 | |
72 @Test | |
73 public void testCountingCoverage() { | |
74 final CoverageTracker tool = new CoverageTracker(); | |
75 tool.install(); | |
76 final RootNode expr13rootNode = createExpr13TestRootNode(); | |
77 | |
78 // Not probed yet. | |
79 assertEquals(13, expr13rootNode.execute(null)); | |
80 assertTrue(tool.getCounts().isEmpty()); | |
81 | |
82 final Node addNode = expr13rootNode.getChildren().iterator().next(); | |
83 final Probe probe = addNode.probe(); | |
84 | |
85 // Probed but not tagged yet. | |
86 assertEquals(13, expr13rootNode.execute(null)); | |
87 assertTrue(tool.getCounts().isEmpty()); | |
88 | |
89 probe.tagAs(StandardSyntaxTag.STATEMENT, "fake statement for testing"); | |
90 | |
91 // Counting now; execute once | |
92 assertEquals(13, expr13rootNode.execute(null)); | |
93 | |
94 final Long[] longs1 = tool.getCounts().get(addNode.getSourceSection().getSource()); | |
95 assertNotNull(longs1); | |
96 assertEquals(longs1.length, 2); | |
97 assertNull(longs1[0]); // Line 1 is empty (text lines are 1-based) | |
98 assertEquals(1L, longs1[1].longValue()); // Expression is on line 2 | |
99 | |
100 // Execute 99 more times | |
101 for (int i = 0; i < 99; i++) { | |
102 assertEquals(13, expr13rootNode.execute(null)); | |
103 } | |
104 | |
105 final Long[] longs100 = tool.getCounts().get(addNode.getSourceSection().getSource()); | |
106 assertNotNull(longs100); | |
107 assertEquals(longs100.length, 2); | |
108 assertNull(longs100[0]); | |
109 assertEquals(100L, longs100[1].longValue()); | |
110 | |
111 tool.dispose(); | |
112 } | |
113 | |
114 } |