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]

(From OE-Core rev: 01a242645cc12daed3f4da30d8c49813642d75e6)

Signed-off-by: Humberto Ibarra <humberto.ibarra.lopez@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Humberto Ibarra 2016-03-11 10:28:24 -06:00 committed by Richard Purdie
parent 4489ef1f6d
commit 35be679513
1 changed files with 44 additions and 64 deletions

View File

@ -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))
return sorted(list(ts))
tags = get_matches(list(values))
ts = [ tc for tc in all_tests if str(tc.tctag) in tags ]
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']