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

Unified Diff: test/mjsunit/code-coverage-block.js

Issue 2882973002: [coverage] Block coverage with support for IfStatements (Closed)
Patch Set: Address comments Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/code-coverage-block.js
diff --git a/test/mjsunit/code-coverage-block.js b/test/mjsunit/code-coverage-block.js
new file mode 100644
index 0000000000000000000000000000000000000000..0e4d7ace24a534609c134781f69a2b37ce76a4bc
--- /dev/null
+++ b/test/mjsunit/code-coverage-block.js
@@ -0,0 +1,83 @@
+// 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
+
+// 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");
+}
+
+%DebugToggleBlockCoverage(true);
+
+TestCoverage(
+"call an IIFE",
+`
+(function f() {})();
+`,
+[{"start":0,"end":20,"count":1},{"start":1,"end":16,"count":1}]
+);
+
+TestCoverage(
+"call locally allocated function",
+`
+for (var i = 0; i < 10; i++) {
+ let f = () => 1;
+ i += f();
+}
+`,
+[{"start":0,"end":63,"count":1},{"start":41,"end":48,"count":5}]
+);
+
+TestCoverage(
+"if statements",
+`
+function g() {}
+function f(x) {
+ if (x == 42) {
+ if (x == 43) g(); else g();
+ }
+ if (x == 42) { g(); } else { g(); }
+ if (x == 42) g(); else g();
+ if (false) g(); else g();
+ if (false) g();
+ if (true) g(); else g();
+ if (true) g();
+}
+f(42);
+f(43);
+`,
+[{"start":0,"end":258,"count":1},
+ {"start":0,"end":15,"count":11},
+ {"start":16,"end":244,"count":2},
+ {"start":45,"end":83,"count":1},
+ {"start":64,"end":69,"count":0},
+ {"start":71,"end":79,"count":1},
+ {"start":98,"end":107,"count":1},
+ {"start":109,"end":121,"count":1},
+ {"start":136,"end":141,"count":1},
+ {"start":143,"end":151,"count":1},
+ {"start":164,"end":169,"count":0},
+ {"start":171,"end":179,"count":2},
+ {"start":192,"end":197,"count":0},
+ {"start":209,"end":214,"count":2},
+ {"start":216,"end":224,"count":0},
+ {"start":236,"end":241,"count":2}]
+);
+
+%DebugToggleBlockCoverage(false);
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698