Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1164218 - Allow running individual mochitests and reftests in cha…
Browse files Browse the repository at this point in the history
…os mode. r=roc,froydnj
  • Loading branch information
staktrace committed Jun 4, 2015
1 parent fee329a commit 8621efd
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 5 deletions.
17 changes: 17 additions & 0 deletions dom/base/nsDOMWindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "nsJSEnvironment.h"
#include "nsJSUtils.h"

#include "mozilla/ChaosMode.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/MiscEvents.h"
#include "mozilla/MouseEvents.h"
Expand Down Expand Up @@ -3776,6 +3777,22 @@ nsDOMWindowUtils::GetServiceWorkersTestingEnabled(bool *aEnabled)
return NS_OK;
}

NS_IMETHODIMP
nsDOMWindowUtils::EnterChaosMode()
{
MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
ChaosMode::enterChaosMode();
return NS_OK;
}

NS_IMETHODIMP
nsDOMWindowUtils::LeaveChaosMode()
{
MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
ChaosMode::leaveChaosMode();
return NS_OK;
}

NS_INTERFACE_MAP_BEGIN(nsTranslationNodeList)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsITranslationNodeList)
Expand Down
15 changes: 14 additions & 1 deletion dom/interfaces/base/nsIDOMWindowUtils.idl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest;
interface nsIObserver;

[scriptable, uuid(7719798a-62fa-4dff-a6ed-782256649232)]
[scriptable, uuid(098d9f0d-7809-4d3c-8fc6-e5b3fb71835b)]
interface nsIDOMWindowUtils : nsISupports {

/**
Expand Down Expand Up @@ -1812,6 +1812,19 @@ interface nsIDOMWindowUtils : nsISupports {
* Enable some service workers testing features.
*/
attribute boolean serviceWorkersTestingEnabled;

/**
* Increase the chaos mode activation level. An equivalent number of
* calls to leaveChaosMode must be made in order to restore the original
* chaos mode state. If the activation level is nonzero all chaos mode
* features are activated.
*/
void enterChaosMode();

/**
* Decrease the chaos mode activation level. See enterChaosMode().
*/
void leaveChaosMode();
};

[scriptable, uuid(c694e359-7227-4392-a138-33c0cc1f15a6)]
Expand Down
21 changes: 17 additions & 4 deletions layout/tools/reftest/reftest.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,9 @@ function ReadManifest(aURL, inherited_status)
var refPrefSettings = defaultRefPrefSettings.concat();
var fuzzy_max_delta = 2;
var fuzzy_max_pixels = 1;
var chaosMode = false;

while (items[0].match(/^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|test-pref|ref-pref|fuzzy)/)) {
while (items[0].match(/^(fails|needs-focus|random|skip|asserts|slow|require-or|silentfail|pref|test-pref|ref-pref|fuzzy|chaos-mode)/)) {
var item = items.shift();
var stat;
var cond;
Expand Down Expand Up @@ -965,6 +966,9 @@ function ReadManifest(aURL, inherited_status)
fuzzy_max_delta = Number(m[2]);
fuzzy_max_pixels = Number(m[3]);
}
} else if (item == "chaos-mode") {
cond = false;
chaosMode = true;
} else {
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": unexpected item " + item;
}
Expand Down Expand Up @@ -1053,7 +1057,8 @@ function ReadManifest(aURL, inherited_status)
fuzzyMaxDelta: fuzzy_max_delta,
fuzzyMaxPixels: fuzzy_max_pixels,
url1: testURI,
url2: null });
url2: null,
chaosMode: chaosMode });
} else if (items[0] == TYPE_SCRIPT) {
if (items.length != 2)
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": incorrect number of arguments to script";
Expand All @@ -1079,7 +1084,8 @@ function ReadManifest(aURL, inherited_status)
fuzzyMaxDelta: fuzzy_max_delta,
fuzzyMaxPixels: fuzzy_max_pixels,
url1: testURI,
url2: null });
url2: null,
chaosMode: chaosMode });
} else if (items[0] == TYPE_REFTEST_EQUAL || items[0] == TYPE_REFTEST_NOTEQUAL) {
if (items.length != 3)
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": incorrect number of arguments to " + items[0];
Expand Down Expand Up @@ -1108,7 +1114,8 @@ function ReadManifest(aURL, inherited_status)
fuzzyMaxDelta: fuzzy_max_delta,
fuzzyMaxPixels: fuzzy_max_pixels,
url1: testURI,
url2: refURI });
url2: refURI,
chaosMode: chaosMode });
} else {
throw "Error in manifest file " + aURL.spec + " line " + lineNo + ": unknown test type " + items[0];
}
Expand Down Expand Up @@ -1242,6 +1249,9 @@ function StartCurrentTest()
}
else {
gDumpLog("REFTEST TEST-START | " + gURLs[0].prettyPath + "\n");
if (gURLs[0].chaosMode) {
gWindowUtils.enterChaosMode();
}
if (!gURLs[0].needsFocus) {
Blur();
}
Expand Down Expand Up @@ -1863,6 +1873,9 @@ function DoAssertionCheck(numAsserts)
}
}

