Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: base/test/launcher/test_launcher.cc

Issue 2112253002: Add basic tracing support to the gtest launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: trybots Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 new_command_line.PrependWrapper(wrapper); 244 new_command_line.PrependWrapper(wrapper);
241 #endif 245 #endif
242 246
243 return new_command_line; 247 return new_command_line;
244 } 248 }
245 249
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,
Primiano Tucci (use gerrit) 2016/07/01 11:34:29 If you want to you dump the command line as well.
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
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(
Primiano Tucci (use gerrit) 2016/07/01 11:34:29 If this is really what you need it's ok. But if yo
Paweł Hajdan Jr. 2016/07/01 12:47:32 Yeah, it's OK for now. I can take another look if
354 start_time, 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
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(command_line->GetSwitchValuePath(
1048 switches::kTestLauncherTrace));
1049 if (!g_tracer.Get().Dump(trace_path)) {
1050 LOG(ERROR) << "Failed to save test launcher trace.";
Primiano Tucci (use gerrit) 2016/07/01 11:34:30 maybe move this error logging to the Dump method a
Paweł Hajdan Jr. 2016/07/01 12:47:32 This is consistent with above code. I think as an
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698