Clone of official tools

Committer:
screamer
Date:
Sat Jul 16 00:34:03 2016 +0100
Revision:
22:9e85236d8716
Parent:
13:ab47a20b66f0
Sync with the mbedmicro/mbed tools

Who changed what in which revision?

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