Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: test/inspector/cpu-profiler/coverage.js

Issue 2766573003: [debug] introduce precise binary code coverage. (Closed)
Patch Set: fix test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/inspector/cpu-profiler/coverage-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 the V8 project authors. All rights reserved. 1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --allow-natives-syntax
6
5 var source = 7 var source =
6 ` 8 `
7 function fib(x) { 9 function fib(x) {
8 if (x < 2) return 1; 10 if (x < 2) return 1;
9 return fib(x-1) + fib(x-2); 11 return fib(x-1) + fib(x-2);
10 } 12 }
13 function is_optimized(f) {
14 return (%GetOptimizationStatus(f) & 16) ? "optimized" : "unoptimized";
15 }
11 (function iife() { 16 (function iife() {
12 return 1; 17 return 1;
13 })(); 18 })();
14 fib(5); 19 fib(5);
15 `; 20 `;
16 21
17 var break_source = 22 var break_source =
18 ` 23 `
19 function g() { 24 function g() {
20 debugger; 25 debugger;
21 } 26 }
22 function f(x) { 27 function f(x) {
23 if (x == 0) g(); 28 if (x == 0) g();
24 else f(x - 1); 29 else f(x - 1);
25 } 30 }
26 function h() { 31 function h() {
27 g(); 32 g();
28 } 33 }
29 f(3); 34 f(3);
30 `; 35 `;
31 36
32 InspectorTest.log("Test collecting code coverage data with Profiler.collectCover age."); 37 InspectorTest.log("Test collecting code coverage data with Profiler.collectCover age.");
33 38
34 function ClearAndGC() { 39 function ClearAndGC() {
35 return Protocol.Runtime.evaluate({ expression: "fib = null;" }).then(GC); 40 return Protocol.Runtime.evaluate({ expression: "fib = g = f = h = is_optimized = null;" })
41 .then(GC);
36 } 42 }
37 43
38 function GC() { 44 function GC() {
39 return Protocol.HeapProfiler.enable() 45 return Protocol.HeapProfiler.enable()
40 .then(() => Protocol.HeapProfiler.collectGarbage()) 46 .then(() => Protocol.HeapProfiler.collectGarbage())
41 .then(() => Protocol.HeapProfiler.disable()); 47 .then(() => Protocol.HeapProfiler.disable());
42 } 48 }
43 49
44 function LogSorted(message) { 50 function LogSorted(message) {
45 message.result.result.sort((a, b) => parseInt(a.scriptId) - parseInt(b.scriptI d)); 51 message.result.result.sort((a, b) => parseInt(a.scriptId) - parseInt(b.scriptI d));
46 return InspectorTest.logMessage(message); 52 return InspectorTest.logMessage(message);
47 } 53 }
48 54
49 InspectorTest.runTestSuite([ 55 InspectorTest.runTestSuite([
50 function testPreciseBaseline(next) 56 function testPreciseCountBaseline(next)
51 { 57 {
52 Protocol.Runtime.enable() 58 Protocol.Runtime.enable()
53 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "0", persistScript: true })) 59 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : arguments.callee.name, persistScript: true }))
54 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 60 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
55 .then(GC) 61 .then(GC)
56 .then(Protocol.Profiler.enable) 62 .then(Protocol.Profiler.enable)
57 .then(Protocol.Profiler.startPreciseCoverage) 63 .then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
58 .then(Protocol.Profiler.takePreciseCoverage) 64 .then(Protocol.Profiler.takePreciseCoverage)
59 .then(LogSorted) 65 .then(LogSorted)
60 .then(Protocol.Profiler.takePreciseCoverage) 66 .then(Protocol.Profiler.takePreciseCoverage)
61 .then(LogSorted) 67 .then(LogSorted)
62 .then(Protocol.Profiler.stopPreciseCoverage) 68 .then(Protocol.Profiler.stopPreciseCoverage)
63 .then(ClearAndGC)
64 .then(Protocol.Profiler.disable) 69 .then(Protocol.Profiler.disable)
65 .then(Protocol.Runtime.disable) 70 .then(Protocol.Runtime.disable)
71 .then(ClearAndGC)
66 .then(next); 72 .then(next);
67 }, 73 },
68 function testPreciseCoverage(next) 74 function testPreciseCountCoverage(next)
69 { 75 {
70 Protocol.Runtime.enable() 76 Protocol.Runtime.enable()
71 .then(Protocol.Profiler.enable) 77 .then(Protocol.Profiler.enable)
72 .then(Protocol.Profiler.startPreciseCoverage) 78 .then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
73 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "1", persistScript: true })) 79 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : arguments.callee.name, persistScript: true }))
74 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 80 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
75 .then(ClearAndGC) 81 .then(ClearAndGC)
76 .then(InspectorTest.logMessage) 82 .then(InspectorTest.logMessage)
77 .then(Protocol.Profiler.takePreciseCoverage) 83 .then(Protocol.Profiler.takePreciseCoverage)
78 .then(LogSorted) 84 .then(LogSorted)
79 .then(Protocol.Profiler.takePreciseCoverage) 85 .then(Protocol.Profiler.takePreciseCoverage)
80 .then(LogSorted) 86 .then(LogSorted)
81 .then(ClearAndGC)
82 .then(Protocol.Profiler.stopPreciseCoverage) 87 .then(Protocol.Profiler.stopPreciseCoverage)
83 .then(Protocol.Profiler.disable) 88 .then(Protocol.Profiler.disable)
84 .then(Protocol.Runtime.disable) 89 .then(Protocol.Runtime.disable)
90 .then(ClearAndGC)
85 .then(next); 91 .then(next);
86 }, 92 },
87 function testPreciseCoverageFail(next) 93 function testPreciseCoverageFail(next)
88 { 94 {
89 Protocol.Runtime.enable() 95 Protocol.Runtime.enable()
90 .then(Protocol.Profiler.enable) 96 .then(Protocol.Profiler.enable)
91 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "2", persistScript: true })) 97 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : arguments.callee.name, persistScript: true }))
92 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 98 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
93 .then(InspectorTest.logMessage) 99 .then(InspectorTest.logMessage)
94 .then(ClearAndGC) 100 .then(ClearAndGC)
95 .then(Protocol.Profiler.takePreciseCoverage) 101 .then(Protocol.Profiler.takePreciseCoverage)
96 .then(InspectorTest.logMessage) 102 .then(InspectorTest.logMessage)
97 .then(ClearAndGC)
98 .then(Protocol.Profiler.disable) 103 .then(Protocol.Profiler.disable)
99 .then(Protocol.Runtime.disable) 104 .then(Protocol.Runtime.disable)
105 .then(ClearAndGC)
100 .then(next); 106 .then(next);
101 }, 107 },
102 function testBestEffortCoverage(next) 108 function testBestEffortCoverage(next)
103 { 109 {
104 Protocol.Runtime.enable() 110 Protocol.Runtime.enable()
105 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "3", persistScript: true })) 111 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : arguments.callee.name, persistScript: true }))
106 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 112 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
107 .then(InspectorTest.logMessage) 113 .then(InspectorTest.logMessage)
108 .then(ClearAndGC) 114 .then(ClearAndGC)
109 .then(Protocol.Profiler.getBestEffortCoverage) 115 .then(Protocol.Profiler.getBestEffortCoverage)
110 .then(LogSorted) 116 .then(LogSorted)
111 .then(Protocol.Profiler.getBestEffortCoverage) 117 .then(Protocol.Profiler.getBestEffortCoverage)
112 .then(LogSorted) 118 .then(LogSorted)
119 .then(Protocol.Runtime.disable)
113 .then(ClearAndGC) 120 .then(ClearAndGC)
114 .then(Protocol.Runtime.disable)
115 .then(next); 121 .then(next);
116 }, 122 },
117 function testBestEffortCoveragePrecise(next) 123 function testBestEffortCoverageWithPreciseBinaryEnabled(next)
124 {
125 Protocol.Runtime.enable()
126 .then(Protocol.Profiler.enable)
127 .then(Protocol.Profiler.startPreciseCoverage)
128 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: arguments.callee.name, persistScript: true }))
129 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scrip tId }))
130 .then(InspectorTest.logMessage)
131 .then(ClearAndGC)
132 .then(Protocol.Profiler.getBestEffortCoverage)
133 .then(LogSorted)
134 .then(Protocol.Profiler.getBestEffortCoverage)
135 .then(LogSorted)
136 .then(ClearAndGC)
137 .then(Protocol.Profiler.stopPreciseCoverage)
138 .then(Protocol.Profiler.disable)
139 .then(Protocol.Runtime.disable)
140 .then(ClearAndGC)
141 .then(next);
142 },
143 function testBestEffortCoverageWithPreciseCountEnabled(next)
118 { 144 {
119 Protocol.Runtime.enable() 145 Protocol.Runtime.enable()
120 .then(Protocol.Profiler.enable) 146 .then(Protocol.Profiler.enable)
121 .then(Protocol.Profiler.startPreciseCoverage) 147 .then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
122 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : "4", persistScript: true })) 148 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : arguments.callee.name, persistScript: true }))
123 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 149 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
124 .then(InspectorTest.logMessage) 150 .then(InspectorTest.logMessage)
125 .then(ClearAndGC) 151 .then(ClearAndGC)
126 .then(Protocol.Profiler.getBestEffortCoverage) 152 .then(Protocol.Profiler.getBestEffortCoverage)
127 .then(LogSorted) 153 .then(LogSorted)
128 .then(Protocol.Profiler.getBestEffortCoverage) 154 .then(Protocol.Profiler.getBestEffortCoverage)
129 .then(LogSorted) 155 .then(LogSorted)
130 .then(ClearAndGC) 156 .then(ClearAndGC)
131 .then(Protocol.Profiler.stopPreciseCoverage) 157 .then(Protocol.Profiler.stopPreciseCoverage)
132 .then(Protocol.Profiler.disable) 158 .then(Protocol.Profiler.disable)
133 .then(Protocol.Runtime.disable) 159 .then(Protocol.Runtime.disable)
160 .then(ClearAndGC)
134 .then(next); 161 .then(next);
135 }, 162 },
136 function testEnablePreciseCoverageAtPause(next) 163 function testEnablePreciseCountCoverageAtPause(next)
137 { 164 {
138 function handleDebuggerPause() { 165 function handleDebuggerPause() {
139 Protocol.Profiler.enable() 166 Protocol.Profiler.enable()
140 .then(Protocol.Profiler.startPreciseCoverage) 167 .then(() => Protocol.Profiler.startPreciseCoverage({callCount: true}))
141 .then(Protocol.Debugger.resume) 168 .then(Protocol.Debugger.resume)
142 } 169 }
143 Protocol.Debugger.enable(); 170 Protocol.Debugger.enable();
144 Protocol.Debugger.oncePaused().then(handleDebuggerPause); 171 Protocol.Debugger.oncePaused().then(handleDebuggerPause);
145 Protocol.Runtime.enable() 172 Protocol.Runtime.enable()
146 .then(() => Protocol.Runtime.compileScript({ expression: break_source, sou rceURL: "5", persistScript: true })) 173 .then(() => Protocol.Runtime.compileScript({ expression: break_source, sou rceURL: arguments.callee.name, persistScript: true }))
147 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId })) 174 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
148 .then(InspectorTest.logMessage) 175 .then(InspectorTest.logMessage)
149 .then(ClearAndGC) 176 .then(ClearAndGC)
150 .then(Protocol.Profiler.takePreciseCoverage) 177 .then(Protocol.Profiler.takePreciseCoverage)
151 .then(LogSorted) 178 .then(LogSorted)
179 .then(ClearAndGC)
152 .then(Protocol.Profiler.stopPreciseCoverage) 180 .then(Protocol.Profiler.stopPreciseCoverage)
153 .then(Protocol.Profiler.disable) 181 .then(Protocol.Profiler.disable)
154 .then(Protocol.Runtime.disable) 182 .then(Protocol.Runtime.disable)
183 .then(Protocol.Debugger.disable)
184 .then(ClearAndGC)
185 .then(next);
186 },
187 function testPreciseBinaryCoverage(next)
188 {
189 Protocol.Runtime.enable()
190 .then(Protocol.Profiler.enable)
191 .then(Protocol.Profiler.startPreciseCoverage)
192 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL : arguments.callee.name, persistScript: true }))
193 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr iptId }))
194 .then(InspectorTest.logMessage)
195 .then(Protocol.Profiler.takePreciseCoverage)
196 .then(LogSorted)
197 .then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }) )
198 .then(message => InspectorTest.logMessage(message))
199 .then(() => Protocol.Runtime.evaluate({ expression: "fib(20)" }))
200 .then(message => InspectorTest.logMessage(message))
201 .then(() => Protocol.Runtime.evaluate({ expression: "is_optimized(fib)" }) )
202 .then(message => InspectorTest.logMessage(message))
203 .then(Protocol.Profiler.takePreciseCoverage)
204 .then(LogSorted)
205 .then(Protocol.Profiler.stopPreciseCoverage)
206 .then(Protocol.Profiler.disable)
207 .then(Protocol.Runtime.disable)
208 .then(ClearAndGC)
155 .then(next); 209 .then(next);
156 }, 210 },
157 ]); 211 ]);
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/inspector/cpu-profiler/coverage-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698