2 The LLVM Compiler Infrastructure
4 This file is distributed under the University of Illinois Open Source
5 License. See LICENSE.TXT for details.
8 from __future__ import print_function
9 from __future__ import absolute_import
15 from .results_formatter import ResultsFormatter
16 from six.moves import cPickle
19 class RawPickledFormatter(ResultsFormatter):
20 """Formats events as a pickled stream.
22 The parallel test runner has inferiors pickle their results and send them
23 over a socket back to the parallel test. The parallel test runner then
24 aggregates them into the final results formatter (e.g. xUnit).
29 """@return arg parser used to parse formatter-specific options."""
30 parser = super(RawPickledFormatter, cls).arg_parser()
33 class StreamSerializer(object):
35 def serialize(test_event, out_file):
36 # Send it as {serialized_length_of_serialized_bytes}{serialized_bytes}
38 msg = cPickle.dumps(test_event)
39 packet = struct.pack("!I%ds" % len(msg), len(msg), msg)
42 class BlockSerializer(object):
44 def serialize(test_event, out_file):
45 cPickle.dump(test_event, out_file)
47 def __init__(self, out_file, options, file_is_stream):
48 super(RawPickledFormatter, self).__init__(out_file, options, file_is_stream)
49 self.pid = os.getpid()
51 self.serializer = self.StreamSerializer()
53 self.serializer = self.BlockSerializer()
55 def handle_event(self, test_event):
56 super(RawPickledFormatter, self).handle_event(test_event)
58 # Convert initialize/terminate events into job_begin/job_end events.
59 event_type = test_event["event"]
60 if event_type is None:
63 if event_type == "initialize":
64 test_event["event"] = "job_begin"
65 elif event_type == "terminate":
66 test_event["event"] = "job_end"
69 test_event["pid"] = self.pid
71 # Serialize the test event.
72 self.serializer.serialize(test_event, self.out_file)