Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Unified Diff: base/test/launcher/test_launcher.cc

Issue 2515573003: Make test filters play nice (Closed)
Patch Set: Make test filters play nice Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/test/launcher/test_launcher.h ('K') | « base/test/launcher/test_launcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/launcher/test_launcher.cc
diff --git a/base/test/launcher/test_launcher.cc b/base/test/launcher/test_launcher.cc
index 8528b1d5fd906be59fcb11b9648981ff6996eff2..668ab57864f18f99cf39ef62e755c9eb57dca943 100644
--- a/base/test/launcher/test_launcher.cc
+++ b/base/test/launcher/test_launcher.cc
@@ -826,13 +826,6 @@ bool TestLauncher::Init() {
worker_thread_->Start();
}
- if (command_line->HasSwitch(switches::kTestLauncherFilterFile) &&
- command_line->HasSwitch(kGTestFilterFlag)) {
- LOG(ERROR) << "Only one of --test-launcher-filter-file and --gtest_filter "
- << "at a time is allowed.";
- return false;
- }
-
if (command_line->HasSwitch(switches::kTestLauncherFilterFile)) {
base::FilePath filter_file_path = base::MakeAbsoluteFilePath(
command_line->GetSwitchValuePath(switches::kTestLauncherFilterFile));
@@ -853,26 +846,31 @@ bool TestLauncher::Init() {
if (filter_line[0] == '-')
negative_test_filter_.push_back(filter_line.substr(1));
else
- positive_test_filter_.push_back(filter_line);
+ positive_test_filter_file_.push_back(filter_line);
+ }
+ }
+ // Split --gtest_filter at '-', if there is one, to separate into
+ // positive filter and negative filter portions.
+ std::string filter = command_line->GetSwitchValueASCII(kGTestFilterFlag);
+ size_t dash_pos = filter.find('-');
+ if (dash_pos == std::string::npos) {
+ for (std::string test_name : SplitString(filter, ":", base::TRIM_WHITESPACE,
Paweł Hajdan Jr. 2016/11/28 12:56:14 nit: Why do we need the loops for the positive fil
katthomas 2016/11/29 21:38:26 Oops, should have changed that back. Thanks for ca
+ base::SPLIT_WANT_ALL)) {
+ positive_test_filter_gtest_.push_back(test_name);
}
} else {
- // Split --gtest_filter at '-', if there is one, to separate into
- // positive filter and negative filter portions.
- std::string filter = command_line->GetSwitchValueASCII(kGTestFilterFlag);
- size_t dash_pos = filter.find('-');
- if (dash_pos == std::string::npos) {
- positive_test_filter_ = SplitString(
- filter, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- } else {
- // Everything up to the dash.
- positive_test_filter_ = SplitString(
- filter.substr(0, dash_pos), ":", base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
-
- // Everything after the dash.
- negative_test_filter_ = SplitString(
- filter.substr(dash_pos + 1), ":", base::TRIM_WHITESPACE,
- base::SPLIT_WANT_ALL);
+ // Everything up to the dash.
+ for (std::string test_name :
+ SplitString(filter.substr(0, dash_pos), ":", base::TRIM_WHITESPACE,
+ base::SPLIT_WANT_ALL)) {
+ positive_test_filter_gtest_.push_back(test_name);
+ }
+
+ // Everything after the dash.
+ for (std::string test_name :
+ SplitString(filter.substr(dash_pos + 1), ":", base::TRIM_WHITESPACE,
+ base::SPLIT_WANT_ALL)) {
+ negative_test_filter_.push_back(test_name);
}
}
@@ -952,65 +950,81 @@ bool TestLauncher::Init() {
}
void TestLauncher::RunTests() {
- std::vector<std::string> test_names;
- for (size_t i = 0; i < tests_.size(); i++) {
- std::string test_name = FormatFullTestName(
- tests_[i].test_case_name, tests_[i].test_name);
-
- results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line);
+ // Compute the intersection of the gtest and filter file positive filters
Paweł Hajdan Jr. 2016/11/28 12:56:13 Could you explain more reasoning behind this? It
Dirk Pranke 2016/11/29 02:07:15 I'm interpreting "Could you explain more" as "writ
katthomas 2016/11/29 21:38:26 Oh right, I didn't realize you could match pattern
+ std::sort(positive_test_filter_file_.begin(),
+ positive_test_filter_file_.end());
+ std::sort(positive_test_filter_gtest_.begin(),
+ positive_test_filter_gtest_.end());
+ std::set_intersection(
+ positive_test_filter_file_.begin(), positive_test_filter_file_.end(),
+ positive_test_filter_gtest_.begin(), positive_test_filter_gtest_.end(),
+ std::back_inserter(positive_test_filter_));
- const CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (test_name.find("DISABLED") != std::string::npos) {
- results_tracker_.AddDisabledTest(test_name);
+ std::vector<std::string> test_names;
+ bool has_positive_filter = !positive_test_filter_file_.empty() ||
+ !positive_test_filter_gtest_.empty();
+ if (!has_positive_filter || !positive_test_filter_.empty() ||
+ !negative_test_filter_.empty()) {
+ for (size_t i = 0; i < tests_.size(); i++) {
+ std::string test_name =
+ FormatFullTestName(tests_[i].test_case_name, tests_[i].test_name);
+
+ results_tracker_.AddTest(test_name, tests_[i].file, tests_[i].line);
+
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (test_name.find("DISABLED") != std::string::npos) {
+ results_tracker_.AddDisabledTest(test_name);
+
+ // Skip disabled tests unless explicitly requested.
+ if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag))
+ continue;
+ }
- // Skip disabled tests unless explicitly requested.
- if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag))
+ if (!launcher_delegate_->ShouldRunTest(tests_[i].test_case_name,
+ tests_[i].test_name)) {
continue;
- }
-
- if (!launcher_delegate_->ShouldRunTest(
- tests_[i].test_case_name, tests_[i].test_name)) {
- continue;
- }
-
- // Count tests in the binary, before we apply filter and sharding.
- test_found_count_++;
-
- std::string test_name_no_disabled = TestNameWithoutDisabledPrefix(
- test_name);
+ }
- // Skip the test that doesn't match the filter (if given).
- if (!positive_test_filter_.empty()) {
- bool found = false;
- for (size_t k = 0; k < positive_test_filter_.size(); ++k) {
- if (MatchPattern(test_name, positive_test_filter_[k]) ||
- MatchPattern(test_name_no_disabled, positive_test_filter_[k])) {
- found = true;
- break;
+ // Count tests in the binary, before we apply filter and sharding.
+ test_found_count_++;
+
+ std::string test_name_no_disabled =
+ TestNameWithoutDisabledPrefix(test_name);
+
+ // Skip the test that doesn't match the filter (if given).
+ if (!positive_test_filter_.empty()) {
+ bool found = false;
+ for (size_t k = 0; k < positive_test_filter_.size(); ++k) {
+ if (MatchPattern(test_name, positive_test_filter_[k]) ||
+ MatchPattern(test_name_no_disabled, positive_test_filter_[k])) {
+ found = true;
+ break;
+ }
}
- }
- if (!found)
- continue;
- }
- if (!negative_test_filter_.empty()) {
- bool excluded = false;
- for (size_t k = 0; k < negative_test_filter_.size(); ++k) {
- if (MatchPattern(test_name, negative_test_filter_[k]) ||
- MatchPattern(test_name_no_disabled, negative_test_filter_[k])) {
- excluded = true;
- break;
+ if (!found)
+ continue;
+ }
+ if (!negative_test_filter_.empty()) {
+ bool excluded = false;
+ for (size_t k = 0; k < negative_test_filter_.size(); ++k) {
+ if (MatchPattern(test_name, negative_test_filter_[k]) ||
+ MatchPattern(test_name_no_disabled, negative_test_filter_[k])) {
+ excluded = true;
+ break;
+ }
}
+
+ if (excluded)
+ continue;
}
- if (excluded)
+ if (Hash(test_name) % total_shards_ !=
+ static_cast<uint32_t>(shard_index_))
continue;
- }
-
- if (Hash(test_name) % total_shards_ != static_cast<uint32_t>(shard_index_))
- continue;
- test_names.push_back(test_name);
+ test_names.push_back(test_name);
+ }
}
// Save an early test summary in case the launcher crashes or gets killed.
« base/test/launcher/test_launcher.h ('K') | « base/test/launcher/test_launcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698