diff options
author | Stefan Stanacar <stefanx.stanacar@intel.com> | 2013-06-28 11:01:40 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-07-09 10:48:11 +0100 |
commit | 7765c27705e90381975fb2b89ea2181287517761 (patch) | |
tree | 95a1a822d3e287a96fe8b7e17697b5fe71d38558 /meta/lib/oeqa | |
parent | e0e32b978e5af128d7ff4ee2686777b49f919e27 (diff) | |
download | openembedded-core-7765c27705e90381975fb2b89ea2181287517761.tar.gz openembedded-core-7765c27705e90381975fb2b89ea2181287517761.tar.bz2 openembedded-core-7765c27705e90381975fb2b89ea2181287517761.zip |
lib/oeqa/oetest.py: base module for all runtime unittests
This module contains the base class for all runtime tests
and some helper methods.
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Radu Moisan <radu.moisan@intel.com>
Diffstat (limited to 'meta/lib/oeqa')
-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 @@ +import os, re, mmap +import unittest +import inspect +import bb +from oeqa.utils.sshcontrol import SSHControl + + +def runTests(tc): + + # set the context object passed from the test class + setattr(oeRuntimeTest, "tc", tc) + + # prepare test suite, loader and runner + suite = unittest.TestSuite() + testloader = unittest.TestLoader() + testloader.sortTestMethodsUsing = None + runner = unittest.TextTestRunner(verbosity=2) + + bb.note("Test modules %s" % tc.testslist) + suite = testloader.loadTestsFromNames(tc.testslist) + bb.note("Found %s tests" % suite.countTestCases()) + + result = runner.run(suite) + + return result + + + +class oeRuntimeTest(unittest.TestCase): + testFailures = [] + testSkipped = [] + testErrors = [] + pscmd = "ps" + + def __init__(self, methodName='runTest'): + self.target = oeRuntimeTest.tc.target + super(oeRuntimeTest, self).__init__(methodName) + + + def run(self, result=None): + super(oeRuntimeTest, self).run(result) + + # we add to our own lists the results, we use those for decorators + if len(result.failures) > len(oeRuntimeTest.testFailures): + oeRuntimeTest.testFailures.append(str(result.failures[-1][0]).split()[0]) + if len(result.skipped) > len(oeRuntimeTest.testSkipped): + oeRuntimeTest.testSkipped.append(str(result.skipped[-1][0]).split()[0]) + if len(result.errors) > len(oeRuntimeTest.testErrors): + oeRuntimeTest.testErrors.append(str(result.errors[-1][0]).split()[0]) + + @classmethod + def hasPackage(self, pkg): + + pkgfile = os.path.join(oeRuntimeTest.tc.d.getVar("WORKDIR", True), "installed_pkgs.txt") + + with open(pkgfile) as f: + data = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) + match = re.search(pkg, data) + data.close() + + if match: + return True + + return False + + @classmethod + def hasFeature(self,feature): + + if feature in oeRuntimeTest.tc.d.getVar("IMAGE_FEATURES", True).split() or \ + feature in oeRuntimeTest.tc.d.getVar("DISTRO_FEATURES", True).split(): + return True + else: + return False + + + + +def getmodule(pos=2): + # stack returns a list of tuples containg frame information + # First element of the list the is current frame, caller is 1 + frameinfo = inspect.stack()[pos] + modname = inspect.getmodulename(frameinfo[1]) + #modname = inspect.getmodule(frameinfo[0]).__name__ + return modname + +def skipModule(reason, pos=2): + modname = getmodule(pos) + if modname not in oeRuntimeTest.tc.testsrequired: + raise unittest.SkipTest("%s: %s" % (modname, reason)) + else: + bb.warn("Test %s is required, not skipping" % modname) + +def skipModuleIf(cond, reason): + + if cond: + skipModule(reason, 3) + +def skipModuleUnless(cond, reason): + + if not cond: + skipModule(reason, 3) |