[oe-commits] [openembedded-core] 03/04: scripts/oe-selftest: Add search expression matching to run/list options

git at git.openembedded.org git at git.openembedded.org
Fri Mar 11 17:31:22 UTC 2016


rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 4eb6c0cbfd96e983cd55540d13c76c01f78c07e9
Author: Humberto Ibarra <humberto.ibarra.lopez at intel.com>
AuthorDate: Fri Mar 11 10:28:24 2016 -0600

    scripts/oe-selftest: Add search expression matching to run/list options
    
    The oe-selftest script required an exact matching for the parameters
    passed to its run-tests-by and list-tests-by options. Many tests
    can be retrieved here and filtering is a must.
    
    This patch add this filtering functionality by enabling the use
    of wildcards such as "*".
    
    [Yocto #8916]
    
    Signed-off-by: Humberto Ibarra <humberto.ibarra.lopez at intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 scripts/oe-selftest | 108 +++++++++++++++++++++-------------------------------
 1 file changed, 44 insertions(+), 64 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index de98a6c..4c92f6d 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -243,93 +243,73 @@ def get_all_tests():
         testlist += get_tests_from_module(tmod)
     return testlist
 
-
-def create_testsuite_by(criteria, keyword):
-    # Create a testsuite based on 'keyword'
-    # criteria: name, class, module, id, tag
-    # keyword: a list of tests, classes, modules, ids, tags
-    # NOTE: globing would be nice?
-
-    ts = set()
-    all_tests = get_all_tests()
-
-    if criteria == 'name':
-        for tc in all_tests:
-            if tc.tcname in keyword:
-                ts.add(tc.fullpath)
-
-    elif criteria == 'class':
-        for tc in all_tests:
-            if tc.tcclass in keyword:
-                ts.add(tc.fullpath)
-
-    elif criteria == 'module':
-        for tc in all_tests:
-            if tc.tcmodule in keyword:
-                ts.add(tc.fullpath)
-    elif criteria == 'id':
-        for tc in all_tests:
-            if str(tc.tcid) in keyword:
-                ts.add(tc.fullpath)
-    elif criteria == 'tag':
-        for tc in all_tests:
-            # tc can have multiple tags (as list or tuple) otherwise as str
-            if isinstance(tc.tctag, (list, tuple)):
-                for tag in tc.tctag:
-                    if str(tag) in keyword:
-                        ts.add(tc.fullpath)
-            elif tc.tctag in keyword:
-                ts.add(tc.fullpath)
-
-    return sorted(list(ts))
-
-
 def get_testsuite_by(criteria, keyword):
     # Get a testsuite based on 'keyword'
     # criteria: name, class, module, id, tag
     # keyword: a list of tests, classes, modules, ids, tags
-    # NOTE: globing would be nice?
-    ts = set()
+
+    import re
+    import fnmatch
+
+    ts = []
     all_tests = get_all_tests()
 
+    def get_matches(values):
+        # Get a items and return the ones that match with keyword(s)
+        # values: the list of items (names, modules, classes...)
+        result = []
+        remaining = values[:]
+        for key in keyword:
+            if key in remaining:
+                # Regular matching of exact item
+                result.append(key)
+                remaining.remove(key)
+            else:
+                # Wildcard matching
+                pattern = re.compile(fnmatch.translate(r"%s" % key))
+                added = [ x for x in remaining if pattern.match(x) ]
+                result.extend(added)
+                remaining = [ x for x in remaining if not x in added ]
+
+        return result
+
     if criteria == 'name':
-        for tc in all_tests:
-            if tc.tcname in keyword:
-                ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+        names = get_matches([ tc.tcname for tc in all_tests ])
+        ts = [ tc for tc in all_tests if tc.tcname in names ]
 
     elif criteria == 'class':
-        for tc in all_tests:
-            if tc.tcclass in keyword:
-                ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+        classes = get_matches([ tc.tcclass for tc in all_tests ])
+        ts = [ tc for tc in all_tests if tc.tcclass in classes ]
 
     elif criteria == 'module':
-        for tc in all_tests:
-            if tc.tcmodule in keyword:
-                ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+        modules = get_matches([ tc.tcmodule for tc in all_tests ])
+        ts = [ tc for tc in all_tests if tc.tcmodule in modules ]
+
     elif criteria == 'id':
-        for tc in all_tests:
-            if str(tc.tcid) in keyword:
-                ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+        ids = get_matches([ str(tc.tcid) for tc in all_tests ])
+        ts = [ tc for tc in all_tests if str(tc.tcid) in ids ]
+
     elif criteria == 'tag':
+        values = set()
         for tc in all_tests:
             # tc can have multiple tags (as list or tuple) otherwise as str
             if isinstance(tc.tctag, (list, tuple)):
-                for tag in tc.tctag:
-                    if str(tag) in keyword:
-                        ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
-            elif str(tc.tctag) in keyword:
-                ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule))
+                values |= { str(tag) for tag in tc.tctag }
+            else:
+                values.add(str(tc.tctag))
+
+        tags = get_matches(list(values))
+        ts = [ tc for tc in all_tests if str(tc.tctag) in tags ]
 
-    return sorted(list(ts))
+    return ts
 
 
 def list_testsuite_by(criteria, keyword):
     # Get a testsuite based on 'keyword'
     # criteria: name, class, module, id, tag
     # keyword: a list of tests, classes, modules, ids, tags
-    # NOTE: globing would be nice?
 
-    ts = get_testsuite_by(criteria, keyword)
+    ts = sorted([ (tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule) for tc in get_testsuite_by(criteria, keyword) ])
 
     print '%-4s\t%-20s\t%-60s\t%-25s\t%-20s' % ('id', 'tag', 'name', 'class', 'module')
     print '_' * 150
@@ -459,7 +439,7 @@ def main():
         else:
             criteria = args.run_tests_by[0]
             keyword = args.run_tests_by[1:]
-            ts = create_testsuite_by(criteria, keyword)
+            ts = sorted([ tc.fullpath for tc in get_testsuite_by(criteria, keyword) ])
 
     if args.list_tests_by and len(args.list_tests_by) >= 2:
         valid_options = ['name', 'class', 'module', 'id', 'tag']

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list