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

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

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 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 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #endif 9 #endif
10 10
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 SignalFDWatcher() { 143 SignalFDWatcher() {
144 } 144 }
145 145
146 void OnFileCanReadWithoutBlocking(int fd) override { 146 void OnFileCanReadWithoutBlocking(int fd) override {
147 fprintf(stdout, "\nCaught signal. Killing spawned test processes...\n"); 147 fprintf(stdout, "\nCaught signal. Killing spawned test processes...\n");
148 fflush(stdout); 148 fflush(stdout);
149 149
150 KillSpawnedTestProcesses(); 150 KillSpawnedTestProcesses();
151 151
152 // The signal would normally kill the process, so exit now. 152 // The signal would normally kill the process, so exit now.
153 exit(1); 153 _exit(1);
154 } 154 }
155 155
156 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } 156 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); }
157 157
158 private: 158 private:
159 DISALLOW_COPY_AND_ASSIGN(SignalFDWatcher); 159 DISALLOW_COPY_AND_ASSIGN(SignalFDWatcher);
160 }; 160 };
161 #endif // defined(OS_POSIX) 161 #endif // defined(OS_POSIX)
162 162
163 // Parses the environment variable var as an Int32. If it is unset, returns 163 // Parses the environment variable var as an Int32. If it is unset, returns
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 g_live_processes.Get().insert(std::make_pair(process.Handle(), 303 g_live_processes.Get().insert(std::make_pair(process.Handle(),
304 command_line)); 304 command_line));
305 } 305 }
306 306
307 int exit_code = 0; 307 int exit_code = 0;
308 if (!process.WaitForExitWithTimeout(timeout, &exit_code)) { 308 if (!process.WaitForExitWithTimeout(timeout, &exit_code)) {
309 *was_timeout = true; 309 *was_timeout = true;
310 exit_code = -1; // Set a non-zero exit code to signal a failure. 310 exit_code = -1; // Set a non-zero exit code to signal a failure.
311 311
312 // Ensure that the process terminates. 312 // Ensure that the process terminates.
313 KillProcess(process.Handle(), -1, true); 313 process.Terminate(-1, true);
314 } 314 }
315 315
316 { 316 {
317 // Note how we grab the log before issuing a possibly broad process kill. 317 // Note how we grab the log before issuing a possibly broad process kill.
318 // Other code parts that grab the log kill processes, so avoid trying 318 // Other code parts that grab the log kill processes, so avoid trying
319 // to do that twice and trigger all kinds of log messages. 319 // to do that twice and trigger all kinds of log messages.
320 AutoLock lock(g_live_processes_lock.Get()); 320 AutoLock lock(g_live_processes_lock.Get());
321 321
322 #if defined(OS_POSIX) 322 #if defined(OS_POSIX)
323 if (exit_code != 0) { 323 if (exit_code != 0) {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } else if (print_test_stdio == "always") { 563 } else if (print_test_stdio == "always") {
564 print_snippet = true; 564 print_snippet = true;
565 } else if (print_test_stdio == "never") { 565 } else if (print_test_stdio == "never") {
566 print_snippet = false; 566 print_snippet = false;
567 } else { 567 } else {
568 LOG(WARNING) << "Invalid value of " << switches::kTestLauncherPrintTestStdio 568 LOG(WARNING) << "Invalid value of " << switches::kTestLauncherPrintTestStdio
569 << ": " << print_test_stdio; 569 << ": " << print_test_stdio;
570 } 570 }
571 if (print_snippet) { 571 if (print_snippet) {
572 std::vector<std::string> snippet_lines; 572 std::vector<std::string> snippet_lines;
573 SplitString(result.output_snippet, '\n', &snippet_lines); 573 SplitStringDontTrim(result.output_snippet, '\n', &snippet_lines);
574 if (snippet_lines.size() > kOutputSnippetLinesLimit) { 574 if (snippet_lines.size() > kOutputSnippetLinesLimit) {
575 size_t truncated_size = snippet_lines.size() - kOutputSnippetLinesLimit; 575 size_t truncated_size = snippet_lines.size() - kOutputSnippetLinesLimit;
576 snippet_lines.erase( 576 snippet_lines.erase(
577 snippet_lines.begin(), 577 snippet_lines.begin(),
578 snippet_lines.begin() + truncated_size); 578 snippet_lines.begin() + truncated_size);
579 snippet_lines.insert(snippet_lines.begin(), "<truncated>"); 579 snippet_lines.insert(snippet_lines.begin(), "<truncated>");
580 } 580 }
581 fprintf(stdout, "%s", JoinString(snippet_lines, "\n").c_str()); 581 fprintf(stdout, "%s", JoinString(snippet_lines, "\n").c_str());
582 fflush(stdout); 582 fflush(stdout);
583 } 583 }
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 } 1081 }
1082 1082
1083 std::string snippet(full_output.substr(run_pos)); 1083 std::string snippet(full_output.substr(run_pos));
1084 if (end_pos != std::string::npos) 1084 if (end_pos != std::string::npos)
1085 snippet = full_output.substr(run_pos, end_pos - run_pos); 1085 snippet = full_output.substr(run_pos, end_pos - run_pos);
1086 1086
1087 return snippet; 1087 return snippet;
1088 } 1088 }
1089 1089
1090 } // namespace base 1090 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698