Bug 1471573 - Support resetting/dumping coverage counters for mochitest. r=jmaher
☠☠ backed out by 7a80adc796d7 ☠ ☠
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Wed, 27 Jun 2018 17:56:09 +0100
changeset 425027 0903f7dc6c7f3d7f10fec403d2ebee470e887876
parent 425026 eb34fd6b8ce3b9e9fdf8d4610530b7d6ec693765
child 425028 5019176ab037fe17b5eb38e6cbb08f562fc102c0
push id34232
push userrgurzau@mozilla.com
push dateWed, 04 Jul 2018 16:30:38 +0000
treeherdermozilla-central@6c0fa9a675c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1471573
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1471573 - Support resetting/dumping coverage counters for mochitest. r=jmaher
testing/mochitest/browser-test.js
testing/mochitest/tests/SimpleTest/TestRunner.js
testing/mozharness/scripts/desktop_unittest.py
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -418,16 +418,17 @@ function Tester(aTests, structuredLogger
 
   this.MemoryStats = simpleTestScope.MemoryStats;
   this.ContentTask = ChromeUtils.import("resource://testing-common/ContentTask.jsm", null).ContentTask;
   this.BrowserTestUtils = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm", null).BrowserTestUtils;
   this.TestUtils = ChromeUtils.import("resource://testing-common/TestUtils.jsm", null).TestUtils;
   this.Promise = ChromeUtils.import("resource://gre/modules/Promise.jsm", null).Promise;
   this.PromiseTestUtils = ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", null).PromiseTestUtils;
   this.Assert = ChromeUtils.import("resource://testing-common/Assert.jsm", null).Assert;
+  this.PerTestCoverageUtils = ChromeUtils.import("resource://testing-common/PerTestCoverageUtils.jsm", null).PerTestCoverageUtils;
 
   this.PromiseTestUtils.init();
 
   this.SimpleTestOriginal = {};
   SIMPLETEST_OVERRIDES.forEach(m => {
     this.SimpleTestOriginal[m] = this.SimpleTest[m];
   });
 
@@ -496,16 +497,18 @@ Tester.prototype = {
 
     if (gConfig.jscovDirPrefix) {
       let coveragePath = gConfig.jscovDirPrefix;
       let {CoverageCollector} = ChromeUtils.import("resource://testing-common/CoverageUtils.jsm",
                                                    {});
       this._coverageCollector = new CoverageCollector(coveragePath);
     }
 
+    this.PerTestCoverageUtils.beforeTestSync();
+
     this.structuredLogger.info("*** Start BrowserChrome Test Results ***");
     Services.console.registerListener(this);
     this._globalProperties = Object.keys(window);
     this._globalPropertyWhitelist = [
       "navigator", "constructor", "top",
       "Application",
       "__SS_tabsToRestore", "__SSi",
       "webConsoleCommandController",
@@ -685,16 +688,18 @@ Tester.prototype = {
   },
 
   async nextTest() {
     if (this.currentTest) {
       if (this._coverageCollector) {
         this._coverageCollector.recordTestCoverage(this.currentTest.path);
       }
 
+      this.PerTestCoverageUtils.afterTestSync();
+
       // Run cleanup functions for the current test before moving on to the
       // next one.
       let testScope = this.currentTest.scope;
       while (testScope.__cleanupFunctions.length > 0) {
         let func = testScope.__cleanupFunctions.shift();
         try {
           let result = await func.apply(testScope);
           if (isGenerator(result)) {
--- a/testing/mochitest/tests/SimpleTest/TestRunner.js
+++ b/testing/mochitest/tests/SimpleTest/TestRunner.js
@@ -360,16 +360,20 @@ TestRunner.runTests = function (/*url...
     SpecialPowers.registerProcessCrashObservers();
 
     // Initialize code coverage
     if (TestRunner.jscovDirPrefix != "") {
         var CoverageCollector = SpecialPowers.Cu.import("resource://testing-common/CoverageUtils.jsm", {}).CoverageCollector;
         coverageCollector = new CoverageCollector(TestRunner.jscovDirPrefix);
     }
 
+    let reset = false;
+    SpecialPowers.requestResetCoverageCounters(() => reset = true);
+    SpecialPowers.Services.tm.spinEventLoopUntil(() => reset);
+
     TestRunner._urls = flattenArguments(arguments);
 
     var singleTestRun = this._urls.length <= 1 && TestRunner.repeat <= 1;
     TestRunner.showTestReport = singleTestRun;
     var frame = $('testframe');
     frame.src = "";
     if (singleTestRun) {
         // Can't use document.body because this runs in a XUL doc as well...
@@ -524,16 +528,20 @@ TestRunner.testFinished = function(tests
         TestRunner.updateUI([{ result: false }]);
         return;
     }
 
     if (TestRunner.jscovDirPrefix != "") {
         coverageCollector.recordTestCoverage(TestRunner.currentTestURL);
     }
 
+    let dumped = false;
+    SpecialPowers.requestDumpCoverageCounters(() => dumped = true);
+    SpecialPowers.Services.tm.spinEventLoopUntil(() => dumped);
+
     TestRunner._lastTestFinished = TestRunner._currentTest;
     TestRunner._loopIsRestarting = false;
 
     // TODO : replace this by a function that returns the mem data as an object
     // that's dumped later with the test_end message
     MemoryStats.dump(TestRunner._currentTest,
                      TestRunner.currentTestURL,
                      TestRunner.dumpOutputDirectory,
--- a/testing/mozharness/scripts/desktop_unittest.py
+++ b/testing/mozharness/scripts/desktop_unittest.py
@@ -886,19 +886,21 @@ class DesktopUnittest(TestingMixin, Merc
 
                         executed_tests = executed_tests + 1
 
                     final_cmd = copy.copy(cmd)
                     final_cmd.extend(per_test_args)
 
                     if self.per_test_coverage:
                         gcov_dir, jsvm_dir = self.set_coverage_env(env)
-                        # Per-test reset/dump is only supported for xpcshell and
+                        # Per-test reset/dump is only supported for xpcshell/mochitest and
                         # Linux for the time being.
-                        if not is_baseline_test and suite == 'xpcshell' and self._is_linux():
+                        if not is_baseline_test and \
+                           suite_category in ['mochitest', 'xpcshell'] and \
+                           self._is_linux():
                             env['GCOV_RESULTS_DIR'] = tempfile.mkdtemp()
 
                     return_code = self.run_command(final_cmd, cwd=dirs['abs_work_dir'],
                                                    output_timeout=cmd_timeout,
                                                    output_parser=parser,
                                                    env=env)
 
                     if self.per_test_coverage: