summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa
diff options
context:
space:
mode:
authorzjh <junhuix.zhang@intel.com>2015-09-02 15:39:54 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-04 16:23:52 +0100
commitfac0d67ec25f357684bcd0c80be282e1bca3adef (patch)
tree6bdf3ffc8fbb5f84d0ea6cf7fc0fee1e6d2ff553 /meta/lib/oeqa
parent1efd172dd89d13e10269c13d9ed8bb1c7f7ea2f0 (diff)
downloadpoky-fac0d67ec25f357684bcd0c80be282e1bca3adef.tar.gz
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>
Diffstat (limited to 'meta/lib/oeqa')
-rw-r--r--meta/lib/oeqa/oetest.py28
-rw-r--r--meta/lib/oeqa/utils/decorators.py34
2 files changed, 60 insertions, 2 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
index 4773bdd4d8..9724325083 100644
--- a/meta/lib/oeqa/oetest.py
+++ b/meta/lib/oeqa/oetest.py
@@ -12,9 +12,32 @@ import unittest
12import inspect 12import inspect
13import subprocess 13import subprocess
14import bb 14import bb
15from oeqa.utils.decorators import LogResults 15from oeqa.utils.decorators import LogResults, gettag
16from sys import exc_info, exc_clear 16from sys import exc_info, exc_clear
17 17
18def getVar(obj):
19 #extend form dict, if a variable didn't exists, need find it in testcase
20 class VarDict(dict):
21 def __getitem__(self, key):
22 return gettag(obj, key)
23 return VarDict()
24
25def checkTags(tc, tagexp):
26 return eval(tagexp, None, getVar(tc))
27
28
29def filterByTagExp(testsuite, tagexp):
30 if not tagexp:
31 return testsuite
32 caseList = []
33 for each in testsuite:
34 if not isinstance(each, unittest.BaseTestSuite):
35 if checkTags(each, tagexp):
36 caseList.append(each)
37 else:
38 caseList.append(filterByTagExp(each, tagexp))
39 return testsuite.__class__(caseList)
40
18def loadTests(tc, type="runtime"): 41def loadTests(tc, type="runtime"):
19 if type == "runtime": 42 if type == "runtime":
20 # set the context object passed from the test class 43 # set the context object passed from the test class
@@ -29,6 +52,7 @@ def loadTests(tc, type="runtime"):
29 testloader = unittest.TestLoader() 52 testloader = unittest.TestLoader()
30 testloader.sortTestMethodsUsing = None 53 testloader.sortTestMethodsUsing = None
31 suites = [testloader.loadTestsFromName(name) for name in tc.testslist] 54 suites = [testloader.loadTestsFromName(name) for name in tc.testslist]
55 suites = filterByTagExp(suites, getattr(tc, "tagexp", None))
32 56
33 def getTests(test): 57 def getTests(test):
34 '''Return all individual tests executed when running the suite.''' 58 '''Return all individual tests executed when running the suite.'''
@@ -86,6 +110,8 @@ def runTests(tc, type="runtime"):
86 110
87 suite = loadTests(tc, type) 111 suite = loadTests(tc, type)
88 bb.note("Test modules %s" % tc.testslist) 112 bb.note("Test modules %s" % tc.testslist)
113 if hasattr(tc, "tagexp") and tc.tagexp:
114 bb.note("Filter test cases by tags: %s" % tc.tagexp)
89 bb.note("Found %s tests" % suite.countTestCases()) 115 bb.note("Found %s tests" % suite.countTestCases())
90 runner = unittest.TextTestRunner(verbosity=2) 116 runner = unittest.TextTestRunner(verbosity=2)
91 result = runner.run(suite) 117 result = runner.run(suite)
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index b9fc76c9ee..769b4fffdd 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -185,4 +185,36 @@ def timeout(seconds):
185 return wrapped_f 185 return wrapped_f
186 else: 186 else:
187 return fn 187 return fn
188 return decorator \ No newline at end of file 188 return decorator
189
190__tag_prefix = "tag__"
191def tag(*args, **kwargs):
192 """Decorator that adds attributes to classes or functions
193 for use with the Attribute (-a) plugin.
194 """
195 def wrap_ob(ob):
196 for name in args:
197 setattr(ob, __tag_prefix + name, True)
198 for name, value in kwargs.iteritems():
199 setattr(ob, __tag_prefix + name, value)
200 return ob
201 return wrap_ob
202
203def gettag(obj, key, default=None):
204 key = __tag_prefix + key
205 if not isinstance(obj, unittest.TestCase):
206 return getattr(obj, key, default)
207 tc_method = getattr(obj, obj._testMethodName)
208 ret = getattr(tc_method, key, getattr(obj, key, default))
209 return ret
210
211def getAllTags(obj):
212 def __gettags(o):
213 r = {k[len(__tag_prefix):]:getattr(o,k) for k in dir(o) if k.startswith(__tag_prefix)}
214 return r
215 if not isinstance(obj, unittest.TestCase):
216 return __gettags(obj)
217 tc_method = getattr(obj, obj._testMethodName)
218 ret = __gettags(obj)
219 ret.update(__gettags(tc_method))
220 return ret