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_at_least_one_positive_filter_ = !filter_a.empty() || !filter_b.empty(); | |
| 957 if (!has_at_least_one_positive_filter_) { | |
| 958 return; | |
| 959 } else { | |
|
Dirk Pranke
2016/12/01 20:42:56
If you have the early return on line 958, you don'
| |
| 960 // If two positive filters are present, only run tests that match a pattern | |
| 961 // in both filters. | |
| 962 if (!filter_a.empty() && !filter_b.empty()) { | |
| 963 for (size_t i = 0; i < tests_.size(); i++) { | |
| 964 std::string test_name = | |
| 965 FormatFullTestName(tests_[i].test_case_name, tests_[i].test_name); | |
| 966 bool found_a = false; | |
| 967 bool found_b = false; | |
| 968 for (size_t k = 0; k < filter_a.size(); ++k) { | |
| 969 found_a = found_a || MatchPattern(test_name, filter_a[k]); | |
| 970 } | |
| 971 for (size_t k = 0; k < filter_b.size(); ++k) { | |
| 972 found_b = found_b || MatchPattern(test_name, filter_b[k]); | |
| 973 } | |
| 974 if (found_a && found_b) { | |
| 975 positive_test_filter_.push_back(test_name); | |
| 976 } | |
| 977 } | |
| 978 } else if (!filter_a.empty()) { | |
| 979 positive_test_filter_ = filter_a; | |
| 980 } else { | |
| 981 positive_test_filter_ = filter_b; | |
| 982 } | |
| 983 } | |
| 984 } | |
| 985 | |
| 954 void TestLauncher::RunTests() { | 986 void TestLauncher::RunTests() { |
| 955 std::vector<std::string> test_names; | 987 std::vector<std::string> test_names; |
| 956 for (size_t i = 0; i < tests_.size(); i++) { | 988 for (size_t i = 0; i < tests_.size(); i++) { |
| 957 std::string test_name = FormatFullTestName( | 989 std::string test_name = |
| 958 tests_[i].test_case_name, tests_[i].test_name); | 990 FormatFullTestName(tests_[i].test_case_name, tests_[i].test_name); |
| 959 | 991 |
| 960 results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line); | 992 results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line); |
| 961 | 993 |
| 962 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 994 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 963 if (test_name.find("DISABLED") != std::string::npos) { | 995 if (test_name.find("DISABLED") != std::string::npos) { |
| 964 results_tracker_.AddDisabledTest(test_name); | 996 results_tracker_.AddDisabledTest(test_name); |
| 965 | 997 |
| 966 // Skip disabled tests unless explicitly requested. | 998 // Skip disabled tests unless explicitly requested. |
| 967 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) | 999 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) |
| 968 continue; | 1000 continue; |
| 969 } | 1001 } |
| 970 | 1002 |
| 971 if (!launcher_delegate_->ShouldRunTest( | 1003 if (!launcher_delegate_->ShouldRunTest(tests_[i].test_case_name, |
| 972 tests_[i].test_case_name, tests_[i].test_name)) { | 1004 tests_[i].test_name)) { |
| 973 continue; | 1005 continue; |
| 974 } | 1006 } |
| 975 | 1007 |
| 976 // Count tests in the binary, before we apply filter and sharding. | 1008 // Count tests in the binary, before we apply filter and sharding. |
| 977 test_found_count_++; | 1009 test_found_count_++; |
| 978 | 1010 |
| 979 std::string test_name_no_disabled = TestNameWithoutDisabledPrefix( | 1011 std::string test_name_no_disabled = |
| 980 test_name); | 1012 TestNameWithoutDisabledPrefix(test_name); |
| 981 | 1013 |
| 982 // Skip the test that doesn't match the filter (if given). | 1014 // Skip the test that doesn't match the filter (if given). |
| 983 if (!positive_test_filter_.empty()) { | 1015 if (has_at_least_one_positive_filter_) { |
|
Dirk Pranke
2016/12/01 20:42:56
This is a better name, thanks!
| |
| 984 bool found = false; | 1016 bool found = false; |
| 985 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { | 1017 for (auto filter : positive_test_filter_) { |
| 986 if (MatchPattern(test_name, positive_test_filter_[k]) || | 1018 if (MatchPattern(test_name, filter) || |
| 987 MatchPattern(test_name_no_disabled, positive_test_filter_[k])) { | 1019 MatchPattern(test_name_no_disabled, filter)) { |
| 988 found = true; | 1020 found = true; |
| 989 break; | 1021 break; |
| 990 } | 1022 } |
| 991 } | 1023 } |
| 992 | 1024 |
| 993 if (!found) | 1025 if (!found) |
| 994 continue; | 1026 continue; |
| 995 } | 1027 } |
| 996 if (!negative_test_filter_.empty()) { | 1028 if (!negative_test_filter_.empty()) { |
| 997 bool excluded = false; | 1029 bool excluded = false; |
| 998 for (size_t k = 0; k < negative_test_filter_.size(); ++k) { | 1030 for (auto filter : negative_test_filter_) { |
| 999 if (MatchPattern(test_name, negative_test_filter_[k]) || | 1031 if (MatchPattern(test_name, filter) || |
| 1000 MatchPattern(test_name_no_disabled, negative_test_filter_[k])) { | 1032 MatchPattern(test_name_no_disabled, filter)) { |
| 1001 excluded = true; | 1033 excluded = true; |
| 1002 break; | 1034 break; |
| 1003 } | 1035 } |
| 1004 } | 1036 } |
| 1005 | 1037 |
| 1006 if (excluded) | 1038 if (excluded) |
| 1007 continue; | 1039 continue; |
| 1008 } | 1040 } |
| 1009 | 1041 |
| 1010 if (Hash(test_name) % total_shards_ != static_cast<uint32_t>(shard_index_)) | 1042 if (Hash(test_name) % total_shards_ != static_cast<uint32_t>(shard_index_)) |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 } | 1200 } |
| 1169 | 1201 |
| 1170 std::string snippet(full_output.substr(run_pos)); | 1202 std::string snippet(full_output.substr(run_pos)); |
| 1171 if (end_pos != std::string::npos) | 1203 if (end_pos != std::string::npos) |
| 1172 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1204 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 1173 | 1205 |
| 1174 return snippet; | 1206 return snippet; |
| 1175 } | 1207 } |
| 1176 | 1208 |
| 1177 } // namespace base | 1209 } // namespace base |
| OLD | NEW |