[Lldb-commits] [lldb] 9199457 - [LLDB/test] Simplify result formatter code
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Jul 20 05:57:33 PDT 2020
Author: Pavel Labath
Date: 2020-07-20T14:56:49+02:00
New Revision: 9199457bfb5a77121a950df5417fadbf8174cdde
URL: https://github.com/llvm/llvm-project/commit/9199457bfb5a77121a950df5417fadbf8174cdde
DIFF: https://github.com/llvm/llvm-project/commit/9199457bfb5a77121a950df5417fadbf8174cdde.diff
LOG: [LLDB/test] Simplify result formatter code
Now that the main test results are reported through lit, and we only
have one formatter class, this code is unnecessarily baroque.
Added:
Modified:
lldb/packages/Python/lldbsuite/test/dotest.py
lldb/packages/Python/lldbsuite/test_event/formatter/__init__.py
lldb/packages/Python/lldbsuite/test_event/formatter/results_formatter.py
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 67f227cad715..3989ce1bc4d5 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -47,6 +47,7 @@
from lldbsuite.test_event import formatter
from . import test_result
from lldbsuite.test_event.event_builder import EventBuilder
+from lldbsuite.test_event.formatter.results_formatter import ResultsFormatter
from ..support import seven
@@ -453,27 +454,6 @@ def parseOptionsAndInitTestdirs():
lldbtest_config.codesign_identity = args.codesign_identity
-
-def setupTestResults():
- """Sets up test results-related objects based on arg settings."""
-
- # Create the results formatter.
- formatter_spec = formatter.create_results_formatter(
- "lldbsuite.test_event.formatter.results_formatter.ResultsFormatter")
- if formatter_spec is not None and formatter_spec.formatter is not None:
- configuration.results_formatter_object = formatter_spec.formatter
-
- # Send an initialize message to the formatter.
- initialize_event = EventBuilder.bare_event("initialize")
- initialize_event["worker_count"] = 1
-
- formatter_spec.formatter.handle_event(initialize_event)
-
- # Make sure we clean up the formatter on shutdown.
- if formatter_spec.cleanup_func is not None:
- atexit.register(formatter_spec.cleanup_func)
-
-
def setupSysPath():
"""
Add LLDB.framework/Resources/Python to the search paths for modules.
@@ -933,8 +913,7 @@ def run_suite():
#
parseOptionsAndInitTestdirs()
- # Setup test results (test results formatter and output handling).
- setupTestResults()
+ configuration.results_formatter_object = ResultsFormatter(sys.stdout)
setupSysPath()
diff --git a/lldb/packages/Python/lldbsuite/test_event/formatter/__init__.py b/lldb/packages/Python/lldbsuite/test_event/formatter/__init__.py
index d6609d353c85..a1feb389321d 100644
--- a/lldb/packages/Python/lldbsuite/test_event/formatter/__init__.py
+++ b/lldb/packages/Python/lldbsuite/test_event/formatter/__init__.py
@@ -4,63 +4,3 @@
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
-from __future__ import print_function
-from __future__ import absolute_import
-
-# System modules
-import importlib
-import socket
-import sys
-
-# Third-party modules
-
-# LLDB modules
-
-
-# Ignore method count on DTOs.
-# pylint: disable=too-few-public-methods
-class CreatedFormatter(object):
- """Provides transfer object for returns from create_results_formatter()."""
-
- def __init__(self, formatter, cleanup_func):
- self.formatter = formatter
- self.cleanup_func = cleanup_func
-
-
-def create_results_formatter(formatter_name):
- """Sets up a test results formatter.
-
- @param config an instance of FormatterConfig
- that indicates how to setup the ResultsFormatter.
-
- @return an instance of CreatedFormatter.
- """
-
- # Create an instance of the class.
- # First figure out the package/module.
- components = formatter_name.split(".")
- module = importlib.import_module(".".join(components[:-1]))
-
- # Create the class name we need to load.
- cls = getattr(module, components[-1])
-
- # Handle formatter options for the results formatter class.
- formatter_arg_parser = cls.arg_parser()
- command_line_options = []
-
- formatter_options = formatter_arg_parser.parse_args(
- command_line_options)
-
- # Create the TestResultsFormatter given the processed options.
- results_formatter_object = cls(sys.stdout, formatter_options)
-
- def shutdown_formatter():
- """Shuts down the formatter when it is no longer needed."""
- # Tell the formatter to write out anything it may have
- # been saving until the very end (e.g. xUnit results
- # can't complete its output until this point).
- results_formatter_object.send_terminate_as_needed()
-
- return CreatedFormatter(
- results_formatter_object,
- shutdown_formatter)
diff --git a/lldb/packages/Python/lldbsuite/test_event/formatter/results_formatter.py b/lldb/packages/Python/lldbsuite/test_event/formatter/results_formatter.py
index 140a31928740..5032df6451c2 100644
--- a/lldb/packages/Python/lldbsuite/test_event/formatter/results_formatter.py
+++ b/lldb/packages/Python/lldbsuite/test_event/formatter/results_formatter.py
@@ -44,18 +44,10 @@ class ResultsFormatter(object):
ResultFormatter lifetime looks like the following:
# The result formatter is created.
- # The argparse options dictionary is generated from calling
- # the SomeResultFormatter.arg_parser() with the options data
- # passed to dotest.py via the "--results-formatter-options"
- # argument. See the help on that for syntactic requirements
- # on getting that parsed correctly.
- formatter = SomeResultFormatter(file_like_object, argparse_options_dict)
# Single call to session start, before parsing any events.
formatter.begin_session()
- formatter.handle_event({"event":"initialize",...})
-
# Zero or more calls specified for events recorded during the test session.
# The parallel test runner manages getting results from all the inferior
# dotest processes, so from a new format perspective, don't worry about
@@ -76,10 +68,6 @@ class ResultsFormatter(object):
The lldb test framework passes these test events in real time, so they
arrive as they come in.
- In the case of the parallel test runner, the dotest inferiors
- add a 'pid' field to the dictionary that indicates which inferior
- pid generated the event.
-
Note more events may be added in the future to support richer test
reporting functionality. One example: creating a true flaky test
result category so that unexpected successes really mean the test
@@ -100,29 +88,13 @@ class ResultsFormatter(object):
expectations about when the call should be chained.
"""
- @classmethod
- def arg_parser(cls):
- """@return arg parser used to parse formatter-specific options."""
- parser = argparse.ArgumentParser(
- description='{} options'.format(cls.__name__),
- usage=('dotest.py --results-formatter-options='
- '"--option1 value1 [--option2 value2 [...]]"'))
- parser.add_argument(
- "--dump-results",
- action="store_true",
- help=('dump the raw results data after printing '
- 'the summary output.'))
- return parser
-
- def __init__(self, out_file, options):
+ def __init__(self, out_file):
super(ResultsFormatter, self).__init__()
self.out_file = out_file
- self.options = options
self.using_terminal = False
if not self.out_file:
raise Exception("ResultsFormatter created with no file object")
self.start_time_by_test = {}
- self.terminate_called = False
# Track the most recent test start event by worker index.
# We'll use this to assign TIMEOUT and exceptional
@@ -341,9 +313,7 @@ def handle_event(self, test_event):
self._maybe_remap_expected_failure(test_event)
event_type = test_event.get("event", "")
- if event_type == "terminate":
- self.terminate_called = True
- elif event_type in EventBuilder.RESULT_TYPES:
+ if event_type in EventBuilder.RESULT_TYPES:
# Clear the most recently started test for the related
# worker.
worker_index = test_event.get("worker_index", None)
@@ -440,12 +410,6 @@ def is_using_terminal(self):
output should be avoided."""
return self.using_terminal
- def send_terminate_as_needed(self):
- """sends the terminate event if it hasn't been received yet."""
- if not self.terminate_called:
- terminate_event = EventBuilder.bare_event("terminate")
- self.handle_event(terminate_event)
-
# Derived classes may require self access
# pylint: disable=no-self-use
# noinspection PyMethodMayBeStatic,PyMethodMayBeStatic
@@ -707,15 +671,6 @@ def print_results(self, out_file):
self._print_summary_counts(
out_file, categories, result_events_by_status, extra_results)
- if self.options.dump_results:
- # Debug dump of the key/result info for all categories.
- self._print_banner(out_file, "Results Dump")
- for status, events_by_key in result_events_by_status.items():
- out_file.write("\nSTATUS: {}\n".format(status))
- for key, event in events_by_key:
- out_file.write("key: {}\n".format(key))
- out_file.write("event: {}\n".format(event))
-
def clear_file_level_issues(self, tests_for_rerun, out_file):
"""Clear file-charged issues in any of the test rerun files.
More information about the lldb-commits
mailing list