Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,16 @@
class BuildError(Exception):
def __init__(self, called_process_error):
super(BuildError, self).__init__("Error when building test subject")
self.command = called_process_error.lldb_extensions.get(
"command", "<command unavailable>")
self.build_error = called_process_error.lldb_extensions.get(
"stderr_content", "<error output unavailable>")
def __str__(self):
return self.format_build_error(self.command, self.build_error)
@staticmethod
def format_build_error(command, command_output):
return "Error when building test subject.\n\nBuild Command:\n{}\n\nBuild Command Output:\n{}".format(
command, command_output)

View File

@ -0,0 +1,209 @@
"""
The LLVM Compiler Infrastructure
This file is distributed under the University of Illinois Open Source
License. See LICENSE.TXT for details.
Sync lldb and related source from a local machine to a remote machine.
This facilitates working on the lldb sourcecode on multiple machines
and multiple OS types, verifying changes across all.
This module provides asyncore channels used within the LLDB test
framework.
"""
from __future__ import print_function
from __future__ import absolute_import
# System modules
import asyncore
import socket
# Third-party modules
from six.moves import cPickle
# LLDB modules
class UnpicklingForwardingReaderChannel(asyncore.dispatcher):
"""Provides an unpickling, forwarding asyncore dispatch channel reader.
Inferior dotest.py processes with side-channel-based test results will
send test result event data in a pickled format, one event at a time.
This class supports reconstructing the pickled data and forwarding it
on to its final destination.
The channel data is written in the form:
{num_payload_bytes}#{payload_bytes}
The bulk of this class is devoted to reading and parsing out
the payload bytes.
"""
def __init__(self, file_object, async_map, forwarding_func):
asyncore.dispatcher.__init__(self, sock=file_object, map=async_map)
self.header_contents = b""
self.packet_bytes_remaining = 0
self.reading_header = True
self.ibuffer = b''
self.forwarding_func = forwarding_func
if forwarding_func is None:
# This whole class is useless if we do nothing with the
# unpickled results.
raise Exception("forwarding function must be set")
# Initiate all connections by sending an ack. This allows
# the initiators of the socket to await this to ensure
# that this end is up and running (and therefore already
# into the async map).
ack_bytes = b'*'
file_object.send(ack_bytes)
def deserialize_payload(self):
"""Unpickles the collected input buffer bytes and forwards."""
if len(self.ibuffer) > 0:
self.forwarding_func(cPickle.loads(self.ibuffer))
self.ibuffer = b''
def consume_header_bytes(self, data):
"""Consumes header bytes from the front of data.
@param data the incoming data stream bytes
@return any data leftover after consuming header bytes.
"""
# We're done if there is no content.
if not data or (len(data) == 0):
return None
full_header_len = 4
assert len(self.header_contents) < full_header_len
bytes_avail = len(data)
bytes_needed = full_header_len - len(self.header_contents)
header_bytes_avail = min(bytes_needed, bytes_avail)
self.header_contents += data[:header_bytes_avail]
if len(self.header_contents) == full_header_len:
import struct
# End of header.
self.packet_bytes_remaining = struct.unpack(
"!I", self.header_contents)[0]
self.header_contents = b""
self.reading_header = False
return data[header_bytes_avail:]
# If we made it here, we've exhausted the data and
# we're still parsing header content.
return None
def consume_payload_bytes(self, data):
"""Consumes payload bytes from the front of data.
@param data the incoming data stream bytes
@return any data leftover after consuming remaining payload bytes.
"""
if not data or (len(data) == 0):
# We're done and there's nothing to do.
return None
data_len = len(data)
if data_len <= self.packet_bytes_remaining:
# We're consuming all the data provided.
self.ibuffer += data
self.packet_bytes_remaining -= data_len
# If we're no longer waiting for payload bytes,
# we flip back to parsing header bytes and we
# unpickle the payload contents.
if self.packet_bytes_remaining < 1:
self.reading_header = True
self.deserialize_payload()
# We're done, no more data left.
return None
else:
# We're only consuming a portion of the data since
# the data contains more than the payload amount.
self.ibuffer += data[:self.packet_bytes_remaining]
data = data[self.packet_bytes_remaining:]
# We now move on to reading the header.
self.reading_header = True
self.packet_bytes_remaining = 0
# And we can deserialize the payload.
self.deserialize_payload()
# Return the remaining data.
return data
def handle_read(self):
# Read some data from the socket.
try:
data = self.recv(8192)
# print('driver socket READ: %d bytes' % len(data))
except socket.error as socket_error:
print(
"\nINFO: received socket error when reading data "
"from test inferior:\n{}".format(socket_error))
raise
except Exception as general_exception:
print(
"\nERROR: received non-socket error when reading data "
"from the test inferior:\n{}".format(general_exception))
raise
# Consume the message content.
while data and (len(data) > 0):
# If we're reading the header, gather header bytes.
if self.reading_header:
data = self.consume_header_bytes(data)
else:
data = self.consume_payload_bytes(data)
def handle_close(self):
# print("socket reader: closing port")
self.close()
class UnpicklingForwardingListenerChannel(asyncore.dispatcher):
"""Provides a socket listener asyncore channel for unpickling/forwarding.
This channel will listen on a socket port (use 0 for host-selected). Any
client that connects will have an UnpicklingForwardingReaderChannel handle
communication over the connection.
The dotest parallel test runners, when collecting test results, open the
test results side channel over a socket. This channel handles connections
from inferiors back to the test runner. Each worker fires up a listener
for each inferior invocation. This simplifies the asyncore.loop() usage,
one of the reasons for implementing with asyncore. This listener shuts
down once a single connection is made to it.
"""
def __init__(self, async_map, host, port, backlog_count, forwarding_func):
asyncore.dispatcher.__init__(self, map=async_map)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind((host, port))
self.address = self.socket.getsockname()
self.listen(backlog_count)
self.handler = None
self.async_map = async_map
self.forwarding_func = forwarding_func
if forwarding_func is None:
# This whole class is useless if we do nothing with the
# unpickled results.
raise Exception("forwarding function must be set")
def handle_accept(self):
(sock, addr) = self.socket.accept()
if sock and addr:
# print('Incoming connection from %s' % repr(addr))
self.handler = UnpicklingForwardingReaderChannel(
sock, self.async_map, self.forwarding_func)
def handle_close(self):
self.close()

