2017-07-25 10:01:51 +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.
|
|
|
|
|
|
|
|
// Flags: --allow-natives-syntax
|
|
|
|
|
|
|
|
let TestCoverage;
|
|
|
|
let TestCoverageNoGC;
|
|
|
|
|
|
|
|
let nop;
|
2017-07-26 08:36:01 +00:00
|
|
|
let gen;
|
2017-07-25 10:01:51 +00:00
|
|
|
|
|
|
|
!function() {
|
|
|
|
function GetCoverage(source) {
|
|
|
|
for (var script of %DebugCollectCoverage()) {
|
2018-07-05 20:34:14 +00:00
|
|
|
if (script.script === source) return script;
|
2017-07-25 10:01:51 +00:00
|
|
|
}
|
|
|
|
return undefined;
|
2017-07-26 08:36:01 +00:00
|
|
|
};
|
2017-07-25 10:01:51 +00:00
|
|
|
|
2019-09-11 14:15:08 +00:00
|
|
|
function TestCoverageInternal(
|
|
|
|
name, source, expectation, collect_garbage, prettyPrintResults) {
|
2017-07-25 10:01:51 +00:00
|
|
|
source = source.trim();
|
|
|
|
eval(source);
|
|
|
|
if (collect_garbage) %CollectGarbage("collect dead objects");
|
|
|
|
var covfefe = GetCoverage(source);
|
|
|
|
var stringified_result = JSON.stringify(covfefe);
|
|
|
|
var stringified_expectation = JSON.stringify(expectation);
|
2019-09-11 14:15:08 +00:00
|
|
|
const mismatch = stringified_result != stringified_expectation;
|
|
|
|
if (mismatch) {
|
|
|
|
console.log(stringified_result.replace(/[}],[{]/g, "},\n {"));
|
|
|
|
}
|
|
|
|
if (prettyPrintResults) {
|
|
|
|
console.log("=== Coverage Expectation ===")
|
|
|
|
for (const {start,end,count} of expectation) {
|
|
|
|
console.log(`Range [${start}, ${end}) (count: ${count})`);
|
|
|
|
console.log(source.substring(start, end));
|
|
|
|
}
|
|
|
|
console.log("=== Coverage Results ===")
|
|
|
|
for (const {start,end,count} of covfefe) {
|
|
|
|
console.log(`Range [${start}, ${end}) (count: ${count})`);
|
|
|
|
console.log(source.substring(start, end));
|
|
|
|
}
|
|
|
|
console.log("========================")
|
2017-07-25 10:01:51 +00:00
|
|
|
}
|
|
|
|
assertEquals(stringified_expectation, stringified_result, name + " failed");
|
2017-07-26 08:36:01 +00:00
|
|
|
};
|
2017-07-25 10:01:51 +00:00
|
|
|
|
2019-09-11 14:15:08 +00:00
|
|
|
TestCoverage = function(name, source, expectation, prettyPrintResults) {
|
|
|
|
TestCoverageInternal(name, source, expectation, true, prettyPrintResults);
|
2017-07-26 08:36:01 +00:00
|
|
|
};
|
2017-07-25 10:01:51 +00:00
|
|
|
|
2019-09-11 14:15:08 +00:00
|
|
|
TestCoverageNoGC = function(name, source, expectation, prettyPrintResults) {
|
|
|
|
TestCoverageInternal(name, source, expectation, false, prettyPrintResults);
|
2017-07-26 08:36:01 +00:00
|
|
|
};
|
2017-07-25 10:01:51 +00:00
|
|
|
|
2017-07-26 08:36:01 +00:00
|
|
|
nop = function() {};
|
|
|
|
|
|
|
|
gen = function*() {
|
|
|
|
yield 1;
|
|
|
|
yield 2;
|
|
|
|
yield 3;
|
|
|
|
};
|
2017-07-25 10:01:51 +00:00
|
|
|
}();
|