summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa
diff options
context:
space:
mode:
authorLucian Musat <georgex.l.musat@intel.com>2014-06-27 17:32:13 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-07-03 17:41:17 +0100
commitae03111791f45036e7c24378b06b997f8c7cb0a7 (patch)
tree6a82a37ec4d6a0a9d61ea4eb1892df72887fd2a6 /meta/lib/oeqa
parent52a6d20519870103134166d91e22d21fd736195d (diff)
downloadpoky-ae03111791f45036e7c24378b06b997f8c7cb0a7.tar.gz
Added testcase decorator to use in logging. Added class decorator LogResults that outputs test results in separate log file.
(From OE-Core rev: 7e2b73f1ccfe2968ef780fef2edfaa31c3dae853) Signed-off-by: Lucian Musat <georgex.l.musat@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa')
-rw-r--r--meta/lib/oeqa/selftest/base.py2
-rw-r--r--meta/lib/oeqa/selftest/bblayers.py6
-rw-r--r--meta/lib/oeqa/utils/decorators.py66
3 files changed, 74 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/base.py b/meta/lib/oeqa/selftest/base.py
index fc880e9d26..80b9b4b312 100644
--- a/meta/lib/oeqa/selftest/base.py
+++ b/meta/lib/oeqa/selftest/base.py
@@ -15,7 +15,9 @@ import errno
15 15
16import oeqa.utils.ftools as ftools 16import oeqa.utils.ftools as ftools
17from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer 17from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer
18from oeqa.utils.decorators import LogResults
18 19
20@LogResults
19class oeSelfTest(unittest.TestCase): 21class oeSelfTest(unittest.TestCase):
20 22
21 log = logging.getLogger("selftest.base") 23 log = logging.getLogger("selftest.base")
diff --git a/meta/lib/oeqa/selftest/bblayers.py b/meta/lib/oeqa/selftest/bblayers.py
index 52aa4f8112..1ead8e8671 100644
--- a/meta/lib/oeqa/selftest/bblayers.py
+++ b/meta/lib/oeqa/selftest/bblayers.py
@@ -7,25 +7,31 @@ import shutil
7import oeqa.utils.ftools as ftools 7import oeqa.utils.ftools as ftools
8from oeqa.selftest.base import oeSelfTest 8from oeqa.selftest.base import oeSelfTest
9from oeqa.utils.commands import runCmd 9from oeqa.utils.commands import runCmd
10from oeqa.utils.decorators import testcase
10 11
11class BitbakeLayers(oeSelfTest): 12class BitbakeLayers(oeSelfTest):
12 13
14 @testcase(756)
13 def test_bitbakelayers_showcrossdepends(self): 15 def test_bitbakelayers_showcrossdepends(self):
14 result = runCmd('bitbake-layers show-cross-depends') 16 result = runCmd('bitbake-layers show-cross-depends')
15 self.assertTrue('aspell' in result.output) 17 self.assertTrue('aspell' in result.output)
16 18
19 @testcase(83)
17 def test_bitbakelayers_showlayers(self): 20 def test_bitbakelayers_showlayers(self):
18 result = runCmd('bitbake-layers show_layers') 21 result = runCmd('bitbake-layers show_layers')
19 self.assertTrue('meta-selftest' in result.output) 22 self.assertTrue('meta-selftest' in result.output)
20 23
24 @testcase(93)
21 def test_bitbakelayers_showappends(self): 25 def test_bitbakelayers_showappends(self):
22 result = runCmd('bitbake-layers show_appends') 26 result = runCmd('bitbake-layers show_appends')
23 self.assertTrue('xcursor-transparent-theme_0.1.1.bbappend' in result.output, msg='xcursor-transparent-theme_0.1.1.bbappend file was not recognised') 27 self.assertTrue('xcursor-transparent-theme_0.1.1.bbappend' in result.output, msg='xcursor-transparent-theme_0.1.1.bbappend file was not recognised')
24 28
29 @testcase(90)
25 def test_bitbakelayers_showoverlayed(self): 30 def test_bitbakelayers_showoverlayed(self):
26 result = runCmd('bitbake-layers show_overlayed') 31 result = runCmd('bitbake-layers show_overlayed')
27 self.assertTrue('aspell' in result.output, msg='xcursor-transparent-theme_0.1.1.bbappend file was not recognised') 32 self.assertTrue('aspell' in result.output, msg='xcursor-transparent-theme_0.1.1.bbappend file was not recognised')
28 33
34 @testcase(95)
29 def test_bitbakelayers_flatten(self): 35 def test_bitbakelayers_flatten(self):
30 self.assertFalse(os.path.isdir(os.path.join(self.builddir, 'test'))) 36 self.assertFalse(os.path.isdir(os.path.join(self.builddir, 'test')))
31 result = runCmd('bitbake-layers flatten test') 37 result = runCmd('bitbake-layers flatten test')
diff --git a/meta/lib/oeqa/utils/decorators.py b/meta/lib/oeqa/utils/decorators.py
index b99da8d76d..a0d94e6d24 100644
--- a/meta/lib/oeqa/utils/decorators.py
+++ b/meta/lib/oeqa/utils/decorators.py
@@ -7,6 +7,8 @@
7# creating dependecies between two test methods. 7# creating dependecies between two test methods.
8 8
9from oeqa.oetest import * 9from oeqa.oetest import *
10import logging
11import sys
10 12
11class skipIfFailure(object): 13class skipIfFailure(object):
12 14
@@ -48,3 +50,67 @@ class skipUnlessPassed(object):
48 return f(*args) 50 return f(*args)
49 wrapped_f.__name__ = f.__name__ 51 wrapped_f.__name__ = f.__name__
50 return wrapped_f 52 return wrapped_f
53
54class testcase(object):
55
56 def __init__(self, test_case):
57 self.test_case = test_case
58
59 def __call__(self, func):
60 def wrapped_f(*args):
61 return func(*args)
62 wrapped_f.test_case = self.test_case
63 return wrapped_f
64
65def LogResults(original_class):
66 orig_method = original_class.run
67
68 #rewrite the run method of unittest.TestCase to add testcase logging
69 def run(self, result, *args, **kws):
70 orig_method(self, result, *args, **kws)
71 passed = True
72 testMethod = getattr(self, self._testMethodName)
73
74 #if test case is decorated then use it's number, else use it's name
75 try:
76 test_case = testMethod.test_case
77 except AttributeError:
78 test_case = self._testMethodName
79
80 #create custom logging level for filtering.
81 custom_log_level = 100
82 logging.addLevelName(custom_log_level, 'RESULTS')
83 caller = os.path.basename(sys.argv[0])
84
85 def results(self, message, *args, **kws):
86 if self.isEnabledFor(custom_log_level):
87 self.log(custom_log_level, message, *args, **kws)
88 logging.Logger.results = results
89
90 logging.basicConfig(filename=os.path.join(os.getcwd(),'results-'+caller+'.log'),
91 filemode='w',
92 format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
93 datefmt='%H:%M:%S',
94 level=custom_log_level)
95 local_log = logging.getLogger(caller)
96
97 #check status of tests and record it
98 for (name, msg) in result.errors:
99 if self._testMethodName == str(name).split(' ')[0]:
100 local_log.results("Testcase "+str(test_case)+": ERROR")
101 local_log.results("Testcase "+str(test_case)+":\n"+msg)
102 passed = False
103 for (name, msg) in result.failures:
104 if self._testMethodName == str(name).split(' ')[0]:
105 local_log.results("Testcase "+str(test_case)+": FAILED")
106 local_log.results("Testcase "+str(test_case)+":\n"+msg)
107 passed = False
108 for (name, msg) in result.skipped:
109 if self._testMethodName == str(name).split(' ')[0]:
110 local_log.results("Testcase "+str(test_case)+": SKIPPED")
111 passed = False
112 if passed:
113 local_log.results("Testcase "+str(test_case)+": PASSED")
114
115 original_class.run = run
116 return original_class