View File

@ -0,0 +1,482 @@
"""
The LLVM Compiler Infrastructure
This file is distributed under the University of Illinois Open Source
License. See LICENSE.TXT for details.
Provides a class to build Python test event data structures.
"""
from __future__ import print_function
from __future__ import absolute_import
# System modules
import inspect
import time
import traceback
# Third-party modules
# LLDB modules
from . import build_exception
class EventBuilder(object):
"""Helper class to build test result event dictionaries."""
BASE_DICTIONARY = None
# Test Event Types
TYPE_JOB_RESULT = "job_result"
TYPE_TEST_RESULT = "test_result"
TYPE_TEST_START = "test_start"
TYPE_MARK_TEST_RERUN_ELIGIBLE = "test_eligible_for_rerun"
TYPE_MARK_TEST_EXPECTED_FAILURE = "test_expected_failure"
TYPE_SESSION_TERMINATE = "terminate"
RESULT_TYPES = {TYPE_JOB_RESULT, TYPE_TEST_RESULT}
# Test/Job Status Tags
STATUS_EXCEPTIONAL_EXIT = "exceptional_exit"
STATUS_SUCCESS = "success"
STATUS_FAILURE = "failure"
STATUS_EXPECTED_FAILURE = "expected_failure"
STATUS_EXPECTED_TIMEOUT = "expected_timeout"
STATUS_UNEXPECTED_SUCCESS = "unexpected_success"
STATUS_SKIP = "skip"
STATUS_ERROR = "error"
STATUS_TIMEOUT = "timeout"
"""Test methods or jobs with a status matching any of these
status values will cause a testrun failure, unless
the test methods rerun and do not trigger an issue when rerun."""
TESTRUN_ERROR_STATUS_VALUES = {
STATUS_ERROR,
STATUS_EXCEPTIONAL_EXIT,
STATUS_FAILURE,
STATUS_TIMEOUT}
@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
@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
@staticmethod
def _assert_is_python_sourcefile(test_filename):
if test_filename is not None:
if not test_filename.endswith(".py"):
raise Exception(
"source python filename has unexpected extension: {}".format(test_filename))
return test_filename
@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)
# Determine the filename for the test case. If there is an attribute
# for it, use it. Otherwise, determine from the TestCase class path.
if hasattr(test, "test_filename"):
test_filename = EventBuilder._assert_is_python_sourcefile(
test.test_filename)
else:
test_filename = EventBuilder._assert_is_python_sourcefile(
inspect.getsourcefile(test.__class__))
event = EventBuilder.bare_event(event_type)
event.update({
"test_class": test_class_name,
"test_name": test_name,
"test_filename": test_filename
})
return event
@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])
@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]
@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
"""
event = EventBuilder._event_dictionary_common(
test, EventBuilder.TYPE_TEST_RESULT)
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)
backtrace = EventBuilder._error_tuple_traceback(error_tuple)
if backtrace is not None:
event["issue_backtrace"] = traceback.format_tb(backtrace)
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
"""
return EventBuilder._event_dictionary_common(
test, EventBuilder.TYPE_TEST_START)
@staticmethod
def event_for_success(test):
"""Returns an event dictionary for a successful test.
@param test a unittest.TestCase instance.
@return the event dictionary
"""
return EventBuilder._event_dictionary_test_result(
test, EventBuilder.STATUS_SUCCESS)
@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(
test, EventBuilder.STATUS_UNEXPECTED_SUCCESS)
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(
test, EventBuilder.STATUS_FAILURE, error_tuple)
@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(
test, EventBuilder.STATUS_EXPECTED_FAILURE, error_tuple)
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
"""
event = EventBuilder._event_dictionary_test_result(
test, EventBuilder.STATUS_SKIP)
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
"""
event = EventBuilder._event_dictionary_issue(
test, EventBuilder.STATUS_ERROR, error_tuple)
event["issue_phase"] = "test"
return event
@staticmethod
def event_for_build_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(
test, EventBuilder.STATUS_ERROR, error_tuple)
event["issue_phase"] = "build"
build_error = error_tuple[1]
event["build_command"] = build_error.command
event["build_error"] = build_error.build_error
return event
@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(
test, EventBuilder.STATUS_ERROR, error_tuple)
event["issue_phase"] = "cleanup"
return event
@staticmethod
def event_for_job_test_add_error(test_filename, exception, backtrace):
event = EventBuilder.bare_event(EventBuilder.TYPE_JOB_RESULT)
event["status"] = EventBuilder.STATUS_ERROR
if test_filename is not None:
event["test_filename"] = EventBuilder._assert_is_python_sourcefile(
test_filename)
if exception is not None and "__class__" in dir(exception):
event["issue_class"] = exception.__class__
event["issue_message"] = exception
if backtrace is not None:
event["issue_backtrace"] = backtrace
return event
@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"] = EventBuilder._assert_is_python_sourcefile(
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"] = EventBuilder._assert_is_python_sourcefile(
test_filename)
if command_line is not None:
event["command_line"] = command_line
return event
@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 re-runnable
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
@staticmethod
def event_for_mark_test_expected_failure(test):
"""Creates an event that indicates the specified test is expected
to fail.
@param test the TestCase instance to which this pertains.
@return an event that specifies the given test is expected to fail.
"""
event = EventBuilder._event_dictionary_common(
test,
EventBuilder.TYPE_MARK_TEST_EXPECTED_FAILURE)
return event
@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)

