blob: 55e9a798613404610c2de68442af2f5911e1d3e0 [file] [log] [blame]
[email protected]536a17e42011-04-11 22:14:291// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]c36a87af2010-09-10 20:38:412// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cbb9f50f2010-10-05 19:03:055#include "base/test/test_timeouts.h"
[email protected]c36a87af2010-09-10 20:38:416
[email protected]c56bef4d2013-10-15 20:29:037#include <algorithm>
8
[email protected]c36a87af2010-09-10 20:38:419#include "base/command_line.h"
[email protected]7f0aac7c2013-07-24 19:34:0410#include "base/debug/debugger.h"
[email protected]c36a87af2010-09-10 20:38:4111#include "base/logging.h"
[email protected]dfa049e2013-02-07 02:57:2212#include "base/strings/string_number_conversions.h"
[email protected]cbb9f50f2010-10-05 19:03:0513#include "base/test/test_switches.h"
avid351e5a2015-12-24 03:28:0214#include "build/build_config.h"
[email protected]c36a87af2010-09-10 20:38:4115
16namespace {
17
[email protected]14ef8132014-06-16 14:24:2818// ASan/TSan/MSan instrument each memory access. This may slow the execution
[email protected]f6eea352013-04-19 12:56:5119// down significantly.
[email protected]3a8b8382014-06-17 13:53:5720#if defined(MEMORY_SANITIZER)
[email protected]9a3fa072014-07-28 11:45:1621// 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.
23static const int kTimeoutMultiplier = 6;
Nico Weber68fb0262014-09-09 19:58:1724#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
thakis1fba5a62015-01-15 18:17:5727static const int kTimeoutMultiplier = 3;
[email protected]3a8b8382014-06-17 13:53:5728#elif defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
29 defined(SYZYASAN)
[email protected]e5135dac2012-06-04 13:15:2830static const int kTimeoutMultiplier = 2;
[email protected]29cd9782011-11-15 08:43:2831#else
32static const int kTimeoutMultiplier = 1;
33#endif
34
[email protected]7f0aac7c2013-07-24 19:34:0435const int kAlmostInfiniteTimeoutMs = 100000000;
36
[email protected]78859c72010-09-21 17:44:2137// Sets value to the greatest of:
[email protected]29cd9782011-11-15 08:43:2838// 1) value's current value multiplied by kTimeoutMultiplier (assuming
39// InitializeTimeout is called only once per value).
[email protected]78859c72010-09-21 17:44:2140// 2) min_value.
[email protected]29cd9782011-11-15 08:43:2841// 3) the numerical value given by switch_name on the command line multiplied
42// by kTimeoutMultiplier.
[email protected]78859c72010-09-21 17:44:2143void InitializeTimeout(const char* switch_name, int min_value, int* value) {
[email protected]c36a87af2010-09-10 20:38:4144 DCHECK(value);
pgal.u-szeged421dddb2014-11-25 12:55:0245 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
46 std::string string_value(base::CommandLine::ForCurrentProcess()->
47 GetSwitchValueASCII(switch_name));
[email protected]c36a87af2010-09-10 20:38:4148 int timeout;
49 base::StringToInt(string_value, &timeout);
50 *value = std::max(*value, timeout);
51 }
[email protected]29cd9782011-11-15 08:43:2852 *value *= kTimeoutMultiplier;
[email protected]78859c72010-09-21 17:44:2153 *value = std::max(*value, min_value);
54}
55
56// Sets value to the greatest of:
[email protected]29cd9782011-11-15 08:43:2857// 1) value's current value multiplied by kTimeoutMultiplier.
[email protected]78859c72010-09-21 17:44:2158// 2) 0
[email protected]29cd9782011-11-15 08:43:2859// 3) the numerical value given by switch_name on the command line multiplied
60// by kTimeoutMultiplier.
[email protected]78859c72010-09-21 17:44:2161void InitializeTimeout(const char* switch_name, int* value) {
62 InitializeTimeout(switch_name, 0, value);
[email protected]c36a87af2010-09-10 20:38:4163}
64
65} // namespace
66
67// static
68bool TestTimeouts::initialized_ = false;
69
70// The timeout values should increase in the order they appear in this block.
71// static
[email protected]32ba25f82010-12-16 18:49:5272int TestTimeouts::tiny_timeout_ms_ = 100;
[email protected]cef642e2011-09-12 16:51:3073int TestTimeouts::action_timeout_ms_ = 10000;
[email protected]343a30b2013-06-12 16:40:1674#ifndef NDEBUG
75int TestTimeouts::action_max_timeout_ms_ = 45000;
76#else
[email protected]5def54a2012-11-28 18:07:0177int TestTimeouts::action_max_timeout_ms_ = 30000;
[email protected]343a30b2013-06-12 16:40:1678#endif // NDEBUG
[email protected]45e4701d32010-09-15 00:16:2379
[email protected]b7be8b272013-11-23 02:01:0480int TestTimeouts::test_launcher_timeout_ms_ = 45000;
[email protected]616965f2013-09-24 17:00:1481
[email protected]45e4701d32010-09-15 00:16:2382// static
[email protected]c36a87af2010-09-10 20:38:4183void TestTimeouts::Initialize() {
84 if (initialized_) {
85 NOTREACHED();
86 return;
87 }
88 initialized_ = true;
89
[email protected]7f0aac7c2013-07-24 19:34:0490 if (base::debug::BeingDebugged()) {
91 fprintf(stdout,
92 "Detected presence of a debugger, running without test timeouts.\n");
93 }
94
[email protected]78859c72010-09-21 17:44:2195 // Note that these timeouts MUST be initialized in the correct order as
96 // per the CHECKS below.
[email protected]32ba25f82010-12-16 18:49:5297 InitializeTimeout(switches::kTestTinyTimeout, &tiny_timeout_ms_);
[email protected]7f0aac7c2013-07-24 19:34:0498 InitializeTimeout(switches::kUiTestActionTimeout,
99 base::debug::BeingDebugged() ? kAlmostInfiniteTimeoutMs
100 : tiny_timeout_ms_,
[email protected]32ba25f82010-12-16 18:49:52101 &action_timeout_ms_);
[email protected]78859c72010-09-21 17:44:21102 InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_,
103 &action_max_timeout_ms_);
[email protected]78859c72010-09-21 17:44:21104
[email protected]616965f2013-09-24 17:00:14105 // Test launcher timeout is independent from anything above action timeout.
phajdan.jr5f0e5ec082014-08-25 15:11:27106 InitializeTimeout(switches::kTestLauncherTimeout, action_timeout_ms_,
[email protected]616965f2013-09-24 17:00:14107 &test_launcher_timeout_ms_);
108
[email protected]78859c72010-09-21 17:44:21109 // The timeout values should be increasing in the right order.
[email protected]32ba25f82010-12-16 18:49:52110 CHECK(tiny_timeout_ms_ <= action_timeout_ms_);
[email protected]dabfc502010-09-16 19:10:39111 CHECK(action_timeout_ms_ <= action_max_timeout_ms_);
[email protected]616965f2013-09-24 17:00:14112
phajdan.jr5f0e5ec082014-08-25 15:11:27113 CHECK(action_timeout_ms_ <= test_launcher_timeout_ms_);
[email protected]c36a87af2010-09-10 20:38:41114}