michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_ChaosMode_h michael@0: #define mozilla_ChaosMode_h michael@0: michael@0: #include michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: michael@0: /** michael@0: * When "chaos mode" is activated, code that makes implicitly nondeterministic michael@0: * choices is encouraged to make random and extreme choices, to test more michael@0: * code paths and uncover bugs. michael@0: */ michael@0: class ChaosMode michael@0: { michael@0: public: michael@0: static bool isActive() michael@0: { michael@0: // Flip this to true to activate chaos mode michael@0: return false; michael@0: } michael@0: michael@0: /** michael@0: * Returns a somewhat (but not uniformly) random uint32_t < aBound. michael@0: * Not to be used for anything except ChaosMode, since it's not very random. michael@0: */ michael@0: static uint32_t randomUint32LessThan(uint32_t aBound) michael@0: { michael@0: return uint32_t(rand()) % aBound; michael@0: } michael@0: }; michael@0: michael@0: } /* namespace mozilla */ michael@0: michael@0: #endif /* mozilla_ChaosMode_h */