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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 const TestLauncher::GTestProcessCompletedCallback& completed_callback, | 383 const TestLauncher::GTestProcessCompletedCallback& completed_callback, |
384 const TestLauncher::GTestProcessLaunchedCallback& launched_callback) { | 384 const TestLauncher::GTestProcessLaunchedCallback& launched_callback) { |
385 TimeTicks start_time = TimeTicks::Now(); | 385 TimeTicks start_time = TimeTicks::Now(); |
386 | 386 |
387 // Redirect child process output to a file. | 387 // Redirect child process output to a file. |
388 FilePath output_file; | 388 FilePath output_file; |
389 CHECK(CreateTemporaryFile(&output_file)); | 389 CHECK(CreateTemporaryFile(&output_file)); |
390 | 390 |
391 LaunchOptions options; | 391 LaunchOptions options; |
392 #if defined(OS_WIN) | 392 #if defined(OS_WIN) |
| 393 options.inherit_mode = test_launch_options.inherit_mode; |
| 394 options.handles_to_inherit = test_launch_options.handles_to_inherit; |
| 395 |
393 win::ScopedHandle handle; | 396 win::ScopedHandle handle; |
394 | 397 |
395 if (redirect_stdio) { | 398 if (redirect_stdio) { |
396 handle.Set(CreateFile(output_file.value().c_str(), GENERIC_WRITE, | 399 handle.Set(CreateFile(output_file.value().c_str(), GENERIC_WRITE, |
397 FILE_SHARE_READ | FILE_SHARE_DELETE, nullptr, | 400 FILE_SHARE_READ | FILE_SHARE_DELETE, nullptr, |
398 OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL)); | 401 OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL)); |
399 CHECK(handle.IsValid()); | 402 CHECK(handle.IsValid()); |
400 options.inherit_handles = true; | |
401 options.stdin_handle = INVALID_HANDLE_VALUE; | 403 options.stdin_handle = INVALID_HANDLE_VALUE; |
402 options.stdout_handle = handle.Get(); | 404 options.stdout_handle = handle.Get(); |
403 options.stderr_handle = handle.Get(); | 405 options.stderr_handle = handle.Get(); |
404 } | 406 // See LaunchOptions.stdout_handle comments for why this compares against |
405 | 407 // FILE_TYPE_CHAR. |
406 if (test_launch_options.inherit_handles) { | 408 if (options.inherit_mode == base::LaunchOptions::Inherit::kSpecific && |
407 if (!options.inherit_handles) { | 409 GetFileType(handle.Get()) != FILE_TYPE_CHAR) |
408 options.inherit_handles = true; | 410 options.handles_to_inherit.push_back(handle.Get()); |
409 options.stdin_handle = nullptr; | |
410 options.stdout_handle = nullptr; | |
411 options.stderr_handle = nullptr; | |
412 } | |
413 DCHECK(!options.handles_to_inherit); | |
414 options.handles_to_inherit = test_launch_options.handles_to_inherit; | |
415 } | 411 } |
416 | 412 |
417 #elif defined(OS_POSIX) | 413 #elif defined(OS_POSIX) |
418 options.new_process_group = true; | 414 options.new_process_group = true; |
419 #if defined(OS_LINUX) | 415 #if defined(OS_LINUX) |
420 options.kill_on_parent_death = true; | 416 options.kill_on_parent_death = true; |
421 #endif // defined(OS_LINUX) | 417 #endif // defined(OS_LINUX) |
422 | 418 |
423 FileHandleMappingVector fds_mapping; | |
424 ScopedFD output_file_fd; | 419 ScopedFD output_file_fd; |
425 | 420 |
| 421 options.fds_to_remap = test_launch_options.fds_to_remap; |
426 if (redirect_stdio) { | 422 if (redirect_stdio) { |
427 output_file_fd.reset(open(output_file.value().c_str(), O_RDWR)); | 423 output_file_fd.reset(open(output_file.value().c_str(), O_RDWR)); |
428 CHECK(output_file_fd.is_valid()); | 424 CHECK(output_file_fd.is_valid()); |
429 | 425 |
430 fds_mapping.push_back(std::make_pair(output_file_fd.get(), STDOUT_FILENO)); | 426 options.fds_to_remap.push_back( |
431 fds_mapping.push_back(std::make_pair(output_file_fd.get(), STDERR_FILENO)); | 427 std::make_pair(output_file_fd.get(), STDOUT_FILENO)); |
432 options.fds_to_remap = &fds_mapping; | 428 options.fds_to_remap.push_back( |
433 } | 429 std::make_pair(output_file_fd.get(), STDERR_FILENO)); |
434 if (test_launch_options.fds_to_remap) { | |
435 fds_mapping.insert(fds_mapping.end(), | |
436 test_launch_options.fds_to_remap->begin(), | |
437 test_launch_options.fds_to_remap->end()); | |
438 options.fds_to_remap = &fds_mapping; | |
439 } | 430 } |
440 #endif | 431 #endif |
441 | 432 |
442 bool was_timeout = false; | 433 bool was_timeout = false; |
443 int exit_code = LaunchChildTestProcessWithOptions( | 434 int exit_code = LaunchChildTestProcessWithOptions( |
444 command_line, options, test_launch_options.flags, timeout, | 435 command_line, options, test_launch_options.flags, timeout, |
445 launched_callback, &was_timeout); | 436 launched_callback, &was_timeout); |
446 | 437 |
447 if (redirect_stdio) { | 438 if (redirect_stdio) { |
448 #if defined(OS_WIN) | 439 #if defined(OS_WIN) |
(...skipping 26 matching lines...) Expand all Loading... |
475 const char kGTestFilterFlag[] = "gtest_filter"; | 466 const char kGTestFilterFlag[] = "gtest_filter"; |
476 const char kGTestFlagfileFlag[] = "gtest_flagfile"; | 467 const char kGTestFlagfileFlag[] = "gtest_flagfile"; |
477 const char kGTestHelpFlag[] = "gtest_help"; | 468 const char kGTestHelpFlag[] = "gtest_help"; |
478 const char kGTestListTestsFlag[] = "gtest_list_tests"; | 469 const char kGTestListTestsFlag[] = "gtest_list_tests"; |
479 const char kGTestRepeatFlag[] = "gtest_repeat"; | 470 const char kGTestRepeatFlag[] = "gtest_repeat"; |
480 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; | 471 const char kGTestRunDisabledTestsFlag[] = "gtest_also_run_disabled_tests"; |
481 const char kGTestOutputFlag[] = "gtest_output"; | 472 const char kGTestOutputFlag[] = "gtest_output"; |
482 | 473 |
483 TestLauncherDelegate::~TestLauncherDelegate() {} | 474 TestLauncherDelegate::~TestLauncherDelegate() {} |
484 | 475 |
| 476 TestLauncher::LaunchOptions::LaunchOptions() = default; |
| 477 TestLauncher::LaunchOptions::LaunchOptions(const LaunchOptions& other) = |
| 478 default; |
| 479 TestLauncher::LaunchOptions::~LaunchOptions() = default; |
| 480 |
485 TestLauncher::TestLauncher(TestLauncherDelegate* launcher_delegate, | 481 TestLauncher::TestLauncher(TestLauncherDelegate* launcher_delegate, |
486 size_t parallel_jobs) | 482 size_t parallel_jobs) |
487 : launcher_delegate_(launcher_delegate), | 483 : launcher_delegate_(launcher_delegate), |
488 total_shards_(1), | 484 total_shards_(1), |
489 shard_index_(0), | 485 shard_index_(0), |
490 cycles_(1), | 486 cycles_(1), |
491 test_found_count_(0), | 487 test_found_count_(0), |
492 test_started_count_(0), | 488 test_started_count_(0), |
493 test_finished_count_(0), | 489 test_finished_count_(0), |
494 test_success_count_(0), | 490 test_success_count_(0), |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 } | 1220 } |
1225 | 1221 |
1226 std::string snippet(full_output.substr(run_pos)); | 1222 std::string snippet(full_output.substr(run_pos)); |
1227 if (end_pos != std::string::npos) | 1223 if (end_pos != std::string::npos) |
1228 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1224 snippet = full_output.substr(run_pos, end_pos - run_pos); |
1229 | 1225 |
1230 return snippet; | 1226 return snippet; |
1231 } | 1227 } |
1232 | 1228 |
1233 } // namespace base | 1229 } // namespace base |
OLD | NEW |