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"
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;
19 static const int kTimeoutMultiplier
= 1;
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).
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
) {
30 if (CommandLine::ForCurrentProcess()->HasSwitch(switch_name
)) {
31 std::string
string_value(
32 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name
));
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.
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
);
53 bool TestTimeouts::initialized_
= false;
55 // The timeout values should increase in the order they appear in this block.
57 int TestTimeouts::tiny_timeout_ms_
= 100;
58 int TestTimeouts::action_timeout_ms_
= 10000;
60 int TestTimeouts::action_max_timeout_ms_
= 45000;
62 int TestTimeouts::action_max_timeout_ms_
= 30000;
64 int TestTimeouts::large_test_timeout_ms_
= 10 * 60 * 1000;
67 void TestTimeouts::Initialize() {
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_
,
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_
);