Skip to content

Commit 458b46c

Browse files
authored
Merge pull request #1873 from theotherjimmy/file-reporter
Adds a simple text file report format
2 parents 36ff1f7 + 65517d6 commit 458b46c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

tools/singletest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def get_version():
230230
_opts_report_html_file_name=opts.report_html_file_name,
231231
_opts_report_junit_file_name=opts.report_junit_file_name,
232232
_opts_report_build_file_name=opts.report_build_file_name,
233+
_opts_report_text_file_name=opts.report_text_file_name,
233234
_test_spec=test_spec,
234235
_opts_goanna_for_mbed_sdk=opts.goanna_for_mbed_sdk,
235236
_opts_goanna_for_tests=opts.goanna_for_tests,

tools/test_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def __init__(self,
166166
_opts_report_html_file_name=None,
167167
_opts_report_junit_file_name=None,
168168
_opts_report_build_file_name=None,
169+
_opts_report_text_file_name=None,
169170
_opts_build_report={},
170171
_opts_build_properties={},
171172
_test_spec={},
@@ -224,6 +225,7 @@ def __init__(self,
224225
self.opts_report_html_file_name = _opts_report_html_file_name
225226
self.opts_report_junit_file_name = _opts_report_junit_file_name
226227
self.opts_report_build_file_name = _opts_report_build_file_name
228+
self.opts_report_text_file_name = _opts_report_text_file_name
227229
self.opts_goanna_for_mbed_sdk = _opts_goanna_for_mbed_sdk
228230
self.opts_goanna_for_tests = _opts_goanna_for_tests
229231
self.opts_shuffle_test_order = _opts_shuffle_test_order
@@ -1513,6 +1515,10 @@ def singletest_in_cli_mode(single_test):
15131515
# Export results in form of JUnit XML report to separate file
15141516
report_exporter = ReportExporter(ResultExporterType.JUNIT)
15151517
report_exporter.report_to_file(test_summary_ext, single_test.opts_report_junit_file_name, test_suite_properties=test_suite_properties_ext)
1518+
if single_test.opts_report_text_file_name:
1519+
# Export results in form of a text file
1520+
report_exporter = ReportExporter(ResultExporterType.TEXT)
1521+
report_exporter.report_to_file(test_summary_ext, single_test.opts_report_text_file_name, test_suite_properties=test_suite_properties_ext)
15161522
if single_test.opts_report_build_file_name:
15171523
# Export build results as html report to sparate file
15181524
report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build")
@@ -1926,6 +1932,10 @@ def get_default_test_options_parser():
19261932
dest="report_build_file_name",
19271933
help="Output the build results to a junit xml file")
19281934

1935+
parser.add_option("", "--report-text",
1936+
dest="report_text_file_name",
1937+
help="Output the build results to a text file")
1938+
19291939
parser.add_option('', '--verbose-skipped',
19301940
dest='verbose_skipped_tests',
19311941
default=False,

tools/test_exporters.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
"""
1919

2020
from tools.utils import construct_enum, mkdir
21+
from prettytable import PrettyTable
2122
import os
2223

2324
ResultExporterType = construct_enum(HTML='Html_Exporter',
2425
JUNIT='JUnit_Exporter',
2526
JUNIT_OPER='JUnit_Exporter_Interoperability',
2627
BUILD='Build_Exporter',
28+
TEXT='Text_Exporter',
2729
PRINT='Print_Exporter')
2830

2931

@@ -88,6 +90,8 @@ def report(self, test_summary_ext, test_suite_properties=None,
8890
elif self.result_exporter_type == ResultExporterType.PRINT:
8991
# JUNIT exporter for interoperability test
9092
return self.exporter_print(test_summary_ext, print_log_for_failures=print_log_for_failures)
93+
elif self.result_exporter_type == ResultExporterType.TEXT:
94+
return self.exporter_text(test_summary_ext)
9195
return None
9296

9397
def report_to_file(self, test_summary_ext, file_name, test_suite_properties=None):
@@ -352,3 +356,59 @@ def exporter_print(self, test_result_ext, print_log_for_failures=False):
352356
return False
353357
else:
354358
return True
359+
360+
def exporter_text(self, test_result_ext):
361+
""" Prints well-formed summary with results (SQL table like)
362+
table shows target x test results matrix across
363+
"""
364+
success_code = 0 # Success code that can be leter returned to
365+
# Pretty table package is used to print results
366+
pt = PrettyTable(["Result", "Target", "Toolchain", "Test ID", "Test Description",
367+
"Elapsed Time", "Timeout"])
368+
pt.align["Result"] = "l" # Left align
369+
pt.align["Target"] = "l" # Left align
370+
pt.align["Toolchain"] = "l" # Left align
371+
pt.align["Test ID"] = "l" # Left align
372+
pt.align["Test Description"] = "l" # Left align
373+
pt.padding_width = 1 # One space between column edges and contents (default)
374+
375+
result_dict = {"OK" : 0,
376+
"FAIL" : 0,
377+
"ERROR" : 0,
378+
"UNDEF" : 0,
379+
"IOERR_COPY" : 0,
380+
"IOERR_DISK" : 0,
381+
"IOERR_SERIAL" : 0,
382+
"TIMEOUT" : 0,
383+
"NO_IMAGE" : 0,
384+
"MBED_ASSERT" : 0,
385+
"BUILD_FAILED" : 0,
386+
"NOT_SUPPORTED" : 0
387+
}
388+
unique_test_ids = self.get_all_unique_test_ids(test_result_ext)
389+
targets = sorted(test_result_ext.keys())
390+
for target in targets:
391+
toolchains = sorted(test_result_ext[target].keys())
392+
for toolchain in toolchains:
393+
test_cases = []
394+
tests = sorted(test_result_ext[target][toolchain].keys())
395+
for test in tests:
396+
test_results = test_result_ext[target][toolchain][test]
397+
for test_res in test_results:
398+
test_ids = sorted(test_res.keys())
399+
for test_no in test_ids:
400+
test_result = test_res[test_no]
401+
result_dict[test_result['result']] += 1
402+
pt.add_row([test_result['result'],
403+
test_result['target_name'],
404+
test_result['toolchain_name'],
405+
test_result['id'],
406+
test_result['description'],
407+
test_result['elapsed_time'],
408+
test_result['duration']])
409+
result = pt.get_string()
410+
result += "\n"
411+
412+
# Print result count
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()])
414+
return result

0 commit comments

Comments
 (0)