[Lldb-commits] [lldb] r332293 - [lit] Fix several tests that fail when using Python 3 or on Windows

Stella Stamenova via lldb-commits lldb-commits at lists.llvm.org
Mon May 14 14:04:24 PDT 2018


Author: stella.stamenova
Date: Mon May 14 14:04:24 2018
New Revision: 332293

URL: http://llvm.org/viewvc/llvm-project?rev=332293&view=rev
Log:
[lit] Fix several tests that fail when using Python 3 or on Windows

Summary:
1) In logtest.cpp, the name of the file that is reported is not always capitalized, so split the comparison to validate the file (case insensitive) and function (case sensitive) separately
2) Update the gdb remote client tests to work with Python 3. In Python 3, socket sends/receives data as bytes rather than byte strings. This also updates the usage of .hex() - this is no longer available in Python 3, so use hexlify instead

Reviewers: asmith, labath, zturner

Reviewed By: labath

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D46773

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestGDBRemoteClient.py
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py
    lldb/trunk/unittests/Utility/LogTest.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestGDBRemoteClient.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestGDBRemoteClient.py?rev=332293&r1=332292&r2=332293&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestGDBRemoteClient.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/TestGDBRemoteClient.py Mon May 14 14:04:24 2018
@@ -1,4 +1,5 @@
 import lldb
+import binascii
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test.decorators import *
 from gdbclientutils import *
@@ -25,7 +26,7 @@ class TestGDBRemoteClient(GDBRemoteTestB
 
             # Then, when we are asked to attach, error out.
             def vAttach(self, pid):
-                return "E42;" + error_msg.encode("hex")
+                return "E42;" + binascii.hexlify(error_msg.encode()).decode()
 
         self.server.responder = MyResponder()
 

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py?rev=332293&r1=332292&r2=332293&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/gdb_remote_client/gdbclientutils.py Mon May 14 14:04:24 2018
@@ -76,7 +76,7 @@ def hex_decode_bytes(hex_bytes):
 
 class MockGDBServerResponder:
     """
-    A base class for handing client packets and issuing server responses for
+    A base class for handling client packets and issuing server responses for
     GDB tests.
 
     This handles many typical situations, while still allowing subclasses to
@@ -278,10 +278,14 @@ class MockGDBServer:
                 data = self._client.recv(4096)
                 if data is None or len(data) == 0:
                     break
+                # In Python 2, sockets return byte strings. In Python 3, sockets return bytes.
+                # If we got bytes (and not a byte string), decode them to a string for later handling.
+                if isinstance(data, bytes) and not isinstance(data, str):
+                    data = data.decode()
+                self._receive(data)
             except Exception as e:
                 self._client.close()
                 break
-            self._receive(data)
 
     def _receive(self, data):
         """
@@ -329,7 +333,7 @@ class MockGDBServer:
                 i += 1
             else:
                 raise self.InvalidPacketException(
-                        "Unexexpected leading byte: %s" % data[0])
+                        "Unexpected leading byte: %s" % data[0])
 
         # If we're looking beyond the start of the received data, then we're
         # looking for the end of the packet content, denoted by a #.
@@ -370,9 +374,9 @@ class MockGDBServer:
             return
         response = ""
         # We'll handle the ack stuff here since it's not something any of the
-        # tests will be concerned about, and it'll get turned off quicly anyway.
+        # tests will be concerned about, and it'll get turned off quickly anyway.
         if self._shouldSendAck:
-            self._client.sendall('+')
+            self._client.sendall('+'.encode())
         if packet == "QStartNoAckMode":
             self._shouldSendAck = False
             response = "OK"
@@ -382,6 +386,10 @@ class MockGDBServer:
         # Handle packet framing since we don't want to bother tests with it.
         if response is not None:
             framed = frame_packet(response)
+            # In Python 2, sockets send byte strings. In Python 3, sockets send bytes.
+            # If we got a string (and not a byte string), encode it before sending.
+            if isinstance(framed, str) and not isinstance(framed, bytes):
+                framed = framed.encode()
             self._client.sendall(framed)
 
     PACKET_ACK = object()
@@ -459,6 +467,7 @@ class GDBRemoteTestBase(TestBase):
         i = 0
         j = 0
         log = self.server.responder.packetLog
+        
         while i < len(packets) and j < len(log):
             if log[j] == packets[i]:
                 i += 1

Modified: lldb/trunk/unittests/Utility/LogTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/LogTest.cpp?rev=332293&r1=332292&r2=332293&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/LogTest.cpp (original)
+++ lldb/trunk/unittests/Utility/LogTest.cpp Mon May 14 14:04:24 2018
@@ -225,12 +225,17 @@ TEST_F(LogChannelEnabledTest, log_option
     EXPECT_EQ(1, sscanf(Msg.str().c_str(), "%d Hello World", &seq_no));
   }
 
-  EXPECT_TRUE(EnableChannel(getStream(), LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION,
-                            "chan", {}, Err));
-  EXPECT_EQ(
-      "LogTest.cpp:logAndTakeOutput                                 Hello "
-      "World\n",
-      logAndTakeOutput("Hello World"));
+  {
+    EXPECT_TRUE(EnableChannel(getStream(), LLDB_LOG_OPTION_PREPEND_FILE_FUNCTION,
+                              "chan", {}, Err));
+    llvm::StringRef Msg = logAndTakeOutput("Hello World");
+    char File[12];
+    char Function[17];
+      
+    sscanf(Msg.str().c_str(), "%[^:]:%s                                 Hello World", File, Function);
+    EXPECT_STRCASEEQ("LogTest.cpp", File);
+    EXPECT_STREQ("logAndTakeOutput", Function);
+  }
 
   EXPECT_TRUE(EnableChannel(
       getStream(), LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD, "chan", {}, Err));




More information about the lldb-commits mailing list