Chromium Code Reviews| 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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 fprintf(stdout, "Using %" PRIuS " parallel jobs.\n", parallel_jobs_); | 819 fprintf(stdout, "Using %" PRIuS " parallel jobs.\n", parallel_jobs_); |
| 820 fflush(stdout); | 820 fflush(stdout); |
| 821 if (parallel_jobs_ > 1U) { | 821 if (parallel_jobs_ > 1U) { |
| 822 worker_pool_owner_ = MakeUnique<SequencedWorkerPoolOwner>( | 822 worker_pool_owner_ = MakeUnique<SequencedWorkerPoolOwner>( |
| 823 parallel_jobs_, "test_launcher"); | 823 parallel_jobs_, "test_launcher"); |
| 824 } else { | 824 } else { |
| 825 worker_thread_ = MakeUnique<Thread>("test_launcher"); | 825 worker_thread_ = MakeUnique<Thread>("test_launcher"); |
| 826 worker_thread_->Start(); | 826 worker_thread_->Start(); |
| 827 } | 827 } |
| 828 | 828 |
| 829 if (command_line->HasSwitch(switches::kTestLauncherFilterFile) && | 829 std::vector<std::string> positive_file_filter; |
| 830 command_line->HasSwitch(kGTestFilterFlag)) { | 830 std::vector<std::string> positive_gtest_filter; |
| 831 LOG(ERROR) << "Only one of --test-launcher-filter-file and --gtest_filter " | |
| 832 << "at a time is allowed."; | |
| 833 return false; | |
| 834 } | |
| 835 | 831 |
| 836 if (command_line->HasSwitch(switches::kTestLauncherFilterFile)) { | 832 if (command_line->HasSwitch(switches::kTestLauncherFilterFile)) { |
| 837 base::FilePath filter_file_path = base::MakeAbsoluteFilePath( | 833 base::FilePath filter_file_path = base::MakeAbsoluteFilePath( |
| 838 command_line->GetSwitchValuePath(switches::kTestLauncherFilterFile)); | 834 command_line->GetSwitchValuePath(switches::kTestLauncherFilterFile)); |
| 839 std::string filter; | 835 std::string filter; |
| 840 if (!ReadFileToString(filter_file_path, &filter)) { | 836 if (!ReadFileToString(filter_file_path, &filter)) { |
| 841 LOG(ERROR) << "Failed to read the filter file."; | 837 LOG(ERROR) << "Failed to read the filter file."; |
| 842 return false; | 838 return false; |
| 843 } | 839 } |
| 844 | 840 |
| 845 // Parse the file contents (see //testing/buildbot/filters/README.md | 841 // Parse the file contents (see //testing/buildbot/filters/README.md |
| 846 // for file syntax and other info). | 842 // for file syntax and other info). |
| 847 std::vector<std::string> filter_lines = SplitString( | 843 std::vector<std::string> filter_lines = SplitString( |
| 848 filter, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 844 filter, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 849 for (const std::string& filter_line : filter_lines) { | 845 for (const std::string& filter_line : filter_lines) { |
| 850 if (filter_line.empty() || filter_line[0] == '#') | 846 if (filter_line.empty() || filter_line[0] == '#') |
| 851 continue; | 847 continue; |
| 852 | 848 |
| 853 if (filter_line[0] == '-') | 849 if (filter_line[0] == '-') |
| 854 negative_test_filter_.push_back(filter_line.substr(1)); | 850 negative_test_filter_.push_back(filter_line.substr(1)); |
| 855 else | 851 else |
| 856 positive_test_filter_.push_back(filter_line); | 852 positive_file_filter.push_back(filter_line); |
| 857 } | 853 } |
| 854 } | |
| 855 // Split --gtest_filter at '-', if there is one, to separate into | |
| 856 // positive filter and negative filter portions. | |
| 857 std::string filter = command_line->GetSwitchValueASCII(kGTestFilterFlag); | |
| 858 size_t dash_pos = filter.find('-'); | |
| 859 if (dash_pos == std::string::npos) { | |
| 860 positive_gtest_filter = | |
| 861 SplitString(filter, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
| 858 } else { | 862 } else { |
| 859 // Split --gtest_filter at '-', if there is one, to separate into | 863 // Everything up to the dash. |
| 860 // positive filter and negative filter portions. | 864 positive_gtest_filter = |
| 861 std::string filter = command_line->GetSwitchValueASCII(kGTestFilterFlag); | 865 SplitString(filter.substr(0, dash_pos), ":", base::TRIM_WHITESPACE, |
| 862 size_t dash_pos = filter.find('-'); | 866 base::SPLIT_WANT_ALL); |
| 863 if (dash_pos == std::string::npos) { | |
| 864 positive_test_filter_ = SplitString( | |
| 865 filter, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
| 866 } else { | |
| 867 // Everything up to the dash. | |
| 868 positive_test_filter_ = SplitString( | |
| 869 filter.substr(0, dash_pos), ":", base::TRIM_WHITESPACE, | |
| 870 base::SPLIT_WANT_ALL); | |
| 871 | 867 |
| 872 // Everything after the dash. | 868 // Everything after the dash. |
| 873 negative_test_filter_ = SplitString( | 869 for (std::string pattern : |
| 874 filter.substr(dash_pos + 1), ":", base::TRIM_WHITESPACE, | 870 SplitString(filter.substr(dash_pos + 1), ":", base::TRIM_WHITESPACE, |
| 875 base::SPLIT_WANT_ALL); | 871 base::SPLIT_WANT_ALL)) { |
| 872 negative_test_filter_.push_back(pattern); | |
| 876 } | 873 } |
| 877 } | 874 } |
| 878 | 875 |
| 879 if (!launcher_delegate_->GetTests(&tests_)) { | 876 if (!launcher_delegate_->GetTests(&tests_)) { |
| 880 LOG(ERROR) << "Failed to get list of tests."; | 877 LOG(ERROR) << "Failed to get list of tests."; |
| 881 return false; | 878 return false; |
| 882 } | 879 } |
| 883 | 880 |
| 881 CombinePositiveTestFilters(positive_gtest_filter, positive_file_filter); | |
| 882 | |
| 884 if (!results_tracker_.Init(*command_line)) { | 883 if (!results_tracker_.Init(*command_line)) { |
| 885 LOG(ERROR) << "Failed to initialize test results tracker."; | 884 LOG(ERROR) << "Failed to initialize test results tracker."; |
| 886 return 1; | 885 return 1; |
| 887 } | 886 } |
| 888 | 887 |
| 889 #if defined(NDEBUG) | 888 #if defined(NDEBUG) |
| 890 results_tracker_.AddGlobalTag("MODE_RELEASE"); | 889 results_tracker_.AddGlobalTag("MODE_RELEASE"); |
| 891 #else | 890 #else |
| 892 results_tracker_.AddGlobalTag("MODE_DEBUG"); | 891 results_tracker_.AddGlobalTag("MODE_DEBUG"); |
| 893 #endif | 892 #endif |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 results_tracker_.AddGlobalTag("CPU_32_BITS"); | 943 results_tracker_.AddGlobalTag("CPU_32_BITS"); |
| 945 #endif | 944 #endif |
| 946 | 945 |
| 947 #if defined(ARCH_CPU_64_BITS) | 946 #if defined(ARCH_CPU_64_BITS) |
| 948 results_tracker_.AddGlobalTag("CPU_64_BITS"); | 947 results_tracker_.AddGlobalTag("CPU_64_BITS"); |
| 949 #endif | 948 #endif |
| 950 | 949 |
| 951 return true; | 950 return true; |
| 952 } | 951 } |
| 953 | 952 |
| 953 void TestLauncher::CombinePositiveTestFilters( | |
| 954 std::vector<std::string> filter_a, | |
| 955 std::vector<std::string> filter_b) { | |
| 956 has_positive_filter_ = !filter_a.empty() || !filter_b.empty(); | |
| 957 if (has_positive_filter_) { | |
|
Paweł Hajdan Jr.
2016/12/01 17:50:43
nit: Instead of big nested block, return early:
i
katthomas
2016/12/01 19:06:52
Done.
| |
| 958 // If two positive filters are present, only run tests that match a pattern | |
| 959 // in both filters. | |
| 960 if (!filter_a.empty() && !filter_b.empty()) { | |
| 961 for (size_t i = 0; i < tests_.size(); i++) { | |
| 962 std::string test_name = | |
| 963 FormatFullTestName(tests_[i].test_case_name, tests_[i].test_name); | |
| 964 bool found_a = false; | |
| 965 bool found_b = false; | |
| 966 for (size_t k = 0; k < filter_a.size(); ++k) { | |
| 967 found_a = found_a || MatchPattern(test_name, filter_a[k]); | |
| 968 } | |
| 969 for (size_t k = 0; k < filter_b.size(); ++k) { | |
| 970 found_b = found_b || MatchPattern(test_name, filter_b[k]); | |
| 971 } | |
| 972 if (found_a && found_b) { | |
| 973 positive_test_filter_.push_back(test_name); | |
| 974 } | |
| 975 } | |
| 976 } else if (!filter_a.empty()) { | |
| 977 positive_test_filter_ = filter_a; | |
| 978 } else { | |
| 979 positive_test_filter_ = filter_b; | |
| 980 } | |
| 981 } | |
| 982 } | |
| 983 | |
| 954 void TestLauncher::RunTests() { | 984 void TestLauncher::RunTests() { |
| 955 std::vector<std::string> test_names; | 985 std::vector<std::string> test_names; |
| 956 for (size_t i = 0; i < tests_.size(); i++) { | 986 for (size_t i = 0; i < tests_.size(); i++) { |
| 957 std::string test_name = FormatFullTestName( | 987 std::string test_name = |
| 958 tests_[i].test_case_name, tests_[i].test_name); | 988 FormatFullTestName(tests_[i].test_case_name, tests_[i].test_name); |
| 959 | 989 |
| 960 results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line); | 990 results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line); |
| 961 | 991 |
| 962 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 992 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 963 if (test_name.find("DISABLED") != std::string::npos) { | 993 if (test_name.find("DISABLED") != std::string::npos) { |
| 964 results_tracker_.AddDisabledTest(test_name); | 994 results_tracker_.AddDisabledTest(test_name); |
| 965 | 995 |
| 966 // Skip disabled tests unless explicitly requested. | 996 // Skip disabled tests unless explicitly requested. |
| 967 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) | 997 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) |
| 968 continue; | 998 continue; |
| 969 } | 999 } |
| 970 | 1000 |
| 971 if (!launcher_delegate_->ShouldRunTest( | 1001 if (!launcher_delegate_->ShouldRunTest(tests_[i].test_case_name, |
| 972 tests_[i].test_case_name, tests_[i].test_name)) { | 1002 tests_[i].test_name)) { |
| 973 continue; | 1003 continue; |
| 974 } | 1004 } |
| 975 | 1005 |
| 976 // Count tests in the binary, before we apply filter and sharding. | 1006 // Count tests in the binary, before we apply filter and sharding. |
| 977 test_found_count_++; | 1007 test_found_count_++; |
| 978 | 1008 |
| 979 std::string test_name_no_disabled = TestNameWithoutDisabledPrefix( | 1009 std::string test_name_no_disabled = |
| 980 test_name); | 1010 TestNameWithoutDisabledPrefix(test_name); |
| 981 | 1011 |
| 982 // Skip the test that doesn't match the filter (if given). | 1012 // Skip the test that doesn't match the filter (if given). |
| 983 if (!positive_test_filter_.empty()) { | 1013 if (has_positive_filter_) { |
| 984 bool found = false; | 1014 bool found = false; |
| 985 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { | 1015 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { |
|
Dirk Pranke
2016/12/01 01:40:00
The code is easier to read as a range-based loop,
katthomas
2016/12/01 19:06:52
Ah, good point. Well, those aren't member variable
| |
| 986 if (MatchPattern(test_name, positive_test_filter_[k]) || | 1016 if (MatchPattern(test_name, positive_test_filter_[k]) || |
| 987 MatchPattern(test_name_no_disabled, positive_test_filter_[k])) { | 1017 MatchPattern(test_name_no_disabled, positive_test_filter_[k])) { |
| 988 found = true; | 1018 found = true; |
| 989 break; | 1019 break; |
| 990 } | 1020 } |
| 991 } | 1021 } |
| 992 | 1022 |
| 993 if (!found) | 1023 if (!found) |
| 994 continue; | 1024 continue; |
| 995 } | 1025 } |
| 996 if (!negative_test_filter_.empty()) { | 1026 if (!negative_test_filter_.empty()) { |
| 997 bool excluded = false; | 1027 bool excluded = false; |
| 998 for (size_t k = 0; k < negative_test_filter_.size(); ++k) { | 1028 for (size_t k = 0; k < negative_test_filter_.size(); ++k) { |
|
Dirk Pranke
2016/12/01 01:40:00
same comment about the range-based loop.
katthomas
2016/12/01 19:06:52
Done.
| |
| 999 if (MatchPattern(test_name, negative_test_filter_[k]) || | 1029 if (MatchPattern(test_name, negative_test_filter_[k]) || |
| 1000 MatchPattern(test_name_no_disabled, negative_test_filter_[k])) { | 1030 MatchPattern(test_name_no_disabled, negative_test_filter_[k])) { |
| 1001 excluded = true; | 1031 excluded = true; |
| 1002 break; | 1032 break; |
| 1003 } | 1033 } |
| 1004 } | 1034 } |
| 1005 | 1035 |
| 1006 if (excluded) | 1036 if (excluded) |
| 1007 continue; | 1037 continue; |
| 1008 } | 1038 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 } | 1198 } |
| 1169 | 1199 |
| 1170 std::string snippet(full_output.substr(run_pos)); | 1200 std::string snippet(full_output.substr(run_pos)); |
| 1171 if (end_pos != std::string::npos) | 1201 if (end_pos != std::string::npos) |
| 1172 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1202 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 1173 | 1203 |
| 1174 return snippet; | 1204 return snippet; |
| 1175 } | 1205 } |
| 1176 | 1206 |
| 1177 } // namespace base | 1207 } // namespace base |
| OLD | NEW |