| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_suite.h" | 5 #include "base/test/test_suite.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 const base::CommandLine& command_line = | 101 const base::CommandLine& command_line = |
| 102 *base::CommandLine::ForCurrentProcess(); | 102 *base::CommandLine::ForCurrentProcess(); |
| 103 if (command_line.HasSwitch(switches::kProfilingFile)) | 103 if (command_line.HasSwitch(switches::kProfilingFile)) |
| 104 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile); | 104 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile); |
| 105 else | 105 else |
| 106 profile_name = std::string(kDefaultProfileName); | 106 profile_name = std::string(kDefaultProfileName); |
| 107 } | 107 } |
| 108 return profile_name; | 108 return profile_name; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void InitializeLogging() { |
| 112 #if defined(OS_ANDROID) |
| 113 InitAndroidTestLogging(); |
| 114 #else |
| 115 FilePath exe; |
| 116 PathService::Get(FILE_EXE, &exe); |
| 117 FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log")); |
| 118 logging::LoggingSettings settings; |
| 119 settings.logging_dest = logging::LOG_TO_ALL; |
| 120 settings.log_file = log_filename.value().c_str(); |
| 121 settings.delete_old = logging::DELETE_OLD_LOG_FILE; |
| 122 logging::InitLogging(settings); |
| 123 // We want process and thread IDs because we may have multiple processes. |
| 124 // Note: temporarily enabled timestamps in an effort to catch bug 6361. |
| 125 logging::SetLogItems(true, true, true, true); |
| 126 #endif // !defined(OS_ANDROID) |
| 127 } |
| 128 |
| 111 } // namespace | 129 } // namespace |
| 112 | 130 |
| 113 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { | 131 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { |
| 114 TestSuite test_suite(argc, argv); | 132 TestSuite test_suite(argc, argv); |
| 115 return LaunchUnitTests(argc, argv, | 133 return LaunchUnitTests(argc, argv, |
| 116 Bind(&TestSuite::Run, Unretained(&test_suite))); | 134 Bind(&TestSuite::Run, Unretained(&test_suite))); |
| 117 } | 135 } |
| 118 | 136 |
| 119 TestSuite::TestSuite(int argc, char** argv) | 137 TestSuite::TestSuite(int argc, char** argv) |
| 120 : initialized_command_line_(false), created_feature_list_(false) { | 138 : initialized_command_line_(false), created_feature_list_(false) { |
| 121 PreInitialize(); | 139 PreInitialize(); |
| 122 InitializeFromCommandLine(argc, argv); | 140 InitializeFromCommandLine(argc, argv); |
| 141 // Logging must be initialized before any thread has a chance to call logging |
| 142 // functions. |
| 143 InitializeLogging(); |
| 123 } | 144 } |
| 124 | 145 |
| 125 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
| 126 TestSuite::TestSuite(int argc, wchar_t** argv) | 147 TestSuite::TestSuite(int argc, wchar_t** argv) |
| 127 : initialized_command_line_(false), created_feature_list_(false) { | 148 : initialized_command_line_(false), created_feature_list_(false) { |
| 128 PreInitialize(); | 149 PreInitialize(); |
| 129 InitializeFromCommandLine(argc, argv); | 150 InitializeFromCommandLine(argc, argv); |
| 151 // Logging must be initialized before any thread has a chance to call logging |
| 152 // functions. |
| 153 InitializeLogging(); |
| 130 } | 154 } |
| 131 #endif // defined(OS_WIN) | 155 #endif // defined(OS_WIN) |
| 132 | 156 |
| 133 TestSuite::~TestSuite() { | 157 TestSuite::~TestSuite() { |
| 134 if (initialized_command_line_) | 158 if (initialized_command_line_) |
| 135 CommandLine::Reset(); | 159 CommandLine::Reset(); |
| 136 } | 160 } |
| 137 | 161 |
| 138 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { | 162 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { |
| 139 initialized_command_line_ = CommandLine::Init(argc, argv); | 163 initialized_command_line_ = CommandLine::Init(argc, argv); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // one didn't exist previously), it will be cleared in Shutdown() via | 335 // one didn't exist previously), it will be cleared in Shutdown() via |
| 312 // ClearInstanceForTesting(). | 336 // ClearInstanceForTesting(). |
| 313 created_feature_list_ = | 337 created_feature_list_ = |
| 314 FeatureList::InitializeInstance(std::string(), std::string()); | 338 FeatureList::InitializeInstance(std::string(), std::string()); |
| 315 | 339 |
| 316 #if defined(OS_IOS) | 340 #if defined(OS_IOS) |
| 317 InitIOSTestMessageLoop(); | 341 InitIOSTestMessageLoop(); |
| 318 #endif // OS_IOS | 342 #endif // OS_IOS |
| 319 | 343 |
| 320 #if defined(OS_ANDROID) | 344 #if defined(OS_ANDROID) |
| 321 InitAndroidTest(); | 345 InitAndroidTestMessageLoop(); |
| 322 #else | |
| 323 // Initialize logging. | |
| 324 FilePath exe; | |
| 325 PathService::Get(FILE_EXE, &exe); | |
| 326 FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log")); | |
| 327 logging::LoggingSettings settings; | |
| 328 settings.logging_dest = logging::LOG_TO_ALL; | |
| 329 settings.log_file = log_filename.value().c_str(); | |
| 330 settings.delete_old = logging::DELETE_OLD_LOG_FILE; | |
| 331 logging::InitLogging(settings); | |
| 332 // We want process and thread IDs because we may have multiple processes. | |
| 333 // Note: temporarily enabled timestamps in an effort to catch bug 6361. | |
| 334 logging::SetLogItems(true, true, true, true); | |
| 335 #endif // else defined(OS_ANDROID) | 346 #endif // else defined(OS_ANDROID) |
| 336 | 347 |
| 337 CHECK(debug::EnableInProcessStackDumping()); | 348 CHECK(debug::EnableInProcessStackDumping()); |
| 338 #if defined(OS_WIN) | 349 #if defined(OS_WIN) |
| 339 RouteStdioToConsole(true); | 350 RouteStdioToConsole(true); |
| 340 // Make sure we run with high resolution timer to minimize differences | 351 // Make sure we run with high resolution timer to minimize differences |
| 341 // between production code and test code. | 352 // between production code and test code. |
| 342 Time::EnableHighResolutionTimer(true); | 353 Time::EnableHighResolutionTimer(true); |
| 343 #endif // defined(OS_WIN) | 354 #endif // defined(OS_WIN) |
| 344 | 355 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 393 |
| 383 void TestSuite::Shutdown() { | 394 void TestSuite::Shutdown() { |
| 384 base::debug::StopProfiling(); | 395 base::debug::StopProfiling(); |
| 385 | 396 |
| 386 // Clear the FeatureList that was created by Initialize(). | 397 // Clear the FeatureList that was created by Initialize(). |
| 387 if (created_feature_list_) | 398 if (created_feature_list_) |
| 388 FeatureList::ClearInstanceForTesting(); | 399 FeatureList::ClearInstanceForTesting(); |
| 389 } | 400 } |
| 390 | 401 |
| 391 } // namespace base | 402 } // namespace base |
| OLD | NEW |