sergeyu@chromium.org | 0f6abbc | 2010-10-06 04:03:05 +0900 | [diff] [blame^] | 1 | // Copyright (c) 2010 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. |
| 4 | |
| 5 | #include "base/test/test_timeouts.h" |
| 6 | |
| 7 | #include "base/command_line.h" |
| 8 | #include "base/logging.h" |
| 9 | #include "base/string_number_conversions.h" |
| 10 | #include "base/test/test_switches.h" |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | // Sets value to the greatest of: |
| 15 | // 1) value's current value. |
| 16 | // 2) min_value. |
| 17 | // 3) the numerical value given by switch_name on the command line. |
| 18 | void InitializeTimeout(const char* switch_name, int min_value, int* value) { |
| 19 | DCHECK(value); |
| 20 | if (CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { |
| 21 | std::string string_value( |
| 22 | CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name)); |
| 23 | int timeout; |
| 24 | base::StringToInt(string_value, &timeout); |
| 25 | *value = std::max(*value, timeout); |
| 26 | } |
| 27 | *value = std::max(*value, min_value); |
| 28 | } |
| 29 | |
| 30 | // Sets value to the greatest of: |
| 31 | // 1) value's current value. |
| 32 | // 2) 0 |
| 33 | // 3) the numerical value given by switch_name on the command line. |
| 34 | void InitializeTimeout(const char* switch_name, int* value) { |
| 35 | InitializeTimeout(switch_name, 0, value); |
| 36 | } |
| 37 | |
| 38 | } // namespace |
| 39 | |
| 40 | // static |
| 41 | bool TestTimeouts::initialized_ = false; |
| 42 | |
| 43 | // The timeout values should increase in the order they appear in this block. |
| 44 | // static |
| 45 | int TestTimeouts::action_timeout_ms_ = 2000; |
| 46 | int TestTimeouts::action_max_timeout_ms_ = 15000; |
| 47 | int TestTimeouts::large_test_timeout_ms_ = 3 * 60 * 1000; |
| 48 | int TestTimeouts::huge_test_timeout_ms_ = 10 * 60 * 1000; |
| 49 | |
| 50 | // static |
| 51 | int TestTimeouts::command_execution_timeout_ms_ = 25000; |
| 52 | |
| 53 | // static |
| 54 | int TestTimeouts::wait_for_terminate_timeout_ms_ = 15000; |
| 55 | |
| 56 | // static |
| 57 | int TestTimeouts::live_operation_timeout_ms_ = 30000; |
| 58 | |
| 59 | // static |
| 60 | void TestTimeouts::Initialize() { |
| 61 | if (initialized_) { |
| 62 | NOTREACHED(); |
| 63 | return; |
| 64 | } |
| 65 | initialized_ = true; |
| 66 | |
| 67 | // Note that these timeouts MUST be initialized in the correct order as |
| 68 | // per the CHECKS below. |
| 69 | InitializeTimeout(switches::kUiTestActionTimeout, &action_timeout_ms_); |
| 70 | InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_, |
| 71 | &action_max_timeout_ms_); |
| 72 | InitializeTimeout(switches::kTestLargeTimeout, action_max_timeout_ms_, |
| 73 | &large_test_timeout_ms_); |
| 74 | InitializeTimeout(switches::kUiTestTimeout, large_test_timeout_ms_, |
| 75 | &huge_test_timeout_ms_); |
| 76 | |
| 77 | // The timeout values should be increasing in the right order. |
| 78 | CHECK(action_timeout_ms_ <= action_max_timeout_ms_); |
| 79 | CHECK(action_max_timeout_ms_ <= large_test_timeout_ms_); |
| 80 | CHECK(large_test_timeout_ms_ <= huge_test_timeout_ms_); |
| 81 | |
| 82 | InitializeTimeout(switches::kUiTestCommandExecutionTimeout, |
| 83 | &command_execution_timeout_ms_); |
| 84 | InitializeTimeout(switches::kUiTestTerminateTimeout, |
| 85 | &wait_for_terminate_timeout_ms_); |
| 86 | |
| 87 | InitializeTimeout(switches::kLiveOperationTimeout, |
| 88 | &live_operation_timeout_ms_); |
| 89 | } |