Commit 3bcc6b3e authored by Michal Majewski's avatar Michal Majewski Committed by Commit Bot

[test] Filter tests based on cmd line processor

Bug: v8:6917
Change-Id: I7fa8f1857f338551dd7acd1b25eb7e9feb376576
Cq-Include-Trybots: luci.v8.try:v8_linux64_fyi_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/866720Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Michał Majewski <majeski@google.com>
Cr-Commit-Position: refs/heads/master@{#50602}
parent 767deb50
...@@ -27,7 +27,7 @@ from testrunner.local.variants import ALL_VARIANTS ...@@ -27,7 +27,7 @@ from testrunner.local.variants import ALL_VARIANTS
from testrunner.objects import context from testrunner.objects import context
from testrunner.objects import predictable from testrunner.objects import predictable
from testrunner.testproc.execution import ExecutionProc from testrunner.testproc.execution import ExecutionProc
from testrunner.testproc.filter import StatusFileFilterProc from testrunner.testproc.filter import StatusFileFilterProc, NameFilterProc
from testrunner.testproc.loader import LoadProc from testrunner.testproc.loader import LoadProc
from testrunner.testproc.progress import (VerboseProgressIndicator, from testrunner.testproc.progress import (VerboseProgressIndicator,
ResultsTracker) ResultsTracker)
...@@ -400,8 +400,10 @@ class StandardTestRunner(base_runner.BaseTestRunner): ...@@ -400,8 +400,10 @@ class StandardTestRunner(base_runner.BaseTestRunner):
for s in suites: for s in suites:
s.ReadStatusFile(variables) s.ReadStatusFile(variables)
s.ReadTestCases(ctx) s.ReadTestCases(ctx)
if len(args) > 0: if not options.infra_staging:
s.FilterTestCasesByArgs(args) # Tests will be filtered in the test processors pipeline
if len(args) > 0:
s.FilterTestCasesByArgs(args)
all_tests += s.tests all_tests += s.tests
# First filtering by status applying the generic rules (tests without # First filtering by status applying the generic rules (tests without
...@@ -486,8 +488,9 @@ class StandardTestRunner(base_runner.BaseTestRunner): ...@@ -486,8 +488,9 @@ class StandardTestRunner(base_runner.BaseTestRunner):
outproc_factory = None outproc_factory = None
if options.infra_staging: if options.infra_staging:
exit_code = self._run_test_procs(suites, options, progress_indicator, exit_code = self._run_test_procs(suites, args, options,
ctx, outproc_factory) progress_indicator, ctx,
outproc_factory)
else: else:
runner = execution.Runner(suites, progress_indicator, ctx, runner = execution.Runner(suites, progress_indicator, ctx,
outproc_factory) outproc_factory)
...@@ -559,8 +562,8 @@ class StandardTestRunner(base_runner.BaseTestRunner): ...@@ -559,8 +562,8 @@ class StandardTestRunner(base_runner.BaseTestRunner):
count += 1 count += 1
return shard return shard
def _run_test_procs(self, suites, options, progress_indicator, context, def _run_test_procs(self, suites, args, options, progress_indicator,
outproc_factory): context, outproc_factory):
jobs = options.j jobs = options.j
print '>>> Running with test processors' print '>>> Running with test processors'
...@@ -570,6 +573,7 @@ class StandardTestRunner(base_runner.BaseTestRunner): ...@@ -570,6 +573,7 @@ class StandardTestRunner(base_runner.BaseTestRunner):
procs = [ procs = [
loader, loader,
NameFilterProc(args),
VariantProc(VARIANTS), VariantProc(VARIANTS),
StatusFileFilterProc(options.slow_tests, options.pass_fail_tests), StatusFileFilterProc(options.slow_tests, options.pass_fail_tests),
results, results,
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
from collections import defaultdict
import fnmatch
from . import base from . import base
...@@ -43,3 +46,38 @@ class StatusFileFilterProc(base.TestProcFilter): ...@@ -43,3 +46,38 @@ class StatusFileFilterProc(base.TestProcFilter):
(self._pass_fail_tests_mode == 'run' and not is_pass_fail) or (self._pass_fail_tests_mode == 'run' and not is_pass_fail) or
(self._pass_fail_tests_mode == 'skip' and is_pass_fail) (self._pass_fail_tests_mode == 'skip' and is_pass_fail)
) )
class NameFilterProc(base.TestProcFilter):
"""Filters tests based on command-line arguments.
args can be a glob: asterisks in any position of the name
represent zero or more characters. Without asterisks, only exact matches
will be used with the exeption of the test-suite name as argument.
"""
def __init__(self, args):
super(NameFilterProc, self).__init__()
self._globs = defaultdict(list)
for a in args:
argpath = a.split('/')
suitename = argpath[0]
path = '/'.join(argpath[1:])
self._globs[suitename].append(path)
for s, globs in self._globs.iteritems():
if not globs or '*' in globs:
self._globs[s] = []
def _filter(self, test):
globs = self._globs.get(test.suite.name)
if globs is None:
return True
if not globs:
return False
for g in globs:
if fnmatch.fnmatch(test.path, g):
return False
return True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment