| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // the test launcher to people looking at the output (no output for a long | 83 // the test launcher to people looking at the output (no output for a long |
| 84 // time is mysterious and gives no info about what is happening) 3) help | 84 // time is mysterious and gives no info about what is happening) 3) help |
| 85 // debugging in case the process hangs anyway. | 85 // debugging in case the process hangs anyway. |
| 86 const int kOutputTimeoutSeconds = 15; | 86 const int kOutputTimeoutSeconds = 15; |
| 87 | 87 |
| 88 // Limit of output snippet lines when printing to stdout. | 88 // Limit of output snippet lines when printing to stdout. |
| 89 // Avoids flooding the logs with amount of output that gums up | 89 // Avoids flooding the logs with amount of output that gums up |
| 90 // the infrastructure. | 90 // the infrastructure. |
| 91 const size_t kOutputSnippetLinesLimit = 5000; | 91 const size_t kOutputSnippetLinesLimit = 5000; |
| 92 | 92 |
| 93 // Limit of output snippet size. Exceeding this limit |
| 94 // results in truncating the output and failing the test. |
| 95 const size_t kOutputSnippetBytesLimit = 2.5 * 1024 * 1024; |
| 96 |
| 93 // Set of live launch test processes with corresponding lock (it is allowed | 97 // Set of live launch test processes with corresponding lock (it is allowed |
| 94 // for callers to launch processes on different threads). | 98 // for callers to launch processes on different threads). |
| 95 LazyInstance<std::map<ProcessHandle, CommandLine> > g_live_processes | 99 LazyInstance<std::map<ProcessHandle, CommandLine> > g_live_processes |
| 96 = LAZY_INSTANCE_INITIALIZER; | 100 = LAZY_INSTANCE_INITIALIZER; |
| 97 LazyInstance<Lock> g_live_processes_lock = LAZY_INSTANCE_INITIALIZER; | 101 LazyInstance<Lock> g_live_processes_lock = LAZY_INSTANCE_INITIALIZER; |
| 98 | 102 |
| 99 // Performance trace generator. | 103 // Performance trace generator. |
| 100 LazyInstance<TestLauncherTracer> g_tracer = LAZY_INSTANCE_INITIALIZER; | 104 LazyInstance<TestLauncherTracer> g_tracer = LAZY_INSTANCE_INITIALIZER; |
| 101 | 105 |
| 102 #if defined(OS_POSIX) | 106 #if defined(OS_POSIX) |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 | 565 |
| 562 GetTaskRunner()->PostTask( | 566 GetTaskRunner()->PostTask( |
| 563 FROM_HERE, | 567 FROM_HERE, |
| 564 Bind(&DoLaunchChildTestProcess, new_command_line, timeout, options, | 568 Bind(&DoLaunchChildTestProcess, new_command_line, timeout, options, |
| 565 redirect_stdio, RetainedRef(ThreadTaskRunnerHandle::Get()), | 569 redirect_stdio, RetainedRef(ThreadTaskRunnerHandle::Get()), |
| 566 Bind(&TestLauncher::OnLaunchTestProcessFinished, Unretained(this), | 570 Bind(&TestLauncher::OnLaunchTestProcessFinished, Unretained(this), |
| 567 completed_callback), | 571 completed_callback), |
| 568 launched_callback)); | 572 launched_callback)); |
| 569 } | 573 } |
| 570 | 574 |
| 571 void TestLauncher::OnTestFinished(const TestResult& result) { | 575 void TestLauncher::OnTestFinished(const TestResult& original_result) { |
| 572 ++test_finished_count_; | 576 ++test_finished_count_; |
| 573 | 577 |
| 578 TestResult result(original_result); |
| 579 |
| 580 if (result.output_snippet.length() > kOutputSnippetBytesLimit) { |
| 581 if (result.status == TestResult::TEST_SUCCESS) |
| 582 result.status = TestResult::TEST_EXCESSIVE_OUTPUT; |
| 583 result.output_snippet = StringPrintf( |
| 584 "<truncated (%" PRIuS " bytes)>\n", result.output_snippet.length()) + |
| 585 result.output_snippet.substr( |
| 586 result.output_snippet.length() - kOutputSnippetLinesLimit) + |
| 587 "\n"; |
| 588 } |
| 589 |
| 574 bool print_snippet = false; | 590 bool print_snippet = false; |
| 575 std::string print_test_stdio("auto"); | 591 std::string print_test_stdio("auto"); |
| 576 if (CommandLine::ForCurrentProcess()->HasSwitch( | 592 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 577 switches::kTestLauncherPrintTestStdio)) { | 593 switches::kTestLauncherPrintTestStdio)) { |
| 578 print_test_stdio = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 594 print_test_stdio = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 579 switches::kTestLauncherPrintTestStdio); | 595 switches::kTestLauncherPrintTestStdio); |
| 580 } | 596 } |
| 581 if (print_test_stdio == "auto") { | 597 if (print_test_stdio == "auto") { |
| 582 print_snippet = (result.status != TestResult::TEST_SUCCESS); | 598 print_snippet = (result.status != TestResult::TEST_SUCCESS); |
| 583 } else if (print_test_stdio == "always") { | 599 } else if (print_test_stdio == "always") { |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 } | 1158 } |
| 1143 | 1159 |
| 1144 std::string snippet(full_output.substr(run_pos)); | 1160 std::string snippet(full_output.substr(run_pos)); |
| 1145 if (end_pos != std::string::npos) | 1161 if (end_pos != std::string::npos) |
| 1146 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1162 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 1147 | 1163 |
| 1148 return snippet; | 1164 return snippet; |
| 1149 } | 1165 } |
| 1150 | 1166 |
| 1151 } // namespace base | 1167 } // namespace base |
| OLD | NEW |