Skip to content

Adds a simple text file report format #1873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/singletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def get_version():
_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,
Expand Down
10 changes: 10 additions & 0 deletions tools/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __init__(self,
_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={},
Expand Down Expand Up @@ -224,6 +225,7 @@ def __init__(self,
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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
60 changes: 60 additions & 0 deletions tools/test_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
"""

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')


Expand Down Expand Up @@ -88,6 +90,8 @@ def report(self, test_summary_ext, test_suite_properties=None,
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):
Expand Down Expand Up @@ -351,3 +355,59 @@ def exporter_print(self, test_result_ext, print_log_for_failures=False):
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", "Timeout"])
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