Clone of official tools

Committer:
Anders Blomdell
Date:
Thu Feb 04 17:17:13 2021 +0100
Revision:
47:21ae3e5a7128
Parent:
43:2a7da56ebd24
Add a few normpath calls

Who changed what in which revision?

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