2017-02-22 10:21:57 +00:00
|
|
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
var source =
|
|
|
|
`
|
|
|
|
function fib(x) {
|
|
|
|
if (x < 2) return 1;
|
|
|
|
return fib(x-1) + fib(x-2);
|
|
|
|
}
|
|
|
|
(function iife() {
|
|
|
|
return 1;
|
|
|
|
})();
|
|
|
|
fib(5);
|
|
|
|
`;
|
|
|
|
|
2017-02-28 20:22:24 +00:00
|
|
|
InspectorTest.log("Test collecting code coverage data with Profiler.collectCoverage.");
|
2017-02-22 10:21:57 +00:00
|
|
|
|
|
|
|
function ClearAndGC() {
|
2017-03-06 20:49:11 +00:00
|
|
|
return Protocol.Runtime.evaluate({ expression: "fib = null;" }).then(GC);
|
|
|
|
}
|
|
|
|
|
|
|
|
function GC() {
|
|
|
|
return Protocol.HeapProfiler.enable()
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(() => Protocol.HeapProfiler.collectGarbage())
|
|
|
|
.then(() => Protocol.HeapProfiler.disable());
|
|
|
|
}
|
|
|
|
|
2017-02-24 09:17:56 +00:00
|
|
|
function LogSorted(message) {
|
|
|
|
message.result.result.sort((a, b) => parseInt(a.scriptId) - parseInt(b.scriptId));
|
|
|
|
return InspectorTest.logMessage(message);
|
|
|
|
}
|
|
|
|
|
2017-02-22 10:21:57 +00:00
|
|
|
InspectorTest.runTestSuite([
|
2017-03-06 20:49:11 +00:00
|
|
|
function testPreciseBaseline(next)
|
|
|
|
{
|
|
|
|
Protocol.Runtime.enable()
|
|
|
|
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "0", persistScript: true }))
|
|
|
|
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
|
|
|
|
.then(GC)
|
|
|
|
.then(Protocol.Profiler.enable)
|
|
|
|
.then(Protocol.Profiler.startPreciseCoverage)
|
|
|
|
.then(Protocol.Profiler.takePreciseCoverage)
|
|
|
|
.then(LogSorted)
|
|
|
|
.then(Protocol.Profiler.takePreciseCoverage)
|
|
|
|
.then(LogSorted)
|
|
|
|
.then(Protocol.Profiler.stopPreciseCoverage)
|
|
|
|
.then(ClearAndGC)
|
|
|
|
.then(Protocol.Profiler.disable)
|
|
|
|
.then(Protocol.Runtime.disable)
|
|
|
|
.then(next);
|
|
|
|
},
|
2017-02-22 10:21:57 +00:00
|
|
|
function testPreciseCoverage(next)
|
|
|
|
{
|
|
|
|
Protocol.Runtime.enable()
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.enable)
|
|
|
|
.then(Protocol.Profiler.startPreciseCoverage)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "1", persistScript: true }))
|
|
|
|
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
|
|
|
|
.then(ClearAndGC)
|
|
|
|
.then(InspectorTest.logMessage)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.takePreciseCoverage)
|
2017-02-24 09:17:56 +00:00
|
|
|
.then(LogSorted)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.takePreciseCoverage)
|
2017-02-24 09:17:56 +00:00
|
|
|
.then(LogSorted)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(ClearAndGC)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.stopPreciseCoverage)
|
|
|
|
.then(Protocol.Profiler.disable)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(Protocol.Runtime.disable)
|
|
|
|
.then(next);
|
|
|
|
},
|
|
|
|
function testPreciseCoverageFail(next)
|
|
|
|
{
|
|
|
|
Protocol.Runtime.enable()
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.enable)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "2", persistScript: true }))
|
|
|
|
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
|
|
|
|
.then(InspectorTest.logMessage)
|
|
|
|
.then(ClearAndGC)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.takePreciseCoverage)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(InspectorTest.logMessage)
|
|
|
|
.then(ClearAndGC)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.disable)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(Protocol.Runtime.disable)
|
|
|
|
.then(next);
|
|
|
|
},
|
|
|
|
function testBestEffortCoverage(next)
|
|
|
|
{
|
|
|
|
Protocol.Runtime.enable()
|
|
|
|
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "3", persistScript: true }))
|
|
|
|
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
|
|
|
|
.then(InspectorTest.logMessage)
|
|
|
|
.then(ClearAndGC)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.getBestEffortCoverage)
|
2017-02-24 09:17:56 +00:00
|
|
|
.then(LogSorted)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.getBestEffortCoverage)
|
2017-02-24 09:17:56 +00:00
|
|
|
.then(LogSorted)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(ClearAndGC)
|
|
|
|
.then(Protocol.Runtime.disable)
|
|
|
|
.then(next);
|
|
|
|
},
|
|
|
|
function testBestEffortCoveragePrecise(next)
|
|
|
|
{
|
|
|
|
Protocol.Runtime.enable()
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.enable)
|
|
|
|
.then(Protocol.Profiler.startPreciseCoverage)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "4", persistScript: true }))
|
|
|
|
.then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))
|
|
|
|
.then(InspectorTest.logMessage)
|
|
|
|
.then(ClearAndGC)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.getBestEffortCoverage)
|
2017-02-24 09:17:56 +00:00
|
|
|
.then(LogSorted)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.getBestEffortCoverage)
|
2017-02-24 09:17:56 +00:00
|
|
|
.then(LogSorted)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(ClearAndGC)
|
2017-02-25 02:44:56 +00:00
|
|
|
.then(Protocol.Profiler.stopPreciseCoverage)
|
|
|
|
.then(Protocol.Profiler.disable)
|
2017-02-22 10:21:57 +00:00
|
|
|
.then(Protocol.Runtime.disable)
|
|
|
|
.then(next);
|
|
|
|
},
|
|
|
|
]);
|