2015-09-15 21:38:04 +00:00
|
|
|
"""
|
|
|
|
The LLVM Compiler Infrastructure
|
|
|
|
|
|
|
|
This file is distributed under the University of Illinois Open Source
|
|
|
|
License. See LICENSE.TXT for details.
|
|
|
|
|
|
|
|
Provides classes used by the test results reporting infrastructure
|
|
|
|
within the LLDB test suite.
|
|
|
|
"""
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
from __future__ import print_function
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-05 19:22:28 +00:00
|
|
|
from __future__ import absolute_import
|
2015-10-23 17:04:29 +00:00
|
|
|
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-05 19:22:28 +00:00
|
|
|
# System modules
|
2015-09-15 21:38:04 +00:00
|
|
|
import argparse
|
2015-12-08 00:53:56 +00:00
|
|
|
import importlib
|
2015-09-15 21:38:04 +00:00
|
|
|
import inspect
|
|
|
|
import os
|
2015-09-18 21:01:13 +00:00
|
|
|
import pprint
|
2015-12-08 00:53:56 +00:00
|
|
|
import socket
|
2015-09-15 21:38:04 +00:00
|
|
|
import sys
|
|
|
|
import threading
|
|
|
|
import time
|
2015-09-18 07:08:09 +00:00
|
|
|
import traceback
|
2015-09-15 21:38:04 +00:00
|
|
|
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-05 19:22:28 +00:00
|
|
|
# Third-party modules
|
2015-10-23 19:52:36 +00:00
|
|
|
import six
|
2015-10-21 17:48:52 +00:00
|
|
|
from six.moves import cPickle
|
|
|
|
|
Python 3 - Turn on absolute imports, and fix existing imports.
Absolute imports were introduced in Python 2.5 as a feature
(e.g. from __future__ import absolute_import), and made default
in Python 3.
When absolute imports are enabled, the import system changes in
a couple of ways:
1) The `import foo` syntax will *only* search sys.path. If `foo`
isn't in sys.path, it won't be found. Period. Without absolute
imports, the import system will also search the same directory
that the importing file resides in, so that you can easily
import from the same folder.
2) From inside a package, you can use a dot syntax to refer to higher
levels of the current package. For example, if you are in the
package lldbsuite.test.utility, then ..foo refers to
lldbsuite.test.foo. You can use this notation with the
`from X import Y` syntax to write intra-package references. For
example, using the previous locationa s a starting point, writing
`from ..support import seven` would import lldbsuite.support.seven
Since this is now the default behavior in Python 3, this means that
importing from the same directory with `import foo` *no longer works*.
As a result, the only way to have portable code is to force absolute
imports for all versions of Python.
See PEP 0328 [https://www.python.org/dev/peps/pep-0328/] for more
information about absolute and relative imports.
Differential Revision: http://reviews.llvm.org/D14342
Reviewed By: Todd Fiala
llvm-svn: 252191
2015-11-05 19:22:28 +00:00
|
|
|
# LLDB modules
|
2015-12-08 00:53:56 +00:00
|
|
|
|
2015-12-09 06:45:43 +00:00
|
|
|
|
|
|
|
# Ignore method count on DTOs.
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
class FormatterConfig(object):
|
|
|
|
"""Provides formatter configuration info to create_results_formatter()."""
|
|
|
|
def __init__(self):
|
|
|
|
self.filename = None
|
|
|
|
self.port = None
|
|
|
|
self.formatter_name = None
|
|
|
|
self.formatter_options = None
|
|
|
|
|
|
|
|
|
|
|
|
# Ignore method count on DTOs.
|
|
|
|
# pylint: disable=too-few-public-methods
|
2015-12-08 00:53:56 +00:00
|
|
|
class CreatedFormatter(object):
|
2015-12-09 06:45:43 +00:00
|
|
|
"""Provides transfer object for returns from create_results_formatter()."""
|
2015-12-08 00:53:56 +00:00
|
|
|
def __init__(self, formatter, cleanup_func):
|
|
|
|
self.formatter = formatter
|
|
|
|
self.cleanup_func = cleanup_func
|
|
|
|
|
|
|
|
|
2015-12-09 06:45:43 +00:00
|
|
|
def create_results_formatter(config):
|
2015-12-08 00:53:56 +00:00
|
|
|
"""Sets up a test results formatter.
|
|
|
|
|
|
|
|
@param config an instance of FormatterConfig
|
|
|
|
that indicates how to setup the ResultsFormatter.
|
|
|
|
|
|
|
|
@return an instance of CreatedFormatter.
|
|
|
|
"""
|
|
|
|
def create_socket(port):
|
|
|
|
"""Creates a socket to the localhost on the given port.
|
|
|
|
|
|
|
|
@param port the port number of the listenering port on
|
|
|
|
the localhost.
|
|
|
|
|
|
|
|
@return (socket object, socket closing function)
|
|
|
|
"""
|
|
|
|
def socket_closer(open_sock):
|
|
|
|
"""Close down an opened socket properly."""
|
|
|
|
open_sock.shutdown(socket.SHUT_RDWR)
|
|
|
|
open_sock.close()
|
|
|
|
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
sock.connect(("localhost", port))
|
|
|
|
return (sock, lambda: socket_closer(sock))
|
|
|
|
|
|
|
|
default_formatter_name = None
|
|
|
|
results_file_object = None
|
|
|
|
cleanup_func = None
|
|
|
|
|
2015-12-09 06:45:43 +00:00
|
|
|
if config.filename:
|
2015-12-08 00:53:56 +00:00
|
|
|
# Open the results file for writing.
|
2015-12-09 06:45:43 +00:00
|
|
|
if config.filename == 'stdout':
|
2015-12-08 00:53:56 +00:00
|
|
|
results_file_object = sys.stdout
|
|
|
|
cleanup_func = None
|
2015-12-09 06:45:43 +00:00
|
|
|
elif config.filename == 'stderr':
|
2015-12-08 00:53:56 +00:00
|
|
|
results_file_object = sys.stderr
|
|
|
|
cleanup_func = None
|
|
|
|
else:
|
2015-12-09 06:45:43 +00:00
|
|
|
results_file_object = open(config.filename, "w")
|
2015-12-08 00:53:56 +00:00
|
|
|
cleanup_func = results_file_object.close
|
|
|
|
default_formatter_name = (
|
2015-12-09 19:32:14 +00:00
|
|
|
"lldbsuite.test.xunit_formatter.XunitFormatter")
|
2015-12-09 06:45:43 +00:00
|
|
|
elif config.port:
|
2015-12-08 00:53:56 +00:00
|
|
|
# Connect to the specified localhost port.
|
2015-12-09 06:45:43 +00:00
|
|
|
results_file_object, cleanup_func = create_socket(config.port)
|
2015-12-08 00:53:56 +00:00
|
|
|
default_formatter_name = (
|
|
|
|
"lldbsuite.test.result_formatter.RawPickledFormatter")
|
|
|
|
|
|
|
|
# If we have a results formatter name specified and we didn't specify
|
|
|
|
# a results file, we should use stdout.
|
2015-12-09 06:45:43 +00:00
|
|
|
if config.formatter_name is not None and results_file_object is None:
|
2015-12-08 00:53:56 +00:00
|
|
|
# Use stdout.
|
|
|
|
results_file_object = sys.stdout
|
|
|
|
cleanup_func = None
|
|
|
|
|
|
|
|
if results_file_object:
|
|
|
|
# We care about the formatter. Choose user-specified or, if
|
|
|
|
# none specified, use the default for the output type.
|
2015-12-09 06:45:43 +00:00
|
|
|
if config.formatter_name:
|
|
|
|
formatter_name = config.formatter_name
|
2015-12-08 00:53:56 +00:00
|
|
|
else:
|
|
|
|
formatter_name = default_formatter_name
|
|
|
|
|
|
|
|
# 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()
|
2015-12-09 06:45:43 +00:00
|
|
|
if config.formatter_options and len(config.formatter_options) > 0:
|
|
|
|
command_line_options = config.formatter_options
|
2015-12-08 00:53:56 +00:00
|
|
|
else:
|
|
|
|
command_line_options = []
|
|
|
|
|
|
|
|
formatter_options = formatter_arg_parser.parse_args(
|
|
|
|
command_line_options)
|
|
|
|
|
|
|
|
# Create the TestResultsFormatter given the processed options.
|
|
|
|
results_formatter_object = cls(results_file_object, 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()
|
|
|
|
|
|
|
|
# And now close out the output file-like object.
|
|
|
|
if cleanup_func is not None:
|
|
|
|
cleanup_func()
|
|
|
|
|
|
|
|
return CreatedFormatter(
|
|
|
|
results_formatter_object,
|
|
|
|
shutdown_formatter)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2015-09-15 21:38:04 +00:00
|
|
|
class EventBuilder(object):
|
|
|
|
"""Helper class to build test result event dictionaries."""
|
2015-09-18 21:01:13 +00:00
|
|
|
|
|
|
|
BASE_DICTIONARY = None
|
|
|
|
|
2015-12-09 06:45:43 +00:00
|
|
|
# Test Event Types
|
|
|
|
TYPE_JOB_RESULT = "job_result"
|
|
|
|
TYPE_TEST_RESULT = "test_result"
|
|
|
|
TYPE_TEST_START = "test_start"
|
2015-12-11 18:06:47 +00:00
|
|
|
TYPE_MARK_TEST_RERUN_ELIGIBLE = "test_eligible_for_rerun"
|
2015-12-09 06:45:43 +00:00
|
|
|
|
|
|
|
# Test/Job Status Tags
|
|
|
|
STATUS_EXCEPTIONAL_EXIT = "exceptional_exit"
|
2015-12-02 18:48:38 +00:00
|
|
|
STATUS_SUCCESS = "success"
|
|
|
|
STATUS_FAILURE = "failure"
|
|
|
|
STATUS_EXPECTED_FAILURE = "expected_failure"
|
|
|
|
STATUS_UNEXPECTED_SUCCESS = "unexpected_success"
|
|
|
|
STATUS_SKIP = "skip"
|
|
|
|
STATUS_ERROR = "error"
|
2015-12-09 06:45:43 +00:00
|
|
|
STATUS_TIMEOUT = "timeout"
|
2015-12-02 18:48:38 +00:00
|
|
|
|
2015-09-15 21:38:04 +00:00
|
|
|
@staticmethod
|
|
|
|
def _get_test_name_info(test):
|
|
|
|
"""Returns (test-class-name, test-method-name) from a test case instance.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@return tuple containing (test class name, test method name)
|
|
|
|
"""
|
|
|
|
test_class_components = test.id().split(".")
|
|
|
|
test_class_name = ".".join(test_class_components[:-1])
|
|
|
|
test_name = test_class_components[-1]
|
|
|
|
return (test_class_name, test_name)
|
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
@staticmethod
|
|
|
|
def bare_event(event_type):
|
|
|
|
"""Creates an event with default additions, event type and timestamp.
|
|
|
|
|
|
|
|
@param event_type the value set for the "event" key, used
|
|
|
|
to distinguish events.
|
|
|
|
|
|
|
|
@returns an event dictionary with all default additions, the "event"
|
|
|
|
key set to the passed in event_type, and the event_time value set to
|
|
|
|
time.time().
|
|
|
|
"""
|
|
|
|
if EventBuilder.BASE_DICTIONARY is not None:
|
|
|
|
# Start with a copy of the "always include" entries.
|
|
|
|
event = dict(EventBuilder.BASE_DICTIONARY)
|
|
|
|
else:
|
|
|
|
event = {}
|
|
|
|
|
|
|
|
event.update({
|
|
|
|
"event": event_type,
|
|
|
|
"event_time": time.time()
|
|
|
|
})
|
|
|
|
return event
|
|
|
|
|
2015-09-15 21:38:04 +00:00
|
|
|
@staticmethod
|
|
|
|
def _event_dictionary_common(test, event_type):
|
|
|
|
"""Returns an event dictionary setup with values for the given event type.
|
|
|
|
|
|
|
|
@param test the unittest.TestCase instance
|
|
|
|
|
|
|
|
@param event_type the name of the event type (string).
|
|
|
|
|
|
|
|
@return event dictionary with common event fields set.
|
|
|
|
"""
|
|
|
|
test_class_name, test_name = EventBuilder._get_test_name_info(test)
|
2015-09-18 21:01:13 +00:00
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
event = EventBuilder.bare_event(event_type)
|
|
|
|
event.update({
|
2015-09-15 21:38:04 +00:00
|
|
|
"test_class": test_class_name,
|
|
|
|
"test_name": test_name,
|
2015-09-18 22:57:04 +00:00
|
|
|
"test_filename": inspect.getfile(test.__class__)
|
2015-09-18 21:01:13 +00:00
|
|
|
})
|
2015-12-11 18:06:47 +00:00
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
return event
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _error_tuple_class(error_tuple):
|
|
|
|
"""Returns the unittest error tuple's error class as a string.
|
|
|
|
|
|
|
|
@param error_tuple the error tuple provided by the test framework.
|
|
|
|
|
|
|
|
@return the error type (typically an exception) raised by the
|
|
|
|
test framework.
|
|
|
|
"""
|
|
|
|
type_var = error_tuple[0]
|
|
|
|
module = inspect.getmodule(type_var)
|
|
|
|
if module:
|
|
|
|
return "{}.{}".format(module.__name__, type_var.__name__)
|
|
|
|
else:
|
|
|
|
return type_var.__name__
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _error_tuple_message(error_tuple):
|
|
|
|
"""Returns the unittest error tuple's error message.
|
|
|
|
|
|
|
|
@param error_tuple the error tuple provided by the test framework.
|
|
|
|
|
|
|
|
@return the error message provided by the test framework.
|
|
|
|
"""
|
|
|
|
return str(error_tuple[1])
|
|
|
|
|
2015-09-18 07:08:09 +00:00
|
|
|
@staticmethod
|
|
|
|
def _error_tuple_traceback(error_tuple):
|
|
|
|
"""Returns the unittest error tuple's error message.
|
|
|
|
|
|
|
|
@param error_tuple the error tuple provided by the test framework.
|
|
|
|
|
|
|
|
@return the error message provided by the test framework.
|
|
|
|
"""
|
|
|
|
return error_tuple[2]
|
|
|
|
|
2015-09-15 21:38:04 +00:00
|
|
|
@staticmethod
|
|
|
|
def _event_dictionary_test_result(test, status):
|
|
|
|
"""Returns an event dictionary with common test result fields set.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@param status the status/result of the test
|
|
|
|
(e.g. "success", "failure", etc.)
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
"""
|
2015-12-09 06:45:43 +00:00
|
|
|
event = EventBuilder._event_dictionary_common(
|
|
|
|
test, EventBuilder.TYPE_TEST_RESULT)
|
2015-09-15 21:38:04 +00:00
|
|
|
event["status"] = status
|
|
|
|
return event
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _event_dictionary_issue(test, status, error_tuple):
|
|
|
|
"""Returns an event dictionary with common issue-containing test result
|
|
|
|
fields set.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@param status the status/result of the test
|
|
|
|
(e.g. "success", "failure", etc.)
|
|
|
|
|
|
|
|
@param error_tuple the error tuple as reported by the test runner.
|
|
|
|
This is of the form (type<error>, error).
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
"""
|
|
|
|
event = EventBuilder._event_dictionary_test_result(test, status)
|
|
|
|
event["issue_class"] = EventBuilder._error_tuple_class(error_tuple)
|
|
|
|
event["issue_message"] = EventBuilder._error_tuple_message(error_tuple)
|
2015-09-18 21:01:13 +00:00
|
|
|
backtrace = EventBuilder._error_tuple_traceback(error_tuple)
|
|
|
|
if backtrace is not None:
|
|
|
|
event["issue_backtrace"] = traceback.format_tb(backtrace)
|
2015-09-15 21:38:04 +00:00
|
|
|
return event
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_start(test):
|
|
|
|
"""Returns an event dictionary for the test start event.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
"""
|
2015-12-09 06:45:43 +00:00
|
|
|
return EventBuilder._event_dictionary_common(
|
|
|
|
test, EventBuilder.TYPE_TEST_START)
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_success(test):
|
|
|
|
"""Returns an event dictionary for a successful test.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
"""
|
2015-12-02 18:48:38 +00:00
|
|
|
return EventBuilder._event_dictionary_test_result(
|
|
|
|
test, EventBuilder.STATUS_SUCCESS)
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_unexpected_success(test, bugnumber):
|
|
|
|
"""Returns an event dictionary for a test that succeeded but was
|
|
|
|
expected to fail.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@param bugnumber the issue identifier for the bug tracking the
|
|
|
|
fix request for the test expected to fail (but is in fact
|
|
|
|
passing here).
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
|
|
|
|
"""
|
|
|
|
event = EventBuilder._event_dictionary_test_result(
|
2015-12-02 18:48:38 +00:00
|
|
|
test, EventBuilder.STATUS_UNEXPECTED_SUCCESS)
|
2015-09-15 21:38:04 +00:00
|
|
|
if bugnumber:
|
|
|
|
event["bugnumber"] = str(bugnumber)
|
|
|
|
return event
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_failure(test, error_tuple):
|
|
|
|
"""Returns an event dictionary for a test that failed.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@param error_tuple the error tuple as reported by the test runner.
|
|
|
|
This is of the form (type<error>, error).
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
"""
|
|
|
|
return EventBuilder._event_dictionary_issue(
|
2015-12-02 18:48:38 +00:00
|
|
|
test, EventBuilder.STATUS_FAILURE, error_tuple)
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_expected_failure(test, error_tuple, bugnumber):
|
|
|
|
"""Returns an event dictionary for a test that failed as expected.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@param error_tuple the error tuple as reported by the test runner.
|
|
|
|
This is of the form (type<error>, error).
|
|
|
|
|
|
|
|
@param bugnumber the issue identifier for the bug tracking the
|
|
|
|
fix request for the test expected to fail.
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
|
|
|
|
"""
|
|
|
|
event = EventBuilder._event_dictionary_issue(
|
2015-12-02 18:48:38 +00:00
|
|
|
test, EventBuilder.STATUS_EXPECTED_FAILURE, error_tuple)
|
2015-09-15 21:38:04 +00:00
|
|
|
if bugnumber:
|
|
|
|
event["bugnumber"] = str(bugnumber)
|
|
|
|
return event
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_skip(test, reason):
|
|
|
|
"""Returns an event dictionary for a test that was skipped.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@param reason the reason why the test is being skipped.
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
"""
|
2015-12-02 18:48:38 +00:00
|
|
|
event = EventBuilder._event_dictionary_test_result(
|
|
|
|
test, EventBuilder.STATUS_SKIP)
|
2015-09-15 21:38:04 +00:00
|
|
|
event["skip_reason"] = reason
|
|
|
|
return event
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_error(test, error_tuple):
|
|
|
|
"""Returns an event dictionary for a test that hit a test execution error.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@param error_tuple the error tuple as reported by the test runner.
|
|
|
|
This is of the form (type<error>, error).
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
"""
|
2015-12-02 18:48:38 +00:00
|
|
|
return EventBuilder._event_dictionary_issue(
|
|
|
|
test, EventBuilder.STATUS_ERROR, error_tuple)
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_cleanup_error(test, error_tuple):
|
|
|
|
"""Returns an event dictionary for a test that hit a test execution error
|
|
|
|
during the test cleanup phase.
|
|
|
|
|
|
|
|
@param test a unittest.TestCase instance.
|
|
|
|
|
|
|
|
@param error_tuple the error tuple as reported by the test runner.
|
|
|
|
This is of the form (type<error>, error).
|
|
|
|
|
|
|
|
@return the event dictionary
|
|
|
|
"""
|
|
|
|
event = EventBuilder._event_dictionary_issue(
|
2015-12-02 18:48:38 +00:00
|
|
|
test, EventBuilder.STATUS_ERROR, error_tuple)
|
2015-09-15 21:38:04 +00:00
|
|
|
event["issue_phase"] = "cleanup"
|
|
|
|
return event
|
|
|
|
|
2015-12-09 06:45:43 +00:00
|
|
|
@staticmethod
|
|
|
|
def event_for_job_exceptional_exit(
|
|
|
|
pid, worker_index, exception_code, exception_description,
|
|
|
|
test_filename, command_line):
|
|
|
|
"""Creates an event for a job (i.e. process) exit due to signal.
|
|
|
|
|
|
|
|
@param pid the process id for the job that failed
|
|
|
|
@param worker_index optional id for the job queue running the process
|
|
|
|
@param exception_code optional code
|
|
|
|
(e.g. SIGTERM integer signal number)
|
|
|
|
@param exception_description optional string containing symbolic
|
|
|
|
representation of the issue (e.g. "SIGTERM")
|
|
|
|
@param test_filename the path to the test filename that exited
|
|
|
|
in some exceptional way.
|
|
|
|
@param command_line the Popen-style list provided as the command line
|
|
|
|
for the process that timed out.
|
|
|
|
|
|
|
|
@return an event dictionary coding the job completion description.
|
|
|
|
"""
|
|
|
|
event = EventBuilder.bare_event(EventBuilder.TYPE_JOB_RESULT)
|
|
|
|
event["status"] = EventBuilder.STATUS_EXCEPTIONAL_EXIT
|
|
|
|
if pid is not None:
|
|
|
|
event["pid"] = pid
|
|
|
|
if worker_index is not None:
|
|
|
|
event["worker_index"] = int(worker_index)
|
|
|
|
if exception_code is not None:
|
|
|
|
event["exception_code"] = exception_code
|
|
|
|
if exception_description is not None:
|
|
|
|
event["exception_description"] = exception_description
|
|
|
|
if test_filename is not None:
|
|
|
|
event["test_filename"] = test_filename
|
|
|
|
if command_line is not None:
|
|
|
|
event["command_line"] = command_line
|
|
|
|
return event
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def event_for_job_timeout(pid, worker_index, test_filename, command_line):
|
|
|
|
"""Creates an event for a job (i.e. process) timeout.
|
|
|
|
|
|
|
|
@param pid the process id for the job that timed out
|
|
|
|
@param worker_index optional id for the job queue running the process
|
|
|
|
@param test_filename the path to the test filename that timed out.
|
|
|
|
@param command_line the Popen-style list provided as the command line
|
|
|
|
for the process that timed out.
|
|
|
|
|
|
|
|
@return an event dictionary coding the job completion description.
|
|
|
|
"""
|
|
|
|
event = EventBuilder.bare_event(EventBuilder.TYPE_JOB_RESULT)
|
|
|
|
event["status"] = "timeout"
|
|
|
|
if pid is not None:
|
|
|
|
event["pid"] = pid
|
|
|
|
if worker_index is not None:
|
|
|
|
event["worker_index"] = int(worker_index)
|
|
|
|
if test_filename is not None:
|
|
|
|
event["test_filename"] = test_filename
|
|
|
|
if command_line is not None:
|
|
|
|
event["command_line"] = command_line
|
|
|
|
return event
|
|
|
|
|
2015-12-11 18:06:47 +00:00
|
|
|
@staticmethod
|
|
|
|
def event_for_mark_test_rerun_eligible(test):
|
|
|
|
"""Creates an event that indicates the specified test is explicitly
|
|
|
|
eligible for rerun.
|
|
|
|
|
|
|
|
Note there is a mode that will enable test rerun eligibility at the
|
|
|
|
global level. These markings for explicit rerun eligibility are
|
|
|
|
intended for the mode of running where only explicitly rerunnable
|
|
|
|
tests are rerun upon hitting an issue.
|
|
|
|
|
|
|
|
@param test the TestCase instance to which this pertains.
|
|
|
|
|
|
|
|
@return an event that specifies the given test as being eligible to
|
|
|
|
be rerun.
|
|
|
|
"""
|
|
|
|
event = EventBuilder._event_dictionary_common(
|
|
|
|
test,
|
|
|
|
EventBuilder.TYPE_MARK_TEST_RERUN_ELIGIBLE)
|
|
|
|
return event
|
|
|
|
|
2015-09-18 21:01:13 +00:00
|
|
|
@staticmethod
|
|
|
|
def add_entries_to_all_events(entries_dict):
|
|
|
|
"""Specifies a dictionary of entries to add to all test events.
|
|
|
|
|
|
|
|
This provides a mechanism for, say, a parallel test runner to
|
|
|
|
indicate to each inferior dotest.py that it should add a
|
|
|
|
worker index to each.
|
|
|
|
|
|
|
|
Calling this method replaces all previous entries added
|
|
|
|
by a prior call to this.
|
|
|
|
|
|
|
|
Event build methods will overwrite any entries that collide.
|
|
|
|
Thus, the passed in dictionary is the base, which gets merged
|
|
|
|
over by event building when keys collide.
|
|
|
|
|
|
|
|
@param entries_dict a dictionary containing key and value
|
|
|
|
pairs that should be merged into all events created by the
|
|
|
|
event generator. May be None to clear out any extra entries.
|
|
|
|
"""
|
|
|
|
EventBuilder.BASE_DICTIONARY = dict(entries_dict)
|
|
|
|
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
class ResultsFormatter(object):
|
|
|
|
"""Provides interface to formatting test results out to a file-like object.
|
|
|
|
|
|
|
|
This class allows the LLDB test framework's raw test-realted
|
|
|
|
events to be processed and formatted in any manner desired.
|
|
|
|
Test events are represented by python dictionaries, formatted
|
|
|
|
as in the EventBuilder class above.
|
|
|
|
|
|
|
|
ResultFormatter instances are given a file-like object in which
|
|
|
|
to write their results.
|
|
|
|
|
|
|
|
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, argpared_options_dict)
|
|
|
|
|
|
|
|
# Single call to session start, before parsing any events.
|
|
|
|
formatter.begin_session()
|
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
formatter.handle_event({"event":"initialize",...})
|
|
|
|
|
2015-09-15 21:38:04 +00:00
|
|
|
# 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
|
|
|
|
# that. The formatter will be presented with a single stream of events
|
|
|
|
# sandwiched between a single begin_session()/end_session() pair in the
|
|
|
|
# parallel test runner process/thread.
|
|
|
|
for event in zero_or_more_test_events():
|
2015-09-18 22:45:31 +00:00
|
|
|
formatter.handle_event(event)
|
2015-09-15 21:38:04 +00:00
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
# Single call to terminate/wrap-up. Formatters that need all the
|
|
|
|
# data before they can print a correct result (e.g. xUnit/JUnit),
|
|
|
|
# this is where the final report can be generated.
|
|
|
|
formatter.handle_event({"event":"terminate",...})
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
It is not the formatter's responsibility to close the file_like_object.
|
|
|
|
(i.e. do not close it).
|
|
|
|
|
|
|
|
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
|
|
|
|
is marked incorrectly (either should be marked flaky, or is indeed
|
|
|
|
passing consistently now and should have the xfail marker
|
|
|
|
removed). In this case, a flaky_success and flaky_fail event
|
|
|
|
likely will be added to capture these and support reporting things
|
|
|
|
like percentages of flaky test passing so we can see if we're
|
|
|
|
making some things worse/better with regards to failure rates.
|
|
|
|
|
|
|
|
Another example: announcing all the test methods that are planned
|
|
|
|
to be run, so we can better support redo operations of various kinds
|
|
|
|
(redo all non-run tests, redo non-run tests except the one that
|
|
|
|
was running [perhaps crashed], etc.)
|
|
|
|
|
|
|
|
Implementers are expected to override all the public methods
|
|
|
|
provided in this class. See each method's docstring to see
|
|
|
|
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 [...]]"'))
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def __init__(self, out_file, options):
|
|
|
|
super(ResultsFormatter, self).__init__()
|
|
|
|
self.out_file = out_file
|
|
|
|
self.options = options
|
2015-09-19 00:39:09 +00:00
|
|
|
self.using_terminal = False
|
2015-09-15 21:38:04 +00:00
|
|
|
if not self.out_file:
|
|
|
|
raise Exception("ResultsFormatter created with no file object")
|
|
|
|
self.start_time_by_test = {}
|
2015-09-22 00:15:50 +00:00
|
|
|
self.terminate_called = False
|
2015-09-15 21:38:04 +00:00
|
|
|
|
2015-12-02 18:48:38 +00:00
|
|
|
# Store counts of test_result events by status.
|
|
|
|
self.result_status_counts = {
|
|
|
|
EventBuilder.STATUS_SUCCESS: 0,
|
|
|
|
EventBuilder.STATUS_EXPECTED_FAILURE: 0,
|
|
|
|
EventBuilder.STATUS_SKIP: 0,
|
|
|
|
EventBuilder.STATUS_UNEXPECTED_SUCCESS: 0,
|
|
|
|
EventBuilder.STATUS_FAILURE: 0,
|
2015-12-09 06:45:43 +00:00
|
|
|
EventBuilder.STATUS_ERROR: 0,
|
|
|
|
EventBuilder.STATUS_TIMEOUT: 0,
|
|
|
|
EventBuilder.STATUS_EXCEPTIONAL_EXIT: 0
|
2015-12-02 18:48:38 +00:00
|
|
|
}
|
|
|
|
|
2015-12-09 06:45:43 +00:00
|
|
|
# Track the most recent test start event by worker index.
|
|
|
|
# We'll use this to assign TIMEOUT and exceptional
|
|
|
|
# exits to the most recent test started on a given
|
|
|
|
# worker index.
|
|
|
|
self.started_tests_by_worker = {}
|
|
|
|
|
2015-09-15 21:38:04 +00:00
|
|
|
# Lock that we use while mutating inner state, like the
|
|
|
|
# total test count and the elements. We minimize how
|
|
|
|
# long we hold the lock just to keep inner state safe, not
|
|
|
|
# entirely consistent from the outside.
|
|
|
|
self.lock = threading.Lock()
|
|
|
|
|
2015-12-09 06:45:43 +00:00
|
|
|
def _maybe_remap_job_result_event(self, test_event):
|
|
|
|
"""Remaps timeout/exceptional exit job results to last test method running.
|
|
|
|
|
|
|
|
@param test_event the job_result test event. This is an in/out
|
|
|
|
parameter. It will be modified if it can be mapped to a test_result
|
|
|
|
of the same status, using details from the last-running test method
|
|
|
|
known to be most recently started on the same worker index.
|
|
|
|
"""
|
|
|
|
test_start = None
|
|
|
|
|
|
|
|
job_status = test_event["status"]
|
|
|
|
if job_status in [
|
|
|
|
EventBuilder.STATUS_TIMEOUT,
|
|
|
|
EventBuilder.STATUS_EXCEPTIONAL_EXIT]:
|
|
|
|
worker_index = test_event.get("worker_index", None)
|
|
|
|
if worker_index is not None:
|
|
|
|
test_start = self.started_tests_by_worker.get(
|
|
|
|
worker_index, None)
|
|
|
|
|
|
|
|
# If we have a test start to remap, do it here.
|
|
|
|
if test_start is not None:
|
|
|
|
test_event["event"] = EventBuilder.TYPE_TEST_RESULT
|
|
|
|
|
|
|
|
# Fill in all fields from test start not present in
|
|
|
|
# job status message.
|
|
|
|
for (start_key, start_value) in test_start.items():
|
|
|
|
if start_key not in test_event:
|
|
|
|
test_event[start_key] = start_value
|
|
|
|
|
|
|
|
# Always take the value of test_filename from test_start,
|
|
|
|
# as it was gathered by class introspections. Job status
|
|
|
|
# has less refined info available to it, so might be missing
|
|
|
|
# path info.
|
|
|
|
if "test_filename" in test_start:
|
|
|
|
test_event["test_filename"] = test_start["test_filename"]
|
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
def handle_event(self, test_event):
|
|
|
|
"""Handles the test event for collection into the formatter output.
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
Derived classes may override this but should call down to this
|
|
|
|
implementation first.
|
|
|
|
|
|
|
|
@param test_event the test event as formatted by one of the
|
|
|
|
event_for_* calls.
|
|
|
|
"""
|
2015-09-22 00:15:50 +00:00
|
|
|
# Keep track of whether terminate was received. We do this so
|
|
|
|
# that a process can call the 'terminate' event on its own, to
|
|
|
|
# close down a formatter at the appropriate time. Then the
|
|
|
|
# atexit() cleanup can call the "terminate if it hasn't been
|
|
|
|
# called yet".
|
|
|
|
if test_event is not None:
|
2015-12-02 18:48:38 +00:00
|
|
|
event_type = test_event.get("event", "")
|
2015-12-09 06:45:43 +00:00
|
|
|
# We intentionally allow event_type to be checked anew
|
|
|
|
# after this check below since this check may rewrite
|
|
|
|
# the event type
|
|
|
|
if event_type == EventBuilder.TYPE_JOB_RESULT:
|
|
|
|
# Possibly convert the job status (timeout, exceptional exit)
|
|
|
|
# to an appropriate test_result event.
|
|
|
|
self._maybe_remap_job_result_event(test_event)
|
|
|
|
event_type = test_event.get("event", "")
|
|
|
|
|
2015-12-02 18:48:38 +00:00
|
|
|
if event_type == "terminate":
|
2015-09-22 00:15:50 +00:00
|
|
|
self.terminate_called = True
|
2015-12-11 11:05:24 +00:00
|
|
|
elif (event_type == EventBuilder.TYPE_TEST_RESULT or
|
|
|
|
event_type == EventBuilder.TYPE_JOB_RESULT):
|
2015-12-09 06:45:43 +00:00
|
|
|
# Keep track of event counts per test/job result status type.
|
|
|
|
# The only job (i.e. inferior process) results that make it
|
|
|
|
# here are ones that cannot be remapped to the most recently
|
|
|
|
# started test for the given worker index.
|
2015-12-02 18:48:38 +00:00
|
|
|
status = test_event["status"]
|
|
|
|
self.result_status_counts[status] += 1
|
2015-12-09 06:45:43 +00:00
|
|
|
# Clear the most recently started test for the related worker.
|
|
|
|
worker_index = test_event.get("worker_index", None)
|
|
|
|
if worker_index is not None:
|
|
|
|
self.started_tests_by_worker.pop(worker_index, None)
|
|
|
|
elif event_type == EventBuilder.TYPE_TEST_START:
|
|
|
|
# Keep track of the most recent test start event
|
|
|
|
# for the related worker.
|
|
|
|
worker_index = test_event.get("worker_index", None)
|
|
|
|
if worker_index is not None:
|
|
|
|
self.started_tests_by_worker[worker_index] = test_event
|
2015-09-15 21:38:04 +00:00
|
|
|
|
|
|
|
def track_start_time(self, test_class, test_name, start_time):
|
2015-12-02 18:48:38 +00:00
|
|
|
"""tracks the start time of a test so elapsed time can be computed.
|
2015-09-15 21:38:04 +00:00
|
|
|
|
2015-12-02 18:48:38 +00:00
|
|
|
this alleviates the need for test results to be processed serially
|
|
|
|
by test. it will save the start time for the test so that
|
2015-09-15 21:38:04 +00:00
|
|
|
elapsed_time_for_test() can compute the elapsed time properly.
|
|
|
|
"""
|
|
|
|
if test_class is None or test_name is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
test_key = "{}.{}".format(test_class, test_name)
|
|
|
|
with self.lock:
|
|
|
|
self.start_time_by_test[test_key] = start_time
|
|
|
|
|
|
|
|
def elapsed_time_for_test(self, test_class, test_name, end_time):
|
2015-12-02 18:48:38 +00:00
|
|
|
"""returns the elapsed time for a test.
|
2015-09-15 21:38:04 +00:00
|
|
|
|
2015-12-02 18:48:38 +00:00
|
|
|
this function can only be called once per test and requires that
|
2015-09-15 21:38:04 +00:00
|
|
|
the track_start_time() method be called sometime prior to calling
|
|
|
|
this method.
|
|
|
|
"""
|
|
|
|
if test_class is None or test_name is None:
|
|
|
|
return -2.0
|
|
|
|
|
|
|
|
test_key = "{}.{}".format(test_class, test_name)
|
|
|
|
with self.lock:
|
|
|
|
if test_key not in self.start_time_by_test:
|
|
|
|
return -1.0
|
|
|
|
else:
|
|
|
|
start_time = self.start_time_by_test[test_key]
|
|
|
|
del self.start_time_by_test[test_key]
|
|
|
|
return end_time - start_time
|
|
|
|
|
2015-09-19 00:39:09 +00:00
|
|
|
def is_using_terminal(self):
|
2015-12-02 18:48:38 +00:00
|
|
|
"""returns true if this results formatter is using the terminal and
|
2015-09-22 00:15:50 +00:00
|
|
|
output should be avoided."""
|
2015-09-19 00:39:09 +00:00
|
|
|
return self.using_terminal
|
2015-09-15 21:38:04 +00:00
|
|
|
|
2015-09-22 00:15:50 +00:00
|
|
|
def send_terminate_as_needed(self):
|
2015-12-02 18:48:38 +00:00
|
|
|
"""sends the terminate event if it hasn't been received yet."""
|
2015-09-22 00:15:50 +00:00
|
|
|
if not self.terminate_called:
|
|
|
|
terminate_event = EventBuilder.bare_event("terminate")
|
|
|
|
self.handle_event(terminate_event)
|
|
|
|
|
2015-12-02 18:48:38 +00:00
|
|
|
# Derived classes may require self access
|
|
|
|
# pylint: disable=no-self-use
|
|
|
|
def replaces_summary(self):
|
|
|
|
"""Returns whether the results formatter includes a summary
|
|
|
|
suitable to replace the old lldb test run results.
|
|
|
|
|
|
|
|
@return True if the lldb test runner can skip its summary
|
|
|
|
generation when using this results formatter; False otherwise.
|
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
|
|
|
def counts_by_test_result_status(self, status):
|
|
|
|
"""Returns number of test method results for the given status.
|
|
|
|
|
|
|
|
@status_result a test result status (e.g. success, fail, skip)
|
|
|
|
as defined by the EventBuilder.STATUS_* class members.
|
|
|
|
|
|
|
|
@return an integer returning the number of test methods matching
|
|
|
|
the given test result status.
|
|
|
|
"""
|
|
|
|
return self.result_status_counts[status]
|
|
|
|
|
2015-09-22 06:32:50 +00:00
|
|
|
|
2015-09-15 21:38:04 +00:00
|
|
|
class RawPickledFormatter(ResultsFormatter):
|
|
|
|
"""Formats events as a pickled stream.
|
|
|
|
|
|
|
|
The parallel test runner has inferiors pickle their results and send them
|
|
|
|
over a socket back to the parallel test. The parallel test runner then
|
|
|
|
aggregates them into the final results formatter (e.g. xUnit).
|
|
|
|
"""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def arg_parser(cls):
|
|
|
|
"""@return arg parser used to parse formatter-specific options."""
|
|
|
|
parser = super(RawPickledFormatter, cls).arg_parser()
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def __init__(self, out_file, options):
|
|
|
|
super(RawPickledFormatter, self).__init__(out_file, options)
|
|
|
|
self.pid = os.getpid()
|
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
def handle_event(self, test_event):
|
|
|
|
super(RawPickledFormatter, self).handle_event(test_event)
|
2015-09-15 21:38:04 +00:00
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
# Convert initialize/terminate events into job_begin/job_end events.
|
|
|
|
event_type = test_event["event"]
|
|
|
|
if event_type is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
if event_type == "initialize":
|
|
|
|
test_event["event"] = "job_begin"
|
|
|
|
elif event_type == "terminate":
|
|
|
|
test_event["event"] = "job_end"
|
|
|
|
|
|
|
|
# Tack on the pid.
|
|
|
|
test_event["pid"] = self.pid
|
2015-09-15 21:38:04 +00:00
|
|
|
|
2015-12-02 23:07:33 +00:00
|
|
|
# Send it as {serialized_length_of_serialized_bytes}{serialized_bytes}
|
|
|
|
import struct
|
|
|
|
msg = cPickle.dumps(test_event)
|
|
|
|
packet = struct.pack("!I%ds" % len(msg), len(msg), msg)
|
|
|
|
self.out_file.send(packet)
|
2015-09-15 21:38:04 +00:00
|
|
|
|
2015-09-18 21:01:13 +00:00
|
|
|
|
|
|
|
class DumpFormatter(ResultsFormatter):
|
|
|
|
"""Formats events to the file as their raw python dictionary format."""
|
|
|
|
|
2015-09-18 22:45:31 +00:00
|
|
|
def handle_event(self, test_event):
|
|
|
|
super(DumpFormatter, self).handle_event(test_event)
|
2015-09-18 21:01:13 +00:00
|
|
|
self.out_file.write("\n" + pprint.pformat(test_event) + "\n")
|