Bug 955888. Part 1: Add ChaosMode.h base functionality. r=waldo
authorRobert O'Callahan <robert@ocallahan.org>
Mon, 03 Mar 2014 18:12:17 +1300
changeset 172650 f656d2fd42644436d984504570af35e6d57bc5ec
parent 172649 7fec954d58b650fedc8c39c5db83f754d65821b6
child 172651 4d971e595980f6bce7155357d61f526f79448bfa
push id40796
push userrocallahan@mozilla.com
push dateSat, 08 Mar 2014 23:38:58 +0000
treeherdermozilla-inbound@c7d86e2ddfea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs955888
milestone30.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 955888. Part 1: Add ChaosMode.h base functionality. r=waldo
mfbt/ChaosMode.h
mfbt/moz.build
new file mode 100644
--- /dev/null
+++ b/mfbt/ChaosMode.h
@@ -0,0 +1,41 @@
+/* -*- 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/. */
+
+#ifndef mozilla_ChaosMode_h
+#define mozilla_ChaosMode_h
+
+#include <stdint.h>
+#include <stdlib.h>
+
+namespace mozilla {
+
+/**
+ * When "chaos mode" is activated, code that makes implicitly nondeterministic
+ * choices is encouraged to make random and extreme choices, to test more
+ * code paths and uncover bugs.
+ */
+class ChaosMode
+{
+  public:
+    static bool isActive()
+    {
+      // Flip this to true to activate chaos mode
+      return false;
+    }
+
+    /**
+     * Returns a somewhat (but not uniformly) random uint32_t < aBound.
+     * Not to be used for anything except ChaosMode, since it's not very random.
+     */
+    static uint32_t randomUint32LessThan(uint32_t aBound)
+    {
+      return uint32_t(rand()) % aBound;
+    }
+};
+
+} /* namespace mozilla */
+
+#endif /* mozilla_ChaosMode_h */
--- a/mfbt/moz.build
+++ b/mfbt/moz.build
@@ -13,16 +13,17 @@ EXPORTS.mozilla = [
     'AllocPolicy.h',
     'Array.h',
     'ArrayUtils.h',
     'Assertions.h',
     'Atomics.h',
     'Attributes.h',
     'BloomFilter.h',
     'Casting.h',
+    'ChaosMode.h',
     'Char16.h',
     'CheckedInt.h',
     'Compiler.h',
     'Compression.h',
     'Constants.h',
     'DebugOnly.h',
     'decimal/Decimal.h',
     'Endian.h',