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