| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 static auto* map = new std::map<ProcessHandle, CommandLine>; | 107 static auto* map = new std::map<ProcessHandle, CommandLine>; |
| 108 return map; | 108 return map; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Performance trace generator. | 111 // Performance trace generator. |
| 112 TestLauncherTracer* GetTestLauncherTracer() { | 112 TestLauncherTracer* GetTestLauncherTracer() { |
| 113 static auto* tracer = new TestLauncherTracer; | 113 static auto* tracer = new TestLauncherTracer; |
| 114 return tracer; | 114 return tracer; |
| 115 } | 115 } |
| 116 | 116 |
| 117 #if defined(OS_POSIX) | 117 // TODO(fuchsia): Fuchsia does not have POSIX signals, but equivalent |
| 118 // functionality will probably be necessary eventually. See |
| 119 // https://crbug.com/706592. |
| 120 #if defined(OS_POSIX) && !defined(OS_FUCHSIA) |
| 118 // Self-pipe that makes it possible to do complex shutdown handling | 121 // Self-pipe that makes it possible to do complex shutdown handling |
| 119 // outside of the signal handler. | 122 // outside of the signal handler. |
| 120 int g_shutdown_pipe[2] = { -1, -1 }; | 123 int g_shutdown_pipe[2] = { -1, -1 }; |
| 121 | 124 |
| 122 void ShutdownPipeSignalHandler(int signal) { | 125 void ShutdownPipeSignalHandler(int signal) { |
| 123 HANDLE_EINTR(write(g_shutdown_pipe[1], "q", 1)); | 126 HANDLE_EINTR(write(g_shutdown_pipe[1], "q", 1)); |
| 124 } | 127 } |
| 125 | 128 |
| 126 void KillSpawnedTestProcesses() { | 129 void KillSpawnedTestProcesses() { |
| 127 // Keep the lock until exiting the process to prevent further processes | 130 // Keep the lock until exiting the process to prevent further processes |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // Terminates any launched child processes and exits the process. | 166 // Terminates any launched child processes and exits the process. |
| 164 void OnShutdownPipeReadable() { | 167 void OnShutdownPipeReadable() { |
| 165 fprintf(stdout, "\nCaught signal. Killing spawned test processes...\n"); | 168 fprintf(stdout, "\nCaught signal. Killing spawned test processes...\n"); |
| 166 fflush(stdout); | 169 fflush(stdout); |
| 167 | 170 |
| 168 KillSpawnedTestProcesses(); | 171 KillSpawnedTestProcesses(); |
| 169 | 172 |
| 170 // The signal would normally kill the process, so exit now. | 173 // The signal would normally kill the process, so exit now. |
| 171 _exit(1); | 174 _exit(1); |
| 172 } | 175 } |
| 173 #endif // defined(OS_POSIX) | 176 #endif // defined(OS_POSIX) && !defined(OS_FUCHSIA) |
| 174 | 177 |
| 175 // Parses the environment variable var as an Int32. If it is unset, returns | 178 // Parses the environment variable var as an Int32. If it is unset, returns |
| 176 // true. If it is set, unsets it then converts it to Int32 before | 179 // true. If it is set, unsets it then converts it to Int32 before |
| 177 // returning it in |result|. Returns true on success. | 180 // returning it in |result|. Returns true on success. |
| 178 bool TakeInt32FromEnvironment(const char* const var, int32_t* result) { | 181 bool TakeInt32FromEnvironment(const char* const var, int32_t* result) { |
| 179 std::unique_ptr<Environment> env(Environment::Create()); | 182 std::unique_ptr<Environment> env(Environment::Create()); |
| 180 std::string str_val; | 183 std::string str_val; |
| 181 | 184 |
| 182 if (!env->GetVar(var, &str_val)) | 185 if (!env->GetVar(var, &str_val)) |
| 183 return true; | 186 return true; |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 TestLauncher::~TestLauncher() {} | 520 TestLauncher::~TestLauncher() {} |
| 518 | 521 |
| 519 bool TestLauncher::Run() { | 522 bool TestLauncher::Run() { |
| 520 if (!Init()) | 523 if (!Init()) |
| 521 return false; | 524 return false; |
| 522 | 525 |
| 523 // Value of |cycles_| changes after each iteration. Keep track of the | 526 // Value of |cycles_| changes after each iteration. Keep track of the |
| 524 // original value. | 527 // original value. |
| 525 int requested_cycles = cycles_; | 528 int requested_cycles = cycles_; |
| 526 | 529 |
| 527 #if defined(OS_POSIX) | 530 // TODO(fuchsia): Fuchsia does not have POSIX signals. Something similiar to |
| 531 // this will likely need to be implemented. See https://crbug.com/706592. |
| 532 #if defined(OS_POSIX) && !defined(OS_FUCHSIA) |
| 528 CHECK_EQ(0, pipe(g_shutdown_pipe)); | 533 CHECK_EQ(0, pipe(g_shutdown_pipe)); |
| 529 | 534 |
| 530 struct sigaction action; | 535 struct sigaction action; |
| 531 memset(&action, 0, sizeof(action)); | 536 memset(&action, 0, sizeof(action)); |
| 532 sigemptyset(&action.sa_mask); | 537 sigemptyset(&action.sa_mask); |
| 533 action.sa_handler = &ShutdownPipeSignalHandler; | 538 action.sa_handler = &ShutdownPipeSignalHandler; |
| 534 | 539 |
| 535 CHECK_EQ(0, sigaction(SIGINT, &action, NULL)); | 540 CHECK_EQ(0, sigaction(SIGINT, &action, NULL)); |
| 536 CHECK_EQ(0, sigaction(SIGQUIT, &action, NULL)); | 541 CHECK_EQ(0, sigaction(SIGQUIT, &action, NULL)); |
| 537 CHECK_EQ(0, sigaction(SIGTERM, &action, NULL)); | 542 CHECK_EQ(0, sigaction(SIGTERM, &action, NULL)); |
| 538 | 543 |
| 539 auto controller = base::FileDescriptorWatcher::WatchReadable( | 544 auto controller = base::FileDescriptorWatcher::WatchReadable( |
| 540 g_shutdown_pipe[0], base::Bind(&OnShutdownPipeReadable)); | 545 g_shutdown_pipe[0], base::Bind(&OnShutdownPipeReadable)); |
| 541 #endif // defined(OS_POSIX) | 546 #endif // defined(OS_POSIX) && !defined(OS_FUCHSIA) |
| 542 | 547 |
| 543 // Start the watchdog timer. | 548 // Start the watchdog timer. |
| 544 watchdog_timer_.Reset(); | 549 watchdog_timer_.Reset(); |
| 545 | 550 |
| 546 ThreadTaskRunnerHandle::Get()->PostTask( | 551 ThreadTaskRunnerHandle::Get()->PostTask( |
| 547 FROM_HERE, BindOnce(&TestLauncher::RunTestIteration, Unretained(this))); | 552 FROM_HERE, BindOnce(&TestLauncher::RunTestIteration, Unretained(this))); |
| 548 | 553 |
| 549 RunLoop().Run(); | 554 RunLoop().Run(); |
| 550 | 555 |
| 551 if (requested_cycles != 1) | 556 if (requested_cycles != 1) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 result.status == TestResult::TEST_UNKNOWN) { | 677 result.status == TestResult::TEST_UNKNOWN) { |
| 673 test_broken_count_++; | 678 test_broken_count_++; |
| 674 } | 679 } |
| 675 size_t broken_threshold = | 680 size_t broken_threshold = |
| 676 std::max(static_cast<size_t>(20), test_found_count_ / 10); | 681 std::max(static_cast<size_t>(20), test_found_count_ / 10); |
| 677 if (!force_run_broken_tests_ && test_broken_count_ >= broken_threshold) { | 682 if (!force_run_broken_tests_ && test_broken_count_ >= broken_threshold) { |
| 678 fprintf(stdout, "Too many badly broken tests (%" PRIuS "), exiting now.\n", | 683 fprintf(stdout, "Too many badly broken tests (%" PRIuS "), exiting now.\n", |
| 679 test_broken_count_); | 684 test_broken_count_); |
| 680 fflush(stdout); | 685 fflush(stdout); |
| 681 | 686 |
| 682 #if defined(OS_POSIX) | 687 #if defined(OS_POSIX) && !defined(OS_FUCHSIA) |
| 683 KillSpawnedTestProcesses(); | 688 KillSpawnedTestProcesses(); |
| 684 #endif // defined(OS_POSIX) | 689 #endif // defined(OS_POSIX) && !defined(OS_FUCHSIA) |
| 685 | 690 |
| 686 MaybeSaveSummaryAsJSON({"BROKEN_TEST_EARLY_EXIT", kUnreliableResultsTag}); | 691 MaybeSaveSummaryAsJSON({"BROKEN_TEST_EARLY_EXIT", kUnreliableResultsTag}); |
| 687 | 692 |
| 688 exit(1); | 693 exit(1); |
| 689 } | 694 } |
| 690 | 695 |
| 691 if (test_finished_count_ != test_started_count_) | 696 if (test_finished_count_ != test_started_count_) |
| 692 return; | 697 return; |
| 693 | 698 |
| 694 if (tests_to_retry_.empty() || retry_count_ >= retry_limit_) { | 699 if (tests_to_retry_.empty() || retry_count_ >= retry_limit_) { |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 } | 1217 } |
| 1213 | 1218 |
| 1214 std::string snippet(full_output.substr(run_pos)); | 1219 std::string snippet(full_output.substr(run_pos)); |
| 1215 if (end_pos != std::string::npos) | 1220 if (end_pos != std::string::npos) |
| 1216 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1221 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 1217 | 1222 |
| 1218 return snippet; | 1223 return snippet; |
| 1219 } | 1224 } |
| 1220 | 1225 |
| 1221 } // namespace base | 1226 } // namespace base |
| OLD | NEW |