Index: llvm/utils/lit/lit/reports.py =================================================================== --- llvm/utils/lit/lit/reports.py +++ llvm/utils/lit/lit/reports.py @@ -1,3 +1,4 @@ +import abc import base64 import datetime import itertools @@ -7,17 +8,24 @@ import lit.Test - def by_suite_and_test_path(test): # Suite names are not necessarily unique. Include object identity in sort # key to avoid mixing tests of different suites. return (test.suite.name, id(test.suite), test.path_in_suite) -class JsonReport(object): +class _ReportBase(abc.ABC): def __init__(self, output_file): self.output_file = output_file + self.skipped_codes = {lit.Test.EXCLUDED, + lit.Test.SKIPPED, lit.Test.UNSUPPORTED} + + @abc.abstractmethod + def write_results(self, tests, elapsed): + ... + +class JsonReport(_ReportBase): def write_results(self, tests, elapsed): unexecuted_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED} tests = [t for t in tests if t.result.code not in unexecuted_codes] @@ -84,12 +92,7 @@ return s.translate(_invalid_xml_chars_dict) -class XunitReport(object): - def __init__(self, output_file): - self.output_file = output_file - self.skipped_codes = {lit.Test.EXCLUDED, - lit.Test.SKIPPED, lit.Test.UNSUPPORTED} - +class XunitReport(_ReportBase): def write_results(self, tests, elapsed): tests.sort(key=by_suite_and_test_path) tests_by_suite = itertools.groupby(tests, lambda t: t.suite) @@ -191,10 +194,7 @@ return test_data -class ResultDBReport(object): - def __init__(self, output_file): - self.output_file = output_file - +class ResultDBReport(_ReportBase): def write_results(self, tests, elapsed): unexecuted_codes = {lit.Test.EXCLUDED, lit.Test.SKIPPED} tests = [t for t in tests if t.result.code not in unexecuted_codes] @@ -239,13 +239,10 @@ file.write('\n') -class TimeTraceReport(object): - def __init__(self, output_file): - self.output_file = output_file - self.skipped_codes = {lit.Test.EXCLUDED, - lit.Test.SKIPPED, lit.Test.UNSUPPORTED} - +class TimeTraceReport(_ReportBase): def write_results(self, tests, elapsed): + del elapsed + # Find when first test started so we can make start times relative. first_start_time = min([t.result.start for t in tests]) events = [self._get_test_event(