 Chromium Code Reviews
 Chromium Code Reviews Issue 14882007:
  Android: support glob-style gtest filters with content browser tests  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 14882007:
  Android: support glob-style gtest filters with content browser tests  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: build/android/pylib/browsertests/dispatch.py | 
| diff --git a/build/android/pylib/browsertests/dispatch.py b/build/android/pylib/browsertests/dispatch.py | 
| index c598d6447bd88ef7fe621c4fb22f2b1a21e6404d..23a05f17d3c52e63893b8d39a79e8ae024cab4ec 100644 | 
| --- a/build/android/pylib/browsertests/dispatch.py | 
| +++ b/build/android/pylib/browsertests/dispatch.py | 
| @@ -2,6 +2,7 @@ | 
| # Use of this source code is governed by a BSD-style license that can be | 
| # found in the LICENSE file. | 
| +import fnmatch | 
| import logging | 
| import os | 
| @@ -53,12 +54,12 @@ def Dispatch(options): | 
| constants.BROWSERTEST_TEST_ACTIVITY_NAME, | 
| constants.BROWSERTEST_COMMAND_LINE_FILE) | 
| - # Get tests and split them up based on the number of devices. | 
| + # Get tests and split them up based on the number of devices. | 
| + all_enabled = gtest_dispatch.GetAllEnabledTests(RunnerFactory, | 
| + attached_devices) | 
| if options.gtest_filter: | 
| - all_tests = [t for t in options.gtest_filter.split(':') if t] | 
| + all_tests = _ApplyGtestFilter(all_enabled, options.gtest_filter) | 
| else: | 
| - all_enabled = gtest_dispatch.GetAllEnabledTests(RunnerFactory, | 
| - attached_devices) | 
| all_tests = _FilterTests(all_enabled) | 
| # Run tests. | 
| @@ -82,6 +83,30 @@ def _FilterTests(all_enabled_tests): | 
| """Filters out tests and fixtures starting with PRE_ and MANUAL_.""" | 
| return [t for t in all_enabled_tests if _ShouldRunOnBot(t)] | 
| +def _ApplyGtestFilter(all_enabled_tests, gtest_filter): | 
| 
frankf
2013/05/16 01:15:52
Take a look at //chrome/test/pylib/common/unittest
 
Sami
2013/05/16 10:41:34
Thanks for the tip -- code reuse ftw!
 | 
| + """Computes the list of tests that match a gtest filter. | 
| + | 
| + Args: | 
| + all_enabled_tests: List of available and enabled tests. | 
| + gtest_filter: Gtest filter string. See testing/gtest/src/gtest.cc. | 
| + | 
| + Returns: | 
| + A list of tests that match the given gtest filter. | 
| + """ | 
| + filter_patterns = [t for t in gtest_filter.split(':') if t] | 
| + # Any test that matches a positive patterns but does not match any negative | 
| + # pattern should be returned. | 
| + result = set() | 
| + for pattern in filter_patterns: | 
| + if not pattern.startswith('-'): | 
| + result.update([t for t in all_enabled_tests | 
| + if fnmatch.fnmatch(t, pattern)]) | 
| + for pattern in filter_patterns: | 
| + if pattern.startswith('-'): | 
| + result.difference_update([t for t in all_tests | 
| 
frankf
2013/05/16 01:15:52
all_tests -> all_enabeld_tests
 
Sami
2013/05/16 10:41:34
Oops, well spotted.
 | 
| + if fnmatch.fnmatch(t, pattern[1:])]) | 
| + return list(result) | 
| + | 
| def _ShouldRunOnBot(test): | 
| fixture, case = test.split('.', 1) | 
| if _StartsWith(fixture, case, "PRE_"): |