Bluetooth: fix header sentry comment style
[chromium-blink-merge.git] / base / test / test_timeouts.cc
blobe8e4153ffa6991cee628dca3e0fa694143d41ffb
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/test/test_timeouts.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/test/test_switches.h"
12 namespace {
14 // ASan and TSan instrument each memory access. This may slow the execution
15 // down significantly.
16 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER)
17 static const int kTimeoutMultiplier = 2;
18 #else
19 static const int kTimeoutMultiplier = 1;
20 #endif
22 // Sets value to the greatest of:
23 // 1) value's current value multiplied by kTimeoutMultiplier (assuming
24 // InitializeTimeout is called only once per value).
25 // 2) min_value.
26 // 3) the numerical value given by switch_name on the command line multiplied
27 // by kTimeoutMultiplier.
28 void InitializeTimeout(const char* switch_name, int min_value, int* value) {
29 DCHECK(value);
30 if (CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
31 std::string string_value(
32 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name));
33 int timeout;
34 base::StringToInt(string_value, &timeout);
35 *value = std::max(*value, timeout);
37 *value *= kTimeoutMultiplier;
38 *value = std::max(*value, min_value);
41 // Sets value to the greatest of:
42 // 1) value's current value multiplied by kTimeoutMultiplier.
43 // 2) 0
44 // 3) the numerical value given by switch_name on the command line multiplied
45 // by kTimeoutMultiplier.
46 void InitializeTimeout(const char* switch_name, int* value) {
47 InitializeTimeout(switch_name, 0, value);
50 } // namespace
52 // static
53 bool TestTimeouts::initialized_ = false;
55 // The timeout values should increase in the order they appear in this block.
56 // static
57 int TestTimeouts::tiny_timeout_ms_ = 100;
58 int TestTimeouts::action_timeout_ms_ = 10000;
59 #ifndef NDEBUG
60 int TestTimeouts::action_max_timeout_ms_ = 45000;
61 #else
62 int TestTimeouts::action_max_timeout_ms_ = 30000;
63 #endif // NDEBUG
64 int TestTimeouts::large_test_timeout_ms_ = 10 * 60 * 1000;
66 // static
67 void TestTimeouts::Initialize() {
68 if (initialized_) {
69 NOTREACHED();
70 return;
72 initialized_ = true;
74 // Note that these timeouts MUST be initialized in the correct order as
75 // per the CHECKS below.
76 InitializeTimeout(switches::kTestTinyTimeout, &tiny_timeout_ms_);
77 InitializeTimeout(switches::kUiTestActionTimeout, tiny_timeout_ms_,
78 &action_timeout_ms_);
79 InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_,
80 &action_max_timeout_ms_);
81 InitializeTimeout(switches::kTestLargeTimeout, action_max_timeout_ms_,
82 &large_test_timeout_ms_);
84 // The timeout values should be increasing in the right order.
85 CHECK(tiny_timeout_ms_ <= action_timeout_ms_);
86 CHECK(action_timeout_ms_ <= action_max_timeout_ms_);
87 CHECK(action_max_timeout_ms_ <= large_test_timeout_ms_);