Commit 6e4d2a60 authored by jgruber's avatar jgruber Committed by Commit Bot

[coverage] Refactor tests

Refactor common test code into code-coverage-utils.js and add tests to
verify counter behavior in opt/no-opt situations.

Bug: v8:6000
Change-Id: I07e62345476e8c81521c491ae605ddaf71600667
Reviewed-on: https://chromium-review.googlesource.com/584449Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46888}
parent 5448c7c1
......@@ -3,26 +3,11 @@
// found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt
// Files: test/mjsunit/code-coverage-utils.js
// Test code coverage without explicitly activating it upfront.
function GetCoverage(source) {
for (var script of %DebugCollectCoverage()) {
if (script.script.source == source) return script;
}
return undefined;
}
function TestCoverage(name, source, expectation) {
source = source.trim();
eval(source);
var coverage = GetCoverage(source);
var result = JSON.stringify(coverage);
print(result);
assertEquals(JSON.stringify(expectation), result, name + " failed");
}
TestCoverage(
TestCoverageNoGC(
"call simple function twice",
`
function f() {}
......@@ -33,7 +18,7 @@ f();
{"start":0,"end":15,"count":1}]
);
TestCoverage(
TestCoverageNoGC(
"call arrow function twice",
`
var f = () => 1;
......@@ -44,7 +29,7 @@ f();
{"start":8,"end":15,"count":1}]
);
TestCoverage(
TestCoverageNoGC(
"call nested function",
`
function f() {
......@@ -60,7 +45,7 @@ f();
{"start":17,"end":32,"count":1}]
);
TestCoverage(
TestCoverageNoGC(
"call recursive function",
`
function fib(x) {
......
// 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 --no-always-opt --block-coverage
// Flags: --no-stress-fullcodegen --harmony-async-iteration --no-opt
// Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true);
TestCoverage(
"optimized and inlined functions",
`
function g() { if (true) nop(); } // 0000
function f() { g(); g(); } // 0050
f(); f(); %OptimizeFunctionOnNextCall(f); // 0100
f(); f(); f(); f(); f(); f(); // 0150
`,
[{"start":0,"end":199,"count":1},
{"start":0,"end":33,"count":16},
{"start":50,"end":76,"count":8}]
);
%DebugToggleBlockCoverage(false);
// 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 --no-always-opt --block-coverage
// Flags: --no-stress-fullcodegen --harmony-async-iteration --opt
// Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true);
TestCoverage(
"optimized and inlined functions",
`
function g() { if (true) nop(); } // 0000
function f() { g(); g(); } // 0050
f(); f(); %OptimizeFunctionOnNextCall(f); // 0100
f(); f(); f(); f(); f(); f(); // 0150
`,
[{"start":0,"end":199,"count":1},
{"start":0,"end":33,"count":4}, // TODO(jgruber): Invocation count is off.
{"start":25,"end":33,"count":16},
{"start":50,"end":76,"count":2}] // TODO(jgruber): Invocation count is off.
);
%DebugToggleBlockCoverage(false);
......@@ -2,32 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt --ignition --block-coverage --harmony-async-iteration
// Flags: --no-stress-fullcodegen
// Test precise code coverage.
function GetCoverage(source) {
for (var script of %DebugCollectCoverage()) {
if (script.script.source == source) return script;
}
return undefined;
}
function TestCoverage(name, source, expectation) {
source = source.trim();
eval(source);
%CollectGarbage("collect dead objects");
var covfefe = GetCoverage(source);
var stringified_result = JSON.stringify(covfefe);
var stringified_expectation = JSON.stringify(expectation);
if (stringified_result != stringified_expectation) {
print(stringified_result.replace(/[}],[{]/g, "},\n {"));
}
assertEquals(stringified_expectation, stringified_result, name + " failed");
}
function nop() {}
// Flags: --allow-natives-syntax --no-always-opt --block-coverage
// Flags: --no-stress-fullcodegen --harmony-async-iteration
// Files: test/mjsunit/code-coverage-utils.js
%DebugToggleBlockCoverage(true);
......
......@@ -3,26 +3,10 @@
// found in the LICENSE file.
// Flags: --allow-natives-syntax --no-always-opt --no-stress-fullcodegen
// Files: test/mjsunit/code-coverage-utils.js
// Test precise code coverage.
function GetCoverage(source) {
for (var script of %DebugCollectCoverage()) {
if (script.script.source == source) return script;
}
return undefined;
}
function TestCoverage(name, source, expectation) {
source = source.trim();
eval(source);
%CollectGarbage("collect dead objects");
var coverage = GetCoverage(source);
var result = JSON.stringify(coverage);
print(result);
assertEquals(JSON.stringify(expectation), result, name + " failed");
}
// Without precise coverage enabled, we lose coverage data to the GC.
TestCoverage(
"call an IIFE",
......
// 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;
!function() {
function GetCoverage(source) {
for (var script of %DebugCollectCoverage()) {
if (script.script.source == source) return script;
}
return undefined;
}
function TestCoverageInternal(name, source, expectation, collect_garbage) {
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);
if (stringified_result != stringified_expectation) {
print(stringified_result.replace(/[}],[{]/g, "},\n {"));
}
assertEquals(stringified_expectation, stringified_result, name + " failed");
}
TestCoverage = function(name, source, expectation) {
TestCoverageInternal(name, source, expectation, true);
}
TestCoverageNoGC = function(name, source, expectation) {
TestCoverageInternal(name, source, expectation, false);
}
nop = function() {}
}();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment