From 6906b97ba01322105435655d7ac1c0ffcb38ff8d Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Tue, 21 Jun 2016 16:20:19 -0500 Subject: [PATCH] Adds a simple text file report format Should resolve #1583 --- tools/singletest.py | 1 + tools/test_api.py | 10 +++++++ tools/test_exporters.py | 60 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/tools/singletest.py b/tools/singletest.py index 058b96d4d1..4142878b0b 100644 --- a/tools/singletest.py +++ b/tools/singletest.py @@ -230,6 +230,7 @@ if __name__ == '__main__': _opts_report_html_file_name=opts.report_html_file_name, _opts_report_junit_file_name=opts.report_junit_file_name, _opts_report_build_file_name=opts.report_build_file_name, + _opts_report_text_file_name=opts.report_text_file_name, _test_spec=test_spec, _opts_goanna_for_mbed_sdk=opts.goanna_for_mbed_sdk, _opts_goanna_for_tests=opts.goanna_for_tests, diff --git a/tools/test_api.py b/tools/test_api.py index 745bce563f..2fec9b3108 100644 --- a/tools/test_api.py +++ b/tools/test_api.py @@ -166,6 +166,7 @@ class SingleTestRunner(object): _opts_report_html_file_name=None, _opts_report_junit_file_name=None, _opts_report_build_file_name=None, + _opts_report_text_file_name=None, _opts_build_report={}, _opts_build_properties={}, _test_spec={}, @@ -224,6 +225,7 @@ class SingleTestRunner(object): self.opts_report_html_file_name = _opts_report_html_file_name self.opts_report_junit_file_name = _opts_report_junit_file_name self.opts_report_build_file_name = _opts_report_build_file_name + self.opts_report_text_file_name = _opts_report_text_file_name self.opts_goanna_for_mbed_sdk = _opts_goanna_for_mbed_sdk self.opts_goanna_for_tests = _opts_goanna_for_tests self.opts_shuffle_test_order = _opts_shuffle_test_order @@ -1513,6 +1515,10 @@ def singletest_in_cli_mode(single_test): # Export results in form of JUnit XML report to separate file report_exporter = ReportExporter(ResultExporterType.JUNIT) report_exporter.report_to_file(test_summary_ext, single_test.opts_report_junit_file_name, test_suite_properties=test_suite_properties_ext) + if single_test.opts_report_text_file_name: + # Export results in form of a text file + report_exporter = ReportExporter(ResultExporterType.TEXT) + report_exporter.report_to_file(test_summary_ext, single_test.opts_report_text_file_name, test_suite_properties=test_suite_properties_ext) if single_test.opts_report_build_file_name: # Export build results as html report to sparate file report_exporter = ReportExporter(ResultExporterType.JUNIT, package="build") @@ -1926,6 +1932,10 @@ def get_default_test_options_parser(): dest="report_build_file_name", help="Output the build results to a junit xml file") + parser.add_option("", "--report-text", + dest="report_text_file_name", + help="Output the build results to a text file") + parser.add_option('', '--verbose-skipped', dest='verbose_skipped_tests', default=False, diff --git a/tools/test_exporters.py b/tools/test_exporters.py index 6a5aba466e..40a24544e2 100644 --- a/tools/test_exporters.py +++ b/tools/test_exporters.py @@ -18,12 +18,14 @@ Author: Przemyslaw Wirkus """ from tools.utils import construct_enum, mkdir +from prettytable import PrettyTable import os ResultExporterType = construct_enum(HTML='Html_Exporter', JUNIT='JUnit_Exporter', JUNIT_OPER='JUnit_Exporter_Interoperability', BUILD='Build_Exporter', + TEXT='Text_Exporter', PRINT='Print_Exporter') @@ -88,6 +90,8 @@ class ReportExporter(): elif self.result_exporter_type == ResultExporterType.PRINT: # JUNIT exporter for interoperability test return self.exporter_print(test_summary_ext, print_log_for_failures=print_log_for_failures) + elif self.result_exporter_type == ResultExporterType.TEXT: + return self.exporter_text(test_summary_ext) return None def report_to_file(self, test_summary_ext, file_name, test_suite_properties=None): @@ -351,3 +355,59 @@ class ReportExporter(): return False else: return True + + def exporter_text(self, test_result_ext): + """ Prints well-formed summary with results (SQL table like) + table shows target x test results matrix across + """ + success_code = 0 # Success code that can be leter returned to + # Pretty table package is used to print results + pt = PrettyTable(["Result", "Target", "Toolchain", "Test ID", "Test Description", + "Elapsed Time (sec)", "Timeout (sec)"]) + pt.align["Result"] = "l" # Left align + pt.align["Target"] = "l" # Left align + pt.align["Toolchain"] = "l" # Left align + pt.align["Test ID"] = "l" # Left align + pt.align["Test Description"] = "l" # Left align + pt.padding_width = 1 # One space between column edges and contents (default) + + result_dict = {"OK" : 0, + "FAIL" : 0, + "ERROR" : 0, + "UNDEF" : 0, + "IOERR_COPY" : 0, + "IOERR_DISK" : 0, + "IOERR_SERIAL" : 0, + "TIMEOUT" : 0, + "NO_IMAGE" : 0, + "MBED_ASSERT" : 0, + "BUILD_FAILED" : 0, + "NOT_SUPPORTED" : 0 + } + unique_test_ids = self.get_all_unique_test_ids(test_result_ext) + targets = sorted(test_result_ext.keys()) + for target in targets: + toolchains = sorted(test_result_ext[target].keys()) + for toolchain in toolchains: + test_cases = [] + tests = sorted(test_result_ext[target][toolchain].keys()) + for test in tests: + test_results = test_result_ext[target][toolchain][test] + for test_res in test_results: + test_ids = sorted(test_res.keys()) + for test_no in test_ids: + test_result = test_res[test_no] + result_dict[test_result['result']] += 1 + pt.add_row([test_result['result'], + test_result['target_name'], + test_result['toolchain_name'], + test_result['id'], + test_result['description'], + test_result['elapsed_time'], + test_result['duration']]) + result = pt.get_string() + result += "\n" + + # Print result count + result += "Result: " + ' / '.join(['%s %s' % (value, key) for (key, value) in {k: v for k, v in result_dict.items() if v != 0}.iteritems()]) + return result