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

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

Issue 23480061: GTTF: launch test processes using job objects on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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/process/launch_win.cc ('k') | chrome/browser/component_updater/component_patcher_win.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/test_launcher.h" 5 #include "base/test/test_launcher.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 533
534 int LaunchChildTestProcessWithOptions(const CommandLine& command_line, 534 int LaunchChildTestProcessWithOptions(const CommandLine& command_line,
535 const LaunchOptions& options, 535 const LaunchOptions& options,
536 base::TimeDelta timeout, 536 base::TimeDelta timeout,
537 bool* was_timeout) { 537 bool* was_timeout) {
538 #if defined(OS_POSIX) 538 #if defined(OS_POSIX)
539 // Make sure an option we rely on is present - see LaunchChildGTestProcess. 539 // Make sure an option we rely on is present - see LaunchChildGTestProcess.
540 DCHECK(options.new_process_group); 540 DCHECK(options.new_process_group);
541 #endif 541 #endif
542 542
543 LaunchOptions new_options(options);
544
545 #if defined(OS_WIN)
546 DCHECK(!new_options.job_handle);
547
548 win::ScopedHandle job_handle(CreateJobObject(NULL, NULL));
549 if (!job_handle.IsValid()) {
550 LOG(ERROR) << "Could not create JobObject.";
551 return -1;
552 }
553
554 // Allow break-away from job since sandbox and few other places rely on it
555 // on Windows versions prior to Windows 8 (which supports nested jobs).
556 // TODO(phajdan.jr): Do not allow break-away on Windows 8.
557 if (!SetJobObjectLimitFlags(job_handle.Get(),
558 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE |
cpu_(ooo_6.6-7.5) 2013/09/10 21:08:56 but the job closes because its owned by the scoped
Paweł Hajdan Jr. 2013/09/10 21:49:53 Yes, this is intended: by the time this function r
559 JOB_OBJECT_LIMIT_BREAKAWAY_OK)) {
560 LOG(ERROR) << "Could not SetJobObjectLimitFlags.";
cpu_(ooo_6.6-7.5) 2013/09/10 21:08:56 so if the sandbox breaks away from your job then y
Paweł Hajdan Jr. 2013/09/10 21:49:53 This is not worse than the current state of things
561 return false;
sky 2013/09/11 19:29:06 -1?
Paweł Hajdan Jr. 2013/09/11 20:43:08 Done.
562 }
563
564 new_options.job_handle = job_handle.Get();
565 #endif // defined(OS_WIN)
566
543 base::ProcessHandle process_handle; 567 base::ProcessHandle process_handle;
544 if (!base::LaunchProcess(command_line, options, &process_handle)) 568 if (!base::LaunchProcess(command_line, new_options, &process_handle))
545 return -1; 569 return -1;
546 570
547 int exit_code = 0; 571 int exit_code = 0;
548 if (!base::WaitForExitCodeWithTimeout(process_handle, 572 if (!base::WaitForExitCodeWithTimeout(process_handle,
549 &exit_code, 573 &exit_code,
550 timeout)) { 574 timeout)) {
551 *was_timeout = true; 575 *was_timeout = true;
552 exit_code = -1; // Set a non-zero exit code to signal a failure. 576 exit_code = -1; // Set a non-zero exit code to signal a failure.
553 577
554 // Ensure that the process terminates. 578 // Ensure that the process terminates.
555 base::KillProcess(process_handle, -1, true); 579 base::KillProcess(process_handle, -1, true);
cpu_(ooo_6.6-7.5) 2013/09/10 21:08:56 do we need 579?
Paweł Hajdan Jr. 2013/09/10 21:49:53 Yes. For example, POSIX (Linux, Mac...).
556 } 580 }
557 581
558 #if defined(OS_POSIX) 582 #if defined(OS_POSIX)
559 if (exit_code != 0) { 583 if (exit_code != 0) {
560 // On POSIX, in case the test does not exit cleanly, either due to a crash 584 // On POSIX, in case the test does not exit cleanly, either due to a crash
561 // or due to it timing out, we need to clean up any child processes that 585 // or due to it timing out, we need to clean up any child processes that
562 // it might have created. On Windows, child processes are automatically 586 // it might have created. On Windows, child processes are automatically
563 // cleaned up using JobObjects. 587 // cleaned up using JobObjects.
564 base::KillProcessGroup(process_handle); 588 base::KillProcessGroup(process_handle);
565 } 589 }
(...skipping 29 matching lines...) Expand all
595 cycles, 619 cycles,
596 &exit_code, 620 &exit_code,
597 true)); 621 true));
598 622
599 MessageLoop::current()->Run(); 623 MessageLoop::current()->Run();
600 624
601 return exit_code; 625 return exit_code;
602 } 626 }
603 627
604 } // namespace base 628 } // namespace base
OLDNEW
« no previous file with comments | « base/process/launch_win.cc ('k') | chrome/browser/component_updater/component_patcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698