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