View File

@ -0,0 +1,163 @@
"""
The LLVM Compiler Infrastructure
This file is distributed under the University of Illinois Open Source
License. See LICENSE.TXT for details.
"""
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 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
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(config):
"""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 listening 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))
# Wait for the ack from the listener side.
# This is needed to prevent a race condition
# in the main dosep.py processing loop: we
# can't allow a worker queue thread to die
# that has outstanding messages to a listener
# socket before the listener socket asyncore
# listener socket gets spun up; otherwise,
# we lose the test result info.
read_bytes = sock.recv(1)
if read_bytes is None or (len(read_bytes) < 1) or (read_bytes != b'*'):
raise Exception(
"listening socket did not respond with ack byte: response={}".format(read_bytes))
return sock, lambda: socket_closer(sock)
default_formatter_name = None
results_file_object = None
cleanup_func = None
file_is_stream = False
if config.filename:
# Open the results file for writing.
if config.filename == 'stdout':
results_file_object = sys.stdout
cleanup_func = None
elif config.filename == 'stderr':
results_file_object = sys.stderr
cleanup_func = None
else:
results_file_object = open(config.filename, "w")
cleanup_func = results_file_object.close
default_formatter_name = (
"lldbsuite.test_event.formatter.xunit.XunitFormatter")
elif config.port:
# Connect to the specified localhost port.
results_file_object, cleanup_func = create_socket(config.port)
default_formatter_name = (
"lldbsuite.test_event.formatter.pickled.RawPickledFormatter")
file_is_stream = True
# If we have a results formatter name specified and we didn't specify
# a results file, we should use stdout.
if config.formatter_name is not None and results_file_object is None:
# 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.
if config.formatter_name:
formatter_name = config.formatter_name
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()
if config.formatter_options and len(config.formatter_options) > 0:
command_line_options = config.formatter_options
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,
file_is_stream)
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

View File

@ -0,0 +1,342 @@
"""
The LLVM Compiler Infrastructure
This file is distributed under the University of Illinois Open Source
License. See LICENSE.TXT for details.
"""
from __future__ import absolute_import
from __future__ import print_function
# System modules
import curses
import datetime
import math
import sys
import time
# Third-party modules
# LLDB modules
from lldbsuite.test import lldbcurses
from . import results_formatter
from ..event_builder import EventBuilder
class Curses(results_formatter.ResultsFormatter):
"""Receives live results from tests that are running and reports them to the terminal in a curses GUI"""
def __init__(self, out_file, options, file_is_stream):
# Initialize the parent
super(Curses, self).__init__(out_file, options, file_is_stream)
self.using_terminal = True
self.have_curses = True
self.initialize_event = None
self.jobs = [None] * 64
self.job_tests = [None] * 64
self.results = list()
try:
self.main_window = lldbcurses.intialize_curses()
self.main_window.add_key_action(
'\t',
self.main_window.select_next_first_responder,
"Switch between views that can respond to keyboard input")
self.main_window.refresh()
self.job_panel = None
self.results_panel = None
self.status_panel = None
self.info_panel = None
self.hide_status_list = list()
self.start_time = time.time()
except:
self.have_curses = False
lldbcurses.terminate_curses()
self.using_terminal = False
print("Unexpected error:", sys.exc_info()[0])
raise
self.line_dict = dict()
# self.events_file = open("/tmp/events.txt", "w")
# self.formatters = list()
# if tee_results_formatter:
# self.formatters.append(tee_results_formatter)
def status_to_short_str(self, status, test_event):
if status == EventBuilder.STATUS_SUCCESS:
return '.'
elif status == EventBuilder.STATUS_FAILURE:
return 'F'
elif status == EventBuilder.STATUS_UNEXPECTED_SUCCESS:
return '?'
elif status == EventBuilder.STATUS_EXPECTED_FAILURE:
return 'X'
elif status == EventBuilder.STATUS_SKIP:
return 'S'
elif status == EventBuilder.STATUS_ERROR:
if test_event.get("issue_phase", None) == "build":
# Build failure
return 'B'
else:
return 'E'
elif status == EventBuilder.STATUS_TIMEOUT:
return 'T'
elif status == EventBuilder.STATUS_EXPECTED_TIMEOUT:
return 't'
else:
return status
def show_info_panel(self):
selected_idx = self.results_panel.get_selected_idx()
if selected_idx >= 0 and selected_idx < len(self.results):
if self.info_panel is None:
info_frame = self.results_panel.get_contained_rect(
top_inset=10, left_inset=10, right_inset=10, height=30)
self.info_panel = lldbcurses.BoxedPanel(
info_frame, "Result Details")
# Add a key action for any key that will hide this panel when
# any key is pressed
self.info_panel.add_key_action(-1,
self.hide_info_panel,
'Hide the info panel')
self.info_panel.top()
else:
self.info_panel.show()
self.main_window.push_first_responder(self.info_panel)
test_start = self.results[selected_idx][0]
test_result = self.results[selected_idx][1]
self.info_panel.set_line(
0, "File: %s" %
(test_start['test_filename']))
self.info_panel.set_line(
1, "Test: %s.%s" %
(test_start['test_class'], test_start['test_name']))
self.info_panel.set_line(
2, "Time: %s" %
(test_result['elapsed_time']))
self.info_panel.set_line(3, "Status: %s" % (test_result['status']))
def hide_info_panel(self):
self.main_window.pop_first_responder(self.info_panel)
self.info_panel.hide()
self.main_window.refresh()
def toggle_status(self, status):
if status:
# Toggle showing and hiding results whose status matches "status"
# in "Results" window
if status in self.hide_status_list:
self.hide_status_list.remove(status)
else:
self.hide_status_list.append(status)
self.update_results()
def update_results(self, update=True):
'''Called after a category of test have been show/hidden to update the results list with
what the user desires to see.'''
self.results_panel.clear(update=False)
for result in self.results:
test_result = result[1]
status = test_result['status']
if status in self.hide_status_list:
continue
name = test_result['test_class'] + '.' + test_result['test_name']
self.results_panel.append_line(
'%s (%6.2f sec) %s' %
(self.status_to_short_str(
status,
test_result),
test_result['elapsed_time'],
name))
if update:
self.main_window.refresh()
def handle_event(self, test_event):
with self.lock:
super(Curses, self).handle_event(test_event)
# for formatter in self.formatters:
# formatter.process_event(test_event)
if self.have_curses:
worker_index = -1
if 'worker_index' in test_event:
worker_index = test_event['worker_index']
if 'event' in test_event:
check_for_one_key = True
#print(str(test_event), file=self.events_file)
event = test_event['event']
if self.status_panel:
self.status_panel.update_status(
'time', str(
datetime.timedelta(
seconds=math.floor(
time.time() - self.start_time))))
if event == 'test_start':
name = test_event['test_class'] + \
'.' + test_event['test_name']
self.job_tests[worker_index] = test_event
if 'pid' in test_event:
line = 'pid: %5d ' % (test_event['pid']) + name
else:
line = name
self.job_panel.set_line(worker_index, line)
self.main_window.refresh()
elif event == 'test_result':
status = test_event['status']
self.status_panel.increment_status(status)
if 'pid' in test_event:
line = 'pid: %5d ' % (test_event['pid'])
else:
line = ''
self.job_panel.set_line(worker_index, line)
name = test_event['test_class'] + \
'.' + test_event['test_name']
elapsed_time = test_event[
'event_time'] - self.job_tests[worker_index]['event_time']
if status not in self.hide_status_list:
self.results_panel.append_line(
'%s (%6.2f sec) %s' %
(self.status_to_short_str(
status, test_event), elapsed_time, name))
self.main_window.refresh()
# Append the result pairs
test_event['elapsed_time'] = elapsed_time
self.results.append(
[self.job_tests[worker_index], test_event])
self.job_tests[worker_index] = ''
elif event == 'job_begin':
self.jobs[worker_index] = test_event
if 'pid' in test_event:
line = 'pid: %5d ' % (test_event['pid'])
else:
line = ''
self.job_panel.set_line(worker_index, line)
elif event == 'job_end':
self.jobs[worker_index] = ''
self.job_panel.set_line(worker_index, '')
elif event == 'initialize':
self.initialize_event = test_event
num_jobs = test_event['worker_count']
job_frame = self.main_window.get_contained_rect(
height=num_jobs + 2)
results_frame = self.main_window.get_contained_rect(
top_inset=num_jobs + 2, bottom_inset=1)
status_frame = self.main_window.get_contained_rect(
height=1, top_inset=self.main_window.get_size().h - 1)
self.job_panel = lldbcurses.BoxedPanel(
frame=job_frame, title="Jobs")
self.results_panel = lldbcurses.BoxedPanel(
frame=results_frame, title="Results")
self.results_panel.add_key_action(
curses.KEY_UP,
self.results_panel.select_prev,
"Select the previous list entry")
self.results_panel.add_key_action(
curses.KEY_DOWN, self.results_panel.select_next, "Select the next list entry")
self.results_panel.add_key_action(
curses.KEY_HOME,
self.results_panel.scroll_begin,
"Scroll to the start of the list")
self.results_panel.add_key_action(
curses.KEY_END, self.results_panel.scroll_end, "Scroll to the end of the list")
self.results_panel.add_key_action(
curses.KEY_ENTER,
self.show_info_panel,
"Display info for the selected result item")
self.results_panel.add_key_action(
'.',
lambda: self.toggle_status(
EventBuilder.STATUS_SUCCESS),
"Toggle showing/hiding tests whose status is 'success'")
self.results_panel.add_key_action(
'e',
lambda: self.toggle_status(
EventBuilder.STATUS_ERROR),
"Toggle showing/hiding tests whose status is 'error'")
self.results_panel.add_key_action(
'f',
lambda: self.toggle_status(
EventBuilder.STATUS_FAILURE),
"Toggle showing/hiding tests whose status is 'failure'")
self.results_panel.add_key_action('s', lambda: self.toggle_status(
EventBuilder.STATUS_SKIP), "Toggle showing/hiding tests whose status is 'skip'")
self.results_panel.add_key_action(
'x',
lambda: self.toggle_status(
EventBuilder.STATUS_EXPECTED_FAILURE),
"Toggle showing/hiding tests whose status is 'expected_failure'")
self.results_panel.add_key_action(
'?',
lambda: self.toggle_status(
EventBuilder.STATUS_UNEXPECTED_SUCCESS),
"Toggle showing/hiding tests whose status is 'unexpected_success'")
self.status_panel = lldbcurses.StatusPanel(
frame=status_frame)
self.main_window.add_child(self.job_panel)
self.main_window.add_child(self.results_panel)
self.main_window.add_child(self.status_panel)
self.main_window.set_first_responder(
self.results_panel)
self.status_panel.add_status_item(
name="time",
title="Elapsed",
format="%s",
width=20,
value="0:00:00",
update=False)
self.status_panel.add_status_item(
name=EventBuilder.STATUS_SUCCESS,
title="Success",
format="%u",
width=20,
value=0,
update=False)
self.status_panel.add_status_item(
name=EventBuilder.STATUS_FAILURE,
title="Failure",
format="%u",
width=20,
value=0,
update=False)
self.status_panel.add_status_item(
name=EventBuilder.STATUS_ERROR,
title="Error",
format="%u",
width=20,
value=0,
update=False)
self.status_panel.add_status_item(
name=EventBuilder.STATUS_SKIP,
title="Skipped",
format="%u",
width=20,
value=0,
update=True)
self.status_panel.add_status_item(
name=EventBuilder.STATUS_EXPECTED_FAILURE,
title="Expected Failure",
format="%u",
width=30,
value=0,
update=False)
self.status_panel.add_status_item(
name=EventBuilder.STATUS_UNEXPECTED_SUCCESS,
title="Unexpected Success",
format="%u",
width=30,
value=0,
update=False)
self.main_window.refresh()
elif event == 'terminate':
# self.main_window.key_event_loop()
lldbcurses.terminate_curses()
check_for_one_key = False
self.using_terminal = False
# Check for 1 keypress with no delay
# Check for 1 keypress with no delay
if check_for_one_key:
self.main_window.key_event_loop(0, 1)

View File

@ -0,0 +1,23 @@
"""
The LLVM Compiler Infrastructure
This file is distributed under the University of Illinois Open Source
License. See LICENSE.TXT for details.
"""
from __future__ import print_function
from __future__ import absolute_import
# System modules
import pprint
# Our modules
from .results_formatter import ResultsFormatter
class DumpFormatter(ResultsFormatter):
"""Formats events to the file as their raw python dictionary format."""
def handle_event(self, test_event):
super(DumpFormatter, self).handle_event(test_event)
self.out_file.write("\n" + pprint.pformat(test_event) + "\n")

View File

@ -0,0 +1,80 @@
"""
The LLVM Compiler Infrastructure
This file is distributed under the University of Illinois Open Source
License. See LICENSE.TXT for details.
"""
from __future__ import print_function
from __future__ import absolute_import
# System modules
import os
# Our modules
from .results_formatter import ResultsFormatter
from six.moves import cPickle
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
class StreamSerializer(object):
@staticmethod
def serialize(test_event, out_file):
# 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)
out_file.send(packet)
class BlockSerializer(object):
@staticmethod
def serialize(test_event, out_file):
cPickle.dump(test_event, out_file)
def __init__(self, out_file, options, file_is_stream):
super(
RawPickledFormatter,
self).__init__(
out_file,
options,
file_is_stream)
self.pid = os.getpid()
if file_is_stream:
self.serializer = self.StreamSerializer()
else:
self.serializer = self.BlockSerializer()
def handle_event(self, test_event):
super(RawPickledFormatter, self).handle_event(test_event)
# 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
# Serialize the test event.
self.serializer.serialize(test_event, self.out_file)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
from __future__ import print_function
from lldbsuite.test import lldbtest
from lldbsuite.test import decorators
class NonExistentDecoratorTestCase(lldbtest.TestBase):
mydir = lldbtest.TestBase.compute_mydir(__file__)
@decorators.nonExistentDecorator(bugnumber="yt/1300")
def test(self):
"""Verify non-existent decorators are picked up by test runner."""
pass

View File

@ -0,0 +1,70 @@
#!/usr/bin/env python
"""
Tests that the event system reports issues during decorator
handling as errors.
"""
# System-provided imports
import os
import unittest
# Local-provided imports
import event_collector
class TestCatchInvalidDecorator(unittest.TestCase):
TEST_DIR = os.path.join(
os.path.dirname(__file__),
os.path.pardir,
"resources",
"invalid_decorator")
def test_with_whole_file(self):
"""
Test that a non-existent decorator generates a test-event error
when running all tests in the file.
"""
# Determine the test case file we're using.
test_file = os.path.join(self.TEST_DIR, "TestInvalidDecorator.py")
# Collect all test events generated for this file.
error_results = _filter_error_results(
event_collector.collect_events_whole_file(test_file))
self.assertGreater(
len(error_results),
0,
"At least one job or test error result should have been returned")
def test_with_function_filter(self):
"""
Test that a non-existent decorator generates a test-event error
when running a filtered test.
"""
# Collect all test events generated during running of tests
# in a given directory using a test name filter. Internally,
# this runs through a different code path that needs to be
# set up to catch exceptions.
error_results = _filter_error_results(
event_collector.collect_events_for_directory_with_filter(
self.TEST_DIR,
"NonExistentDecoratorTestCase.test"))
self.assertGreater(
len(error_results),
0,
"At least one job or test error result should have been returned")
def _filter_error_results(events):
# Filter out job result events.
return [
event
for event in events
if event.get("event", None) in ["job_result", "test_result"] and
event.get("status", None) == "error"
]
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,85 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import subprocess
import sys
import tempfile
# noinspection PyUnresolvedReferences
from six.moves import cPickle
def path_to_dotest_py():
return os.path.join(
os.path.dirname(__file__),
os.path.pardir,
os.path.pardir,
os.path.pardir,
os.path.pardir,
os.path.pardir,
os.path.pardir,
"test",
"dotest.py")
def _make_pickled_events_filename():
with tempfile.NamedTemporaryFile(
prefix="lldb_test_event_pickled_event_output",
delete=False) as temp_file:
return temp_file.name
def _collect_events_with_command(command, events_filename):
# Run the single test with dotest.py, outputting
# the raw pickled events to a temp file.
with open(os.devnull, 'w') as dev_null_file:
subprocess.call(
command,
stdout=dev_null_file,
stderr=dev_null_file)
# Unpickle the events
events = []
if os.path.exists(events_filename):
with open(events_filename, "rb") as events_file:
while True:
try:
# print("reading event")
event = cPickle.load(events_file)
# print("read event: {}".format(event))
if event:
events.append(event)
except EOFError:
# This is okay.
break
os.remove(events_filename)
return events
def collect_events_whole_file(test_filename):
events_filename = _make_pickled_events_filename()
command = [
sys.executable,
path_to_dotest_py(),
"--inferior",
"--results-formatter=lldbsuite.test_event.formatter.pickled.RawPickledFormatter",
"--results-file={}".format(events_filename),
"-p",
os.path.basename(test_filename),
os.path.dirname(test_filename)]
return _collect_events_with_command(command, events_filename)
def collect_events_for_directory_with_filter(test_filename, filter_desc):
events_filename = _make_pickled_events_filename()
command = [
sys.executable,
path_to_dotest_py(),
"--inferior",
"--results-formatter=lldbsuite.test_event.formatter.pickled.RawPickledFormatter",
"--results-file={}".format(events_filename),
"-f",
filter_desc,
os.path.dirname(test_filename)]
return _collect_events_with_command(command, events_filename)