diff options
author | Pavel Labath <pavel@labath.sk> | 2019-02-15 07:47:06 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-02-15 07:47:06 +0000 |
commit | 0af864b4b2af54a9c238df793e50b2f81f956b78 (patch) | |
tree | 0d9afe88d0682c5c31a726bb018756718c6dcf93 /lldb/packages/Python/lldbsuite/test | |
parent | b302bd232407cb939b45b4aabb72d1ba24b37cb2 (diff) | |
download | bcm5719-llvm-0af864b4b2af54a9c238df793e50b2f81f956b78.tar.gz bcm5719-llvm-0af864b4b2af54a9c238df793e50b2f81f956b78.zip |
Fix lldb-server test suite for python3
Summary:
This patch finishes the python3-ification of the lldb-server test suite.
It reverts the partial attempt in r352709 to encode/decode the string
via utf8 before writing to the socket. This wasn't enough because the
gdb-remote protocol can sometimes (but not very often) carry binary
data, and the utf8 codec chokes on that. Instead I add utility functions
to the "seven" module for performing "identity" transformations on the
byte data. This basically drills back the hole in the python type system
that the string/bytes distinction was supposed to plug. That is not
ideal, but was the best solution of the alternatives I could come up
with. The options I considered were:
- make use of the type system to add type safety to the test suite: This
required making a lot of changes to the test suite, since most of the
strings would now become byte objects instead, and it was not even
fully clear to me where to draw the line. One extreme solution would
be to just use byte objects everywhere, as the protocol doesn't
support non-ascii characters anyway. However, this appeared to be:
a) weird, because most of the protocol actually deals with strings,
but we would have to prefix everything with 'b'
b) clunky, because the handling of the bytes objects is sufficiently
different in PY2 and PY3 (e.g. b'a'[0] is a string in PY2, but an
int in PY3).
- using the latin1 codec (which gives an identity transformation for the
first 256 code points of unicode) instead of the custom
bytes_to_string functions. This almost could work, but it was still
slightly different between python 2 and 3, because in PY2 in would
return a unicode object, which would then cause problems when
combined with regular strings if it contained 8-bit chars.
With this in mind, I think the best solution for the time being is to
just coerce everything into the string type as early as possible, and
have things proceed indentically on both python versions. Once we stop
supporting python3, we can revisit the idea of using bytes objects more
prevasively.
Reviewers: davide, zturner, serge-sans-paille
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D58177
llvm-svn: 354106
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
5 files changed, 20 insertions, 16 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteModuleInfo.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteModuleInfo.py index 41205302f3b..ef96b55b90d 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteModuleInfo.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteModuleInfo.py @@ -3,6 +3,7 @@ from __future__ import print_function import gdbremote_testcase import lldbgdbserverutils +from lldbsuite.support import seven from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil @@ -21,7 +22,7 @@ class TestGdbRemoteModuleInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.test_sequence.add_log_lines([ 'read packet: $jModulesInfo:[{"file":"%s","triple":"%s"}]]#00' % ( lldbutil.append_to_process_working_directory(self, "a.out"), - info["triple"].decode('hex')), + seven.unhexlify(info["triple"])), {"direction": "send", "regex": r'^\$\[{(.*)}\]\]#[0-9A-Fa-f]{2}', "capture": {1: "spec"}}, diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py index f5169e7e202..da233392016 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py @@ -10,7 +10,7 @@ gdb remote packet functional areas. For now it contains the initial set of tests implemented. """ -from __future__ import print_function +from __future__ import division, print_function import unittest2 @@ -18,6 +18,7 @@ import gdbremote_testcase import lldbgdbserverutils import platform import signal +from lldbsuite.support import seven from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test.lldbdwarf import * @@ -868,7 +869,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod # Ensure what we read from inferior memory is what we wrote. self.assertIsNotNone(context.get("read_contents")) - read_contents = context.get("read_contents").decode("hex") + read_contents = seven.unhexlify(context.get("read_contents")) self.assertEqual(read_contents, MEMORY_CONTENTS) @debugserver_test @@ -1352,7 +1353,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod message_address = int(context.get("message_address"), 16) # Hex-encode the test message, adding null termination. - hex_encoded_message = TEST_MESSAGE.encode("hex") + hex_encoded_message = seven.hexlify(TEST_MESSAGE) # Write the message to the inferior. Verify that we can read it with the hex-encoded (m) # and binary (x) memory read packets. @@ -1467,7 +1468,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod reg_index = self.select_modifiable_register(reg_infos) self.assertIsNotNone(reg_index) - reg_byte_size = int(reg_infos[reg_index]["bitsize"]) / 8 + reg_byte_size = int(reg_infos[reg_index]["bitsize"]) // 8 self.assertTrue(reg_byte_size > 0) # Run the process a bit so threads can start up, and collect register diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py index d934753c6b3..6b807a0347c 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -2,7 +2,7 @@ Base class for gdb-remote test cases. """ -from __future__ import print_function +from __future__ import division, print_function import errno @@ -20,6 +20,7 @@ import tempfile import time from lldbsuite.test import configuration from lldbsuite.test.lldbtest import * +from lldbsuite.support import seven from lldbgdbserverutils import * import logging @@ -589,7 +590,7 @@ class GdbRemoteTestCaseBase(TestBase): if can_read and sock in can_read: recv_bytes = sock.recv(4096) if recv_bytes: - response += recv_bytes.decode("utf-8") + response += seven.bitcast_to_string(recv_bytes) self.assertTrue(expected_content_regex.match(response)) @@ -1235,7 +1236,7 @@ class GdbRemoteTestCaseBase(TestBase): reg_index = reg_info["lldb_register_index"] self.assertIsNotNone(reg_index) - reg_byte_size = int(reg_info["bitsize"]) / 8 + reg_byte_size = int(reg_info["bitsize"]) // 8 self.assertTrue(reg_byte_size > 0) # Handle thread suffix. @@ -1261,7 +1262,7 @@ class GdbRemoteTestCaseBase(TestBase): endian, p_response) # Flip the value by xoring with all 1s - all_one_bits_raw = "ff" * (int(reg_info["bitsize"]) / 8) + all_one_bits_raw = "ff" * (int(reg_info["bitsize"]) // 8) flipped_bits_int = initial_reg_value ^ int(all_one_bits_raw, 16) # print("reg (index={}, name={}): val={}, flipped bits (int={}, hex={:x})".format(reg_index, reg_info["name"], initial_reg_value, flipped_bits_int, flipped_bits_int)) @@ -1476,8 +1477,8 @@ class GdbRemoteTestCaseBase(TestBase): self.assertIsNotNone(context.get("g_c1_contents")) self.assertIsNotNone(context.get("g_c2_contents")) - return (context.get("g_c1_contents").decode("hex") == expected_g_c1) and ( - context.get("g_c2_contents").decode("hex") == expected_g_c2) + return (seven.unhexlify(context.get("g_c1_contents")) == expected_g_c1) and ( + seven.unhexlify(context.get("g_c2_contents")) == expected_g_c2) def single_step_only_steps_one_instruction( self, use_Hc_packet=True, step_instruction="s"): diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py index b0cf6ec61e8..8dd146ae152 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py @@ -1,7 +1,7 @@ """Module for supporting unit testing of the lldb-server debug monitor exe. """ -from __future__ import print_function +from __future__ import division, print_function import os @@ -412,7 +412,7 @@ def pack_register_hex(endian, value, byte_size=None): value = value >> 8 if byte_size: # Add zero-fill to the right/end (MSB side) of the value. - retval += "00" * (byte_size - len(retval) / 2) + retval += "00" * (byte_size - len(retval) // 2) return retval elif endian == 'big': @@ -422,7 +422,7 @@ def pack_register_hex(endian, value, byte_size=None): value = value >> 8 if byte_size: # Add zero-fill to the left/front (MSB side) of the value. - retval = ("00" * (byte_size - len(retval) / 2)) + retval + retval = ("00" * (byte_size - len(retval) // 2)) + retval return retval else: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py index 6f32dcacd35..958d6449b51 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py @@ -9,6 +9,7 @@ import traceback import codecs from six.moves import queue +from lldbsuite.support import seven def _handle_output_packet_string(packet_contents): @@ -19,7 +20,7 @@ def _handle_output_packet_string(packet_contents): elif packet_contents == "OK": return None else: - return packet_contents[1:].decode("hex") + return seven.unhexlify(packet_contents[1:]) def _dump_queue(the_queue): @@ -174,7 +175,7 @@ class SocketPacketPump(object): can_read, _, _ = select.select([self._socket], [], [], 0) if can_read and self._socket in can_read: try: - new_bytes = self._socket.recv(4096) + new_bytes = seven.bitcast_to_string(self._socket.recv(4096)) if self._logger and new_bytes and len(new_bytes) > 0: self._logger.debug( "pump received bytes: {}".format(new_bytes)) |