This source file includes following definitions.
- InitializeTimeout
- InitializeTimeout
- Initialize
#include "base/test/test_timeouts.h"
#include <algorithm>
#include "base/command_line.h"
#include "base/debug/debugger.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/test_switches.h"
namespace {
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || defined(SYZYASAN)
static const int kTimeoutMultiplier = 2;
#else
static const int kTimeoutMultiplier = 1;
#endif
const int kAlmostInfiniteTimeoutMs = 100000000;
void InitializeTimeout(const char* switch_name, int min_value, int* value) {
DCHECK(value);
if (CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
std::string string_value(
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name));
int timeout;
base::StringToInt(string_value, &timeout);
*value = std::max(*value, timeout);
}
*value *= kTimeoutMultiplier;
*value = std::max(*value, min_value);
}
void InitializeTimeout(const char* switch_name, int* value) {
InitializeTimeout(switch_name, 0, value);
}
}
bool TestTimeouts::initialized_ = false;
int TestTimeouts::tiny_timeout_ms_ = 100;
int TestTimeouts::action_timeout_ms_ = 10000;
#ifndef NDEBUG
int TestTimeouts::action_max_timeout_ms_ = 45000;
#else
int TestTimeouts::action_max_timeout_ms_ = 30000;
#endif
int TestTimeouts::large_test_timeout_ms_ = 10 * 60 * 1000;
int TestTimeouts::test_launcher_timeout_ms_ = 45000;
void TestTimeouts::Initialize() {
if (initialized_) {
NOTREACHED();
return;
}
initialized_ = true;
if (base::debug::BeingDebugged()) {
fprintf(stdout,
"Detected presence of a debugger, running without test timeouts.\n");
}
InitializeTimeout(switches::kTestTinyTimeout, &tiny_timeout_ms_);
InitializeTimeout(switches::kUiTestActionTimeout,
base::debug::BeingDebugged() ? kAlmostInfiniteTimeoutMs
: tiny_timeout_ms_,
&action_timeout_ms_);
InitializeTimeout(switches::kUiTestActionMaxTimeout, action_timeout_ms_,
&action_max_timeout_ms_);
InitializeTimeout(switches::kTestLargeTimeout, action_max_timeout_ms_,
&large_test_timeout_ms_);
InitializeTimeout(switches::kTestLauncherTimeout, action_timeout_ms_,
&test_launcher_timeout_ms_);
CHECK(tiny_timeout_ms_ <= action_timeout_ms_);
CHECK(action_timeout_ms_ <= action_max_timeout_ms_);
CHECK(action_max_timeout_ms_ <= large_test_timeout_ms_);
CHECK(action_timeout_ms_ <= test_launcher_timeout_ms_);
}