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

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

Issue 2692273008: Hacky slashy (Closed)
Patch Set: rebase on config CL, and minor fixes Created 3 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
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | base/test/launcher/unit_test_launcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #endif 54 #endif
55 55
56 #if defined(OS_MACOSX) 56 #if defined(OS_MACOSX)
57 #include "base/mac/scoped_nsautorelease_pool.h" 57 #include "base/mac/scoped_nsautorelease_pool.h"
58 #endif 58 #endif
59 59
60 #if defined(OS_WIN) 60 #if defined(OS_WIN)
61 #include "base/win/windows_version.h" 61 #include "base/win/windows_version.h"
62 #endif 62 #endif
63 63
64 #if defined(OS_FUCHSIA)
65 #include <magenta/process.h>
66 #include <magenta/syscalls.h>
67 #endif
68
64 namespace base { 69 namespace base {
65 70
66 // See https://groups.google.com/a/chromium.org/d/msg/chromium-dev/nkdTP7sstSc/u T3FaE_sgkAJ . 71 // See https://groups.google.com/a/chromium.org/d/msg/chromium-dev/nkdTP7sstSc/u T3FaE_sgkAJ .
67 using ::operator<<; 72 using ::operator<<;
68 73
69 // The environment variable name for the total number of test shards. 74 // The environment variable name for the total number of test shards.
70 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; 75 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS";
71 // The environment variable name for the test shard index. 76 // The environment variable name for the test shard index.
72 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; 77 const char kTestShardIndex[] = "GTEST_SHARD_INDEX";
73 78
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 static auto* map = new std::map<ProcessHandle, CommandLine>; 112 static auto* map = new std::map<ProcessHandle, CommandLine>;
108 return map; 113 return map;
109 } 114 }
110 115
111 // Performance trace generator. 116 // Performance trace generator.
112 TestLauncherTracer* GetTestLauncherTracer() { 117 TestLauncherTracer* GetTestLauncherTracer() {
113 static auto* tracer = new TestLauncherTracer; 118 static auto* tracer = new TestLauncherTracer;
114 return tracer; 119 return tracer;
115 } 120 }
116 121
117 #if defined(OS_POSIX) 122 #if defined(OS_POSIX) && !defined(OS_FUCHSIA)
118 // Self-pipe that makes it possible to do complex shutdown handling 123 // Self-pipe that makes it possible to do complex shutdown handling
119 // outside of the signal handler. 124 // outside of the signal handler.
120 int g_shutdown_pipe[2] = { -1, -1 }; 125 int g_shutdown_pipe[2] = { -1, -1 };
121 126
122 void ShutdownPipeSignalHandler(int signal) { 127 void ShutdownPipeSignalHandler(int signal) {
123 HANDLE_EINTR(write(g_shutdown_pipe[1], "q", 1)); 128 HANDLE_EINTR(write(g_shutdown_pipe[1], "q", 1));
124 } 129 }
125 130
126 void KillSpawnedTestProcesses() { 131 void KillSpawnedTestProcesses() {
127 // Keep the lock until exiting the process to prevent further processes 132 // Keep the lock until exiting the process to prevent further processes
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 294
290 if (!SetJobObjectLimitFlags(job_handle.Get(), job_flags)) { 295 if (!SetJobObjectLimitFlags(job_handle.Get(), job_flags)) {
291 LOG(ERROR) << "Could not SetJobObjectLimitFlags."; 296 LOG(ERROR) << "Could not SetJobObjectLimitFlags.";
292 return -1; 297 return -1;
293 } 298 }
294 299
295 new_options.job_handle = job_handle.Get(); 300 new_options.job_handle = job_handle.Get();
296 } 301 }
297 #endif // defined(OS_WIN) 302 #endif // defined(OS_WIN)
298 303
304 #if defined(OS_FUCHSIA)
305 DCHECK_EQ(new_options.job_handle, MX_HANDLE_INVALID);
306 if (flags & TestLauncher::USE_JOB_OBJECTS) {
307 mx_status_t status =
308 mx_job_create(mx_job_default(), 0, &new_options.job_handle);
309 if (status < 0) {
310 LOG(ERROR) << "Failed to create job object";
311 return -1;
312 }
313 }
314 #endif
315
299 #if defined(OS_LINUX) 316 #if defined(OS_LINUX)
300 // To prevent accidental privilege sharing to an untrusted child, processes 317 // To prevent accidental privilege sharing to an untrusted child, processes
301 // are started with PR_SET_NO_NEW_PRIVS. Do not set that here, since this 318 // are started with PR_SET_NO_NEW_PRIVS. Do not set that here, since this
302 // new child will be privileged and trusted. 319 // new child will be privileged and trusted.
303 new_options.allow_new_privs = true; 320 new_options.allow_new_privs = true;
304 #endif 321 #endif
305 322
306 Process process; 323 Process process;
307 324
308 { 325 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // Ensure that the process terminates. 366 // Ensure that the process terminates.
350 process.Terminate(-1, true); 367 process.Terminate(-1, true);
351 } 368 }
352 369
353 { 370 {
354 // Note how we grab the log before issuing a possibly broad process kill. 371 // Note how we grab the log before issuing a possibly broad process kill.
355 // Other code parts that grab the log kill processes, so avoid trying 372 // Other code parts that grab the log kill processes, so avoid trying
356 // to do that twice and trigger all kinds of log messages. 373 // to do that twice and trigger all kinds of log messages.
357 AutoLock lock(*GetLiveProcessesLock()); 374 AutoLock lock(*GetLiveProcessesLock());
358 375
359 #if defined(OS_POSIX) 376 #if defined(OS_POSIX) && !defined(OS_FUCHSIA)
360 if (exit_code != 0) { 377 if (exit_code != 0) {
361 // On POSIX, in case the test does not exit cleanly, either due to a crash 378 // On POSIX, in case the test does not exit cleanly, either due to a crash
362 // or due to it timing out, we need to clean up any child processes that 379 // or due to it timing out, we need to clean up any child processes that
363 // it might have created. On Windows, child processes are automatically 380 // it might have created. On Windows, child processes are automatically
364 // cleaned up using JobObjects. 381 // cleaned up using JobObjects.
365 KillProcessGroup(process.Handle()); 382 KillProcessGroup(process.Handle());
366 } 383 }
367 #endif 384 #endif
368 385
369 GetLiveProcesses()->erase(process.Handle()); 386 GetLiveProcesses()->erase(process.Handle());
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 TestLauncher::~TestLauncher() {} 534 TestLauncher::~TestLauncher() {}
518 535
519 bool TestLauncher::Run() { 536 bool TestLauncher::Run() {
520 if (!Init()) 537 if (!Init())
521 return false; 538 return false;
522 539
523 // Value of |cycles_| changes after each iteration. Keep track of the 540 // Value of |cycles_| changes after each iteration. Keep track of the
524 // original value. 541 // original value.
525 int requested_cycles = cycles_; 542 int requested_cycles = cycles_;
526 543
527 #if defined(OS_POSIX) 544 #if defined(OS_POSIX) && !defined(OS_FUCHSIA)
528 CHECK_EQ(0, pipe(g_shutdown_pipe)); 545 CHECK_EQ(0, pipe(g_shutdown_pipe));
529 546
530 struct sigaction action; 547 struct sigaction action;
531 memset(&action, 0, sizeof(action)); 548 memset(&action, 0, sizeof(action));
532 sigemptyset(&action.sa_mask); 549 sigemptyset(&action.sa_mask);
533 action.sa_handler = &ShutdownPipeSignalHandler; 550 action.sa_handler = &ShutdownPipeSignalHandler;
534 551
535 CHECK_EQ(0, sigaction(SIGINT, &action, NULL)); 552 CHECK_EQ(0, sigaction(SIGINT, &action, NULL));
536 CHECK_EQ(0, sigaction(SIGQUIT, &action, NULL)); 553 CHECK_EQ(0, sigaction(SIGQUIT, &action, NULL));
537 CHECK_EQ(0, sigaction(SIGTERM, &action, NULL)); 554 CHECK_EQ(0, sigaction(SIGTERM, &action, NULL));
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 result.status == TestResult::TEST_UNKNOWN) { 689 result.status == TestResult::TEST_UNKNOWN) {
673 test_broken_count_++; 690 test_broken_count_++;
674 } 691 }
675 size_t broken_threshold = 692 size_t broken_threshold =
676 std::max(static_cast<size_t>(20), test_found_count_ / 10); 693 std::max(static_cast<size_t>(20), test_found_count_ / 10);
677 if (!force_run_broken_tests_ && test_broken_count_ >= broken_threshold) { 694 if (!force_run_broken_tests_ && test_broken_count_ >= broken_threshold) {
678 fprintf(stdout, "Too many badly broken tests (%" PRIuS "), exiting now.\n", 695 fprintf(stdout, "Too many badly broken tests (%" PRIuS "), exiting now.\n",
679 test_broken_count_); 696 test_broken_count_);
680 fflush(stdout); 697 fflush(stdout);
681 698
682 #if defined(OS_POSIX) 699 #if defined(OS_POSIX) && !defined(OS_FUCHSIA)
683 KillSpawnedTestProcesses(); 700 KillSpawnedTestProcesses();
684 #endif // defined(OS_POSIX) 701 #endif // defined(OS_POSIX)
685 702
686 MaybeSaveSummaryAsJSON({"BROKEN_TEST_EARLY_EXIT", kUnreliableResultsTag}); 703 MaybeSaveSummaryAsJSON({"BROKEN_TEST_EARLY_EXIT", kUnreliableResultsTag});
687 704
688 exit(1); 705 exit(1);
689 } 706 }
690 707
691 if (test_finished_count_ != test_started_count_) 708 if (test_finished_count_ != test_started_count_)
692 return; 709 return;
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 } 1229 }
1213 1230
1214 std::string snippet(full_output.substr(run_pos)); 1231 std::string snippet(full_output.substr(run_pos));
1215 if (end_pos != std::string::npos) 1232 if (end_pos != std::string::npos)
1216 snippet = full_output.substr(run_pos, end_pos - run_pos); 1233 snippet = full_output.substr(run_pos, end_pos - run_pos);
1217 1234
1218 return snippet; 1235 return snippet;
1219 } 1236 }
1220 1237
1221 } // namespace base 1238 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | base/test/launcher/unit_test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698