diff options
author | alexandermont <alexandermont@chromium.org> | 2015-12-18 12:30:46 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-18 20:31:47 +0000 |
commit | ce319f72997625e985a6b3819b168e11d330dc2a (patch) | |
tree | d2a3cbcab879407ee85e6b2d301b2051d8cb6180 | |
parent | b370242ecaeee80710008a3e1927fcd1d73f568e (diff) | |
download | chromium_src-ce319f72997625e985a6b3819b168e11d330dc2a.zip chromium_src-ce319f72997625e985a6b3819b168e11d330dc2a.tar.gz chromium_src-ce319f72997625e985a6b3819b168e11d330dc2a.tar.bz2 |
enforce ordering of test execution through filtering in test_runner.py
BUG=569723
Review URL: https://codereview.chromium.org/1531013002
Cr-Commit-Position: refs/heads/master@{#366160}
-rw-r--r-- | build/util/lib/common/PRESUBMIT.py | 16 | ||||
-rw-r--r-- | build/util/lib/common/unittest_util.py | 24 | ||||
-rwxr-xr-x | build/util/lib/common/unittest_util_test.py | 65 | ||||
-rw-r--r-- | testing/buildbot/trybot_analyze_config.json | 1 |
4 files changed, 92 insertions, 14 deletions
diff --git a/build/util/lib/common/PRESUBMIT.py b/build/util/lib/common/PRESUBMIT.py new file mode 100644 index 0000000..fca962f --- /dev/null +++ b/build/util/lib/common/PRESUBMIT.py @@ -0,0 +1,16 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + + +def _RunTests(input_api, output_api): + return (input_api.canned_checks.RunUnitTestsInDirectory( + input_api, output_api, '.', whitelist=[r'.+_test.py$'])) + + +def CheckChangeOnUpload(input_api, output_api): + return _RunTests(input_api, output_api) + + +def CheckChangeOnCommit(input_api, output_api): + return _RunTests(input_api, output_api) diff --git a/build/util/lib/common/unittest_util.py b/build/util/lib/common/unittest_util.py index 189f587..a4fa8ae 100644 --- a/build/util/lib/common/unittest_util.py +++ b/build/util/lib/common/unittest_util.py @@ -132,22 +132,18 @@ def FilterTestNames(all_tests, gtest_filter): positive_patterns = ['*'] if pattern_groups[0]: positive_patterns = pattern_groups[0].split(':') - negative_patterns = None + negative_patterns = [] if len(pattern_groups) > 1: negative_patterns = pattern_groups[1].split(':') tests = [] - for test in all_tests: - # Test name must by matched by one positive pattern. - for pattern in positive_patterns: - if fnmatch.fnmatch(test, pattern): - break - else: - continue - # Test name must not be matched by any negative patterns. - for pattern in negative_patterns or []: - if fnmatch.fnmatch(test, pattern): - break - else: - tests += [test] + test_set = set() + for pattern in positive_patterns: + pattern_tests = [ + test for test in all_tests + if (fnmatch.fnmatch(test, pattern) + and not any(fnmatch.fnmatch(test, p) for p in negative_patterns) + and test not in test_set)] + tests.extend(pattern_tests) + test_set.update(pattern_tests) return tests diff --git a/build/util/lib/common/unittest_util_test.py b/build/util/lib/common/unittest_util_test.py new file mode 100755 index 0000000..1514c9b --- /dev/null +++ b/build/util/lib/common/unittest_util_test.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# pylint: disable=protected-access + +import logging +import sys +import unittest +import unittest_util + + +class FilterTestNamesTest(unittest.TestCase): + + possible_list = ["Foo.One", + "Foo.Two", + "Foo.Three", + "Bar.One", + "Bar.Two", + "Bar.Three", + "Quux.One", + "Quux.Two", + "Quux.Three"] + + def testMatchAll(self): + x = unittest_util.FilterTestNames(self.possible_list, "*") + self.assertEquals(x, self.possible_list) + + def testMatchPartial(self): + x = unittest_util.FilterTestNames(self.possible_list, "Foo.*") + self.assertEquals(x, ["Foo.One", "Foo.Two", "Foo.Three"]) + + def testMatchFull(self): + x = unittest_util.FilterTestNames(self.possible_list, "Foo.Two") + self.assertEquals(x, ["Foo.Two"]) + + def testMatchTwo(self): + x = unittest_util.FilterTestNames(self.possible_list, "Bar.*:Foo.*") + self.assertEquals(x, ["Bar.One", + "Bar.Two", + "Bar.Three", + "Foo.One", + "Foo.Two", + "Foo.Three"]) + + def testMatchWithNegative(self): + x = unittest_util.FilterTestNames(self.possible_list, "Bar.*:Foo.*-*.Three") + self.assertEquals(x, ["Bar.One", + "Bar.Two", + "Foo.One", + "Foo.Two"]) + + def testMatchOverlapping(self): + x = unittest_util.FilterTestNames(self.possible_list, "Bar.*:*.Two") + self.assertEquals(x, ["Bar.One", + "Bar.Two", + "Bar.Three", + "Foo.Two", + "Quux.Two"]) + + +if __name__ == '__main__': + logging.getLogger().setLevel(logging.DEBUG) + unittest.main(verbosity=2) diff --git a/testing/buildbot/trybot_analyze_config.json b/testing/buildbot/trybot_analyze_config.json index 5d502d0..29114ee 100644 --- a/testing/buildbot/trybot_analyze_config.json +++ b/testing/buildbot/trybot_analyze_config.json @@ -16,6 +16,7 @@ "build/get_landmines.py", "build/gyp_chromium", "build/linux/sysroot_ld_path.sh", + "build/util/lib/common/unittest_util.py", "infra/.*", "DEPS", "testing/buildbot/.*", |