diff options
| author | Stefan Stanacar <stefanx.stanacar@intel.com> | 2013-11-01 12:37:56 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-11-05 22:04:28 +0000 |
| commit | 19aeca1cac9bed7851dd7ee45156d6024ab54498 (patch) | |
| tree | 3e32fa3b4ca93ccab0da1d8f912256163c3c698d /meta/lib | |
| parent | 90c709da9b3e8d3167a0ecb6ef91f569a70fe285 (diff) | |
| download | poky-19aeca1cac9bed7851dd7ee45156d6024ab54498.tar.gz | |
lib/oeqa: add oeTest superclass
Add oeTest superclass, make oeRuntimeTest inherit that and
make the necesarry adjustments. Tests in lib/oeqa/runtime don't
change, they still inherit oeRuntimeTest.
We should do this because oetest.py in the future can be a base module
for more stuff than oeRuntimeTest.
(From OE-Core rev: cd4ed41a070bd52c446ac3df8337f17ab9421145)
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
| -rw-r--r-- | meta/lib/oeqa/oetest.py | 40 | ||||
| -rw-r--r-- | meta/lib/oeqa/utils/decorators.py | 10 |
2 files changed, 26 insertions, 24 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index 529abdc19a..3bb3589468 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py | |||
| @@ -17,9 +17,9 @@ from oeqa.utils.sshcontrol import SSHControl | |||
| 17 | def runTests(tc): | 17 | def runTests(tc): |
| 18 | 18 | ||
| 19 | # set the context object passed from the test class | 19 | # set the context object passed from the test class |
| 20 | setattr(oeRuntimeTest, "tc", tc) | 20 | setattr(oeTest, "tc", tc) |
| 21 | # set ps command to use | 21 | # set ps command to use |
| 22 | setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeRuntimeTest.hasPackage("procps") else "ps") | 22 | setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeTest.hasPackage("procps") else "ps") |
| 23 | # prepare test suite, loader and runner | 23 | # prepare test suite, loader and runner |
| 24 | suite = unittest.TestSuite() | 24 | suite = unittest.TestSuite() |
| 25 | testloader = unittest.TestLoader() | 25 | testloader = unittest.TestLoader() |
| @@ -36,33 +36,28 @@ def runTests(tc): | |||
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | class oeRuntimeTest(unittest.TestCase): | 39 | class oeTest(unittest.TestCase): |
| 40 | 40 | ||
| 41 | longMessage = True | 41 | longMessage = True |
| 42 | testFailures = [] | 42 | testFailures = [] |
| 43 | testSkipped = [] | 43 | testSkipped = [] |
| 44 | testErrors = [] | 44 | testErrors = [] |
| 45 | 45 | ||
| 46 | def __init__(self, methodName='runTest'): | ||
| 47 | self.target = oeRuntimeTest.tc.target | ||
| 48 | super(oeRuntimeTest, self).__init__(methodName) | ||
| 49 | |||
| 50 | |||
| 51 | def run(self, result=None): | 46 | def run(self, result=None): |
| 52 | super(oeRuntimeTest, self).run(result) | 47 | super(oeTest, self).run(result) |
| 53 | 48 | ||
| 54 | # we add to our own lists the results, we use those for decorators | 49 | # we add to our own lists the results, we use those for decorators |
| 55 | if len(result.failures) > len(oeRuntimeTest.testFailures): | 50 | if len(result.failures) > len(oeTest.testFailures): |
| 56 | oeRuntimeTest.testFailures.append(str(result.failures[-1][0]).split()[0]) | 51 | oeTest.testFailures.append(str(result.failures[-1][0]).split()[0]) |
| 57 | if len(result.skipped) > len(oeRuntimeTest.testSkipped): | 52 | if len(result.skipped) > len(oeTest.testSkipped): |
| 58 | oeRuntimeTest.testSkipped.append(str(result.skipped[-1][0]).split()[0]) | 53 | oeTest.testSkipped.append(str(result.skipped[-1][0]).split()[0]) |
| 59 | if len(result.errors) > len(oeRuntimeTest.testErrors): | 54 | if len(result.errors) > len(oeTest.testErrors): |
| 60 | oeRuntimeTest.testErrors.append(str(result.errors[-1][0]).split()[0]) | 55 | oeTest.testErrors.append(str(result.errors[-1][0]).split()[0]) |
| 61 | 56 | ||
| 62 | @classmethod | 57 | @classmethod |
| 63 | def hasPackage(self, pkg): | 58 | def hasPackage(self, pkg): |
| 64 | 59 | ||
| 65 | pkgfile = os.path.join(oeRuntimeTest.tc.d.getVar("WORKDIR", True), "installed_pkgs.txt") | 60 | pkgfile = os.path.join(oeTest.tc.d.getVar("WORKDIR", True), "installed_pkgs.txt") |
| 66 | 61 | ||
| 67 | with open(pkgfile) as f: | 62 | with open(pkgfile) as f: |
| 68 | data = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) | 63 | data = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) |
| @@ -77,12 +72,19 @@ class oeRuntimeTest(unittest.TestCase): | |||
| 77 | @classmethod | 72 | @classmethod |
| 78 | def hasFeature(self,feature): | 73 | def hasFeature(self,feature): |
| 79 | 74 | ||
| 80 | if feature in oeRuntimeTest.tc.d.getVar("IMAGE_FEATURES", True).split() or \ | 75 | if feature in oeTest.tc.d.getVar("IMAGE_FEATURES", True).split() or \ |
| 81 | feature in oeRuntimeTest.tc.d.getVar("DISTRO_FEATURES", True).split(): | 76 | feature in oeTest.tc.d.getVar("DISTRO_FEATURES", True).split(): |
| 82 | return True | 77 | return True |
| 83 | else: | 78 | else: |
| 84 | return False | 79 | return False |
| 85 | 80 | ||
| 81 | |||
| 82 | class oeRuntimeTest(oeTest): | ||
| 83 | |||
| 84 | def __init__(self, methodName='runTest'): | ||
| 85 | self.target = oeRuntimeTest.tc.target | ||
| 86 | super(oeRuntimeTest, self).__init__(methodName) | ||
| 87 | |||
| 86 | @classmethod | 88 | @classmethod |
| 87 | def restartTarget(self,params=None): | 89 | def restartTarget(self,params=None): |
| 88 | 90 | ||
| @@ -102,7 +104,7 @@ def getmodule(pos=2): | |||
| 102 | 104 | ||
| 103 | def skipModule(reason, pos=2): | 105 | def skipModule(reason, pos=2): |
| 104 | modname = getmodule(pos) | 106 | modname = getmodule(pos) |
| 105 | if modname not in oeRuntimeTest.tc.testsrequired: | 107 | if modname not in oeTest.tc.testsrequired: |
| 106 | raise unittest.SkipTest("%s: %s" % (modname, reason)) | 108 | raise unittest.SkipTest("%s: %s" % (modname, reason)) |
| 107 | else: | 109 | else: |
| 108 | raise Exception("\nTest %s wants to be skipped.\nReason is: %s" \ | 110 | raise Exception("\nTest %s wants to be skipped.\nReason is: %s" \ |
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py index 33fed5a10b..b99da8d76d 100644 --- a/meta/lib/oeqa/utils/decorators.py +++ b/meta/lib/oeqa/utils/decorators.py | |||
| @@ -15,7 +15,7 @@ class skipIfFailure(object): | |||
| 15 | 15 | ||
| 16 | def __call__(self,f): | 16 | def __call__(self,f): |
| 17 | def wrapped_f(*args): | 17 | def wrapped_f(*args): |
| 18 | if self.testcase in (oeRuntimeTest.testFailures or oeRuntimeTest.testErrors): | 18 | if self.testcase in (oeTest.testFailures or oeTest.testErrors): |
| 19 | raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) | 19 | raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) |
| 20 | return f(*args) | 20 | return f(*args) |
| 21 | wrapped_f.__name__ = f.__name__ | 21 | wrapped_f.__name__ = f.__name__ |
| @@ -28,7 +28,7 @@ class skipIfSkipped(object): | |||
| 28 | 28 | ||
| 29 | def __call__(self,f): | 29 | def __call__(self,f): |
| 30 | def wrapped_f(*args): | 30 | def wrapped_f(*args): |
| 31 | if self.testcase in oeRuntimeTest.testSkipped: | 31 | if self.testcase in oeTest.testSkipped: |
| 32 | raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) | 32 | raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) |
| 33 | return f(*args) | 33 | return f(*args) |
| 34 | wrapped_f.__name__ = f.__name__ | 34 | wrapped_f.__name__ = f.__name__ |
| @@ -41,9 +41,9 @@ class skipUnlessPassed(object): | |||
| 41 | 41 | ||
| 42 | def __call__(self,f): | 42 | def __call__(self,f): |
| 43 | def wrapped_f(*args): | 43 | def wrapped_f(*args): |
| 44 | if self.testcase in oeRuntimeTest.testSkipped or \ | 44 | if self.testcase in oeTest.testSkipped or \ |
| 45 | self.testcase in oeRuntimeTest.testFailures or \ | 45 | self.testcase in oeTest.testFailures or \ |
| 46 | self.testcase in oeRuntimeTest.testErrors: | 46 | self.testcase in oeTest.testErrors: |
| 47 | raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) | 47 | raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase) |
| 48 | return f(*args) | 48 | return f(*args) |
| 49 | wrapped_f.__name__ = f.__name__ | 49 | wrapped_f.__name__ = f.__name__ |
