mirror of
https://git.yoctoproject.org/poky
synced 2026-05-30 12:29:55 +00:00
testimage: filter proper test cases by tags
If a test case is decorate by oeqa.utils.decorators.tag, this case will by add a tag, testrunner will filter these tags by TEST_SUITES_TAGS [YOCTO #7849] (From OE-Core rev: 085589b1018ba4d950baf7bcfb499be02c1b29fc) Signed-off-by: zjh <junhuix.zhang@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
@@ -253,6 +253,8 @@ def testimage_main(d):
|
|||||||
testslist = get_tests_list(d)
|
testslist = get_tests_list(d)
|
||||||
testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"]
|
testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"]
|
||||||
|
|
||||||
|
tagexp = d.getVar("TEST_SUITES_TAGS", True)
|
||||||
|
|
||||||
# we need the host dumper in test context
|
# we need the host dumper in test context
|
||||||
host_dumper = get_host_dumper(d)
|
host_dumper = get_host_dumper(d)
|
||||||
|
|
||||||
@@ -263,6 +265,7 @@ def testimage_main(d):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.d = d
|
self.d = d
|
||||||
self.testslist = testslist
|
self.testslist = testslist
|
||||||
|
self.tagexp = tagexp
|
||||||
self.testsrequired = testsrequired
|
self.testsrequired = testsrequired
|
||||||
self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files")
|
self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files")
|
||||||
self.target = target
|
self.target = target
|
||||||
|
|||||||
+27
-1
@@ -12,9 +12,32 @@ import unittest
|
|||||||
import inspect
|
import inspect
|
||||||
import subprocess
|
import subprocess
|
||||||
import bb
|
import bb
|
||||||
from oeqa.utils.decorators import LogResults
|
from oeqa.utils.decorators import LogResults, gettag
|
||||||
from sys import exc_info, exc_clear
|
from sys import exc_info, exc_clear
|
||||||
|
|
||||||
|
def getVar(obj):
|
||||||
|
#extend form dict, if a variable didn't exists, need find it in testcase
|
||||||
|
class VarDict(dict):
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return gettag(obj, key)
|
||||||
|
return VarDict()
|
||||||
|
|
||||||
|
def checkTags(tc, tagexp):
|
||||||
|
return eval(tagexp, None, getVar(tc))
|
||||||
|
|
||||||
|
|
||||||
|
def filterByTagExp(testsuite, tagexp):
|
||||||
|
if not tagexp:
|
||||||
|
return testsuite
|
||||||
|
caseList = []
|
||||||
|
for each in testsuite:
|
||||||
|
if not isinstance(each, unittest.BaseTestSuite):
|
||||||
|
if checkTags(each, tagexp):
|
||||||
|
caseList.append(each)
|
||||||
|
else:
|
||||||
|
caseList.append(filterByTagExp(each, tagexp))
|
||||||
|
return testsuite.__class__(caseList)
|
||||||
|
|
||||||
def loadTests(tc, type="runtime"):
|
def loadTests(tc, type="runtime"):
|
||||||
if type == "runtime":
|
if type == "runtime":
|
||||||
# set the context object passed from the test class
|
# set the context object passed from the test class
|
||||||
@@ -29,6 +52,7 @@ def loadTests(tc, type="runtime"):
|
|||||||
testloader = unittest.TestLoader()
|
testloader = unittest.TestLoader()
|
||||||
testloader.sortTestMethodsUsing = None
|
testloader.sortTestMethodsUsing = None
|
||||||
suites = [testloader.loadTestsFromName(name) for name in tc.testslist]
|
suites = [testloader.loadTestsFromName(name) for name in tc.testslist]
|
||||||
|
suites = filterByTagExp(suites, getattr(tc, "tagexp", None))
|
||||||
|
|
||||||
def getTests(test):
|
def getTests(test):
|
||||||
'''Return all individual tests executed when running the suite.'''
|
'''Return all individual tests executed when running the suite.'''
|
||||||
@@ -86,6 +110,8 @@ def runTests(tc, type="runtime"):
|
|||||||
|
|
||||||
suite = loadTests(tc, type)
|
suite = loadTests(tc, type)
|
||||||
bb.note("Test modules %s" % tc.testslist)
|
bb.note("Test modules %s" % tc.testslist)
|
||||||
|
if hasattr(tc, "tagexp") and tc.tagexp:
|
||||||
|
bb.note("Filter test cases by tags: %s" % tc.tagexp)
|
||||||
bb.note("Found %s tests" % suite.countTestCases())
|
bb.note("Found %s tests" % suite.countTestCases())
|
||||||
runner = unittest.TextTestRunner(verbosity=2)
|
runner = unittest.TextTestRunner(verbosity=2)
|
||||||
result = runner.run(suite)
|
result = runner.run(suite)
|
||||||
|
|||||||
@@ -186,3 +186,35 @@ def timeout(seconds):
|
|||||||
else:
|
else:
|
||||||
return fn
|
return fn
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
__tag_prefix = "tag__"
|
||||||
|
def tag(*args, **kwargs):
|
||||||
|
"""Decorator that adds attributes to classes or functions
|
||||||
|
for use with the Attribute (-a) plugin.
|
||||||
|
"""
|
||||||
|
def wrap_ob(ob):
|
||||||
|
for name in args:
|
||||||
|
setattr(ob, __tag_prefix + name, True)
|
||||||
|
for name, value in kwargs.iteritems():
|
||||||
|
setattr(ob, __tag_prefix + name, value)
|
||||||
|
return ob
|
||||||
|
return wrap_ob
|
||||||
|
|
||||||
|
def gettag(obj, key, default=None):
|
||||||
|
key = __tag_prefix + key
|
||||||
|
if not isinstance(obj, unittest.TestCase):
|
||||||
|
return getattr(obj, key, default)
|
||||||
|
tc_method = getattr(obj, obj._testMethodName)
|
||||||
|
ret = getattr(tc_method, key, getattr(obj, key, default))
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def getAllTags(obj):
|
||||||
|
def __gettags(o):
|
||||||
|
r = {k[len(__tag_prefix):]:getattr(o,k) for k in dir(o) if k.startswith(__tag_prefix)}
|
||||||
|
return r
|
||||||
|
if not isinstance(obj, unittest.TestCase):
|
||||||
|
return __gettags(obj)
|
||||||
|
tc_method = getattr(obj, obj._testMethodName)
|
||||||
|
ret = __gettags(obj)
|
||||||
|
ret.update(__gettags(tc_method))
|
||||||
|
return ret
|
||||||
|
|||||||
Reference in New Issue
Block a user