about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2016-12-22 17:49:32 +0100
committerAjax <commial@gmail.com>2017-01-14 14:24:16 +0100
commit0cf75919aed484cf406a24132e1716787cd32ac6 (patch)
tree28acbc442b97313dd848f202007d53ab8f8f59a1
parent69376ab17bf46e60bda168a81667e17af620ffe2 (diff)
downloadmiasm-0cf75919aed484cf406a24132e1716787cd32ac6.tar.gz
miasm-0cf75919aed484cf406a24132e1716787cd32ac6.zip
Add a only-tags option for test_all
-rwxr-xr-xtest/test_all.py32
-rw-r--r--test/utils/testset.py50
2 files changed, 51 insertions, 31 deletions
diff --git a/test/test_all.py b/test/test_all.py
index c710a8ab..e49ce514 100755
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -57,7 +57,7 @@ class ArchUnitTest(RegressionTest):
 
 # 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",
@@ -628,6 +628,9 @@ if __name__ == "__main__":
     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()
@@ -637,16 +640,23 @@ By default, no tag is omitted." % ", ".join(TAGS.keys()), default="")
     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 used together: whitelist mode"
 
     # Handle coverage
     coveragerc = None
@@ -736,7 +746,7 @@ By default, no tag is omitted." % ", ".join(TAGS.keys()), default="")
 
 
     # 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()
diff --git a/test/utils/testset.py b/test/utils/testset.py
index 4336f4fa..e1df01a4 100644
--- a/test/utils/testset.py
+++ b/test/utils/testset.py
@@ -267,26 +267,36 @@ class TestSet(object):
         """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")
+        If @include_tags and @exclude_tags are used together, @exclude_tags will
+        act as a blacklist on @include_tags generated tests
+        """
 
-        new_testset_include = []
-        new_testset_exclude = list(self.tests)
+        new_testset = []
 
-        # 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
+        include_tags = set(include_tags)
+        exclude_tags = set(exclude_tags)
+        if include_tags.intersection(exclude_tags):
+            raise ValueError("Tags are mutually included and excluded: %s" % include_tags.intersection(exclude_tags))
 
-        # Update testset list
-        if include_tags:
-            self.tests = new_testset_include
-        elif exclude_tags:
-            self.tests = new_testset_exclude
+        for test in self.tests:
+            tags = set(test.tags)
+            if exclude_tags.intersection(tags):
+                # Ignore the current test because it is excluded
+                continue
+            if not include_tags:
+                new_testset.append(test)
+            else:
+                if include_tags.intersection(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)
+
+        self.tests = new_testset