Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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