Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/CoverageTrackerTest.java @ 21951:9c8c0937da41
Moving all sources into truffle subdirectory
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 17 Jun 2015 10:58:08 +0200 |
parents | graal/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/CoverageTrackerTest.java@3b8bbf51d320 |
children | dc83cc1f94f2 3aad794eec0e |
comparison
equal
deleted
inserted
replaced
21950:2a5011c7e641 | 21951:9c8c0937da41 |
---|---|
1 /* | |
2 * Copyright (c) 2014, 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. Oracle designates this | |
8 * particular file as subject to the "Classpath" exception as provided | |
9 * by Oracle in the LICENSE file that accompanied this code. | |
10 * | |
11 * This code is distributed in the hope that it will be useful, but WITHOUT | |
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 * version 2 for more details (a copy is included in the LICENSE file that | |
15 * accompanied this code). | |
16 * | |
17 * You should have received a copy of the GNU General Public License version | |
18 * 2 along with this work; if not, write to the Free Software Foundation, | |
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 * | |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
22 * or visit www.oracle.com if you need additional information or have any | |
23 * questions. | |
24 */ | |
25 package com.oracle.truffle.tools.test; | |
26 | |
27 import static com.oracle.truffle.tools.test.TestNodes.*; | |
28 import static org.junit.Assert.*; | |
29 | |
30 import org.junit.*; | |
31 | |
32 import com.oracle.truffle.api.instrument.*; | |
33 import com.oracle.truffle.api.nodes.*; | |
34 import com.oracle.truffle.tools.*; | |
35 | |
36 public class CoverageTrackerTest { | |
37 | |
38 @Test | |
39 public void testNoExecution() { | |
40 final CoverageTracker tool = new CoverageTracker(); | |
41 assertEquals(tool.getCounts().entrySet().size(), 0); | |
42 tool.install(); | |
43 assertEquals(tool.getCounts().entrySet().size(), 0); | |
44 tool.setEnabled(false); | |
45 assertEquals(tool.getCounts().entrySet().size(), 0); | |
46 tool.setEnabled(true); | |
47 assertEquals(tool.getCounts().entrySet().size(), 0); | |
48 tool.reset(); | |
49 assertEquals(tool.getCounts().entrySet().size(), 0); | |
50 tool.dispose(); | |
51 assertEquals(tool.getCounts().entrySet().size(), 0); | |
52 } | |
53 | |
54 @Test | |
55 public void testToolCreatedTooLate() { | |
56 final RootNode expr13rootNode = createExpr13TestRootNode(); | |
57 final CoverageTracker tool = new CoverageTracker(); | |
58 tool.install(); | |
59 assertEquals(13, expr13rootNode.execute(null)); | |
60 assertTrue(tool.getCounts().isEmpty()); | |
61 tool.dispose(); | |
62 } | |
63 | |
64 @Test | |
65 public void testToolInstalledcTooLate() { | |
66 final CoverageTracker tool = new CoverageTracker(); | |
67 final RootNode expr13rootNode = createExpr13TestRootNode(); | |
68 tool.install(); | |
69 assertEquals(13, expr13rootNode.execute(null)); | |
70 assertTrue(tool.getCounts().isEmpty()); | |
71 tool.dispose(); | |
72 } | |
73 | |
74 @Test | |
75 public void testCountingCoverage() { | |
76 final CoverageTracker tool = new CoverageTracker(); | |
77 tool.install(); | |
78 final RootNode expr13rootNode = createExpr13TestRootNode(); | |
79 | |
80 // Not probed yet. | |
81 assertEquals(13, expr13rootNode.execute(null)); | |
82 assertTrue(tool.getCounts().isEmpty()); | |
83 | |
84 final Node addNode = expr13rootNode.getChildren().iterator().next(); | |
85 final Probe probe = addNode.probe(); | |
86 | |
87 // Probed but not tagged yet. | |
88 assertEquals(13, expr13rootNode.execute(null)); | |
89 assertTrue(tool.getCounts().isEmpty()); | |
90 | |
91 probe.tagAs(StandardSyntaxTag.STATEMENT, "fake statement for testing"); | |
92 | |
93 // Counting now; execute once | |
94 assertEquals(13, expr13rootNode.execute(null)); | |
95 | |
96 final Long[] longs1 = tool.getCounts().get(addNode.getSourceSection().getSource()); | |
97 assertNotNull(longs1); | |
98 assertEquals(longs1.length, 2); | |
99 assertNull(longs1[0]); // Line 1 is empty (text lines are 1-based) | |
100 assertEquals(1L, longs1[1].longValue()); // Expression is on line 2 | |
101 | |
102 // Execute 99 more times | |
103 for (int i = 0; i < 99; i++) { | |
104 assertEquals(13, expr13rootNode.execute(null)); | |
105 } | |
106 | |
107 final Long[] longs100 = tool.getCounts().get(addNode.getSourceSection().getSource()); | |
108 assertNotNull(longs100); | |
109 assertEquals(longs100.length, 2); | |
110 assertNull(longs100[0]); | |
111 assertEquals(100L, longs100[1].longValue()); | |
112 | |
113 tool.dispose(); | |
114 } | |
115 | |
116 } |