diff options
author | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
commit | c527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch) | |
tree | bb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /meta/lib/oeqa/oetest.py | |
download | poky-daisy-140929.tar.gz |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/lib/oeqa/oetest.py')
-rw-r--r-- | meta/lib/oeqa/oetest.py | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py new file mode 100644 index 0000000000..0db6cb80a9 --- /dev/null +++ b/meta/lib/oeqa/oetest.py | |||
@@ -0,0 +1,107 @@ | |||
1 | # Copyright (C) 2013 Intel Corporation | ||
2 | # | ||
3 | # Released under the MIT license (see COPYING.MIT) | ||
4 | |||
5 | # Main unittest module used by testimage.bbclass | ||
6 | # This provides the oeRuntimeTest base class which is inherited by all tests in meta/lib/oeqa/runtime. | ||
7 | |||
8 | # It also has some helper functions and it's responsible for actually starting the tests | ||
9 | |||
10 | import os, re, mmap | ||
11 | import unittest | ||
12 | import inspect | ||
13 | |||
14 | |||
15 | def loadTests(tc): | ||
16 | |||
17 | # set the context object passed from the test class | ||
18 | setattr(oeTest, "tc", tc) | ||
19 | # set ps command to use | ||
20 | setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeTest.hasPackage("procps") else "ps") | ||
21 | # prepare test suite, loader and runner | ||
22 | suite = unittest.TestSuite() | ||
23 | testloader = unittest.TestLoader() | ||
24 | testloader.sortTestMethodsUsing = None | ||
25 | suite = testloader.loadTestsFromNames(tc.testslist) | ||
26 | |||
27 | return suite | ||
28 | |||
29 | def runTests(tc): | ||
30 | |||
31 | suite = loadTests(tc) | ||
32 | print("Test modules %s" % tc.testslist) | ||
33 | print("Found %s tests" % suite.countTestCases()) | ||
34 | runner = unittest.TextTestRunner(verbosity=2) | ||
35 | result = runner.run(suite) | ||
36 | |||
37 | return result | ||
38 | |||
39 | |||
40 | class oeTest(unittest.TestCase): | ||
41 | |||
42 | longMessage = True | ||
43 | testFailures = [] | ||
44 | testSkipped = [] | ||
45 | testErrors = [] | ||
46 | |||
47 | def run(self, result=None): | ||
48 | super(oeTest, self).run(result) | ||
49 | |||
50 | # we add to our own lists the results, we use those for decorators | ||
51 | if len(result.failures) > len(oeTest.testFailures): | ||
52 | oeTest.testFailures.append(str(result.failures[-1][0]).split()[0]) | ||
53 | if len(result.skipped) > len(oeTest.testSkipped): | ||
54 | oeTest.testSkipped.append(str(result.skipped[-1][0]).split()[0]) | ||
55 | if len(result.errors) > len(oeTest.testErrors): | ||
56 | oeTest.testErrors.append(str(result.errors[-1][0]).split()[0]) | ||
57 | |||
58 | @classmethod | ||
59 | def hasPackage(self, pkg): | ||
60 | |||
61 | if re.search(pkg, oeTest.tc.pkgmanifest): | ||
62 | return True | ||
63 | return False | ||
64 | |||
65 | @classmethod | ||
66 | def hasFeature(self,feature): | ||
67 | |||
68 | if feature in oeTest.tc.imagefeatures or \ | ||
69 | feature in oeTest.tc.distrofeatures: | ||
70 | return True | ||
71 | else: | ||
72 | return False | ||
73 | |||
74 | |||
75 | class oeRuntimeTest(oeTest): | ||
76 | |||
77 | def __init__(self, methodName='runTest'): | ||
78 | self.target = oeRuntimeTest.tc.target | ||
79 | super(oeRuntimeTest, self).__init__(methodName) | ||
80 | |||
81 | |||
82 | def getmodule(pos=2): | ||
83 | # stack returns a list of tuples containg frame information | ||
84 | # First element of the list the is current frame, caller is 1 | ||
85 | frameinfo = inspect.stack()[pos] | ||
86 | modname = inspect.getmodulename(frameinfo[1]) | ||
87 | #modname = inspect.getmodule(frameinfo[0]).__name__ | ||
88 | return modname | ||
89 | |||
90 | def skipModule(reason, pos=2): | ||
91 | modname = getmodule(pos) | ||
92 | if modname not in oeTest.tc.testsrequired: | ||
93 | raise unittest.SkipTest("%s: %s" % (modname, reason)) | ||
94 | else: | ||
95 | raise Exception("\nTest %s wants to be skipped.\nReason is: %s" \ | ||
96 | "\nTest was required in TEST_SUITES, so either the condition for skipping is wrong" \ | ||
97 | "\nor the image really doesn't have the required feature/package when it should." % (modname, reason)) | ||
98 | |||
99 | def skipModuleIf(cond, reason): | ||
100 | |||
101 | if cond: | ||
102 | skipModule(reason, 3) | ||
103 | |||
104 | def skipModuleUnless(cond, reason): | ||
105 | |||
106 | if not cond: | ||
107 | skipModule(reason, 3) | ||