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 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/environment.h" | 14 #include "base/environment.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/format_macros.h" | 17 #include "base/format_macros.h" |
18 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
22 #include "base/process/kill.h" | 22 #include "base/process/kill.h" |
23 #include "base/process/launch.h" | 23 #include "base/process/launch.h" |
24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_split.h" | 25 #include "base/strings/string_split.h" |
26 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
| 27 #include "base/strings/stringize_macros.h" |
27 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
28 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
29 #include "base/test/launcher/test_results_tracker.h" | 30 #include "base/test/launcher/test_results_tracker.h" |
30 #include "base/test/sequenced_worker_pool_owner.h" | 31 #include "base/test/sequenced_worker_pool_owner.h" |
31 #include "base/test/test_switches.h" | 32 #include "base/test/test_switches.h" |
32 #include "base/test/test_timeouts.h" | 33 #include "base/test/test_timeouts.h" |
33 #include "base/threading/thread_checker.h" | 34 #include "base/threading/thread_checker.h" |
34 #include "base/time/time.h" | 35 #include "base/time/time.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 | 37 |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 // Everything after the dash. | 678 // Everything after the dash. |
678 SplitString(filter.substr(dash_pos + 1), ':', &negative_test_filter_); | 679 SplitString(filter.substr(dash_pos + 1), ':', &negative_test_filter_); |
679 } | 680 } |
680 } | 681 } |
681 | 682 |
682 if (!results_tracker_.Init(*command_line)) { | 683 if (!results_tracker_.Init(*command_line)) { |
683 LOG(ERROR) << "Failed to initialize test results tracker."; | 684 LOG(ERROR) << "Failed to initialize test results tracker."; |
684 return 1; | 685 return 1; |
685 } | 686 } |
686 | 687 |
| 688 #if defined(NDEBUG) |
| 689 results_tracker_.AddGlobalTag("MODE_RELEASE"); |
| 690 #else |
| 691 results_tracker_.AddGlobalTag("MODE_DEBUG"); |
| 692 #endif |
| 693 |
| 694 // Operating systems (sorted alphabetically). |
| 695 // Note that they can deliberately overlap, e.g. OS_LINUX is a subset |
| 696 // of OS_POSIX. |
| 697 #if defined(OS_ANDROID) |
| 698 results_tracker_.AddGlobalTag("OS_ANDROID"); |
| 699 #endif |
| 700 |
| 701 #if defined(OS_BSD) |
| 702 results_tracker_.AddGlobalTag("OS_BSD"); |
| 703 #endif |
| 704 |
| 705 #if defined(OS_FREEBSD) |
| 706 results_tracker_.AddGlobalTag("OS_FREEBSD"); |
| 707 #endif |
| 708 |
| 709 #if defined(OS_IOS) |
| 710 results_tracker_.AddGlobalTag("OS_IOS"); |
| 711 #endif |
| 712 |
| 713 #if defined(OS_LINUX) |
| 714 results_tracker_.AddGlobalTag("OS_LINUX"); |
| 715 #endif |
| 716 |
| 717 #if defined(OS_MACOSX) |
| 718 results_tracker_.AddGlobalTag("OS_MACOSX"); |
| 719 #endif |
| 720 |
| 721 #if defined(OS_NACL) |
| 722 results_tracker_.AddGlobalTag("OS_NACL"); |
| 723 #endif |
| 724 |
| 725 #if defined(OS_OPENBSD) |
| 726 results_tracker_.AddGlobalTag("OS_OPENBSD"); |
| 727 #endif |
| 728 |
| 729 #if defined(OS_POSIX) |
| 730 results_tracker_.AddGlobalTag("OS_POSIX"); |
| 731 #endif |
| 732 |
| 733 #if defined(OS_SOLARIS) |
| 734 results_tracker_.AddGlobalTag("OS_SOLARIS"); |
| 735 #endif |
| 736 |
| 737 #if defined(OS_WIN) |
| 738 results_tracker_.AddGlobalTag("OS_WIN"); |
| 739 #endif |
| 740 |
| 741 // CPU-related tags. |
| 742 #if defined(ARCH_CPU_32_BITS) |
| 743 results_tracker_.AddGlobalTag("CPU_32_BITS"); |
| 744 #endif |
| 745 |
| 746 #if defined(ARCH_CPU_64_BITS) |
| 747 results_tracker_.AddGlobalTag("CPU_64_BITS"); |
| 748 #endif |
| 749 |
687 return true; | 750 return true; |
688 } | 751 } |
689 | 752 |
690 void TestLauncher::RunTests() { | 753 void TestLauncher::RunTests() { |
691 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance(); | 754 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance(); |
692 | 755 |
693 int num_runnable_tests = 0; | 756 int num_runnable_tests = 0; |
694 | 757 |
695 std::vector<std::string> test_names; | 758 std::vector<std::string> test_names; |
696 | 759 |
697 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { | 760 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { |
698 const testing::TestCase* test_case = unit_test->GetTestCase(i); | 761 const testing::TestCase* test_case = unit_test->GetTestCase(i); |
699 for (int j = 0; j < test_case->total_test_count(); ++j) { | 762 for (int j = 0; j < test_case->total_test_count(); ++j) { |
700 const testing::TestInfo* test_info = test_case->GetTestInfo(j); | 763 const testing::TestInfo* test_info = test_case->GetTestInfo(j); |
701 std::string test_name = test_info->test_case_name(); | 764 std::string test_name = test_info->test_case_name(); |
702 test_name.append("."); | 765 test_name.append("."); |
703 test_name.append(test_info->name()); | 766 test_name.append(test_info->name()); |
704 | 767 |
705 // Skip disabled tests. | 768 results_tracker_.AddTest(test_name); |
| 769 |
706 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 770 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
707 if (test_name.find("DISABLED") != std::string::npos && | 771 if (test_name.find("DISABLED") != std::string::npos) { |
708 !command_line->HasSwitch(kGTestRunDisabledTestsFlag)) { | 772 results_tracker_.AddDisabledTest(test_name); |
709 continue; | 773 |
| 774 // Skip disabled tests unless explicitly requested. |
| 775 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) |
| 776 continue; |
710 } | 777 } |
711 | 778 |
712 std::string filtering_test_name = | 779 std::string filtering_test_name = |
713 launcher_delegate_->GetTestNameForFiltering(test_case, test_info); | 780 launcher_delegate_->GetTestNameForFiltering(test_case, test_info); |
714 | 781 |
715 // Skip the test that doesn't match the filter (if given). | 782 // Skip the test that doesn't match the filter (if given). |
716 if (!positive_test_filter_.empty()) { | 783 if (!positive_test_filter_.empty()) { |
717 bool found = false; | 784 bool found = false; |
718 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { | 785 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { |
719 if (MatchPattern(filtering_test_name, positive_test_filter_[k])) { | 786 if (MatchPattern(filtering_test_name, positive_test_filter_[k])) { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 | 1071 |
1005 g_live_processes.Get().erase(process_handle); | 1072 g_live_processes.Get().erase(process_handle); |
1006 } | 1073 } |
1007 | 1074 |
1008 base::CloseProcessHandle(process_handle); | 1075 base::CloseProcessHandle(process_handle); |
1009 | 1076 |
1010 return exit_code; | 1077 return exit_code; |
1011 } | 1078 } |
1012 | 1079 |
1013 } // namespace base | 1080 } // namespace base |
OLD | NEW |