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) && | |
| 830 command_line->HasSwitch(kGTestFilterFlag)) { | |
| 831 LOG(ERROR) << "Only one of --test-launcher-filter-file and --gtest_filter " | |
| 832 << "at a time is allowed."; | |
| 833 return false; | |
| 834 } | |
| 835 | |
| 836 if (command_line->HasSwitch(switches::kTestLauncherFilterFile)) { | 829 if (command_line->HasSwitch(switches::kTestLauncherFilterFile)) { |
|
Paweł Hajdan Jr.
2016/11/30 12:41:32
If we're extracting code, I'd suggest this flag-re
katthomas
2016/12/01 00:07:00
I agree it would be better if that parsing was ext
| |
| 837 base::FilePath filter_file_path = base::MakeAbsoluteFilePath( | 830 base::FilePath filter_file_path = base::MakeAbsoluteFilePath( |
| 838 command_line->GetSwitchValuePath(switches::kTestLauncherFilterFile)); | 831 command_line->GetSwitchValuePath(switches::kTestLauncherFilterFile)); |
| 839 std::string filter; | 832 std::string filter; |
| 840 if (!ReadFileToString(filter_file_path, &filter)) { | 833 if (!ReadFileToString(filter_file_path, &filter)) { |
| 841 LOG(ERROR) << "Failed to read the filter file."; | 834 LOG(ERROR) << "Failed to read the filter file."; |
| 842 return false; | 835 return false; |
| 843 } | 836 } |
| 844 | 837 |
| 845 // Parse the file contents (see //testing/buildbot/filters/README.md | 838 // Parse the file contents (see //testing/buildbot/filters/README.md |
| 846 // for file syntax and other info). | 839 // for file syntax and other info). |
| 847 std::vector<std::string> filter_lines = SplitString( | 840 std::vector<std::string> filter_lines = SplitString( |
| 848 filter, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 841 filter, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 849 for (const std::string& filter_line : filter_lines) { | 842 for (const std::string& filter_line : filter_lines) { |
| 850 if (filter_line.empty() || filter_line[0] == '#') | 843 if (filter_line.empty() || filter_line[0] == '#') |
| 851 continue; | 844 continue; |
| 852 | 845 |
| 853 if (filter_line[0] == '-') | 846 if (filter_line[0] == '-') |
| 854 negative_test_filter_.push_back(filter_line.substr(1)); | 847 negative_test_filter_file_.push_back(filter_line.substr(1)); |
| 855 else | 848 else |
| 856 positive_test_filter_.push_back(filter_line); | 849 positive_test_filter_file_.push_back(filter_line); |
| 857 } | 850 } |
| 851 } | |
| 852 // Split --gtest_filter at '-', if there is one, to separate into | |
| 853 // positive filter and negative filter portions. | |
| 854 std::string filter = command_line->GetSwitchValueASCII(kGTestFilterFlag); | |
| 855 size_t dash_pos = filter.find('-'); | |
| 856 if (dash_pos == std::string::npos) { | |
| 857 positive_test_filter_gtest_ = | |
| 858 SplitString(filter, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
| 858 } else { | 859 } else { |
| 859 // Split --gtest_filter at '-', if there is one, to separate into | 860 // Everything up to the dash. |
| 860 // positive filter and negative filter portions. | 861 positive_test_filter_gtest_ = |
| 861 std::string filter = command_line->GetSwitchValueASCII(kGTestFilterFlag); | 862 SplitString(filter.substr(0, dash_pos), ":", base::TRIM_WHITESPACE, |
| 862 size_t dash_pos = filter.find('-'); | 863 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 | 864 |
| 872 // Everything after the dash. | 865 // Everything after the dash. |
| 873 negative_test_filter_ = SplitString( | 866 for (std::string test_name : |
| 874 filter.substr(dash_pos + 1), ":", base::TRIM_WHITESPACE, | 867 SplitString(filter.substr(dash_pos + 1), ":", base::TRIM_WHITESPACE, |
| 875 base::SPLIT_WANT_ALL); | 868 base::SPLIT_WANT_ALL)) { |
| 869 negative_test_filter_gtest_.push_back(test_name); | |
|
Paweł Hajdan Jr.
2016/11/30 12:41:31
Since negative_test_filter_gtest_ doesn't collide
katthomas
2016/12/01 00:07:00
Done.
| |
| 876 } | 870 } |
| 877 } | 871 } |
| 878 | 872 |
| 879 if (!launcher_delegate_->GetTests(&tests_)) { | 873 if (!launcher_delegate_->GetTests(&tests_)) { |
| 880 LOG(ERROR) << "Failed to get list of tests."; | 874 LOG(ERROR) << "Failed to get list of tests."; |
| 881 return false; | 875 return false; |
| 882 } | 876 } |
| 883 | 877 |
| 884 if (!results_tracker_.Init(*command_line)) { | 878 if (!results_tracker_.Init(*command_line)) { |
| 885 LOG(ERROR) << "Failed to initialize test results tracker."; | 879 LOG(ERROR) << "Failed to initialize test results tracker."; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 results_tracker_.AddGlobalTag("CPU_32_BITS"); | 938 results_tracker_.AddGlobalTag("CPU_32_BITS"); |
| 945 #endif | 939 #endif |
| 946 | 940 |
| 947 #if defined(ARCH_CPU_64_BITS) | 941 #if defined(ARCH_CPU_64_BITS) |
| 948 results_tracker_.AddGlobalTag("CPU_64_BITS"); | 942 results_tracker_.AddGlobalTag("CPU_64_BITS"); |
| 949 #endif | 943 #endif |
| 950 | 944 |
| 951 return true; | 945 return true; |
| 952 } | 946 } |
| 953 | 947 |
| 948 void TestLauncher::CombineTestFilters() { | |
| 949 bool has_positive_filter = !positive_test_filter_file_.empty() || | |
| 950 !positive_test_filter_gtest_.empty(); | |
| 951 if (has_positive_filter) { | |
| 952 // If two positive filters are present, only run tests that match a pattern | |
| 953 // in both filters. | |
| 954 if (!positive_test_filter_file_.empty() && | |
| 955 !positive_test_filter_gtest_.empty()) { | |
| 956 for (size_t i = 0; i < tests_.size(); i++) { | |
| 957 std::string test_name = | |
| 958 FormatFullTestName(tests_[i].test_case_name, tests_[i].test_name); | |
| 959 bool found_gtest = false; | |
| 960 bool found_file = false; | |
| 961 for (size_t k = 0; k < positive_test_filter_gtest_.size(); ++k) { | |
| 962 found_gtest = MatchPattern(test_name, positive_test_filter_gtest_[k]); | |
|
Paweł Hajdan Jr.
2016/11/30 12:41:32
This assignment overwrites any previous result. A
katthomas
2016/12/01 00:07:00
Oof, I didn't catch this because I wasn't as thoro
| |
| 963 } | |
| 964 for (size_t k = 0; k < positive_test_filter_file_.size(); ++k) { | |
| 965 found_file = MatchPattern(test_name, positive_test_filter_file_[k]); | |
| 966 } | |
| 967 if (found_gtest && found_file) { | |
| 968 positive_test_filter_.push_back(test_name); | |
| 969 } | |
| 970 } | |
| 971 } else if (!positive_test_filter_file_.empty()) { | |
|
Paweł Hajdan Jr.
2016/11/30 12:41:32
I'm not sure if this case-based code is the simple
katthomas
2016/12/01 00:07:00
Didn't totally follow your advice here, but got th
| |
| 972 positive_test_filter_ = positive_test_filter_file_; | |
| 973 } else { | |
| 974 positive_test_filter_ = positive_test_filter_gtest_; | |
| 975 } | |
| 976 } | |
| 977 negative_test_filter_.reserve(negative_test_filter_gtest_.size() + | |
| 978 negative_test_filter_file_.size()); | |
| 979 negative_test_filter_.insert(negative_test_filter_.end(), | |
| 980 negative_test_filter_gtest_.begin(), | |
| 981 negative_test_filter_gtest_.end()); | |
| 982 negative_test_filter_.insert(negative_test_filter_.end(), | |
| 983 negative_test_filter_file_.begin(), | |
| 984 negative_test_filter_file_.end()); | |
| 985 } | |
| 986 | |
| 954 void TestLauncher::RunTests() { | 987 void TestLauncher::RunTests() { |
| 988 TestLauncher::CombineTestFilters(); | |
|
Paweł Hajdan Jr.
2016/11/30 12:41:32
nit: Is the "TestLauncher::" prefix needed here?
katthomas
2016/12/01 00:07:00
Done.
| |
| 989 | |
| 955 std::vector<std::string> test_names; | 990 std::vector<std::string> test_names; |
| 956 for (size_t i = 0; i < tests_.size(); i++) { | 991 for (size_t i = 0; i < tests_.size(); i++) { |
| 957 std::string test_name = FormatFullTestName( | 992 std::string test_name = |
| 958 tests_[i].test_case_name, tests_[i].test_name); | 993 FormatFullTestName(tests_[i].test_case_name, tests_[i].test_name); |
| 959 | 994 |
| 960 results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line); | 995 results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line); |
| 961 | 996 |
| 962 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 997 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 963 if (test_name.find("DISABLED") != std::string::npos) { | 998 if (test_name.find("DISABLED") != std::string::npos) { |
| 964 results_tracker_.AddDisabledTest(test_name); | 999 results_tracker_.AddDisabledTest(test_name); |
| 965 | 1000 |
| 966 // Skip disabled tests unless explicitly requested. | 1001 // Skip disabled tests unless explicitly requested. |
| 967 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) | 1002 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) |
| 968 continue; | 1003 continue; |
| 969 } | 1004 } |
| 970 | 1005 |
| 971 if (!launcher_delegate_->ShouldRunTest( | 1006 if (!launcher_delegate_->ShouldRunTest(tests_[i].test_case_name, |
| 972 tests_[i].test_case_name, tests_[i].test_name)) { | 1007 tests_[i].test_name)) { |
| 973 continue; | 1008 continue; |
| 974 } | 1009 } |
| 975 | 1010 |
| 976 // Count tests in the binary, before we apply filter and sharding. | 1011 // Count tests in the binary, before we apply filter and sharding. |
| 977 test_found_count_++; | 1012 test_found_count_++; |
| 978 | 1013 |
| 979 std::string test_name_no_disabled = TestNameWithoutDisabledPrefix( | 1014 std::string test_name_no_disabled = |
| 980 test_name); | 1015 TestNameWithoutDisabledPrefix(test_name); |
| 981 | 1016 |
| 982 // Skip the test that doesn't match the filter (if given). | 1017 // Skip the test that doesn't match the filter (if given). |
| 983 if (!positive_test_filter_.empty()) { | 1018 if (!positive_test_filter_.empty() || has_positive_filter) { |
|
Paweł Hajdan Jr.
2016/11/30 12:41:32
Why do we need a separate "has_positive_filter" va
katthomas
2016/12/01 00:07:00
Because there is the possibility that there both f
| |
| 984 bool found = false; | 1019 bool found = false; |
| 985 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { | 1020 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { |
| 986 if (MatchPattern(test_name, positive_test_filter_[k]) || | 1021 if (MatchPattern(test_name, positive_test_filter_[k]) || |
| 987 MatchPattern(test_name_no_disabled, positive_test_filter_[k])) { | 1022 MatchPattern(test_name_no_disabled, positive_test_filter_[k])) { |
| 988 found = true; | 1023 found = true; |
| 989 break; | 1024 break; |
| 990 } | 1025 } |
| 991 } | 1026 } |
| 992 | 1027 |
| 993 if (!found) | 1028 if (!found) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 } | 1203 } |
| 1169 | 1204 |
| 1170 std::string snippet(full_output.substr(run_pos)); | 1205 std::string snippet(full_output.substr(run_pos)); |
| 1171 if (end_pos != std::string::npos) | 1206 if (end_pos != std::string::npos) |
| 1172 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1207 snippet = full_output.substr(run_pos, end_pos - run_pos); |
| 1173 | 1208 |
| 1174 return snippet; | 1209 return snippet; |
| 1175 } | 1210 } |
| 1176 | 1211 |
| 1177 } // namespace base | 1212 } // namespace base |
| OLD | NEW |