| 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" |
| 11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/debugger.h" | 14 #include "base/debug/debugger.h" |
| 15 #include "base/debug/profiler.h" |
| 15 #include "base/debug/stack_trace.h" | 16 #include "base/debug/stack_trace.h" |
| 16 #include "base/feature_list.h" | 17 #include "base/feature_list.h" |
| 17 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 18 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
| 19 #include "base/i18n/icu_util.h" | 20 #include "base/i18n/icu_util.h" |
| 20 #include "base/logging.h" | 21 #include "base/logging.h" |
| 21 #include "base/macros.h" | 22 #include "base/macros.h" |
| 22 #include "base/memory/ptr_util.h" | 23 #include "base/memory/ptr_util.h" |
| 23 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 24 #include "base/process/launch.h" | 25 #include "base/process/launch.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 void OnTestEnd(const testing::TestInfo& test_info) override { | 86 void OnTestEnd(const testing::TestInfo& test_info) override { |
| 86 *CommandLine::ForCurrentProcess() = old_command_line_; | 87 *CommandLine::ForCurrentProcess() = old_command_line_; |
| 87 } | 88 } |
| 88 | 89 |
| 89 private: | 90 private: |
| 90 CommandLine old_command_line_; | 91 CommandLine old_command_line_; |
| 91 | 92 |
| 92 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); | 93 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); |
| 93 }; | 94 }; |
| 94 | 95 |
| 96 std::string GetProfileName() { |
| 97 static const char kDefaultProfileName[] = "test-profile-{pid}"; |
| 98 CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ()); |
| 99 if (profile_name.empty()) { |
| 100 const base::CommandLine& command_line = |
| 101 *base::CommandLine::ForCurrentProcess(); |
| 102 if (command_line.HasSwitch(switches::kProfilingFile)) |
| 103 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile); |
| 104 else |
| 105 profile_name = std::string(kDefaultProfileName); |
| 106 } |
| 107 return profile_name; |
| 108 } |
| 109 |
| 95 } // namespace | 110 } // namespace |
| 96 | 111 |
| 97 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { | 112 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { |
| 98 TestSuite test_suite(argc, argv); | 113 TestSuite test_suite(argc, argv); |
| 99 return LaunchUnitTests(argc, argv, | 114 return LaunchUnitTests(argc, argv, |
| 100 Bind(&TestSuite::Run, Unretained(&test_suite))); | 115 Bind(&TestSuite::Run, Unretained(&test_suite))); |
| 101 } | 116 } |
| 102 | 117 |
| 103 TestSuite::TestSuite(int argc, char** argv) | 118 TestSuite::TestSuite(int argc, char** argv) |
| 104 : initialized_command_line_(false), created_feature_list_(false) { | 119 : initialized_command_line_(false), created_feature_list_(false) { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 #endif | 370 #endif |
| 356 #endif | 371 #endif |
| 357 | 372 |
| 358 CatchMaybeTests(); | 373 CatchMaybeTests(); |
| 359 ResetCommandLine(); | 374 ResetCommandLine(); |
| 360 AddTestLauncherResultPrinter(); | 375 AddTestLauncherResultPrinter(); |
| 361 | 376 |
| 362 TestTimeouts::Initialize(); | 377 TestTimeouts::Initialize(); |
| 363 | 378 |
| 364 trace_to_file_.BeginTracingFromCommandLineOptions(); | 379 trace_to_file_.BeginTracingFromCommandLineOptions(); |
| 380 |
| 381 base::debug::StartProfiling(GetProfileName()); |
| 365 } | 382 } |
| 366 | 383 |
| 367 void TestSuite::Shutdown() { | 384 void TestSuite::Shutdown() { |
| 385 base::debug::StopProfiling(); |
| 386 |
| 368 // Clear the FeatureList that was created by Initialize(). | 387 // Clear the FeatureList that was created by Initialize(). |
| 369 if (created_feature_list_) | 388 if (created_feature_list_) |
| 370 FeatureList::ClearInstanceForTesting(); | 389 FeatureList::ClearInstanceForTesting(); |
| 371 } | 390 } |
| 372 | 391 |
| 373 } // namespace base | 392 } // namespace base |
| OLD | NEW |