| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/test/test_timeouts.h" | 5 #include "base/test/test_timeouts.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/test/test_switches.h" | 10 #include "base/test/test_switches.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // ASan and TSan instrument each memory access. This may slow the execution | 14 // ASan and TSan instrument each memory access. This may slow the execution |
| 15 // down significantly. | 15 // down significantly. |
| 16 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) | 16 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) |
| 17 static const int kTimeoutMultiplier = 2; | 17 static const int kTimeoutMultiplier = 2; |
| 18 #else | 18 #else |
| 19 static const int kTimeoutMultiplier = 1; | 19 static const int kTimeoutMultiplier = 1; |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 // Sets value to the greatest of: | 22 // Sets value to the greatest of: |
| 23 // 1) value's current value multiplied by kTimeoutMultiplier (assuming | 23 // 1) value's current value multiplied by kTimeoutMultiplier (assuming |
| 24 // InitializeTimeout is called only once per value). | 24 // InitializeTimeout is called only once per value). |
| 25 // 2) min_value. | 25 // 2) min_value. |
| 26 // 3) the numerical value given by switch_name on the command line multiplied | 26 // 3) the numerical value given by switch_name on the command line multiplied |
| 27 // by kTimeoutMultiplier. | 27 // by kTimeoutMultiplier. |
| 28 void InitializeTimeout(const char* switch_name, int min_value, int* value) { | 28 void InitializeTimeout(const std::string& switch_name, |
| 29 int min_value, |
| 30 int* value) { |
| 29 DCHECK(value); | 31 DCHECK(value); |
| 30 if (CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { | 32 if (CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { |
| 31 std::string string_value( | 33 std::string string_value( |
| 32 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name)); | 34 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name)); |
| 33 int timeout; | 35 int timeout; |
| 34 base::StringToInt(string_value, &timeout); | 36 base::StringToInt(string_value, &timeout); |
| 35 *value = std::max(*value, timeout); | 37 *value = std::max(*value, timeout); |
| 36 } | 38 } |
| 37 *value *= kTimeoutMultiplier; | 39 *value *= kTimeoutMultiplier; |
| 38 *value = std::max(*value, min_value); | 40 *value = std::max(*value, min_value); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_, | 81 InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_, |
| 80 &action_max_timeout_ms_); | 82 &action_max_timeout_ms_); |
| 81 InitializeTimeout(switches::kTestLargeTimeout, action_max_timeout_ms_, | 83 InitializeTimeout(switches::kTestLargeTimeout, action_max_timeout_ms_, |
| 82 &large_test_timeout_ms_); | 84 &large_test_timeout_ms_); |
| 83 | 85 |
| 84 // The timeout values should be increasing in the right order. | 86 // The timeout values should be increasing in the right order. |
| 85 CHECK(tiny_timeout_ms_ <= action_timeout_ms_); | 87 CHECK(tiny_timeout_ms_ <= action_timeout_ms_); |
| 86 CHECK(action_timeout_ms_ <= action_max_timeout_ms_); | 88 CHECK(action_timeout_ms_ <= action_max_timeout_ms_); |
| 87 CHECK(action_max_timeout_ms_ <= large_test_timeout_ms_); | 89 CHECK(action_max_timeout_ms_ <= large_test_timeout_ms_); |
| 88 } | 90 } |
| OLD | NEW |