Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 """
borlanic 0:380207fcb5c1 2 mbed SDK
borlanic 0:380207fcb5c1 3 Copyright (c) 2011-2014 ARM Limited
borlanic 0:380207fcb5c1 4
borlanic 0:380207fcb5c1 5 Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:380207fcb5c1 6 you may not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 7 You may obtain a copy of the License at
borlanic 0:380207fcb5c1 8
borlanic 0:380207fcb5c1 9 http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 10
borlanic 0:380207fcb5c1 11 Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 12 distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:380207fcb5c1 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 14 See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 15 limitations under the License.
borlanic 0:380207fcb5c1 16
borlanic 0:380207fcb5c1 17 Author: Przemyslaw Wirkus <Przemyslaw.wirkus@arm.com>
borlanic 0:380207fcb5c1 18 """
borlanic 0:380207fcb5c1 19
borlanic 0:380207fcb5c1 20 from tools.utils import construct_enum, mkdir
borlanic 0:380207fcb5c1 21 from prettytable import PrettyTable
borlanic 0:380207fcb5c1 22 import os
borlanic 0:380207fcb5c1 23
borlanic 0:380207fcb5c1 24 ResultExporterType = construct_enum(HTML='Html_Exporter',
borlanic 0:380207fcb5c1 25 JUNIT='JUnit_Exporter',
borlanic 0:380207fcb5c1 26 JUNIT_OPER='JUnit_Exporter_Interoperability',
borlanic 0:380207fcb5c1 27 BUILD='Build_Exporter',
borlanic 0:380207fcb5c1 28 TEXT='Text_Exporter',
borlanic 0:380207fcb5c1 29 PRINT='Print_Exporter')
borlanic 0:380207fcb5c1 30
borlanic 0:380207fcb5c1 31
borlanic 0:380207fcb5c1 32 class ReportExporter():
borlanic 0:380207fcb5c1 33 """ Class exports extended test result Python data structure to
borlanic 0:380207fcb5c1 34 different formats like HTML, JUnit XML.
borlanic 0:380207fcb5c1 35
borlanic 0:380207fcb5c1 36 Parameter 'test_result_ext' format:
borlanic 0:380207fcb5c1 37
borlanic 0:380207fcb5c1 38 u'uARM': { u'LPC1768': { 'MBED_2': { 0: { 'copy_method': 'shutils.copy()',
borlanic 0:380207fcb5c1 39 'duration': 20,
borlanic 0:380207fcb5c1 40 'elapsed_time': 1.7929999828338623,
borlanic 0:380207fcb5c1 41 'output': 'Host test instrumentation on ...\r\n',
borlanic 0:380207fcb5c1 42 'result': 'OK',
borlanic 0:380207fcb5c1 43 'target_name': u'LPC1768',
borlanic 0:380207fcb5c1 44 'description': 'stdio',
borlanic 0:380207fcb5c1 45 'id': u'MBED_2',
borlanic 0:380207fcb5c1 46 'toolchain_name': u'uARM'}},
borlanic 0:380207fcb5c1 47 """
borlanic 0:380207fcb5c1 48 CSS_STYLE = """<style>
borlanic 0:380207fcb5c1 49 .name{
borlanic 0:380207fcb5c1 50 border: 1px solid;
borlanic 0:380207fcb5c1 51 border-radius: 25px;
borlanic 0:380207fcb5c1 52 width: 100px;
borlanic 0:380207fcb5c1 53 }
borlanic 0:380207fcb5c1 54 .tooltip{
borlanic 0:380207fcb5c1 55 position:absolute;
borlanic 0:380207fcb5c1 56 background-color: #F5DA81;
borlanic 0:380207fcb5c1 57 display:none;
borlanic 0:380207fcb5c1 58 }
borlanic 0:380207fcb5c1 59 </style>
borlanic 0:380207fcb5c1 60 """
borlanic 0:380207fcb5c1 61
borlanic 0:380207fcb5c1 62 JAVASCRIPT = """
borlanic 0:380207fcb5c1 63 <script type="text/javascript">
borlanic 0:380207fcb5c1 64 function show (elem) {
borlanic 0:380207fcb5c1 65 elem.style.display = "block";
borlanic 0:380207fcb5c1 66 }
borlanic 0:380207fcb5c1 67 function hide (elem) {
borlanic 0:380207fcb5c1 68 elem.style.display = "";
borlanic 0:380207fcb5c1 69 }
borlanic 0:380207fcb5c1 70 </script>
borlanic 0:380207fcb5c1 71 """
borlanic 0:380207fcb5c1 72
borlanic 0:380207fcb5c1 73 def __init__(self, result_exporter_type, package="test"):
borlanic 0:380207fcb5c1 74 self.result_exporter_type = result_exporter_type
borlanic 0:380207fcb5c1 75 self.package = package
borlanic 0:380207fcb5c1 76
borlanic 0:380207fcb5c1 77 def report(self, test_summary_ext, test_suite_properties=None,
borlanic 0:380207fcb5c1 78 print_log_for_failures=True):
borlanic 0:380207fcb5c1 79 """ Invokes report depending on exporter_type set in constructor
borlanic 0:380207fcb5c1 80 """
borlanic 0:380207fcb5c1 81 if self.result_exporter_type == ResultExporterType.HTML:
borlanic 0:380207fcb5c1 82 # HTML exporter
borlanic 0:380207fcb5c1 83 return self.exporter_html(test_summary_ext, test_suite_properties)
borlanic 0:380207fcb5c1 84 elif self.result_exporter_type == ResultExporterType.JUNIT:
borlanic 0:380207fcb5c1 85 # JUNIT exporter for results from test suite
borlanic 0:380207fcb5c1 86 return self.exporter_junit(test_summary_ext, test_suite_properties)
borlanic 0:380207fcb5c1 87 elif self.result_exporter_type == ResultExporterType.JUNIT_OPER:
borlanic 0:380207fcb5c1 88 # JUNIT exporter for interoperability test
borlanic 0:380207fcb5c1 89 return self.exporter_junit_ioper(test_summary_ext, test_suite_properties)
borlanic 0:380207fcb5c1 90 elif self.result_exporter_type == ResultExporterType.PRINT:
borlanic 0:380207fcb5c1 91 # JUNIT exporter for interoperability test
borlanic 0:380207fcb5c1 92 return self.exporter_print(test_summary_ext, print_log_for_failures=print_log_for_failures)
borlanic 0:380207fcb5c1 93 elif self.result_exporter_type == ResultExporterType.TEXT:
borlanic 0:380207fcb5c1 94 return self.exporter_text(test_summary_ext)
borlanic 0:380207fcb5c1 95 return None
borlanic 0:380207fcb5c1 96
borlanic 0:380207fcb5c1 97 def report_to_file(self, test_summary_ext, file_name, test_suite_properties=None):
borlanic 0:380207fcb5c1 98 """ Stores report to specified file
borlanic 0:380207fcb5c1 99 """
borlanic 0:380207fcb5c1 100 report = self.report(test_summary_ext, test_suite_properties=test_suite_properties)
borlanic 0:380207fcb5c1 101 self.write_to_file(report, file_name)
borlanic 0:380207fcb5c1 102
borlanic 0:380207fcb5c1 103 def write_to_file(self, report, file_name):
borlanic 0:380207fcb5c1 104 if report is not None:
borlanic 0:380207fcb5c1 105 dirname = os.path.dirname(file_name)
borlanic 0:380207fcb5c1 106 if dirname:
borlanic 0:380207fcb5c1 107 mkdir(dirname)
borlanic 0:380207fcb5c1 108 with open(file_name, 'w') as f:
borlanic 0:380207fcb5c1 109 f.write(report)
borlanic 0:380207fcb5c1 110
borlanic 0:380207fcb5c1 111 def get_tooltip_name(self, toolchain, target, test_id, loop_no):
borlanic 0:380207fcb5c1 112 """ Generate simple unique tool-tip name which can be used.
borlanic 0:380207fcb5c1 113 For example as HTML <div> section id attribute.
borlanic 0:380207fcb5c1 114 """
borlanic 0:380207fcb5c1 115 return "target_test_%s_%s_%s_%s"% (toolchain.lower(), target.lower(), test_id.lower(), loop_no)
borlanic 0:380207fcb5c1 116
borlanic 0:380207fcb5c1 117 def get_result_div_sections(self, test, test_no):
borlanic 0:380207fcb5c1 118 """ Generates separate <DIV> sections which contains test results output.
borlanic 0:380207fcb5c1 119 """
borlanic 0:380207fcb5c1 120
borlanic 0:380207fcb5c1 121 RESULT_COLORS = {'OK': 'LimeGreen',
borlanic 0:380207fcb5c1 122 'FAIL': 'Orange',
borlanic 0:380207fcb5c1 123 'ERROR': 'LightCoral',
borlanic 0:380207fcb5c1 124 'OTHER': 'LightGray',
borlanic 0:380207fcb5c1 125 }
borlanic 0:380207fcb5c1 126
borlanic 0:380207fcb5c1 127 tooltip_name = self.get_tooltip_name(test['toolchain_name'], test['target_name'], test['id'], test_no)
borlanic 0:380207fcb5c1 128 background_color = RESULT_COLORS[test['result'] if test['result'] in RESULT_COLORS else 'OTHER']
borlanic 0:380207fcb5c1 129 result_div_style = "background-color: %s"% background_color
borlanic 0:380207fcb5c1 130
borlanic 0:380207fcb5c1 131 result = """<div class="name" style="%s" onmouseover="show(%s)" onmouseout="hide(%s)">
borlanic 0:380207fcb5c1 132 <center>%s</center>
borlanic 0:380207fcb5c1 133 <div class = "tooltip" id= "%s">
borlanic 0:380207fcb5c1 134 <b>%s</b><br />
borlanic 0:380207fcb5c1 135 <hr />
borlanic 0:380207fcb5c1 136 <b>%s</b> in <b>%.2f sec</b><br />
borlanic 0:380207fcb5c1 137 <hr />
borlanic 0:380207fcb5c1 138 <small>
borlanic 0:380207fcb5c1 139 %s
borlanic 0:380207fcb5c1 140 </small>
borlanic 0:380207fcb5c1 141 </div>
borlanic 0:380207fcb5c1 142 </div>
borlanic 0:380207fcb5c1 143 """% (result_div_style,
borlanic 0:380207fcb5c1 144 tooltip_name,
borlanic 0:380207fcb5c1 145 tooltip_name,
borlanic 0:380207fcb5c1 146 test['result'],
borlanic 0:380207fcb5c1 147 tooltip_name,
borlanic 0:380207fcb5c1 148 test['target_name_unique'],
borlanic 0:380207fcb5c1 149 test['description'],
borlanic 0:380207fcb5c1 150 test['elapsed_time'],
borlanic 0:380207fcb5c1 151 test['output'].replace('\n', '<br />'))
borlanic 0:380207fcb5c1 152 return result
borlanic 0:380207fcb5c1 153
borlanic 0:380207fcb5c1 154 def get_result_tree(self, test_results):
borlanic 0:380207fcb5c1 155 """ If test was run in a loop (we got few results from the same test)
borlanic 0:380207fcb5c1 156 we will show it in a column to see all results.
borlanic 0:380207fcb5c1 157 This function produces HTML table with corresponding results.
borlanic 0:380207fcb5c1 158 """
borlanic 0:380207fcb5c1 159 result = ''
borlanic 0:380207fcb5c1 160 for i, test_result in enumerate(test_results):
borlanic 0:380207fcb5c1 161 result += '<table>'
borlanic 0:380207fcb5c1 162 test_ids = sorted(test_result.keys())
borlanic 0:380207fcb5c1 163 for test_no in test_ids:
borlanic 0:380207fcb5c1 164 test = test_result[test_no]
borlanic 0:380207fcb5c1 165 result += """<tr>
borlanic 0:380207fcb5c1 166 <td valign="top">%s</td>
borlanic 0:380207fcb5c1 167 </tr>"""% self.get_result_div_sections(test, "%d_%d" % (test_no, i))
borlanic 0:380207fcb5c1 168 result += '</table>'
borlanic 0:380207fcb5c1 169 return result
borlanic 0:380207fcb5c1 170
borlanic 0:380207fcb5c1 171 def get_all_unique_test_ids(self, test_result_ext):
borlanic 0:380207fcb5c1 172 """ Gets all unique test ids from all ran tests.
borlanic 0:380207fcb5c1 173 We need this to create complete list of all test ran.
borlanic 0:380207fcb5c1 174 """
borlanic 0:380207fcb5c1 175 result = []
borlanic 0:380207fcb5c1 176 targets = test_result_ext.keys()
borlanic 0:380207fcb5c1 177 for target in targets:
borlanic 0:380207fcb5c1 178 toolchains = test_result_ext[target].keys()
borlanic 0:380207fcb5c1 179 for toolchain in toolchains:
borlanic 0:380207fcb5c1 180 tests = test_result_ext[target][toolchain].keys()
borlanic 0:380207fcb5c1 181 result.extend(tests)
borlanic 0:380207fcb5c1 182 return sorted(list(set(result)))
borlanic 0:380207fcb5c1 183
borlanic 0:380207fcb5c1 184 #
borlanic 0:380207fcb5c1 185 # Exporters functions
borlanic 0:380207fcb5c1 186 #
borlanic 0:380207fcb5c1 187
borlanic 0:380207fcb5c1 188 def exporter_html(self, test_result_ext, test_suite_properties=None):
borlanic 0:380207fcb5c1 189 """ Export test results in proprietary HTML format.
borlanic 0:380207fcb5c1 190 """
borlanic 0:380207fcb5c1 191 result = """<html>
borlanic 0:380207fcb5c1 192 <head>
borlanic 0:380207fcb5c1 193 <title>mbed SDK test suite test result report</title>
borlanic 0:380207fcb5c1 194 %s
borlanic 0:380207fcb5c1 195 %s
borlanic 0:380207fcb5c1 196 </head>
borlanic 0:380207fcb5c1 197 <body>
borlanic 0:380207fcb5c1 198 """% (self.CSS_STYLE, self.JAVASCRIPT)
borlanic 0:380207fcb5c1 199
borlanic 0:380207fcb5c1 200 unique_test_ids = self.get_all_unique_test_ids(test_result_ext)
borlanic 0:380207fcb5c1 201 targets = sorted(test_result_ext.keys())
borlanic 0:380207fcb5c1 202 result += '<table>'
borlanic 0:380207fcb5c1 203 for target in targets:
borlanic 0:380207fcb5c1 204 toolchains = sorted(test_result_ext[target].keys())
borlanic 0:380207fcb5c1 205 for toolchain in toolchains:
borlanic 0:380207fcb5c1 206 result += '<tr>'
borlanic 0:380207fcb5c1 207 result += '<td></td>'
borlanic 0:380207fcb5c1 208 result += '<td></td>'
borlanic 0:380207fcb5c1 209
borlanic 0:380207fcb5c1 210 tests = sorted(test_result_ext[target][toolchain].keys())
borlanic 0:380207fcb5c1 211 for test in unique_test_ids:
borlanic 0:380207fcb5c1 212 result += """<td align="center">%s</td>"""% test
borlanic 0:380207fcb5c1 213 result += """</tr>
borlanic 0:380207fcb5c1 214 <tr>
borlanic 0:380207fcb5c1 215 <td valign="center">%s</td>
borlanic 0:380207fcb5c1 216 <td valign="center"><b>%s</b></td>
borlanic 0:380207fcb5c1 217 """% (toolchain, target)
borlanic 0:380207fcb5c1 218
borlanic 0:380207fcb5c1 219 for test in unique_test_ids:
borlanic 0:380207fcb5c1 220 test_result = self.get_result_tree(test_result_ext[target][toolchain][test]) if test in tests else ''
borlanic 0:380207fcb5c1 221 result += '<td>%s</td>'% (test_result)
borlanic 0:380207fcb5c1 222
borlanic 0:380207fcb5c1 223 result += '</tr>'
borlanic 0:380207fcb5c1 224 result += '</table>'
borlanic 0:380207fcb5c1 225 result += '</body></html>'
borlanic 0:380207fcb5c1 226 return result
borlanic 0:380207fcb5c1 227
borlanic 0:380207fcb5c1 228 def exporter_junit_ioper(self, test_result_ext, test_suite_properties=None):
borlanic 0:380207fcb5c1 229 from junit_xml import TestSuite, TestCase
borlanic 0:380207fcb5c1 230 test_suites = []
borlanic 0:380207fcb5c1 231 test_cases = []
borlanic 0:380207fcb5c1 232
borlanic 0:380207fcb5c1 233 for platform in sorted(test_result_ext.keys()):
borlanic 0:380207fcb5c1 234 # {platform : ['Platform', 'Result', 'Scope', 'Description'])
borlanic 0:380207fcb5c1 235 test_cases = []
borlanic 0:380207fcb5c1 236 for tr_result in test_result_ext[platform]:
borlanic 0:380207fcb5c1 237 result, name, scope, description = tr_result
borlanic 0:380207fcb5c1 238
borlanic 0:380207fcb5c1 239 classname = 'test.ioper.%s.%s.%s' % (platform, name, scope)
borlanic 0:380207fcb5c1 240 elapsed_sec = 0
borlanic 0:380207fcb5c1 241 _stdout = description
borlanic 0:380207fcb5c1 242 _stderr = ''
borlanic 0:380207fcb5c1 243 # Test case
borlanic 0:380207fcb5c1 244 tc = TestCase(name, classname, elapsed_sec, _stdout, _stderr)
borlanic 0:380207fcb5c1 245 # Test case extra failure / error info
borlanic 0:380207fcb5c1 246 if result == 'FAIL':
borlanic 0:380207fcb5c1 247 tc.add_failure_info(description, _stdout)
borlanic 0:380207fcb5c1 248 elif result == 'ERROR':
borlanic 0:380207fcb5c1 249 tc.add_error_info(description, _stdout)
borlanic 0:380207fcb5c1 250 elif result == 'SKIP' or result == 'NOT_SUPPORTED':
borlanic 0:380207fcb5c1 251 tc.add_skipped_info(description, _stdout)
borlanic 0:380207fcb5c1 252
borlanic 0:380207fcb5c1 253 test_cases.append(tc)
borlanic 0:380207fcb5c1 254 ts = TestSuite("test.suite.ioper.%s" % (platform), test_cases)
borlanic 0:380207fcb5c1 255 test_suites.append(ts)
borlanic 0:380207fcb5c1 256 return TestSuite.to_xml_string(test_suites)
borlanic 0:380207fcb5c1 257
borlanic 0:380207fcb5c1 258 def exporter_junit(self, test_result_ext, test_suite_properties=None):
borlanic 0:380207fcb5c1 259 """ Export test results in JUnit XML compliant format
borlanic 0:380207fcb5c1 260 """
borlanic 0:380207fcb5c1 261 from junit_xml import TestSuite, TestCase
borlanic 0:380207fcb5c1 262 test_suites = []
borlanic 0:380207fcb5c1 263 test_cases = []
borlanic 0:380207fcb5c1 264
borlanic 0:380207fcb5c1 265 targets = sorted(test_result_ext.keys())
borlanic 0:380207fcb5c1 266 for target in targets:
borlanic 0:380207fcb5c1 267 toolchains = sorted(test_result_ext[target].keys())
borlanic 0:380207fcb5c1 268 for toolchain in toolchains:
borlanic 0:380207fcb5c1 269 test_cases = []
borlanic 0:380207fcb5c1 270 tests = sorted(test_result_ext[target][toolchain].keys())
borlanic 0:380207fcb5c1 271 for test in tests:
borlanic 0:380207fcb5c1 272 test_results = test_result_ext[target][toolchain][test]
borlanic 0:380207fcb5c1 273 for test_res in test_results:
borlanic 0:380207fcb5c1 274 test_ids = sorted(test_res.keys())
borlanic 0:380207fcb5c1 275 for test_no in test_ids:
borlanic 0:380207fcb5c1 276 test_result = test_res[test_no]
borlanic 0:380207fcb5c1 277 name = test_result['description']
borlanic 0:380207fcb5c1 278 classname = '%s.%s.%s.%s'% (self.package, target, toolchain, test_result['id'])
borlanic 0:380207fcb5c1 279 elapsed_sec = test_result['elapsed_time']
borlanic 0:380207fcb5c1 280 _stdout = test_result['output']
borlanic 0:380207fcb5c1 281
borlanic 0:380207fcb5c1 282 if 'target_name_unique' in test_result:
borlanic 0:380207fcb5c1 283 _stderr = test_result['target_name_unique']
borlanic 0:380207fcb5c1 284 else:
borlanic 0:380207fcb5c1 285 _stderr = test_result['target_name']
borlanic 0:380207fcb5c1 286
borlanic 0:380207fcb5c1 287 # Test case
borlanic 0:380207fcb5c1 288 tc = TestCase(name, classname, elapsed_sec, _stdout, _stderr)
borlanic 0:380207fcb5c1 289
borlanic 0:380207fcb5c1 290 # Test case extra failure / error info
borlanic 0:380207fcb5c1 291 message = test_result['result']
borlanic 0:380207fcb5c1 292 if test_result['result'] == 'FAIL':
borlanic 0:380207fcb5c1 293 tc.add_failure_info(message, _stdout)
borlanic 0:380207fcb5c1 294 elif test_result['result'] == 'SKIP' or test_result["result"] == 'NOT_SUPPORTED':
borlanic 0:380207fcb5c1 295 tc.add_skipped_info(message, _stdout)
borlanic 0:380207fcb5c1 296 elif test_result['result'] != 'OK':
borlanic 0:380207fcb5c1 297 tc.add_error_info(message, _stdout)
borlanic 0:380207fcb5c1 298
borlanic 0:380207fcb5c1 299 test_cases.append(tc)
borlanic 0:380207fcb5c1 300
borlanic 0:380207fcb5c1 301 ts = TestSuite("test.suite.%s.%s"% (target, toolchain), test_cases, properties=test_suite_properties[target][toolchain])
borlanic 0:380207fcb5c1 302 test_suites.append(ts)
borlanic 0:380207fcb5c1 303 return TestSuite.to_xml_string(test_suites)
borlanic 0:380207fcb5c1 304
borlanic 0:380207fcb5c1 305 def exporter_print_helper(self, array, print_log=False):
borlanic 0:380207fcb5c1 306 for item in array:
borlanic 0:380207fcb5c1 307 print(" * %s::%s::%s" % (item["target_name"],
borlanic 0:380207fcb5c1 308 item["toolchain_name"],
borlanic 0:380207fcb5c1 309 item["id"]))
borlanic 0:380207fcb5c1 310 if print_log:
borlanic 0:380207fcb5c1 311 log_lines = item["output"].split("\n")
borlanic 0:380207fcb5c1 312 for log_line in log_lines:
borlanic 0:380207fcb5c1 313 print(" %s" % log_line)
borlanic 0:380207fcb5c1 314
borlanic 0:380207fcb5c1 315 def exporter_print(self, test_result_ext, print_log_for_failures=False):
borlanic 0:380207fcb5c1 316 """ Export test results in print format.
borlanic 0:380207fcb5c1 317 """
borlanic 0:380207fcb5c1 318 failures = []
borlanic 0:380207fcb5c1 319 skips = []
borlanic 0:380207fcb5c1 320 successes = []
borlanic 0:380207fcb5c1 321
borlanic 0:380207fcb5c1 322 unique_test_ids = self.get_all_unique_test_ids(test_result_ext)
borlanic 0:380207fcb5c1 323 targets = sorted(test_result_ext.keys())
borlanic 0:380207fcb5c1 324
borlanic 0:380207fcb5c1 325 for target in targets:
borlanic 0:380207fcb5c1 326 toolchains = sorted(test_result_ext[target].keys())
borlanic 0:380207fcb5c1 327 for toolchain in toolchains:
borlanic 0:380207fcb5c1 328 tests = sorted(test_result_ext[target][toolchain].keys())
borlanic 0:380207fcb5c1 329 for test in tests:
borlanic 0:380207fcb5c1 330 test_runs = test_result_ext[target][toolchain][test]
borlanic 0:380207fcb5c1 331 for test_runner in test_runs:
borlanic 0:380207fcb5c1 332 #test_run = test_result_ext[target][toolchain][test][test_run_number][0]
borlanic 0:380207fcb5c1 333 test_run = test_runner[0]
borlanic 0:380207fcb5c1 334
borlanic 0:380207fcb5c1 335 if "result" in test_run:
borlanic 0:380207fcb5c1 336 if test_run["result"] == "FAIL":
borlanic 0:380207fcb5c1 337 failures.append(test_run)
borlanic 0:380207fcb5c1 338 elif test_run["result"] == "SKIP" or test_run["result"] == "NOT_SUPPORTED":
borlanic 0:380207fcb5c1 339 skips.append(test_run)
borlanic 0:380207fcb5c1 340 elif test_run["result"] == "OK":
borlanic 0:380207fcb5c1 341 successes.append(test_run)
borlanic 0:380207fcb5c1 342 else:
borlanic 0:380207fcb5c1 343 raise Exception("Unhandled result type: %s" % (test_run["result"]))
borlanic 0:380207fcb5c1 344 else:
borlanic 0:380207fcb5c1 345 raise Exception("'test_run' did not have a 'result' value")
borlanic 0:380207fcb5c1 346
borlanic 0:380207fcb5c1 347 if successes:
borlanic 0:380207fcb5c1 348 print("\n\nBuild successes:")
borlanic 0:380207fcb5c1 349 self.exporter_print_helper(successes)
borlanic 0:380207fcb5c1 350
borlanic 0:380207fcb5c1 351 if skips:
borlanic 0:380207fcb5c1 352 print("\n\nBuild skips:")
borlanic 0:380207fcb5c1 353 self.exporter_print_helper(skips)
borlanic 0:380207fcb5c1 354
borlanic 0:380207fcb5c1 355 if failures:
borlanic 0:380207fcb5c1 356 print("\n\nBuild failures:")
borlanic 0:380207fcb5c1 357 self.exporter_print_helper(failures, print_log=print_log_for_failures)
borlanic 0:380207fcb5c1 358 return False
borlanic 0:380207fcb5c1 359 else:
borlanic 0:380207fcb5c1 360 return True
borlanic 0:380207fcb5c1 361
borlanic 0:380207fcb5c1 362 def exporter_text(self, test_result_ext):
borlanic 0:380207fcb5c1 363 """ Prints well-formed summary with results (SQL table like)
borlanic 0:380207fcb5c1 364 table shows target x test results matrix across
borlanic 0:380207fcb5c1 365 """
borlanic 0:380207fcb5c1 366 success_code = 0 # Success code that can be leter returned to
borlanic 0:380207fcb5c1 367 # Pretty table package is used to print results
borlanic 0:380207fcb5c1 368 pt = PrettyTable(["Result", "Target", "Toolchain", "Test ID", "Test Description",
borlanic 0:380207fcb5c1 369 "Elapsed Time", "Timeout"])
borlanic 0:380207fcb5c1 370 pt.align["Result"] = "l" # Left align
borlanic 0:380207fcb5c1 371 pt.align["Target"] = "l" # Left align
borlanic 0:380207fcb5c1 372 pt.align["Toolchain"] = "l" # Left align
borlanic 0:380207fcb5c1 373 pt.align["Test ID"] = "l" # Left align
borlanic 0:380207fcb5c1 374 pt.align["Test Description"] = "l" # Left align
borlanic 0:380207fcb5c1 375 pt.padding_width = 1 # One space between column edges and contents (default)
borlanic 0:380207fcb5c1 376
borlanic 0:380207fcb5c1 377 result_dict = {"OK" : 0,
borlanic 0:380207fcb5c1 378 "FAIL" : 0,
borlanic 0:380207fcb5c1 379 "ERROR" : 0,
borlanic 0:380207fcb5c1 380 "UNDEF" : 0,
borlanic 0:380207fcb5c1 381 "IOERR_COPY" : 0,
borlanic 0:380207fcb5c1 382 "IOERR_DISK" : 0,
borlanic 0:380207fcb5c1 383 "IOERR_SERIAL" : 0,
borlanic 0:380207fcb5c1 384 "TIMEOUT" : 0,
borlanic 0:380207fcb5c1 385 "NO_IMAGE" : 0,
borlanic 0:380207fcb5c1 386 "MBED_ASSERT" : 0,
borlanic 0:380207fcb5c1 387 "BUILD_FAILED" : 0,
borlanic 0:380207fcb5c1 388 "NOT_SUPPORTED" : 0
borlanic 0:380207fcb5c1 389 }
borlanic 0:380207fcb5c1 390 unique_test_ids = self.get_all_unique_test_ids(test_result_ext)
borlanic 0:380207fcb5c1 391 targets = sorted(test_result_ext.keys())
borlanic 0:380207fcb5c1 392 for target in targets:
borlanic 0:380207fcb5c1 393 toolchains = sorted(test_result_ext[target].keys())
borlanic 0:380207fcb5c1 394 for toolchain in toolchains:
borlanic 0:380207fcb5c1 395 test_cases = []
borlanic 0:380207fcb5c1 396 tests = sorted(test_result_ext[target][toolchain].keys())
borlanic 0:380207fcb5c1 397 for test in tests:
borlanic 0:380207fcb5c1 398 test_results = test_result_ext[target][toolchain][test]
borlanic 0:380207fcb5c1 399 for test_res in test_results:
borlanic 0:380207fcb5c1 400 test_ids = sorted(test_res.keys())
borlanic 0:380207fcb5c1 401 for test_no in test_ids:
borlanic 0:380207fcb5c1 402 test_result = test_res[test_no]
borlanic 0:380207fcb5c1 403 result_dict[test_result['result']] += 1
borlanic 0:380207fcb5c1 404 pt.add_row([test_result['result'],
borlanic 0:380207fcb5c1 405 test_result['target_name'],
borlanic 0:380207fcb5c1 406 test_result['toolchain_name'],
borlanic 0:380207fcb5c1 407 test_result['id'],
borlanic 0:380207fcb5c1 408 test_result['description'],
borlanic 0:380207fcb5c1 409 test_result['elapsed_time'],
borlanic 0:380207fcb5c1 410 test_result['duration']])
borlanic 0:380207fcb5c1 411 result = pt.get_string()
borlanic 0:380207fcb5c1 412 result += "\n"
borlanic 0:380207fcb5c1 413
borlanic 0:380207fcb5c1 414 # Print result count
borlanic 0:380207fcb5c1 415 result += "Result: " + ' / '.join(['%s %s' % (value, key) for (key, value) in {k: v for k, v in result_dict.items() if v != 0}.items()])
borlanic 0:380207fcb5c1 416 return result