summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2017-05-26 15:37:32 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-02 13:36:13 +0100
commitb4b9e22c40b7ce315d0286fe656581f81d965043 (patch)
tree9741e2f485ced305130ccd352151663cc6dc6cab
parentc7600278b6c39a311f822b1a7d39339bac3076c2 (diff)
downloadpoky-b4b9e22c40b7ce315d0286fe656581f81d965043.tar.gz
oeqa/core: Move OETestContext.log{Summary, Details} into OETestResult
Those methods are used to write in the log the results so it makes sense to have defined at OETestResult because is a format of the result itself. [YOCTO #11450] (From OE-Core rev: 33a783f59ed4e232f41f8b09dfa7955f2ddc2f80) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/testimage.bbclass4
-rw-r--r--meta/classes/testsdk.bbclass8
-rw-r--r--meta/lib/oeqa/core/context.py93
-rw-r--r--meta/lib/oeqa/core/runner.py88
4 files changed, 97 insertions, 96 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass
index fb214604a9..d42907cf80 100644
--- a/meta/classes/testimage.bbclass
+++ b/meta/classes/testimage.bbclass
@@ -292,8 +292,8 @@ def testimage_main(d):
292 # Show results (if we have them) 292 # Show results (if we have them)
293 if not results: 293 if not results:
294 bb.fatal('%s - FAILED - tests were interrupted during execution' % pn) 294 bb.fatal('%s - FAILED - tests were interrupted during execution' % pn)
295 tc.logSummary(results, pn) 295 results.logSummary(pn)
296 tc.logDetails() 296 results.logDetails()
297 if not results.wasSuccessful(): 297 if not results.wasSuccessful():
298 bb.fatal('%s - FAILED - check the task log and the ssh log' % pn) 298 bb.fatal('%s - FAILED - check the task log and the ssh log' % pn)
299 299
diff --git a/meta/classes/testsdk.bbclass b/meta/classes/testsdk.bbclass
index 4740233910..edea89cbf4 100644
--- a/meta/classes/testsdk.bbclass
+++ b/meta/classes/testsdk.bbclass
@@ -70,8 +70,8 @@ def testsdk_main(d):
70 component = "%s %s" % (pn, OESDKTestContextExecutor.name) 70 component = "%s %s" % (pn, OESDKTestContextExecutor.name)
71 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env)) 71 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
72 72
73 tc.logSummary(result, component, context_msg) 73 result.logSummary(component, context_msg)
74 tc.logDetails() 74 result.logDetails()
75 75
76 if not result.wasSuccessful(): 76 if not result.wasSuccessful():
77 fail = True 77 fail = True
@@ -172,8 +172,8 @@ def testsdkext_main(d):
172 component = "%s %s" % (pn, OESDKExtTestContextExecutor.name) 172 component = "%s %s" % (pn, OESDKExtTestContextExecutor.name)
173 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env)) 173 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
174 174
175 tc.logSummary(result, component, context_msg) 175 result.logSummary(component, context_msg)
176 tc.logDetails() 176 result.logDetails()
177 177
178 if not result.wasSuccessful(): 178 if not result.wasSuccessful():
179 fail = True 179 fail = True
diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py
index 2628651fa3..54958add07 100644
--- a/meta/lib/oeqa/core/context.py
+++ b/meta/lib/oeqa/core/context.py
@@ -7,10 +7,9 @@ import json
7import time 7import time
8import logging 8import logging
9import collections 9import collections
10import re
11 10
12from oeqa.core.loader import OETestLoader 11from oeqa.core.loader import OETestLoader
13from oeqa.core.runner import OETestRunner, xmlEnabled 12from oeqa.core.runner import OETestRunner
14 13
15class OETestContext(object): 14class OETestContext(object):
16 loaderClass = OETestLoader 15 loaderClass = OETestLoader
@@ -59,92 +58,6 @@ class OETestContext(object):
59 58
60 return result 59 return result
61 60
62 def logSummary(self, result, component, context_msg=''):
63 self.logger.info("SUMMARY:")
64 self.logger.info("%s (%s) - Ran %d test%s in %.3fs" % (component,
65 context_msg, result.testsRun, result.testsRun != 1 and "s" or "",
66 (self._run_end_time - self._run_start_time)))
67
68 if result.wasSuccessful():
69 msg = "%s - OK - All required tests passed" % component
70 else:
71 msg = "%s - FAIL - Required tests failed" % component
72 skipped = len(self._results['skipped'])
73 if skipped:
74 msg += " (skipped=%d)" % skipped
75 self.logger.info(msg)
76
77 def _getDetailsNotPassed(self, case, type, desc):
78 found = False
79
80 for (scase, msg) in self._results[type]:
81 # XXX: When XML reporting is enabled scase is
82 # xmlrunner.result._TestInfo instance instead of
83 # string.
84 if xmlEnabled:
85 if case.id() == scase.test_id:
86 found = True
87 break
88 scase_str = scase.test_id
89 else:
90 if case == scase:
91 found = True
92 break
93 scase_str = str(scase)
94
95 # When fails at module or class level the class name is passed as string
96 # so figure out to see if match
97 m = re.search("^setUpModule \((?P<module_name>.*)\)$", scase_str)
98 if m:
99 if case.__class__.__module__ == m.group('module_name'):
100 found = True
101 break
102
103 m = re.search("^setUpClass \((?P<class_name>.*)\)$", scase_str)
104 if m:
105 class_name = "%s.%s" % (case.__class__.__module__,
106 case.__class__.__name__)
107
108 if class_name == m.group('class_name'):
109 found = True
110 break
111
112 if found:
113 return (found, msg)
114
115 return (found, None)
116
117 def logDetails(self):
118 self.logger.info("RESULTS:")
119 for case_name in self._registry['cases']:
120 case = self._registry['cases'][case_name]
121
122 result_types = ['failures', 'errors', 'skipped', 'expectedFailures']
123 result_desc = ['FAILED', 'ERROR', 'SKIPPED', 'EXPECTEDFAIL']
124
125 fail = False
126 desc = None
127 for idx, name in enumerate(result_types):
128 (fail, msg) = self._getDetailsNotPassed(case, result_types[idx],
129 result_desc[idx])
130 if fail:
131 desc = result_desc[idx]
132 break
133
134 oeid = -1
135 for d in case.decorators:
136 if hasattr(d, 'oeid'):
137 oeid = d.oeid
138
139 if fail:
140 self.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(),
141 oeid, desc))
142 if msg:
143 self.logger.info(msg)
144 else:
145 self.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(),
146 oeid, 'PASSED'))
147
148class OETestContextExecutor(object): 61class OETestContextExecutor(object):
149 _context_class = OETestContext 62 _context_class = OETestContext
150 63
@@ -227,8 +140,8 @@ class OETestContextExecutor(object):
227 self.tc = self._context_class(**self.tc_kwargs['init']) 140 self.tc = self._context_class(**self.tc_kwargs['init'])
228 self.tc.loadTests(self.module_paths, **self.tc_kwargs['load']) 141 self.tc.loadTests(self.module_paths, **self.tc_kwargs['load'])
229 rc = self.tc.runTests(**self.tc_kwargs['run']) 142 rc = self.tc.runTests(**self.tc_kwargs['run'])
230 self.tc.logSummary(rc, self.name) 143 rc.logSummary(self.name)
231 self.tc.logDetails() 144 rc.logDetails()
232 145
233 output_link = os.path.join(os.path.dirname(args.output_log), 146 output_link = os.path.join(os.path.dirname(args.output_log),
234 "%s-results.log" % self.name) 147 "%s-results.log" % self.name)
diff --git a/meta/lib/oeqa/core/runner.py b/meta/lib/oeqa/core/runner.py
index 0b04e8d586..75058384ae 100644
--- a/meta/lib/oeqa/core/runner.py
+++ b/meta/lib/oeqa/core/runner.py
@@ -5,6 +5,7 @@ import os
5import time 5import time
6import unittest 6import unittest
7import logging 7import logging
8import re
8 9
9xmlEnabled = False 10xmlEnabled = False
10try: 11try:
@@ -44,6 +45,93 @@ class OETestResult(_TestResult):
44 self.tc._results['skipped'] = self.skipped 45 self.tc._results['skipped'] = self.skipped
45 self.tc._results['expectedFailures'] = self.expectedFailures 46 self.tc._results['expectedFailures'] = self.expectedFailures
46 47
48 def logSummary(self, component, context_msg=''):
49 elapsed_time = self.tc._run_end_time - self.tc._run_start_time
50 self.tc.logger.info("SUMMARY:")
51 self.tc.logger.info("%s (%s) - Ran %d test%s in %.3fs" % (component,
52 context_msg, self.testsRun, self.testsRun != 1 and "s" or "",
53 elapsed_time))
54
55 if self.wasSuccessful():
56 msg = "%s - OK - All required tests passed" % component
57 else:
58 msg = "%s - FAIL - Required tests failed" % component
59 skipped = len(self.tc._results['skipped'])
60 if skipped:
61 msg += " (skipped=%d)" % skipped
62 self.tc.logger.info(msg)
63
64 def _getDetailsNotPassed(self, case, type, desc):
65 found = False
66
67 for (scase, msg) in self.tc._results[type]:
68 # XXX: When XML reporting is enabled scase is
69 # xmlrunner.result._TestInfo instance instead of
70 # string.
71 if xmlEnabled:
72 if case.id() == scase.test_id:
73 found = True
74 break
75 scase_str = scase.test_id
76 else:
77 if case == scase:
78 found = True
79 break
80 scase_str = str(scase)
81
82 # When fails at module or class level the class name is passed as string
83 # so figure out to see if match
84 m = re.search("^setUpModule \((?P<module_name>.*)\)$", scase_str)
85 if m:
86 if case.__class__.__module__ == m.group('module_name'):
87 found = True
88 break
89
90 m = re.search("^setUpClass \((?P<class_name>.*)\)$", scase_str)
91 if m:
92 class_name = "%s.%s" % (case.__class__.__module__,
93 case.__class__.__name__)
94
95 if class_name == m.group('class_name'):
96 found = True
97 break
98
99 if found:
100 return (found, msg)
101
102 return (found, None)
103
104 def logDetails(self):
105 self.tc.logger.info("RESULTS:")
106 for case_name in self.tc._registry['cases']:
107 case = self.tc._registry['cases'][case_name]
108
109 result_types = ['failures', 'errors', 'skipped', 'expectedFailures']
110 result_desc = ['FAILED', 'ERROR', 'SKIPPED', 'EXPECTEDFAIL']
111
112 fail = False
113 desc = None
114 for idx, name in enumerate(result_types):
115 (fail, msg) = self._getDetailsNotPassed(case, result_types[idx],
116 result_desc[idx])
117 if fail:
118 desc = result_desc[idx]
119 break
120
121 oeid = -1
122 for d in case.decorators:
123 if hasattr(d, 'oeid'):
124 oeid = d.oeid
125
126 if fail:
127 self.tc.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(),
128 oeid, desc))
129 if msg:
130 self.tc.logger.info(msg)
131 else:
132 self.tc.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(),
133 oeid, 'PASSED'))
134
47class OETestRunner(_TestRunner): 135class OETestRunner(_TestRunner):
48 streamLoggerClass = OEStreamLogger 136 streamLoggerClass = OEStreamLogger
49 137