Skip to content

Commit

Permalink
Add a only-tags option for test_all
Browse files Browse the repository at this point in the history
  • Loading branch information
commial committed Dec 22, 2016
1 parent 50661f5 commit ed67e6f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 31 deletions.
33 changes: 22 additions & 11 deletions test/test_all.py
Expand Up @@ -55,7 +55,7 @@ def __init__(self, script, jitter ,*args, **kwargs):

# script -> blacklisted jitter
blacklist = {
"x86/unit/mn_float.py": ["python"],
"x86/unit/mn_float.py": ["python", "llvm"],
}
for script in ["x86/sem.py",
"x86/unit/mn_strings.py",
Expand Down Expand Up @@ -622,6 +622,9 @@ class ExampleJitterNoPython(ExampleJitter):
parser.add_argument("-t", "--omit-tags", help="Omit tests based on tags \
(tag1,tag2). Available tags are %s. \
By default, no tag is omitted." % ", ".join(TAGS.keys()), default="")
parser.add_argument("-o", "--only-tags", help="Restrict to tests based on tags \
(tag1,tag2). Available tags are %s. \
By default, all tag are considered." % ", ".join(TAGS.keys()), default="")
parser.add_argument("-n", "--do-not-clean",
help="Do not clean tests products", action="store_true")
args = parser.parse_args()
Expand All @@ -631,16 +634,24 @@ class ExampleJitterNoPython(ExampleJitter):
if args.mono is True or args.coverage is True:
multiproc = False

## Parse omit-tags argument
## Parse omit-tags and only-tags argument
exclude_tags = []
for tag in args.omit_tags.split(","):
if not tag:
continue
if tag not in TAGS:
print "%(red)s[TAG]%(end)s" % cosmetics.colors, \
"Unkown tag '%s'" % tag
exit(-1)
exclude_tags.append(TAGS[tag])
include_tags = []
for dest, src in ((exclude_tags, args.omit_tags),
(include_tags, args.only_tags)):
for tag in src.split(","):
if not tag:
continue
if tag not in TAGS:
print "%(red)s[TAG]%(end)s" % cosmetics.colors, \
"Unkown tag '%s'" % tag
exit(-1)
dest.append(TAGS[tag])

if exclude_tags and include_tags:
print "%(red)s[TAG]%(end)s" % cosmetics.colors, \
"Omit and Only tags cannot be used together"
exit(-1)

# Handle coverage
coveragerc = None
Expand Down Expand Up @@ -733,7 +744,7 @@ class ExampleJitterNoPython(ExampleJitter):


# Filter testset according to tags
testset.filter_tags(exclude_tags=exclude_tags)
testset.filter_tags(exclude_tags=exclude_tags, include_tags=include_tags)

# Run tests
testset.run()
Expand Down
54 changes: 34 additions & 20 deletions test/utils/testset.py
Expand Up @@ -267,26 +267,40 @@ def filter_tags(self, include_tags=None, exclude_tags=None):
"""Filter tests by tags
@include_tags: list of tags' name (whitelist)
@exclude_tags: list of tags' name (blacklist)
@include_tags and @exclude_tags cannot be used together"""

if include_tags and exclude_tags:
raise ValueError("Include and Exclude cannot be used together")

new_testset_include = []
new_testset_exclude = list(self.tests)
If @include_tags and @exclude_tags are used together, @exclude_tags will
act as a blacklist on @include_tags generated tests
"""

# Update include and exclude lists
for index, test in enumerate(self.tests):
for tag in test.tags:
if exclude_tags and tag in exclude_tags:
new_testset_exclude.remove(test)
break
if include_tags and tag in include_tags:
new_testset_include.append(test)
break
new_testset = []

# Update testset list
if include_tags:
self.tests = new_testset_include
elif exclude_tags:
self.tests = new_testset_exclude
# Add tests to consider using the whitelist
for test in self.tests:
for tag in test.tags:
if tag in include_tags:
new_testset.append(test)

# Add tests dependencies
dependency = list(test.depends)
while dependency:
subtest = dependency.pop()
if subtest not in new_testset:
new_testset.append(subtest)
for subdepends in subtest.depends:
if subdepends not in new_testset:
dependency.append(subdepends)
break
else:
# Work on the full testset
new_testset = list(self.tests)

# Update using exclude lists
print len(new_testset)
if exclude_tags:
for test in list(new_testset):
for tag in test.tags:
if tag in exclude_tags:
new_testset.remove(test)
break

self.tests = new_testset

0 comments on commit ed67e6f

Please sign in to comment.