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