diff options
| -rw-r--r-- | meta/classes/testimage.bbclass | 3 | ||||
| -rw-r--r-- | meta/lib/oeqa/oetest.py | 28 | ||||
| -rw-r--r-- | meta/lib/oeqa/utils/decorators.py | 34 |
3 files changed, 63 insertions, 2 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass index 8fa00f5fbf..7c783ea065 100644 --- a/meta/classes/testimage.bbclass +++ b/meta/classes/testimage.bbclass | |||
| @@ -253,6 +253,8 @@ def testimage_main(d): | |||
| 253 | testslist = get_tests_list(d) | 253 | testslist = get_tests_list(d) |
| 254 | testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] | 254 | testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] |
| 255 | 255 | ||
| 256 | tagexp = d.getVar("TEST_SUITES_TAGS", True) | ||
| 257 | |||
| 256 | # we need the host dumper in test context | 258 | # we need the host dumper in test context |
| 257 | host_dumper = get_host_dumper(d) | 259 | host_dumper = get_host_dumper(d) |
| 258 | 260 | ||
| @@ -263,6 +265,7 @@ def testimage_main(d): | |||
| 263 | def __init__(self): | 265 | def __init__(self): |
| 264 | self.d = d | 266 | self.d = d |
| 265 | self.testslist = testslist | 267 | self.testslist = testslist |
| 268 | self.tagexp = tagexp | ||
| 266 | self.testsrequired = testsrequired | 269 | self.testsrequired = testsrequired |
| 267 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") | 270 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") |
| 268 | self.target = target | 271 | self.target = target |
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 | |||
| 12 | import inspect | 12 | import inspect |
| 13 | import subprocess | 13 | import subprocess |
| 14 | import bb | 14 | import bb |
| 15 | from oeqa.utils.decorators import LogResults | 15 | from oeqa.utils.decorators import LogResults, gettag |
| 16 | from sys import exc_info, exc_clear | 16 | from sys import exc_info, exc_clear |
| 17 | 17 | ||
| 18 | def 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 | |||
| 25 | def checkTags(tc, tagexp): | ||
| 26 | return eval(tagexp, None, getVar(tc)) | ||
| 27 | |||
| 28 | |||
| 29 | def 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 | |||
| 18 | def loadTests(tc, type="runtime"): | 41 | def 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__" | ||
| 191 | def 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 | |||
| 203 | def 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 | |||
| 211 | def 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 | ||
