diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /meta/lib/oeqa/oetest.py | |
download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz |
initial commit for Enea Linux 5.0 arm
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 | 106 |
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 | |||
10 | import os, re, mmap | ||
11 | import unittest | ||
12 | import inspect | ||
13 | import subprocess | ||
14 | from oeqa.utils.decorators import LogResults | ||
15 | |||
16 | def 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 | |||
33 | def 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 | ||
44 | class 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 | |||
64 | class 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 | |||
76 | class oeSDKTest(oeTest): | ||
77 | def __init__(self, methodName='runTest'): | ||
78 | self.sdktestdir = oeSDKTest.tc.sdktestdir | ||
79 | super(oeSDKTest, self).__init__(methodName) | ||
80 | |||
81 | def 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 | |||
89 | def 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 | |||
98 | def skipModuleIf(cond, reason): | ||
99 | |||
100 | if cond: | ||
101 | skipModule(reason, 3) | ||
102 | |||
103 | def skipModuleUnless(cond, reason): | ||
104 | |||
105 | if not cond: | ||
106 | skipModule(reason, 3) | ||