diff options
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oeqa/__init__.py | 0 | ||||
-rw-r--r-- | meta/lib/oeqa/oetest.py | 101 |
2 files changed, 101 insertions, 0 deletions
diff --git a/meta/lib/oeqa/__init__.py b/meta/lib/oeqa/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/meta/lib/oeqa/__init__.py | |||
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py new file mode 100644 index 0000000000..24548e9267 --- /dev/null +++ b/meta/lib/oeqa/oetest.py | |||
@@ -0,0 +1,101 @@ | |||
1 | import os, re, mmap | ||
2 | import unittest | ||
3 | import inspect | ||
4 | import bb | ||
5 | from oeqa.utils.sshcontrol import SSHControl | ||
6 | |||
7 | |||
8 | def runTests(tc): | ||
9 | |||
10 | # set the context object passed from the test class | ||
11 | setattr(oeRuntimeTest, "tc", tc) | ||
12 | |||
13 | # prepare test suite, loader and runner | ||
14 | suite = unittest.TestSuite() | ||
15 | testloader = unittest.TestLoader() | ||
16 | testloader.sortTestMethodsUsing = None | ||
17 | runner = unittest.TextTestRunner(verbosity=2) | ||
18 | |||
19 | bb.note("Test modules %s" % tc.testslist) | ||
20 | suite = testloader.loadTestsFromNames(tc.testslist) | ||
21 | bb.note("Found %s tests" % suite.countTestCases()) | ||
22 | |||
23 | result = runner.run(suite) | ||
24 | |||
25 | return result | ||
26 | |||
27 | |||
28 | |||
29 | class oeRuntimeTest(unittest.TestCase): | ||
30 | testFailures = [] | ||
31 | testSkipped = [] | ||
32 | testErrors = [] | ||
33 | pscmd = "ps" | ||
34 | |||
35 | def __init__(self, methodName='runTest'): | ||
36 | self.target = oeRuntimeTest.tc.target | ||
37 | super(oeRuntimeTest, self).__init__(methodName) | ||
38 | |||
39 | |||
40 | def run(self, result=None): | ||
41 | super(oeRuntimeTest, self).run(result) | ||
42 | |||
43 | # we add to our own lists the results, we use those for decorators | ||
44 | if len(result.failures) > len(oeRuntimeTest.testFailures): | ||
45 | oeRuntimeTest.testFailures.append(str(result.failures[-1][0]).split()[0]) | ||
46 | if len(result.skipped) > len(oeRuntimeTest.testSkipped): | ||
47 | oeRuntimeTest.testSkipped.append(str(result.skipped[-1][0]).split()[0]) | ||
48 | if len(result.errors) > len(oeRuntimeTest.testErrors): | ||
49 | oeRuntimeTest.testErrors.append(str(result.errors[-1][0]).split()[0]) | ||
50 | |||
51 | @classmethod | ||
52 | def hasPackage(self, pkg): | ||
53 | |||
54 | pkgfile = os.path.join(oeRuntimeTest.tc.d.getVar("WORKDIR", True), "installed_pkgs.txt") | ||
55 | |||
56 | with open(pkgfile) as f: | ||
57 | data = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) | ||
58 | match = re.search(pkg, data) | ||
59 | data.close() | ||
60 | |||
61 | if match: | ||
62 | return True | ||
63 | |||
64 | return False | ||
65 | |||
66 | @classmethod | ||
67 | def hasFeature(self,feature): | ||
68 | |||
69 | if feature in oeRuntimeTest.tc.d.getVar("IMAGE_FEATURES", True).split() or \ | ||
70 | feature in oeRuntimeTest.tc.d.getVar("DISTRO_FEATURES", True).split(): | ||
71 | return True | ||
72 | else: | ||
73 | return False | ||
74 | |||
75 | |||
76 | |||
77 | |||
78 | def getmodule(pos=2): | ||
79 | # stack returns a list of tuples containg frame information | ||
80 | # First element of the list the is current frame, caller is 1 | ||
81 | frameinfo = inspect.stack()[pos] | ||
82 | modname = inspect.getmodulename(frameinfo[1]) | ||
83 | #modname = inspect.getmodule(frameinfo[0]).__name__ | ||
84 | return modname | ||
85 | |||
86 | def skipModule(reason, pos=2): | ||
87 | modname = getmodule(pos) | ||
88 | if modname not in oeRuntimeTest.tc.testsrequired: | ||
89 | raise unittest.SkipTest("%s: %s" % (modname, reason)) | ||
90 | else: | ||
91 | bb.warn("Test %s is required, not skipping" % modname) | ||
92 | |||
93 | def skipModuleIf(cond, reason): | ||
94 | |||
95 | if cond: | ||
96 | skipModule(reason, 3) | ||
97 | |||
98 | def skipModuleUnless(cond, reason): | ||
99 | |||
100 | if not cond: | ||
101 | skipModule(reason, 3) | ||