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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 std::string output_file_contents; | 465 std::string output_file_contents; |
466 CHECK(ReadFileToString(output_file, &output_file_contents)); | 466 CHECK(ReadFileToString(output_file, &output_file_contents)); |
467 | 467 |
468 if (!DeleteFile(output_file, false)) { | 468 if (!DeleteFile(output_file, false)) { |
469 // This needs to be non-fatal at least for Windows. | 469 // This needs to be non-fatal at least for Windows. |
470 LOG(WARNING) << "Failed to delete " << output_file.AsUTF8Unsafe(); | 470 LOG(WARNING) << "Failed to delete " << output_file.AsUTF8Unsafe(); |
471 } | 471 } |
472 | 472 |
473 // Run target callback on the thread it was originating from, not on | 473 // Run target callback on the thread it was originating from, not on |
474 // a worker pool thread. | 474 // a worker pool thread. |
475 task_runner->PostTask( | 475 task_runner->PostTask(FROM_HERE, |
476 FROM_HERE, | 476 BindOnce(&RunCallback, completed_callback, exit_code, |
477 Bind(&RunCallback, completed_callback, exit_code, | 477 TimeTicks::Now() - start_time, was_timeout, |
478 TimeTicks::Now() - start_time, was_timeout, output_file_contents)); | 478 output_file_contents)); |
479 } | 479 } |
480 | 480 |
481 } // namespace | 481 } // namespace |
482 | 482 |
483 const char kGTestBreakOnFailure[] = "gtest_break_on_failure"; | 483 const char kGTestBreakOnFailure[] = "gtest_break_on_failure"; |
484 const char kGTestFilterFlag[] = "gtest_filter"; | 484 const char kGTestFilterFlag[] = "gtest_filter"; |
485 const char kGTestFlagfileFlag[] = "gtest_flagfile"; | 485 const char kGTestFlagfileFlag[] = "gtest_flagfile"; |
486 const char kGTestHelpFlag[] = "gtest_help"; | 486 const char kGTestHelpFlag[] = "gtest_help"; |
487 const char kGTestListTestsFlag[] = "gtest_list_tests"; | 487 const char kGTestListTestsFlag[] = "gtest_list_tests"; |
488 const char kGTestRepeatFlag[] = "gtest_repeat"; | 488 const char kGTestRepeatFlag[] = "gtest_repeat"; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 CHECK_EQ(0, sigaction(SIGTERM, &action, NULL)); | 537 CHECK_EQ(0, sigaction(SIGTERM, &action, NULL)); |
538 | 538 |
539 auto controller = base::FileDescriptorWatcher::WatchReadable( | 539 auto controller = base::FileDescriptorWatcher::WatchReadable( |
540 g_shutdown_pipe[0], base::Bind(&OnShutdownPipeReadable)); | 540 g_shutdown_pipe[0], base::Bind(&OnShutdownPipeReadable)); |
541 #endif // defined(OS_POSIX) | 541 #endif // defined(OS_POSIX) |
542 | 542 |
543 // Start the watchdog timer. | 543 // Start the watchdog timer. |
544 watchdog_timer_.Reset(); | 544 watchdog_timer_.Reset(); |
545 | 545 |
546 ThreadTaskRunnerHandle::Get()->PostTask( | 546 ThreadTaskRunnerHandle::Get()->PostTask( |
547 FROM_HERE, Bind(&TestLauncher::RunTestIteration, Unretained(this))); | 547 FROM_HERE, BindOnce(&TestLauncher::RunTestIteration, Unretained(this))); |
548 | 548 |
549 RunLoop().Run(); | 549 RunLoop().Run(); |
550 | 550 |
551 if (requested_cycles != 1) | 551 if (requested_cycles != 1) |
552 results_tracker_.PrintSummaryOfAllIterations(); | 552 results_tracker_.PrintSummaryOfAllIterations(); |
553 | 553 |
554 MaybeSaveSummaryAsJSON(std::vector<std::string>()); | 554 MaybeSaveSummaryAsJSON(std::vector<std::string>()); |
555 | 555 |
556 return run_result_; | 556 return run_result_; |
557 } | 557 } |
(...skipping 11 matching lines...) Expand all Loading... |
569 CommandLine new_command_line( | 569 CommandLine new_command_line( |
570 PrepareCommandLineForGTest(command_line, wrapper)); | 570 PrepareCommandLineForGTest(command_line, wrapper)); |
571 | 571 |
572 // When running in parallel mode we need to redirect stdio to avoid mixed-up | 572 // When running in parallel mode we need to redirect stdio to avoid mixed-up |
573 // output. We also always redirect on the bots to get the test output into | 573 // output. We also always redirect on the bots to get the test output into |
574 // JSON summary. | 574 // JSON summary. |
575 bool redirect_stdio = (parallel_jobs_ > 1) || BotModeEnabled(); | 575 bool redirect_stdio = (parallel_jobs_ > 1) || BotModeEnabled(); |
576 | 576 |
577 GetTaskRunner()->PostTask( | 577 GetTaskRunner()->PostTask( |
578 FROM_HERE, | 578 FROM_HERE, |
579 Bind(&DoLaunchChildTestProcess, new_command_line, timeout, options, | 579 BindOnce(&DoLaunchChildTestProcess, new_command_line, timeout, options, |
580 redirect_stdio, RetainedRef(ThreadTaskRunnerHandle::Get()), | 580 redirect_stdio, RetainedRef(ThreadTaskRunnerHandle::Get()), |
581 Bind(&TestLauncher::OnLaunchTestProcessFinished, Unretained(this), | 581 Bind(&TestLauncher::OnLaunchTestProcessFinished, |
582 completed_callback), | 582 Unretained(this), completed_callback), |
583 launched_callback)); | 583 launched_callback)); |
584 } | 584 } |
585 | 585 |
586 void TestLauncher::OnTestFinished(const TestResult& original_result) { | 586 void TestLauncher::OnTestFinished(const TestResult& original_result) { |
587 ++test_finished_count_; | 587 ++test_finished_count_; |
588 | 588 |
589 TestResult result(original_result); | 589 TestResult result(original_result); |
590 | 590 |
591 if (result.output_snippet.length() > kOutputSnippetBytesLimit) { | 591 if (result.output_snippet.length() > kOutputSnippetBytesLimit) { |
592 if (result.status == TestResult::TEST_SUCCESS) | 592 if (result.status == TestResult::TEST_SUCCESS) |
593 result.status = TestResult::TEST_EXCESSIVE_OUTPUT; | 593 result.status = TestResult::TEST_EXCESSIVE_OUTPUT; |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 MaybeSaveSummaryAsJSON({"EARLY_SUMMARY", kUnreliableResultsTag}); | 1064 MaybeSaveSummaryAsJSON({"EARLY_SUMMARY", kUnreliableResultsTag}); |
1065 | 1065 |
1066 test_started_count_ = launcher_delegate_->RunTests(this, test_names); | 1066 test_started_count_ = launcher_delegate_->RunTests(this, test_names); |
1067 | 1067 |
1068 if (test_started_count_ == 0) { | 1068 if (test_started_count_ == 0) { |
1069 fprintf(stdout, "0 tests run\n"); | 1069 fprintf(stdout, "0 tests run\n"); |
1070 fflush(stdout); | 1070 fflush(stdout); |
1071 | 1071 |
1072 // No tests have actually been started, so kick off the next iteration. | 1072 // No tests have actually been started, so kick off the next iteration. |
1073 ThreadTaskRunnerHandle::Get()->PostTask( | 1073 ThreadTaskRunnerHandle::Get()->PostTask( |
1074 FROM_HERE, Bind(&TestLauncher::RunTestIteration, Unretained(this))); | 1074 FROM_HERE, BindOnce(&TestLauncher::RunTestIteration, Unretained(this))); |
1075 } | 1075 } |
1076 } | 1076 } |
1077 | 1077 |
1078 void TestLauncher::RunTestIteration() { | 1078 void TestLauncher::RunTestIteration() { |
1079 const bool stop_on_failure = | 1079 const bool stop_on_failure = |
1080 CommandLine::ForCurrentProcess()->HasSwitch(kGTestBreakOnFailure); | 1080 CommandLine::ForCurrentProcess()->HasSwitch(kGTestBreakOnFailure); |
1081 if (cycles_ == 0 || | 1081 if (cycles_ == 0 || |
1082 (stop_on_failure && test_success_count_ != test_finished_count_)) { | 1082 (stop_on_failure && test_success_count_ != test_finished_count_)) { |
1083 MessageLoop::current()->QuitWhenIdle(); | 1083 MessageLoop::current()->QuitWhenIdle(); |
1084 return; | 1084 return; |
1085 } | 1085 } |
1086 | 1086 |
1087 // Special value "-1" means "repeat indefinitely". | 1087 // Special value "-1" means "repeat indefinitely". |
1088 cycles_ = (cycles_ == -1) ? cycles_ : cycles_ - 1; | 1088 cycles_ = (cycles_ == -1) ? cycles_ : cycles_ - 1; |
1089 | 1089 |
1090 test_found_count_ = 0; | 1090 test_found_count_ = 0; |
1091 test_started_count_ = 0; | 1091 test_started_count_ = 0; |
1092 test_finished_count_ = 0; | 1092 test_finished_count_ = 0; |
1093 test_success_count_ = 0; | 1093 test_success_count_ = 0; |
1094 test_broken_count_ = 0; | 1094 test_broken_count_ = 0; |
1095 retry_count_ = 0; | 1095 retry_count_ = 0; |
1096 tests_to_retry_.clear(); | 1096 tests_to_retry_.clear(); |
1097 results_tracker_.OnTestIterationStarting(); | 1097 results_tracker_.OnTestIterationStarting(); |
1098 | 1098 |
1099 ThreadTaskRunnerHandle::Get()->PostTask( | 1099 ThreadTaskRunnerHandle::Get()->PostTask( |
1100 FROM_HERE, Bind(&TestLauncher::RunTests, Unretained(this))); | 1100 FROM_HERE, BindOnce(&TestLauncher::RunTests, Unretained(this))); |
1101 } | 1101 } |
1102 | 1102 |
1103 void TestLauncher::MaybeSaveSummaryAsJSON( | 1103 void TestLauncher::MaybeSaveSummaryAsJSON( |
1104 const std::vector<std::string>& additional_tags) { | 1104 const std::vector<std::string>& additional_tags) { |
1105 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1105 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
1106 if (command_line->HasSwitch(switches::kTestLauncherSummaryOutput)) { | 1106 if (command_line->HasSwitch(switches::kTestLauncherSummaryOutput)) { |
1107 FilePath summary_path(command_line->GetSwitchValuePath( | 1107 FilePath summary_path(command_line->GetSwitchValuePath( |
1108 switches::kTestLauncherSummaryOutput)); | 1108 switches::kTestLauncherSummaryOutput)); |
1109 if (!results_tracker_.SaveSummaryAsJSON(summary_path, additional_tags)) { | 1109 if (!results_tracker_.SaveSummaryAsJSON(summary_path, additional_tags)) { |
1110 LOG(ERROR) << "Failed to save test launcher output summary."; | 1110 LOG(ERROR) << "Failed to save test launcher output summary."; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 } else { | 1145 } else { |
1146 // Signal failure, but continue to run all requested test iterations. | 1146 // Signal failure, but continue to run all requested test iterations. |
1147 // With the summary of all iterations at the end this is a good default. | 1147 // With the summary of all iterations at the end this is a good default. |
1148 run_result_ = false; | 1148 run_result_ = false; |
1149 } | 1149 } |
1150 | 1150 |
1151 results_tracker_.PrintSummaryOfCurrentIteration(); | 1151 results_tracker_.PrintSummaryOfCurrentIteration(); |
1152 | 1152 |
1153 // Kick off the next iteration. | 1153 // Kick off the next iteration. |
1154 ThreadTaskRunnerHandle::Get()->PostTask( | 1154 ThreadTaskRunnerHandle::Get()->PostTask( |
1155 FROM_HERE, Bind(&TestLauncher::RunTestIteration, Unretained(this))); | 1155 FROM_HERE, BindOnce(&TestLauncher::RunTestIteration, Unretained(this))); |
1156 } | 1156 } |
1157 | 1157 |
1158 void TestLauncher::OnOutputTimeout() { | 1158 void TestLauncher::OnOutputTimeout() { |
1159 DCHECK(thread_checker_.CalledOnValidThread()); | 1159 DCHECK(thread_checker_.CalledOnValidThread()); |
1160 | 1160 |
1161 AutoLock lock(*GetLiveProcessesLock()); | 1161 AutoLock lock(*GetLiveProcessesLock()); |
1162 | 1162 |
1163 fprintf(stdout, "Still waiting for the following processes to finish:\n"); | 1163 fprintf(stdout, "Still waiting for the following processes to finish:\n"); |
1164 | 1164 |
1165 for (const auto& pair : *GetLiveProcesses()) { | 1165 for (const auto& pair : *GetLiveProcesses()) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 } | 1212 } |
1213 | 1213 |
1214 std::string snippet(full_output.substr(run_pos)); | 1214 std::string snippet(full_output.substr(run_pos)); |
1215 if (end_pos != std::string::npos) | 1215 if (end_pos != std::string::npos) |
1216 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1216 snippet = full_output.substr(run_pos, end_pos - run_pos); |
1217 | 1217 |
1218 return snippet; | 1218 return snippet; |
1219 } | 1219 } |
1220 | 1220 |
1221 } // namespace base | 1221 } // namespace base |
OLD | NEW |