if (gURLs[0].chaosMode) {
gWindowUtils.leaveChaosMode();
}
gDumpLog("REFTEST TEST-END | " + gURLs[0].prettyPath + "\n");

// And start the next test.
Expand Down
15 changes: 15 additions & 0 deletions mfbt/ChaosMode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/ChaosMode.h"

namespace mozilla {
namespace detail {

Atomic<uint32_t> gChaosModeCounter(0);

} /* namespace detail */
} /* namespace mozilla */
28 changes: 28 additions & 0 deletions mfbt/ChaosMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
#ifndef mozilla_ChaosMode_h
#define mozilla_ChaosMode_h

#include "mozilla/Atomics.h"
#include "mozilla/EnumSet.h"

#include <stdint.h>
#include <stdlib.h>

namespace mozilla {

namespace detail {
extern MFBT_DATA Atomic<uint32_t> gChaosModeCounter;
}

/**
* When "chaos mode" is activated, code that makes implicitly nondeterministic
* choices is encouraged to make random and extreme choices, to test more
Expand Down Expand Up @@ -44,9 +49,32 @@ class ChaosMode
public:
static bool isActive(ChaosFeature aFeature)
{
if (detail::gChaosModeCounter > 0) {
return true;
}
return sChaosFeatures & aFeature;
}

/**
* Increase the chaos mode activation level. An equivalent number of
* calls to leaveChaosMode must be made in order to restore the original
* chaos mode state. If the activation level is nonzero all chaos mode
* features are activated.
*/
static void enterChaosMode()
{
detail::gChaosModeCounter++;
}

/**
* Decrease the chaos mode activation level. See enterChaosMode().
*/
static void leaveChaosMode()
{
MOZ_ASSERT(detail::gChaosModeCounter > 0);
detail::gChaosModeCounter--;
}

/**
* Returns a somewhat (but not uniformly) random uint32_t < aBound.
* Not to be used for anything except ChaosMode, since it's not very random.
Expand Down
1 change: 1 addition & 0 deletions mfbt/objs.mozbuild
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

mfbt_src_lcppsrcs = [
'ChaosMode.cpp',
'double-conversion/bignum-dtoa.cc',
'double-conversion/bignum.cc',
'double-conversion/cached-powers.cc',
Expand Down
15 changes: 15 additions & 0 deletions testing/mochitest/tests/SimpleTest/SimpleTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ SimpleTest._stopOnLoad = true;
SimpleTest._cleanupFunctions = [];
SimpleTest.expected = 'pass';
SimpleTest.num_failed = 0;
SimpleTest._inChaosMode = false;

SimpleTest.setExpected = function () {
if (parent.TestRunner) {
Expand Down Expand Up @@ -992,6 +993,15 @@ SimpleTest.registerCleanupFunction = function(aFunc) {
SimpleTest._cleanupFunctions.push(aFunc);
};

SimpleTest.testInChaosMode = function() {
if (SimpleTest._inChaosMode) {
// It's already enabled for this test, don't enter twice
return;
}
SpecialPowers.DOMWindowUtils.enterChaosMode();
SimpleTest._inChaosMode = true;
};

/**
* Finishes the tests. This is automatically called, except when
* SimpleTest.waitForExplicitFinish() has been invoked.
Expand Down Expand Up @@ -1020,6 +1030,11 @@ SimpleTest.finish = function() {

SimpleTest._alreadyFinished = true;

if (SimpleTest._inChaosMode) {
SpecialPowers.DOMWindowUtils.leaveChaosMode();
SimpleTest._inChaosMode = false;
}

var afterCleanup = function() {
if (SpecialPowers.DOMWindowUtils.isTestControllingRefreshes) {
SimpleTest.ok(false, "test left refresh driver under test control");
Expand Down

0 comments on commit 8621efd

Please sign in to comment.