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.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py
new file mode 100644
index 0000000000..0b7e7dc42d
--- /dev/null
+++ b/meta/lib/oeqa/oetest.py
@@ -0,0 +1,106 @@
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
13import subprocess
14from oeqa.utils.decorators import LogResults
15
16def loadTests(tc, type="runtime"):
17 if type == "runtime":
18 # set the context object passed from the test class
19 setattr(oeTest, "tc", tc)
20 # set ps command to use
21 setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeTest.hasPackage("procps") else "ps")
22 # prepare test suite, loader and runner
23 suite = unittest.TestSuite()
24 elif type == "sdk":
25 # set the context object passed from the test class
26 setattr(oeTest, "tc", tc)
27 testloader = unittest.TestLoader()
28 testloader.sortTestMethodsUsing = None
29 suite = testloader.loadTestsFromNames(tc.testslist)
30
31 return suite
32
33def runTests(tc, type="runtime"):
34
35 suite = loadTests(tc, type)
36 print("Test modules %s" % tc.testslist)
37 print("Found %s tests" % suite.countTestCases())
38 runner = unittest.TextTestRunner(verbosity=2)
39 result = runner.run(suite)
40
41 return result
42
43@LogResults
44class oeTest(unittest.TestCase):
45
46 longMessage = True
47
48 @classmethod
49 def hasPackage(self, pkg):
50
51 if re.search(pkg, oeTest.tc.pkgmanifest):
52 return True
53 return False
54
55 @classmethod
56 def hasFeature(self,feature):
57
58 if feature in oeTest.tc.imagefeatures or \
59 feature in oeTest.tc.distrofeatures:
60 return True
61 else:
62 return False
63
64class oeRuntimeTest(oeTest):
65 def __init__(self, methodName='runTest'):
66 self.target = oeRuntimeTest.tc.target
67 super(oeRuntimeTest, self).__init__(methodName)
68
69 #TODO: use package_manager.py to install packages on any type of image
70 def install_packages(self, packagelist):
71 for package in packagelist:
72 (status, result) = self.target.run("smart install -y "+package)
73 if status != 0:
74 return status
75
76class oeSDKTest(oeTest):
77 def __init__(self, methodName='runTest'):
78 self.sdktestdir = oeSDKTest.tc.sdktestdir
79 super(oeSDKTest, self).__init__(methodName)
80
81def getmodule(pos=2):
82 # stack returns a list of tuples containg frame information
83 # First element of the list the is current frame, caller is 1
84 frameinfo = inspect.stack()[pos]
85 modname = inspect.getmodulename(frameinfo[1])
86 #modname = inspect.getmodule(frameinfo[0]).__name__
87 return modname
88
89def skipModule(reason, pos=2):
90 modname = getmodule(pos)
91 if modname not in oeTest.tc.testsrequired:
92 raise unittest.SkipTest("%s: %s" % (modname, reason))
93 else:
94 raise Exception("\nTest %s wants to be skipped.\nReason is: %s" \
95 "\nTest was required in TEST_SUITES, so either the condition for skipping is wrong" \
96 "\nor the image really doesn't have the required feature/package when it should." % (modname, reason))
97
98def skipModuleIf(cond, reason):
99
100 if cond:
101 skipModule(reason, 3)
102
103def skipModuleUnless(cond, reason):
104
105 if not cond:
106 skipModule(reason, 3)