[email protected] | 536a17e4 | 2011-04-11 22:14:29 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cbb9f50f | 2010-10-05 19:03:05 | [diff] [blame] | 5 | #include "base/test/test_timeouts.h" |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 6 | |
[email protected] | c56bef4d | 2013-10-15 20:29:03 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 9 | #include "base/command_line.h" |
[email protected] | 7f0aac7c | 2013-07-24 19:34:04 | [diff] [blame] | 10 | #include "base/debug/debugger.h" |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 11 | #include "base/logging.h" |
[email protected] | dfa049e | 2013-02-07 02:57:22 | [diff] [blame] | 12 | #include "base/strings/string_number_conversions.h" |
[email protected] | cbb9f50f | 2010-10-05 19:03:05 | [diff] [blame] | 13 | #include "base/test/test_switches.h" |
avi | d351e5a | 2015-12-24 03:28:02 | [diff] [blame] | 14 | #include "build/build_config.h" |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 15 | |
| 16 | namespace { |
| 17 | |
[email protected] | 14ef813 | 2014-06-16 14:24:28 | [diff] [blame] | 18 | // ASan/TSan/MSan instrument each memory access. This may slow the execution |
[email protected] | f6eea35 | 2013-04-19 12:56:51 | [diff] [blame] | 19 | // down significantly. |
[email protected] | 3a8b838 | 2014-06-17 13:53:57 | [diff] [blame] | 20 | #if defined(MEMORY_SANITIZER) |
[email protected] | 9a3fa07 | 2014-07-28 11:45:16 | [diff] [blame] | 21 | // For MSan the slowdown depends heavily on the value of msan_track_origins GYP |
| 22 | // flag. The multiplier below corresponds to msan_track_origins=1. |
| 23 | static const int kTimeoutMultiplier = 6; |
Nico Weber | 68fb026 | 2014-09-09 19:58:17 | [diff] [blame] | 24 | #elif defined(ADDRESS_SANITIZER) && defined(OS_WIN) |
| 25 | // Asan/Win has not been optimized yet, give it a higher |
| 26 | // timeout multiplier. See http://crbug.com/412471 |
thakis | 1fba5a6 | 2015-01-15 18:17:57 | [diff] [blame] | 27 | static const int kTimeoutMultiplier = 3; |
[email protected] | 3a8b838 | 2014-06-17 13:53:57 | [diff] [blame] | 28 | #elif defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| 29 | defined(SYZYASAN) |
[email protected] | e5135dac | 2012-06-04 13:15:28 | [diff] [blame] | 30 | static const int kTimeoutMultiplier = 2; |
[email protected] | 29cd978 | 2011-11-15 08:43:28 | [diff] [blame] | 31 | #else |
| 32 | static const int kTimeoutMultiplier = 1; |
| 33 | #endif |
| 34 | |
[email protected] | 7f0aac7c | 2013-07-24 19:34:04 | [diff] [blame] | 35 | const int kAlmostInfiniteTimeoutMs = 100000000; |
| 36 | |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 37 | // Sets value to the greatest of: |
[email protected] | 29cd978 | 2011-11-15 08:43:28 | [diff] [blame] | 38 | // 1) value's current value multiplied by kTimeoutMultiplier (assuming |
| 39 | // InitializeTimeout is called only once per value). |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 40 | // 2) min_value. |
[email protected] | 29cd978 | 2011-11-15 08:43:28 | [diff] [blame] | 41 | // 3) the numerical value given by switch_name on the command line multiplied |
| 42 | // by kTimeoutMultiplier. |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 43 | void InitializeTimeout(const char* switch_name, int min_value, int* value) { |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 44 | DCHECK(value); |
pgal.u-szeged | 421dddb | 2014-11-25 12:55:02 | [diff] [blame] | 45 | if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { |
| 46 | std::string string_value(base::CommandLine::ForCurrentProcess()-> |
| 47 | GetSwitchValueASCII(switch_name)); |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 48 | int timeout; |
| 49 | base::StringToInt(string_value, &timeout); |
| 50 | *value = std::max(*value, timeout); |
| 51 | } |
[email protected] | 29cd978 | 2011-11-15 08:43:28 | [diff] [blame] | 52 | *value *= kTimeoutMultiplier; |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 53 | *value = std::max(*value, min_value); |
| 54 | } |
| 55 | |
| 56 | // Sets value to the greatest of: |
[email protected] | 29cd978 | 2011-11-15 08:43:28 | [diff] [blame] | 57 | // 1) value's current value multiplied by kTimeoutMultiplier. |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 58 | // 2) 0 |
[email protected] | 29cd978 | 2011-11-15 08:43:28 | [diff] [blame] | 59 | // 3) the numerical value given by switch_name on the command line multiplied |
| 60 | // by kTimeoutMultiplier. |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 61 | void InitializeTimeout(const char* switch_name, int* value) { |
| 62 | InitializeTimeout(switch_name, 0, value); |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } // namespace |
| 66 | |
| 67 | // static |
| 68 | bool TestTimeouts::initialized_ = false; |
| 69 | |
| 70 | // The timeout values should increase in the order they appear in this block. |
| 71 | // static |
[email protected] | 32ba25f8 | 2010-12-16 18:49:52 | [diff] [blame] | 72 | int TestTimeouts::tiny_timeout_ms_ = 100; |
[email protected] | cef642e | 2011-09-12 16:51:30 | [diff] [blame] | 73 | int TestTimeouts::action_timeout_ms_ = 10000; |
[email protected] | 343a30b | 2013-06-12 16:40:16 | [diff] [blame] | 74 | #ifndef NDEBUG |
| 75 | int TestTimeouts::action_max_timeout_ms_ = 45000; |
| 76 | #else |
[email protected] | 5def54a | 2012-11-28 18:07:01 | [diff] [blame] | 77 | int TestTimeouts::action_max_timeout_ms_ = 30000; |
[email protected] | 343a30b | 2013-06-12 16:40:16 | [diff] [blame] | 78 | #endif // NDEBUG |
[email protected] | 45e4701d3 | 2010-09-15 00:16:23 | [diff] [blame] | 79 | |
[email protected] | b7be8b27 | 2013-11-23 02:01:04 | [diff] [blame] | 80 | int TestTimeouts::test_launcher_timeout_ms_ = 45000; |
[email protected] | 616965f | 2013-09-24 17:00:14 | [diff] [blame] | 81 | |
[email protected] | 45e4701d3 | 2010-09-15 00:16:23 | [diff] [blame] | 82 | // static |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 83 | void TestTimeouts::Initialize() { |
| 84 | if (initialized_) { |
| 85 | NOTREACHED(); |
| 86 | return; |
| 87 | } |
| 88 | initialized_ = true; |
| 89 | |
[email protected] | 7f0aac7c | 2013-07-24 19:34:04 | [diff] [blame] | 90 | if (base::debug::BeingDebugged()) { |
| 91 | fprintf(stdout, |
| 92 | "Detected presence of a debugger, running without test timeouts.\n"); |
| 93 | } |
| 94 | |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 95 | // Note that these timeouts MUST be initialized in the correct order as |
| 96 | // per the CHECKS below. |
[email protected] | 32ba25f8 | 2010-12-16 18:49:52 | [diff] [blame] | 97 | InitializeTimeout(switches::kTestTinyTimeout, &tiny_timeout_ms_); |
[email protected] | 7f0aac7c | 2013-07-24 19:34:04 | [diff] [blame] | 98 | InitializeTimeout(switches::kUiTestActionTimeout, |
| 99 | base::debug::BeingDebugged() ? kAlmostInfiniteTimeoutMs |
| 100 | : tiny_timeout_ms_, |
[email protected] | 32ba25f8 | 2010-12-16 18:49:52 | [diff] [blame] | 101 | &action_timeout_ms_); |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 102 | InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_, |
| 103 | &action_max_timeout_ms_); |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 104 | |
[email protected] | 616965f | 2013-09-24 17:00:14 | [diff] [blame] | 105 | // Test launcher timeout is independent from anything above action timeout. |
phajdan.jr | 5f0e5ec08 | 2014-08-25 15:11:27 | [diff] [blame] | 106 | InitializeTimeout(switches::kTestLauncherTimeout, action_timeout_ms_, |
[email protected] | 616965f | 2013-09-24 17:00:14 | [diff] [blame] | 107 | &test_launcher_timeout_ms_); |
| 108 | |
[email protected] | 78859c7 | 2010-09-21 17:44:21 | [diff] [blame] | 109 | // The timeout values should be increasing in the right order. |
[email protected] | 32ba25f8 | 2010-12-16 18:49:52 | [diff] [blame] | 110 | CHECK(tiny_timeout_ms_ <= action_timeout_ms_); |
[email protected] | dabfc50 | 2010-09-16 19:10:39 | [diff] [blame] | 111 | CHECK(action_timeout_ms_ <= action_max_timeout_ms_); |
[email protected] | 616965f | 2013-09-24 17:00:14 | [diff] [blame] | 112 | |
phajdan.jr | 5f0e5ec08 | 2014-08-25 15:11:27 | [diff] [blame] | 113 | CHECK(action_timeout_ms_ <= test_launcher_timeout_ms_); |
[email protected] | c36a87af | 2010-09-10 20:38:41 | [diff] [blame] | 114 | } |