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/test_launcher.h" | 5 #include "base/test/test_launcher.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 std::string test_name = test_info->test_case_name(); | 476 std::string test_name = test_info->test_case_name(); |
477 test_name.append("."); | 477 test_name.append("."); |
478 test_name.append(test_info->name()); | 478 test_name.append(test_info->name()); |
479 | 479 |
480 // Skip disabled tests. | 480 // Skip disabled tests. |
481 if (test_name.find("DISABLED") != std::string::npos && | 481 if (test_name.find("DISABLED") != std::string::npos && |
482 !command_line->HasSwitch(kGTestRunDisabledTestsFlag)) { | 482 !command_line->HasSwitch(kGTestRunDisabledTestsFlag)) { |
483 continue; | 483 continue; |
484 } | 484 } |
485 | 485 |
| 486 std::string filtering_test_name = |
| 487 launcher_delegate->GetTestNameForFiltering(test_case, test_info); |
| 488 |
486 // Skip the test that doesn't match the filter string (if given). | 489 // Skip the test that doesn't match the filter string (if given). |
487 if ((!positive_filter.empty() && | 490 if ((!positive_filter.empty() && |
488 !MatchesFilter(test_name, positive_filter)) || | 491 !MatchesFilter(filtering_test_name, positive_filter)) || |
489 MatchesFilter(test_name, negative_filter)) { | 492 MatchesFilter(filtering_test_name, negative_filter)) { |
490 continue; | 493 continue; |
491 } | 494 } |
492 | 495 |
493 if (!launcher_delegate->ShouldRunTest(test_case, test_info)) | 496 if (!launcher_delegate->ShouldRunTest(test_case, test_info)) |
494 continue; | 497 continue; |
495 | 498 |
496 bool should_run = ShouldRunTestOnShard(total_shards, shard_index, | 499 bool should_run = ShouldRunTestOnShard(total_shards, shard_index, |
497 num_runnable_tests); | 500 num_runnable_tests); |
498 num_runnable_tests++; | 501 num_runnable_tests++; |
499 if (!should_run) | 502 if (!should_run) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 const char kGTestOutputFlag[] = "gtest_output"; | 565 const char kGTestOutputFlag[] = "gtest_output"; |
563 | 566 |
564 const char kHelpFlag[] = "help"; | 567 const char kHelpFlag[] = "help"; |
565 | 568 |
566 TestResult::TestResult() : status(TEST_UNKNOWN) { | 569 TestResult::TestResult() : status(TEST_UNKNOWN) { |
567 } | 570 } |
568 | 571 |
569 TestLauncherDelegate::~TestLauncherDelegate() { | 572 TestLauncherDelegate::~TestLauncherDelegate() { |
570 } | 573 } |
571 | 574 |
| 575 void PrintTestOutputSnippetOnFailure(const TestResult& result, |
| 576 const std::string& full_output) { |
| 577 if (result.status == TestResult::TEST_SUCCESS) |
| 578 return; |
| 579 |
| 580 size_t run_pos = full_output.find(std::string("[ RUN ] ") + |
| 581 result.GetFullName()); |
| 582 if (run_pos == std::string::npos) |
| 583 return; |
| 584 |
| 585 size_t end_pos = full_output.find(std::string("[ FAILED ] ") + |
| 586 result.GetFullName(), |
| 587 run_pos); |
| 588 if (end_pos != std::string::npos) { |
| 589 size_t newline_pos = full_output.find("\n", end_pos); |
| 590 if (newline_pos != std::string::npos) |
| 591 end_pos = newline_pos + 1; |
| 592 } |
| 593 |
| 594 std::string snippet(full_output.substr(run_pos)); |
| 595 if (end_pos != std::string::npos) |
| 596 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 597 |
| 598 // TODO(phajdan.jr): Indent each line of the snippet so it's more |
| 599 // noticeable. |
| 600 fprintf(stdout, "%s", snippet.c_str()); |
| 601 fflush(stdout); |
| 602 } |
| 603 |
572 int LaunchChildGTestProcess(const CommandLine& command_line, | 604 int LaunchChildGTestProcess(const CommandLine& command_line, |
573 const std::string& wrapper, | 605 const std::string& wrapper, |
574 base::TimeDelta timeout, | 606 base::TimeDelta timeout, |
575 bool* was_timeout) { | 607 bool* was_timeout) { |
576 LaunchOptions options; | 608 LaunchOptions options; |
577 | 609 |
578 #if defined(OS_POSIX) | 610 #if defined(OS_POSIX) |
579 // On POSIX, we launch the test in a new process group with pgid equal to | 611 // On POSIX, we launch the test in a new process group with pgid equal to |
580 // its pid. Any child processes that the test may create will inherit the | 612 // its pid. Any child processes that the test may create will inherit the |
581 // same pgid. This way, if the test is abruptly terminated, we can clean up | 613 // same pgid. This way, if the test is abruptly terminated, we can clean up |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 cycles, | 778 cycles, |
747 &exit_code, | 779 &exit_code, |
748 true)); | 780 true)); |
749 | 781 |
750 MessageLoop::current()->Run(); | 782 MessageLoop::current()->Run(); |
751 | 783 |
752 return exit_code; | 784 return exit_code; |
753 } | 785 } |
754 | 786 |
755 } // namespace base | 787 } // namespace base |
OLD | NEW |