summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/oetest.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/oetest.py')
-rw-r--r--meta/lib/oeqa/oetest.py107
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 0000000..0db6cb8
--- /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
10import os, re, mmap
11import unittest
12import inspect
13
14
15def 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
29def 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
40class 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
75class oeRuntimeTest(oeTest):
76
77 def __init__(self, methodName='runTest'):
78 self.target = oeRuntimeTest.tc.target
79 super(oeRuntimeTest, self).__init__(methodName)
80
81
82def 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
90def 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
99def skipModuleIf(cond, reason):
100
101 if cond:
102 skipModule(reason, 3)
103
104def skipModuleUnless(cond, reason):
105
106 if not cond:
107 skipModule(reason, 3)