| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/launcher/test_launcher.h" | 5 #include "base/test/launcher/test_launcher.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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "base/process/launch.h" | 24 #include "base/process/launch.h" |
| 25 #include "base/single_thread_task_runner.h" | 25 #include "base/single_thread_task_runner.h" |
| 26 #include "base/strings/pattern.h" | 26 #include "base/strings/pattern.h" |
| 27 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/strings/string_split.h" | 28 #include "base/strings/string_split.h" |
| 29 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" |
| 30 #include "base/strings/stringize_macros.h" | 30 #include "base/strings/stringize_macros.h" |
| 31 #include "base/strings/stringprintf.h" | 31 #include "base/strings/stringprintf.h" |
| 32 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
| 33 #include "base/test/gtest_util.h" | 33 #include "base/test/gtest_util.h" |
| 34 #include "base/test/launcher/test_launcher_tracer.h" |
| 34 #include "base/test/launcher/test_results_tracker.h" | 35 #include "base/test/launcher/test_results_tracker.h" |
| 35 #include "base/test/sequenced_worker_pool_owner.h" | 36 #include "base/test/sequenced_worker_pool_owner.h" |
| 36 #include "base/test/test_switches.h" | 37 #include "base/test/test_switches.h" |
| 37 #include "base/test/test_timeouts.h" | 38 #include "base/test/test_timeouts.h" |
| 38 #include "base/threading/thread_checker.h" | 39 #include "base/threading/thread_checker.h" |
| 39 #include "base/threading/thread_task_runner_handle.h" | 40 #include "base/threading/thread_task_runner_handle.h" |
| 40 #include "base/time/time.h" | 41 #include "base/time/time.h" |
| 41 #include "build/build_config.h" | 42 #include "build/build_config.h" |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
| 43 | 44 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // Avoids flooding the logs with amount of output that gums up | 84 // Avoids flooding the logs with amount of output that gums up |
| 84 // the infrastructure. | 85 // the infrastructure. |
| 85 const size_t kOutputSnippetLinesLimit = 5000; | 86 const size_t kOutputSnippetLinesLimit = 5000; |
| 86 | 87 |
| 87 // Set of live launch test processes with corresponding lock (it is allowed | 88 // Set of live launch test processes with corresponding lock (it is allowed |
| 88 // for callers to launch processes on different threads). | 89 // for callers to launch processes on different threads). |
| 89 LazyInstance<std::map<ProcessHandle, CommandLine> > g_live_processes | 90 LazyInstance<std::map<ProcessHandle, CommandLine> > g_live_processes |
| 90 = LAZY_INSTANCE_INITIALIZER; | 91 = LAZY_INSTANCE_INITIALIZER; |
| 91 LazyInstance<Lock> g_live_processes_lock = LAZY_INSTANCE_INITIALIZER; | 92 LazyInstance<Lock> g_live_processes_lock = LAZY_INSTANCE_INITIALIZER; |
| 92 | 93 |
| 94 // Performance trace generator. |
| 95 LazyInstance<TestLauncherTracer> g_tracer = LAZY_INSTANCE_INITIALIZER; |
| 96 |
| 93 #if defined(OS_POSIX) | 97 #if defined(OS_POSIX) |
| 94 // Self-pipe that makes it possible to do complex shutdown handling | 98 // Self-pipe that makes it possible to do complex shutdown handling |
| 95 // outside of the signal handler. | 99 // outside of the signal handler. |
| 96 int g_shutdown_pipe[2] = { -1, -1 }; | 100 int g_shutdown_pipe[2] = { -1, -1 }; |
| 97 | 101 |
| 98 void ShutdownPipeSignalHandler(int signal) { | 102 void ShutdownPipeSignalHandler(int signal) { |
| 99 HANDLE_EINTR(write(g_shutdown_pipe[1], "q", 1)); | 103 HANDLE_EINTR(write(g_shutdown_pipe[1], "q", 1)); |
| 100 } | 104 } |
| 101 | 105 |
| 102 void KillSpawnedTestProcesses() { | 106 void KillSpawnedTestProcesses() { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // Launches a child process using |command_line|. If the child process is still | 250 // Launches a child process using |command_line|. If the child process is still |
| 247 // running after |timeout|, it is terminated and |*was_timeout| is set to true. | 251 // running after |timeout|, it is terminated and |*was_timeout| is set to true. |
| 248 // Returns exit code of the process. | 252 // Returns exit code of the process. |
| 249 int LaunchChildTestProcessWithOptions( | 253 int LaunchChildTestProcessWithOptions( |
| 250 const CommandLine& command_line, | 254 const CommandLine& command_line, |
| 251 const LaunchOptions& options, | 255 const LaunchOptions& options, |
| 252 int flags, | 256 int flags, |
| 253 TimeDelta timeout, | 257 TimeDelta timeout, |
| 254 const TestLauncher::GTestProcessLaunchedCallback& launched_callback, | 258 const TestLauncher::GTestProcessLaunchedCallback& launched_callback, |
| 255 bool* was_timeout) { | 259 bool* was_timeout) { |
| 260 TimeTicks start_time(TimeTicks::Now()); |
| 261 |
| 256 #if defined(OS_POSIX) | 262 #if defined(OS_POSIX) |
| 257 // Make sure an option we rely on is present - see LaunchChildGTestProcess. | 263 // Make sure an option we rely on is present - see LaunchChildGTestProcess. |
| 258 DCHECK(options.new_process_group); | 264 DCHECK(options.new_process_group); |
| 259 #endif | 265 #endif |
| 260 | 266 |
| 261 LaunchOptions new_options(options); | 267 LaunchOptions new_options(options); |
| 262 | 268 |
| 263 #if defined(OS_WIN) | 269 #if defined(OS_WIN) |
| 264 DCHECK(!new_options.job_handle); | 270 DCHECK(!new_options.job_handle); |
| 265 | 271 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // or due to it timing out, we need to clean up any child processes that | 343 // or due to it timing out, we need to clean up any child processes that |
| 338 // it might have created. On Windows, child processes are automatically | 344 // it might have created. On Windows, child processes are automatically |
| 339 // cleaned up using JobObjects. | 345 // cleaned up using JobObjects. |
| 340 KillProcessGroup(process.Handle()); | 346 KillProcessGroup(process.Handle()); |
| 341 } | 347 } |
| 342 #endif | 348 #endif |
| 343 | 349 |
| 344 g_live_processes.Get().erase(process.Handle()); | 350 g_live_processes.Get().erase(process.Handle()); |
| 345 } | 351 } |
| 346 | 352 |
| 353 g_tracer.Get().RecordProcessExecution(start_time, |
| 354 TimeTicks::Now() - start_time); |
| 355 |
| 347 return exit_code; | 356 return exit_code; |
| 348 } | 357 } |
| 349 | 358 |
| 350 void RunCallback(const TestLauncher::GTestProcessCompletedCallback& callback, | 359 void RunCallback(const TestLauncher::GTestProcessCompletedCallback& callback, |
| 351 int exit_code, | 360 int exit_code, |
| 352 const TimeDelta& elapsed_time, | 361 const TimeDelta& elapsed_time, |
| 353 bool was_timeout, | 362 bool was_timeout, |
| 354 const std::string& output) { | 363 const std::string& output) { |
| 355 callback.Run(exit_code, elapsed_time, was_timeout, output); | 364 callback.Run(exit_code, elapsed_time, was_timeout, output); |
| 356 } | 365 } |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 | 1036 |
| 1028 void TestLauncher::MaybeSaveSummaryAsJSON() { | 1037 void TestLauncher::MaybeSaveSummaryAsJSON() { |
| 1029 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1038 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 1030 if (command_line->HasSwitch(switches::kTestLauncherSummaryOutput)) { | 1039 if (command_line->HasSwitch(switches::kTestLauncherSummaryOutput)) { |
| 1031 FilePath summary_path(command_line->GetSwitchValuePath( | 1040 FilePath summary_path(command_line->GetSwitchValuePath( |
| 1032 switches::kTestLauncherSummaryOutput)); | 1041 switches::kTestLauncherSummaryOutput)); |
| 1033 if (!results_tracker_.SaveSummaryAsJSON(summary_path)) { | 1042 if (!results_tracker_.SaveSummaryAsJSON(summary_path)) { |
| 1034 LOG(ERROR) << "Failed to save test launcher output summary."; | 1043 LOG(ERROR) << "Failed to save test launcher output summary."; |
| 1035 } | 1044 } |
| 1036 } | 1045 } |
| 1046 if (command_line->HasSwitch(switches::kTestLauncherTrace)) { |
| 1047 FilePath trace_path( |
| 1048 command_line->GetSwitchValuePath(switches::kTestLauncherTrace)); |
| 1049 if (!g_tracer.Get().Dump(trace_path)) { |
| 1050 LOG(ERROR) << "Failed to save test launcher trace."; |
| 1051 } |
| 1052 } |
| 1037 } | 1053 } |
| 1038 | 1054 |
| 1039 void TestLauncher::OnLaunchTestProcessFinished( | 1055 void TestLauncher::OnLaunchTestProcessFinished( |
| 1040 const GTestProcessCompletedCallback& callback, | 1056 const GTestProcessCompletedCallback& callback, |
| 1041 int exit_code, | 1057 int exit_code, |
| 1042 const TimeDelta& elapsed_time, | 1058 const TimeDelta& elapsed_time, |
| 1043 bool was_timeout, | 1059 bool was_timeout, |
| 1044 const std::string& output) { | 1060 const std::string& output) { |
| 1045 DCHECK(thread_checker_.CalledOnValidThread()); | 1061 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1046 | 1062 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 } | 1137 } |
| 1122 | 1138 |
| 1123 std::string snippet(full_output.substr(run_pos)); | 1139 std::string snippet(full_output.substr(run_pos)); |
| 1124 if (end_pos != std::string::npos) | 1140 if (end_pos != std::string::npos) |
| 1125 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1141 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 1126 | 1142 |
| 1127 return snippet; | 1143 return snippet; |
| 1128 } | 1144 } |
| 1129 | 1145 |
| 1130 } // namespace base | 1146 } // namespace base |
| OLD | NEW |