nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nitsshukla
Date:
Fri Nov 04 12:06:04 2016 +0000
Revision:
7:3a65ef12ba31
Parent:
1:55a6170b404f
kghj;

Who changed what in which revision?

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