Bug 1471573 - Support resetting/dumping coverage counters for mochitest. r=jmaher

--HG--
extra : rebase_source : e8f3a47f6b9abc0a9c8cc48e4683a8e5ed5cc605
This commit is contained in:
Marco Castelluccio 2018-06-27 17:56:09 +01:00
parent 193c9c5524
commit 3ffc5f5666
3 changed files with 17 additions and 2 deletions

View File

@ -423,6 +423,7 @@ function Tester(aTests, structuredLogger, aCallback) {
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();
@ -501,6 +502,8 @@ Tester.prototype = {
this._coverageCollector = new CoverageCollector(coveragePath);
}
this.PerTestCoverageUtils.beforeTestSync();
this.structuredLogger.info("*** Start BrowserChrome Test Results ***");
Services.console.registerListener(this);
this._globalProperties = Object.keys(window);
@ -690,6 +693,8 @@ Tester.prototype = {
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;

View File

@ -365,6 +365,10 @@ TestRunner.runTests = function (/*url...*/) {
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;
@ -529,6 +533,10 @@ TestRunner.testFinished = function(tests) {
coverageCollector.recordTestCoverage(TestRunner.currentTestURL);
}
let dumped = false;
SpecialPowers.requestDumpCoverageCounters(() => dumped = true);
SpecialPowers.Services.tm.spinEventLoopUntil(() => dumped);
TestRunner._lastTestFinished = TestRunner._currentTest;
TestRunner._loopIsRestarting = false;

View File

@ -891,9 +891,11 @@ class DesktopUnittest(TestingMixin, MercurialScript, MozbaseMixin,
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'],