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 #if defined(OS_POSIX) && !defined(OS_FUCHSIA) |
118 // Self-pipe that makes it possible to do complex shutdown handling | 118 // Self-pipe that makes it possible to do complex shutdown handling |
119 // outside of the signal handler. | 119 // outside of the signal handler. |
120 int g_shutdown_pipe[2] = { -1, -1 }; | 120 int g_shutdown_pipe[2] = { -1, -1 }; |
121 | 121 |
122 void ShutdownPipeSignalHandler(int signal) { | 122 void ShutdownPipeSignalHandler(int signal) { |
123 HANDLE_EINTR(write(g_shutdown_pipe[1], "q", 1)); | 123 HANDLE_EINTR(write(g_shutdown_pipe[1], "q", 1)); |
124 } | 124 } |
125 | 125 |
126 void KillSpawnedTestProcesses() { | 126 void KillSpawnedTestProcesses() { |
127 // Keep the lock until exiting the process to prevent further processes | 127 // 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. | 163 // Terminates any launched child processes and exits the process. |
164 void OnShutdownPipeReadable() { | 164 void OnShutdownPipeReadable() { |
165 fprintf(stdout, "\nCaught signal. Killing spawned test processes...\n"); | 165 fprintf(stdout, "\nCaught signal. Killing spawned test processes...\n"); |
166 fflush(stdout); | 166 fflush(stdout); |
167 | 167 |
168 KillSpawnedTestProcesses(); | 168 KillSpawnedTestProcesses(); |
169 | 169 |
170 // The signal would normally kill the process, so exit now. | 170 // The signal would normally kill the process, so exit now. |
171 _exit(1); | 171 _exit(1); |
172 } | 172 } |
173 #endif // defined(OS_POSIX) | 173 #endif // defined(OS_POSIX) && !defined(OS_FUCHSIA) |
174 | 174 |
175 // Parses the environment variable var as an Int32. If it is unset, returns | 175 // 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 | 176 // true. If it is set, unsets it then converts it to Int32 before |
177 // returning it in |result|. Returns true on success. | 177 // returning it in |result|. Returns true on success. |
178 bool TakeInt32FromEnvironment(const char* const var, int32_t* result) { | 178 bool TakeInt32FromEnvironment(const char* const var, int32_t* result) { |
179 std::unique_ptr<Environment> env(Environment::Create()); | 179 std::unique_ptr<Environment> env(Environment::Create()); |
180 std::string str_val; | 180 std::string str_val; |
181 | 181 |
182 if (!env->GetVar(var, &str_val)) | 182 if (!env->GetVar(var, &str_val)) |
183 return true; | 183 return true; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 TestLauncher::~TestLauncher() {} | 517 TestLauncher::~TestLauncher() {} |
518 | 518 |
519 bool TestLauncher::Run() { | 519 bool TestLauncher::Run() { |
520 if (!Init()) | 520 if (!Init()) |
521 return false; | 521 return false; |
522 | 522 |
523 // Value of |cycles_| changes after each iteration. Keep track of the | 523 // Value of |cycles_| changes after each iteration. Keep track of the |
524 // original value. | 524 // original value. |
525 int requested_cycles = cycles_; | 525 int requested_cycles = cycles_; |
526 | 526 |
527 #if defined(OS_POSIX) | 527 #if defined(OS_POSIX) && !defined(OS_FUCHSIA) |
Nico
2017/05/17 15:52:54
Do you expect to never need this? If so, why not?
scottmg
2017/05/17 16:52:51
Done.
| |
528 CHECK_EQ(0, pipe(g_shutdown_pipe)); | 528 CHECK_EQ(0, pipe(g_shutdown_pipe)); |
529 | 529 |
530 struct sigaction action; | 530 struct sigaction action; |
531 memset(&action, 0, sizeof(action)); | 531 memset(&action, 0, sizeof(action)); |
532 sigemptyset(&action.sa_mask); | 532 sigemptyset(&action.sa_mask); |
533 action.sa_handler = &ShutdownPipeSignalHandler; | 533 action.sa_handler = &ShutdownPipeSignalHandler; |
534 | 534 |
535 CHECK_EQ(0, sigaction(SIGINT, &action, NULL)); | 535 CHECK_EQ(0, sigaction(SIGINT, &action, NULL)); |
536 CHECK_EQ(0, sigaction(SIGQUIT, &action, NULL)); | 536 CHECK_EQ(0, sigaction(SIGQUIT, &action, NULL)); |
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) && !defined(OS_FUCHSIA) |
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, BindOnce(&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) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 result.status == TestResult::TEST_UNKNOWN) { | 672 result.status == TestResult::TEST_UNKNOWN) { |
673 test_broken_count_++; | 673 test_broken_count_++; |
674 } | 674 } |
675 size_t broken_threshold = | 675 size_t broken_threshold = |
676 std::max(static_cast<size_t>(20), test_found_count_ / 10); | 676 std::max(static_cast<size_t>(20), test_found_count_ / 10); |
677 if (!force_run_broken_tests_ && test_broken_count_ >= broken_threshold) { | 677 if (!force_run_broken_tests_ && test_broken_count_ >= broken_threshold) { |
678 fprintf(stdout, "Too many badly broken tests (%" PRIuS "), exiting now.\n", | 678 fprintf(stdout, "Too many badly broken tests (%" PRIuS "), exiting now.\n", |
679 test_broken_count_); | 679 test_broken_count_); |
680 fflush(stdout); | 680 fflush(stdout); |
681 | 681 |
682 #if defined(OS_POSIX) | 682 #if defined(OS_POSIX) && !defined(OS_FUCHSIA) |
683 KillSpawnedTestProcesses(); | 683 KillSpawnedTestProcesses(); |
684 #endif // defined(OS_POSIX) | 684 #endif // defined(OS_POSIX) && !defined(OS_FUCHSIA) |
685 | 685 |
686 MaybeSaveSummaryAsJSON({"BROKEN_TEST_EARLY_EXIT", kUnreliableResultsTag}); | 686 MaybeSaveSummaryAsJSON({"BROKEN_TEST_EARLY_EXIT", kUnreliableResultsTag}); |
687 | 687 |
688 exit(1); | 688 exit(1); |
689 } | 689 } |
690 | 690 |
691 if (test_finished_count_ != test_started_count_) | 691 if (test_finished_count_ != test_started_count_) |
692 return; | 692 return; |
693 | 693 |
694 if (tests_to_retry_.empty() || retry_count_ >= retry_limit_) { | 694 if (tests_to_retry_.empty() || retry_count_ >= retry_limit_) { |
(...skipping 517 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 |