diff --git a/lldb/test/api/check_public_api_headers/TestPublicAPIHeaders.py b/lldb/test/api/check_public_api_headers/TestPublicAPIHeaders.py index 0a2c4a1b1d57..46e554f5a39b 100644 --- a/lldb/test/api/check_public_api_headers/TestPublicAPIHeaders.py +++ b/lldb/test/api/check_public_api_headers/TestPublicAPIHeaders.py @@ -3,7 +3,9 @@ There should be nothing unwanted there and a simpe main.cpp which includes SB*.h should compile and link with the LLDB framework.""" -import os, re, StringIO +import lldb_shared + +import os, re import unittest2 from lldbtest import * import lldbutil diff --git a/lldb/test/api/multiple-debuggers/TestMultipleDebuggers.py b/lldb/test/api/multiple-debuggers/TestMultipleDebuggers.py index 1064e37e8a46..369a6b1147e1 100644 --- a/lldb/test/api/multiple-debuggers/TestMultipleDebuggers.py +++ b/lldb/test/api/multiple-debuggers/TestMultipleDebuggers.py @@ -1,6 +1,8 @@ """Test the lldb public C++ api when doing multiple debug sessions simultaneously.""" -import os, re, StringIO +import lldb_shared + +import os, re import unittest2 from lldbtest import * import lldbutil diff --git a/lldb/test/api/multithreaded/TestMultithreaded.py b/lldb/test/api/multithreaded/TestMultithreaded.py index d0cbd8d93d6a..e7be1f342a73 100644 --- a/lldb/test/api/multithreaded/TestMultithreaded.py +++ b/lldb/test/api/multithreaded/TestMultithreaded.py @@ -1,6 +1,8 @@ """Test the lldb public C++ api breakpoint callbacks.""" -import os, re, StringIO +import lldb_shared + +import os, re import unittest2 from lldbtest import * import lldbutil diff --git a/lldb/test/dosep.py b/lldb/test/dosep.py index facd804a3d85..f4133363fb60 100755 --- a/lldb/test/dosep.py +++ b/lldb/test/dosep.py @@ -34,6 +34,8 @@ echo core.%p | sudo tee /proc/sys/kernel/core_pattern from __future__ import print_function +import lldb_shared + # system packages and modules import asyncore import distutils.version @@ -42,12 +44,13 @@ import multiprocessing import multiprocessing.pool import os import platform -import Queue import re import signal import sys import threading +from six.moves import queue + # Add our local test_runner/lib dir to the python path. sys.path.append(os.path.join(os.path.dirname(__file__), "test_runner", "lib")) @@ -336,7 +339,7 @@ def process_dir_worker_multiprocessing( result = process_dir(job[0], job[1], job[2], job[3], inferior_pid_events) result_queue.put(result) - except Queue.Empty: + except queue.Empty: # Fine, we're done. pass @@ -359,7 +362,7 @@ def process_dir_worker_threading(job_queue, result_queue, inferior_pid_events): result = process_dir(job[0], job[1], job[2], job[3], inferior_pid_events) result_queue.put(result) - except Queue.Empty: + except queue.Empty: # Fine, we're done. pass @@ -641,7 +644,7 @@ def handle_ctrl_c(ctrl_c_count, job_queue, workers, inferior_pid_events, try: # Just drain it to stop more work from being started. job_queue.get_nowait() - except Queue.Empty: + except queue.Empty: pass with output_lock: print("Stopped more work from being started.") @@ -834,16 +837,16 @@ def threading_test_runner(num_threads, test_work_items): initialize_global_vars_threading(num_threads, test_work_items) # Create jobs. - job_queue = Queue.Queue() + job_queue = queue.Queue() for test_work_item in test_work_items: job_queue.put(test_work_item) - result_queue = Queue.Queue() + result_queue = queue.Queue() # Create queues for started child pids. Terminating # the threading threads does not terminate the # child processes they spawn. - inferior_pid_events = Queue.Queue() + inferior_pid_events = queue.Queue() # Create workers. We don't use multiprocessing.pool.ThreadedPool # due to challenges with handling ^C keyboard interrupts. diff --git a/lldb/test/dotest_channels.py b/lldb/test/dotest_channels.py index 481ffe13952e..6b6f0be207ee 100644 --- a/lldb/test/dotest_channels.py +++ b/lldb/test/dotest_channels.py @@ -14,10 +14,12 @@ This module provides asyncore channels used within the LLDB test framework. """ +import lldb_shared + import asyncore -import cPickle import socket +from six.moves import cPickle class UnpicklingForwardingReaderChannel(asyncore.dispatcher): """Provides an unpickling, forwarding asyncore dispatch channel reader. diff --git a/lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py b/lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py index f499178c3c26..e6bd49ad2d72 100644 --- a/lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py +++ b/lldb/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py @@ -1,7 +1,6 @@ """ Test that argdumper is a viable launching strategy. """ -import commands import lldb import os import time diff --git a/lldb/test/functionalities/paths/TestPaths.py b/lldb/test/functionalities/paths/TestPaths.py index c581cccc8e70..c9245b03e6bb 100644 --- a/lldb/test/functionalities/paths/TestPaths.py +++ b/lldb/test/functionalities/paths/TestPaths.py @@ -1,7 +1,6 @@ """ Test some lldb command abbreviations. """ -import commands import lldb import os import time diff --git a/lldb/test/functionalities/rerun/TestRerun.py b/lldb/test/functionalities/rerun/TestRerun.py index b1b5465eb42b..1a0430fad683 100644 --- a/lldb/test/functionalities/rerun/TestRerun.py +++ b/lldb/test/functionalities/rerun/TestRerun.py @@ -1,7 +1,6 @@ """ Test that argdumper is a viable launching strategy. """ -import commands import lldb import os import time diff --git a/lldb/test/functionalities/stop-hook/TestStopHookCmd.py b/lldb/test/functionalities/stop-hook/TestStopHookCmd.py index 14017c7a8cf3..df94835e380b 100644 --- a/lldb/test/functionalities/stop-hook/TestStopHookCmd.py +++ b/lldb/test/functionalities/stop-hook/TestStopHookCmd.py @@ -2,9 +2,10 @@ Test lldb target stop-hook command. """ +import lldb_shared + import os import unittest2 -import StringIO import lldb from lldbtest import * import lldbutil diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py index f31012034d6f..1b0a8e011a44 100644 --- a/lldb/test/lldbtest.py +++ b/lldb/test/lldbtest.py @@ -43,7 +43,6 @@ import os.path import re import signal from subprocess import * -import StringIO import time import types import unittest2 @@ -52,11 +51,8 @@ import lldbtest_config import lldbutil from six import add_metaclass - -if sys.version_info.major < 3: - import urlparse -else: - import urllib.parse as urlparse +from six import StringIO as SixStringIO +from six.moves.urllib import parse as urlparse # dosep.py starts lots and lots of dotest instances # This option helps you find if two (or more) dotest instances are using the same @@ -224,15 +220,15 @@ def which(program): return exe_file return None -class recording(StringIO.StringIO): +class recording(SixStringIO): """ A nice little context manager for recording the debugger interactions into our session object. If trace flag is ON, it also emits the interactions into the stderr. """ def __init__(self, test, trace): - """Create a StringIO instance; record the session obj and trace flag.""" - StringIO.StringIO.__init__(self) + """Create a SixStringIO instance; record the session obj and trace flag.""" + SixStringIO.__init__(self) # The test might not have undergone the 'setUp(self)' phase yet, so that # the attribute 'session' might not even exist yet. self.session = getattr(test, "session", None) if test else None @@ -241,7 +237,7 @@ class recording(StringIO.StringIO): def __enter__(self): """ Context management protocol on entry to the body of the with statement. - Just return the StringIO object. + Just return the SixStringIO object. """ return self @@ -249,7 +245,7 @@ class recording(StringIO.StringIO): """ Context management protocol on exit from the body of the with statement. If trace is ON, it emits the recordings into stderr. Always add the - recordings to our session object. And close the StringIO object, too. + recordings to our session object. And close the SixStringIO object, too. """ if self.trace: print(self.getvalue(), file=sys.stderr) diff --git a/lldb/test/lldbutil.py b/lldb/test/lldbutil.py index 80b270de84f7..92cb853bc72d 100644 --- a/lldb/test/lldbutil.py +++ b/lldb/test/lldbutil.py @@ -6,11 +6,14 @@ They can also be useful for general purpose lldb scripting. from __future__ import print_function +import lldb_shared + import lldb import os, sys -import StringIO import re +from six import StringIO as SixStringIO + # =================================================== # Utilities for locating/checking executable programs # =================================================== @@ -41,7 +44,7 @@ def disassemble(target, function_or_symbol): It returns the disassembly content in a string object. """ - buf = StringIO.StringIO() + buf = SixStringIO() insts = function_or_symbol.GetInstructions(target) for i in insts: print(i, file=buf) @@ -670,7 +673,7 @@ def get_stack_frames(thread): def print_stacktrace(thread, string_buffer = False): """Prints a simple stack trace of this thread.""" - output = StringIO.StringIO() if string_buffer else sys.stdout + output = SixStringIO() if string_buffer else sys.stdout target = thread.GetProcess().GetTarget() depth = thread.GetNumFrames() @@ -714,7 +717,7 @@ def print_stacktrace(thread, string_buffer = False): def print_stacktraces(process, string_buffer = False): """Prints the stack traces of all the threads.""" - output = StringIO.StringIO() if string_buffer else sys.stdout + output = SixStringIO() if string_buffer else sys.stdout print("Stack traces for " + str(process), file=output) @@ -786,7 +789,7 @@ def get_args_as_string(frame, showFuncName=True): def print_registers(frame, string_buffer = False): """Prints all the register sets of the frame.""" - output = StringIO.StringIO() if string_buffer else sys.stdout + output = SixStringIO() if string_buffer else sys.stdout print("Register sets for " + str(frame), file=output) @@ -860,7 +863,7 @@ class BasicFormatter(object): """The basic formatter inspects the value object and prints the value.""" def format(self, value, buffer=None, indent=0): if not buffer: - output = StringIO.StringIO() + output = SixStringIO() else: output = buffer # If there is a summary, it suffices. @@ -887,7 +890,7 @@ class ChildVisitingFormatter(BasicFormatter): self.cindent = indent_child def format(self, value, buffer=None): if not buffer: - output = StringIO.StringIO() + output = SixStringIO() else: output = buffer @@ -910,7 +913,7 @@ class RecursiveDecentFormatter(BasicFormatter): self.cindent = indent_child def format(self, value, buffer=None): if not buffer: - output = StringIO.StringIO() + output = SixStringIO() else: output = buffer diff --git a/lldb/test/python_api/frame/TestFrames.py b/lldb/test/python_api/frame/TestFrames.py index 651921128c9a..42fa8b9d1f43 100644 --- a/lldb/test/python_api/frame/TestFrames.py +++ b/lldb/test/python_api/frame/TestFrames.py @@ -3,6 +3,8 @@ Use lldb Python SBFrame API to get the argument values of the call stacks. And other SBFrame API tests. """ +import lldb_shared + import os, time import re import unittest2 @@ -42,8 +44,8 @@ class FrameAPITestCase(TestBase): # depth of 3 of the 'c' leaf function. callsOfA = 0 - import StringIO - session = StringIO.StringIO() + from six import StringIO as SixStringIO + session = SixStringIO() while process.GetState() == lldb.eStateStopped: thread = process.GetThreadAtIndex(0) # Inspect at most 3 frames. diff --git a/lldb/test/test_results.py b/lldb/test/test_results.py index 88715df0dc83..e42496fd487e 100644 --- a/lldb/test/test_results.py +++ b/lldb/test/test_results.py @@ -8,8 +8,9 @@ Provides classes used by the test results reporting infrastructure within the LLDB test suite. """ +import lldb_shared + import argparse -import cPickle import inspect import os import pprint @@ -20,6 +21,8 @@ import time import traceback import xml.sax.saxutils +from six.moves import cPickle + class EventBuilder(object): """Helper class to build test result event dictionaries.""" diff --git a/lldb/test/tools/lldb-server/lldbgdbserverutils.py b/lldb/test/tools/lldb-server/lldbgdbserverutils.py index 05ffd0f0a121..1d4f40dd4d63 100644 --- a/lldb/test/tools/lldb-server/lldbgdbserverutils.py +++ b/lldb/test/tools/lldb-server/lldbgdbserverutils.py @@ -1,16 +1,19 @@ """Module for supporting unit testing of the lldb-server debug monitor exe. """ +import lldb_shared + import os import os.path import platform -import Queue import re import socket_packet_pump import subprocess import time from lldbtest import * +from six.moves import queue + def _get_debug_monitor_from_lldb(lldb_exe, debug_monitor_basename): """Return the debug monitor exe path given the lldb exe path. @@ -215,14 +218,14 @@ def expect_lldb_gdbserver_replay( try: # Grab next entry from the output queue. content = pump.output_queue().get(True, timeout_seconds) - except Queue.Empty: + except queue.Empty: if logger: logger.warning("timeout waiting for stub output (accumulated output:{})".format(pump.get_accumulated_output())) raise Exception("timed out while waiting for output match (accumulated output: {})".format(pump.get_accumulated_output())) else: try: content = pump.packet_queue().get(True, timeout_seconds) - except Queue.Empty: + except queue.Empty: if logger: logger.warning("timeout waiting for packet match (receive buffer: {})".format(pump.get_receive_buffer())) raise Exception("timed out while waiting for packet match (receive buffer: {})".format(pump.get_receive_buffer())) diff --git a/lldb/test/tools/lldb-server/socket_packet_pump.py b/lldb/test/tools/lldb-server/socket_packet_pump.py index c9848f99d2a2..780ff09b7c58 100644 --- a/lldb/test/tools/lldb-server/socket_packet_pump.py +++ b/lldb/test/tools/lldb-server/socket_packet_pump.py @@ -1,10 +1,14 @@ -import Queue + +import lldb_shared + import re import select import threading import traceback import codecs +from six.moves import queue + def _handle_output_packet_string(packet_contents): if (not packet_contents) or (len(packet_contents) < 1): return None @@ -38,8 +42,8 @@ class SocketPacketPump(object): if not pump_socket: raise Exception("pump_socket cannot be None") - self._output_queue = Queue.Queue() - self._packet_queue = Queue.Queue() + self._output_queue = queue.Queue() + self._packet_queue = queue.Queue() self._thread = None self._stop_thread = False self._socket = pump_socket diff --git a/lldb/test/unittest2/result.py b/lldb/test/unittest2/result.py index 74ff8ee4a4d1..af31fbfd8881 100644 --- a/lldb/test/unittest2/result.py +++ b/lldb/test/unittest2/result.py @@ -1,10 +1,12 @@ """Test result object""" +import lldb_shared + import sys import traceback import unittest -from StringIO import StringIO +from six import StringIO as SixStringIO from unittest2 import util from unittest2.compatibility import wraps @@ -61,8 +63,8 @@ class TestResult(unittest.TestResult): self._mirrorOutput = False if self.buffer: if self._stderr_buffer is None: - self._stderr_buffer = StringIO() - self._stdout_buffer = StringIO() + self._stderr_buffer = SixStringIO() + self._stdout_buffer = SixStringIO() sys.stdout = self._stdout_buffer sys.stderr = self._stderr_buffer