[Lldb-commits] [lldb] r254563 - Fix test result serialization to use bytes.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 2 15:07:33 PST 2015


Author: zturner
Date: Wed Dec  2 17:07:33 2015
New Revision: 254563

URL: http://llvm.org/viewvc/llvm-project?rev=254563&view=rev
Log:
Fix test result serialization to use bytes.

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/dotest_channels.py
    lldb/trunk/packages/Python/lldbsuite/test/test_results.py

Modified: lldb/trunk/packages/Python/lldbsuite/test/dotest_channels.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/dotest_channels.py?rev=254563&r1=254562&r2=254563&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/dotest_channels.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/dotest_channels.py Wed Dec  2 17:07:33 2015
@@ -44,7 +44,7 @@ class UnpicklingForwardingReaderChannel(
     def __init__(self, file_object, async_map, forwarding_func):
         asyncore.dispatcher.__init__(self, sock=file_object, map=async_map)
 
-        self.header_contents = ''
+        self.header_contents = b""
         self.packet_bytes_remaining = 0
         self.reading_header = True
         self.ibuffer = b''
@@ -69,17 +69,21 @@ class UnpicklingForwardingReaderChannel(
         if not data or (len(data) == 0):
             return None
 
-        for index in range(len(data)):
-            byte = data[index]
-            if byte != '#':
-                # Header byte.
-                self.header_contents += byte
-            else:
-                # End of header.
-                self.packet_bytes_remaining = int(self.header_contents)
-                self.header_contents = ''
-                self.reading_header = False
-                return data[(index+1):]
+        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.

Modified: lldb/trunk/packages/Python/lldbsuite/test/test_results.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/test_results.py?rev=254563&r1=254562&r2=254563&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/test_results.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/test_results.py Wed Dec  2 17:07:33 2015
@@ -1027,10 +1027,11 @@ class RawPickledFormatter(ResultsFormatt
         # Tack on the pid.
         test_event["pid"] = self.pid
 
-        # Send it as {serialized_length_of_serialized_bytes}#{serialized_bytes}
-        pickled_message = cPickle.dumps(test_event)
-        self.out_file.send("{}#".format(len(pickled_message)))
-        self.out_file.send(pickled_message)
+        # 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)
 
 
 class DumpFormatter(ResultsFormatter):




More information about the lldb-commits mailing list