summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHumberto Ibarra <humberto.ibarra.lopez@intel.com>2016-03-11 10:28:24 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-03-12 22:11:20 +0000
commit01a242645cc12daed3f4da30d8c49813642d75e6 (patch)
tree0add34d3a434f42800a63bc5a0ab763b8f4f3a42
parent0a009dbfff32566341b2888530423f90f1b3d945 (diff)
downloadopenembedded-core-01a242645cc12daed3f4da30d8c49813642d75e6.tar.gz
openembedded-core-01a242645cc12daed3f4da30d8c49813642d75e6.tar.bz2
openembedded-core-01a242645cc12daed3f4da30d8c49813642d75e6.zip
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@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xscripts/oe-selftest108
1 files changed, 44 insertions, 64 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index de98a6cb0d..4c92f6da62 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']