summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Stanacar <stefanx.stanacar@intel.com>2013-06-28 11:01:40 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-07-09 10:53:43 +0100
commit12bf6262f674a6301332cc5fdc10b2757793cfc5 (patch)
tree5744e4bc4a70b4af45a18345173d4808de1e912e
parent1328d49625e0030e00d09d74d35f57bd87b14a04 (diff)
downloadpoky-12bf6262f674a6301332cc5fdc10b2757793cfc5.tar.gz
lib/oeqa/oetest.py: base module for all runtime unittests
This module contains the base class for all runtime tests and some helper methods. (From OE-Core rev: 7765c27705e90381975fb2b89ea2181287517761) Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com> Signed-off-by: Radu Moisan <radu.moisan@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/__init__.py0
-rw-r--r--meta/lib/oeqa/oetest.py101
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 @@
1import os, re, mmap
2import unittest
3import inspect
4import bb
5from oeqa.utils.sshcontrol import SSHControl
6
7
8def 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
29class 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
78def 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
86def 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
93def skipModuleIf(cond, reason):
94
95 if cond:
96 skipModule(reason, 3)
97
98def skipModuleUnless(cond, reason):
99
100 if not cond:
101 skipModule(reason, 3)