Skip to content

Commit 6fef06f

Browse files
authored
Merge pull request #459 from commial/feature/only-tags
Add a only-tags option for test_all
2 parents 29456a7 + 0cf7591 commit 6fef06f

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

test/test_all.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, script, jitter ,*args, **kwargs):
5757

5858
# script -> blacklisted jitter
5959
blacklist = {
60-
"x86/unit/mn_float.py": ["python"],
60+
"x86/unit/mn_float.py": ["python", "llvm"],
6161
}
6262
for script in ["x86/sem.py",
6363
"x86/unit/mn_strings.py",
@@ -628,6 +628,9 @@ class ExampleJitterNoPython(ExampleJitter):
628628
parser.add_argument("-t", "--omit-tags", help="Omit tests based on tags \
629629
(tag1,tag2). Available tags are %s. \
630630
By default, no tag is omitted." % ", ".join(TAGS.keys()), default="")
631+
parser.add_argument("-o", "--only-tags", help="Restrict to tests based on tags \
632+
(tag1,tag2). Available tags are %s. \
633+
By default, all tag are considered." % ", ".join(TAGS.keys()), default="")
631634
parser.add_argument("-n", "--do-not-clean",
632635
help="Do not clean tests products", action="store_true")
633636
args = parser.parse_args()
@@ -637,16 +640,23 @@ class ExampleJitterNoPython(ExampleJitter):
637640
if args.mono is True or args.coverage is True:
638641
multiproc = False
639642

640-
## Parse omit-tags argument
643+
## Parse omit-tags and only-tags argument
641644
exclude_tags = []
642-
for tag in args.omit_tags.split(","):
643-
if not tag:
644-
continue
645-
if tag not in TAGS:
646-
print "%(red)s[TAG]%(end)s" % cosmetics.colors, \
647-
"Unkown tag '%s'" % tag
648-
exit(-1)
649-
exclude_tags.append(TAGS[tag])
645+
include_tags = []
646+
for dest, src in ((exclude_tags, args.omit_tags),
647+
(include_tags, args.only_tags)):
648+
for tag in src.split(","):
649+
if not tag:
650+
continue
651+
if tag not in TAGS:
652+
print "%(red)s[TAG]%(end)s" % cosmetics.colors, \
653+
"Unkown tag '%s'" % tag
654+
exit(-1)
655+
dest.append(TAGS[tag])
656+
657+
if exclude_tags and include_tags:
658+
print "%(red)s[TAG]%(end)s" % cosmetics.colors, \
659+
"Omit and Only used together: whitelist mode"
650660

651661
# Handle coverage
652662
coveragerc = None
@@ -736,7 +746,7 @@ class ExampleJitterNoPython(ExampleJitter):
736746

737747

738748
# Filter testset according to tags
739-
testset.filter_tags(exclude_tags=exclude_tags)
749+
testset.filter_tags(exclude_tags=exclude_tags, include_tags=include_tags)
740750

741751
# Run tests
742752
testset.run()

test/utils/testset.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -267,26 +267,36 @@ def filter_tags(self, include_tags=None, exclude_tags=None):
267267
"""Filter tests by tags
268268
@include_tags: list of tags' name (whitelist)
269269
@exclude_tags: list of tags' name (blacklist)
270-
@include_tags and @exclude_tags cannot be used together"""
271-
272-
if include_tags and exclude_tags:
273-
raise ValueError("Include and Exclude cannot be used together")
270+
If @include_tags and @exclude_tags are used together, @exclude_tags will
271+
act as a blacklist on @include_tags generated tests
272+
"""
274273

275-
new_testset_include = []
276-
new_testset_exclude = list(self.tests)
274+
new_testset = []
277275

278-
# Update include and exclude lists
279-
for index, test in enumerate(self.tests):
280-
for tag in test.tags:
281-
if exclude_tags and tag in exclude_tags:
282-
new_testset_exclude.remove(test)
283-
break
284-
if include_tags and tag in include_tags:
285-
new_testset_include.append(test)
286-
break
276+
include_tags = set(include_tags)
277+
exclude_tags = set(exclude_tags)
278+
if include_tags.intersection(exclude_tags):
279+
raise ValueError("Tags are mutually included and excluded: %s" % include_tags.intersection(exclude_tags))
287280

288-
# Update testset list
289-
if include_tags:
290-
self.tests = new_testset_include
291-
elif exclude_tags:
292-
self.tests = new_testset_exclude
281+
for test in self.tests:
282+
tags = set(test.tags)
283+
if exclude_tags.intersection(tags):
284+
# Ignore the current test because it is excluded
285+
continue
286+
if not include_tags:
287+
new_testset.append(test)
288+
else:
289+
if include_tags.intersection(tags):
290+
new_testset.append(test)
291+
292+
# Add tests dependencies
293+
dependency = list(test.depends)
294+
while dependency:
295+
subtest = dependency.pop()
296+
if subtest not in new_testset:
297+
new_testset.append(subtest)
298+
for subdepends in subtest.depends:
299+
if subdepends not in new_testset:
300+
dependency.append(subdepends)
301+
302+
self.tests = new_testset

0 commit comments

Comments
 (0)