[Lldb-commits] [lldb] 0e9af88 - Remove Python 2 checks from the test suite
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 27 08:26:54 PDT 2022
Author: Jonas Devlieghere
Date: 2022-04-27T08:26:26-07:00
New Revision: 0e9af88b7099fa0588661b5b8d5024b2f25f68d8
URL: https://github.com/llvm/llvm-project/commit/0e9af88b7099fa0588661b5b8d5024b2f25f68d8
DIFF: https://github.com/llvm/llvm-project/commit/0e9af88b7099fa0588661b5b8d5024b2f25f68d8.diff
LOG: Remove Python 2 checks from the test suite
We dropped downstream support for Python 2 in the previous release. Now
that we have branched for the next release the window where this kind of
change could introduce conflicts is closing too. Remove Python 2 checks
from the test suite.
Differential revision: https://reviews.llvm.org/D124429
Added:
Modified:
lldb/test/API/functionalities/step_scripted/TestStepScripted.py
lldb/test/API/lldbtest.py
lldb/test/API/macosx/nslog/TestDarwinNSLogOutput.py
lldb/test/API/python_api/disassemble-raw-data/TestDisassemble_VST1_64.py
lldb/test/API/python_api/file_handle/TestFileHandle.py
lldb/test/API/terminal/TestSTTYBeforeAndAfter.py
Removed:
################################################################################
diff --git a/lldb/test/API/functionalities/step_scripted/TestStepScripted.py b/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
index dc4e83fd57a38..fdd00861809d1 100644
--- a/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
+++ b/lldb/test/API/functionalities/step_scripted/TestStepScripted.py
@@ -19,13 +19,13 @@ def setUp(self):
self.runCmd("command script import Steps.py")
def test_standard_step_out(self):
- """Tests stepping with the scripted thread plan laying over a standard
+ """Tests stepping with the scripted thread plan laying over a standard
thread plan for stepping out."""
self.build()
self.step_out_with_scripted_plan("Steps.StepOut")
def test_scripted_step_out(self):
- """Tests stepping with the scripted thread plan laying over an another
+ """Tests stepping with the scripted thread plan laying over an another
scripted thread plan for stepping out."""
self.build()
self.step_out_with_scripted_plan("Steps.StepScripted")
@@ -54,23 +54,23 @@ def test_misspelled_plan_name(self):
stop_id = process.GetStopID()
# Pass a non-existent class for the plan class:
err = thread.StepUsingScriptedThreadPlan("NoSuchModule.NoSuchPlan")
-
+
# Make sure we got a good error:
self.assertTrue(err.Fail(), "We got a failure state")
msg = err.GetCString()
self.assertIn("NoSuchModule.NoSuchPlan", msg, "Mentioned missing class")
-
+
# Make sure we didn't let the process run:
self.assertEqual(stop_id, process.GetStopID(), "Process didn't run")
-
+
def test_checking_variable(self):
"""Test that we can call SBValue API's from a scripted thread plan - using SBAPI's to step"""
self.do_test_checking_variable(False)
-
+
def test_checking_variable_cli(self):
"""Test that we can call SBValue API's from a scripted thread plan - using cli to step"""
self.do_test_checking_variable(True)
-
+
def do_test_checking_variable(self, use_cli):
self.build()
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
@@ -101,7 +101,7 @@ def do_test_checking_variable(self, use_cli):
# We should not have exited:
self.assertEqual(process.GetState(), lldb.eStateStopped, "We are stopped")
-
+
# We should still be in foo:
self.assertEqual("foo", frame.GetFunctionName())
@@ -127,18 +127,14 @@ def run_step(self, stop_others_value, run_mode, token):
print(Steps.StepReportsStopOthers.stop_mode_dict)
value = Steps.StepReportsStopOthers.stop_mode_dict[token]
self.assertEqual(value, stop_others_value, "Stop others has the correct value.")
-
+
def do_test_stop_others(self):
self.build()
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
"Set a breakpoint here",
self.main_source_file)
# First run with stop others false and see that we got that.
- thread_id = ""
- if sys.version_info.major == 2:
- thread_id = str(threading._get_ident())
- else:
- thread_id = str(threading.get_ident())
+ thread_id = str(threading.get_ident())
# all-threads should set stop others to False.
self.run_step(False, "all-threads", thread_id)
@@ -152,13 +148,8 @@ def do_test_stop_others(self):
# The target.process.run-all-threads should override this:
interp = self.dbg.GetCommandInterpreter()
result = lldb.SBCommandReturnObject()
-
+
interp.HandleCommand("settings set target.process.run-all-threads true", result)
self.assertTrue(result.Succeeded, "setting run-all-threads works.")
self.run_step(False, None, thread_id)
-
-
-
-
-
diff --git a/lldb/test/API/lldbtest.py b/lldb/test/API/lldbtest.py
index 6337f3a429a84..7f620c08ef856 100644
--- a/lldb/test/API/lldbtest.py
+++ b/lldb/test/API/lldbtest.py
@@ -74,16 +74,6 @@ def execute(self, test, litConfig):
timeoutInfo = 'Reached timeout of {} seconds'.format(
litConfig.maxIndividualTestTime)
- if sys.version_info.major == 2:
- # In Python 2, string objects can contain Unicode characters. Use
- # the non-strict 'replace' decoding mode. We cannot use the strict
- # mode right now because lldb's StringPrinter facility and the
- # Python utf8 decoder have
diff erent interpretations of which
- # characters are "printable". This leads to Python utf8 decoding
- # exceptions even though lldb is behaving as expected.
- out = out.decode('utf-8', 'replace')
- err = err.decode('utf-8', 'replace')
-
output = """Script:\n--\n%s\n--\nExit Code: %d\n""" % (
' '.join(cmd), exitCode)
if timeoutInfo is not None:
diff --git a/lldb/test/API/macosx/nslog/TestDarwinNSLogOutput.py b/lldb/test/API/macosx/nslog/TestDarwinNSLogOutput.py
index 2ab217d600b31..2878ef1c6a9d7 100644
--- a/lldb/test/API/macosx/nslog/TestDarwinNSLogOutput.py
+++ b/lldb/test/API/macosx/nslog/TestDarwinNSLogOutput.py
@@ -10,6 +10,7 @@
import lldb
import platform
import re
+import sys
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -57,13 +58,8 @@ def run_lldb_to_breakpoint(self, exe, source_file, line,
# So that the child gets torn down after the test.
import pexpect
- import sys
- if sys.version_info.major == 3:
- self.child = pexpect.spawnu('%s %s %s' % (lldbtest_config.lldbExec,
- self.lldbOption, exe))
- else:
- self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec,
- self.lldbOption, exe))
+ self.child = pexpect.spawnu('%s %s %s' % (lldbtest_config.lldbExec,
+ self.lldbOption, exe))
child = self.child
# Turn on logging for what the child sends back.
diff --git a/lldb/test/API/python_api/disassemble-raw-data/TestDisassemble_VST1_64.py b/lldb/test/API/python_api/disassemble-raw-data/TestDisassemble_VST1_64.py
index 27bd64c080472..61f4279e20d66 100644
--- a/lldb/test/API/python_api/disassemble-raw-data/TestDisassemble_VST1_64.py
+++ b/lldb/test/API/python_api/disassemble-raw-data/TestDisassemble_VST1_64.py
@@ -49,19 +49,17 @@ def split(s):
for i in insts:
print("Disassembled %s" % str(i))
- if sys.version_info.major >= 3:
- sio = StringIO()
- insts.Print(sio)
- self.assertEqual(split(assembly), split(sio.getvalue()))
+ sio = StringIO()
+ insts.Print(sio)
+ self.assertEqual(split(assembly), split(sio.getvalue()))
self.assertEqual(insts.GetSize(), len(split(assembly)))
- if sys.version_info.major >= 3:
- for i,asm in enumerate(split(assembly)):
- inst = insts.GetInstructionAtIndex(i)
- sio = StringIO()
- inst.Print(sio)
- self.assertEqual(asm, sio.getvalue().strip())
+ for i,asm in enumerate(split(assembly)):
+ inst = insts.GetInstructionAtIndex(i)
+ sio = StringIO()
+ inst.Print(sio)
+ self.assertEqual(asm, sio.getvalue().strip())
raw_bytes = bytearray([0x04, 0xf9, 0xed, 0x82])
diff --git a/lldb/test/API/python_api/file_handle/TestFileHandle.py b/lldb/test/API/python_api/file_handle/TestFileHandle.py
index 023c1e99c6cef..5f47c31c161a9 100644
--- a/lldb/test/API/python_api/file_handle/TestFileHandle.py
+++ b/lldb/test/API/python_api/file_handle/TestFileHandle.py
@@ -276,7 +276,6 @@ def test_immediate(self):
self.assertTrue(re.search(r'QUUX', output))
- @skipIf(py_version=['<', (3,)])
def test_immediate_string(self):
f = io.StringIO()
ret = lldb.SBCommandReturnObject()
@@ -291,7 +290,6 @@ def test_immediate_string(self):
self.assertTrue(re.search(r'QUUX', output))
- @skipIf(py_version=['<', (3,)])
def test_immediate_sbfile_string(self):
f = io.StringIO()
ret = lldb.SBCommandReturnObject()
@@ -361,7 +359,6 @@ def test_binary_inout(self):
self.assertIn('Show a list of all debugger commands', output)
- @skipIf(py_version=['<', (3,)])
def test_string_inout(self):
inf = io.StringIO("help help\np/x ~0\n")
outf = io.StringIO()
@@ -377,7 +374,6 @@ def test_string_inout(self):
self.assertIn('0xfff', output)
- @skipIf(py_version=['<', (3,)])
def test_bytes_inout(self):
inf = io.BytesIO(b"help help\nhelp b\n")
outf = io.BytesIO()
@@ -447,7 +443,6 @@ def test_sbfile_write_borrowed(self):
- @skipIf(py_version=['<', (3,)])
def test_sbfile_write_forced(self):
with open(self.out_filename, 'w') as f:
written = MutableBool(False)
@@ -467,7 +462,6 @@ def mywrite(x):
self.assertEqual(f.read().strip(), 'FOO')
- @skipIf(py_version=['<', (3,)])
def test_sbfile_write_forced_borrowed(self):
with open(self.out_filename, 'w') as f:
written = MutableBool(False)
@@ -487,7 +481,6 @@ def mywrite(x):
self.assertEqual(f.read().strip(), 'FOO')
- @skipIf(py_version=['<', (3,)])
def test_sbfile_write_string(self):
f = io.StringIO()
sbf = lldb.SBFile(f)
@@ -499,7 +492,6 @@ def test_sbfile_write_string(self):
self.assertTrue(f.closed)
- @skipIf(py_version=['<', (3,)])
def test_string_out(self):
f = io.StringIO()
status = self.dbg.SetOutputFile(f)
@@ -508,7 +500,6 @@ def test_string_out(self):
self.assertEqual(f.getvalue().strip(), "'foobar'")
- @skipIf(py_version=['<', (3,)])
def test_string_error(self):
f = io.StringIO()
status = self.dbg.SetErrorFile(f)
@@ -518,7 +509,6 @@ def test_string_error(self):
self.assertTrue(re.search(r'error:.*lolwut', errors))
- @skipIf(py_version=['<', (3,)])
def test_sbfile_write_bytes(self):
f = io.BytesIO()
sbf = lldb.SBFile(f)
@@ -529,7 +519,6 @@ def test_sbfile_write_bytes(self):
sbf.Close()
self.assertTrue(f.closed)
- @skipIf(py_version=['<', (3,)])
def test_sbfile_read_string(self):
f = io.StringIO('zork')
sbf = lldb.SBFile(f)
@@ -539,7 +528,6 @@ def test_sbfile_read_string(self):
self.assertEqual(buf[:n], b'zork')
- @skipIf(py_version=['<', (3,)])
def test_sbfile_read_string_one_byte(self):
f = io.StringIO('z')
sbf = lldb.SBFile(f)
@@ -550,7 +538,6 @@ def test_sbfile_read_string_one_byte(self):
self.assertEqual(e.GetCString(), "can't read less than 6 bytes from a utf8 text stream")
- @skipIf(py_version=['<', (3,)])
def test_sbfile_read_bytes(self):
f = io.BytesIO(b'zork')
sbf = lldb.SBFile(f)
@@ -560,7 +547,6 @@ def test_sbfile_read_bytes(self):
self.assertEqual(buf[:n], b'zork')
- @skipIf(py_version=['<', (3,)])
def test_sbfile_out(self):
with open(self.out_filename, 'w') as f:
sbf = lldb.SBFile(f)
@@ -571,7 +557,6 @@ def test_sbfile_out(self):
self.assertEqual(f.read().strip(), '4')
- @skipIf(py_version=['<', (3,)])
def test_file_out(self):
with open(self.out_filename, 'w') as f:
status = self.dbg.SetOutputFile(f)
@@ -605,21 +590,17 @@ def test_file_error(self):
def test_exceptions(self):
self.assertRaises(Exception, lldb.SBFile, None)
self.assertRaises(Exception, lldb.SBFile, "ham sandwich")
- if sys.version_info[0] < 3:
- self.assertRaises(Exception, lldb.SBFile, ReallyBadIO())
- else:
- self.assertRaises(OhNoe, lldb.SBFile, ReallyBadIO())
- error, n = lldb.SBFile(BadIO()).Write(b"FOO")
- self.assertEqual(n, 0)
- self.assertTrue(error.Fail())
- self.assertIn('OH NOE', error.GetCString())
- error, n = lldb.SBFile(BadIO()).Read(bytearray(100))
- self.assertEqual(n, 0)
- self.assertTrue(error.Fail())
- self.assertIn('OH NOE', error.GetCString())
-
-
- @skipIf(py_version=['<', (3,)])
+ self.assertRaises(OhNoe, lldb.SBFile, ReallyBadIO())
+ error, n = lldb.SBFile(BadIO()).Write(b"FOO")
+ self.assertEqual(n, 0)
+ self.assertTrue(error.Fail())
+ self.assertIn('OH NOE', error.GetCString())
+ error, n = lldb.SBFile(BadIO()).Read(bytearray(100))
+ self.assertEqual(n, 0)
+ self.assertTrue(error.Fail())
+ self.assertIn('OH NOE', error.GetCString())
+
+
def test_exceptions_logged(self):
messages = list()
self.dbg.SetLoggingCallback(messages.append)
@@ -629,7 +610,6 @@ def test_exceptions_logged(self):
self.assertTrue(any('OH NOE' in msg for msg in messages))
- @skipIf(py_version=['<', (3,)])
def test_flush(self):
flushed = MutableBool(False)
closed = MutableBool(False)
@@ -695,7 +675,6 @@ def test_close(self):
self.assertTrue(re.search(r'ZAP', output))
- @skipIf(py_version=['<', (3,)])
def test_stdout(self):
f = io.StringIO()
status = self.dbg.SetOutputFile(f)
@@ -718,9 +697,7 @@ def test_stdout_file(self):
self.assertEqual(lines, ["foobar"])
- @skipIf(py_version=['<', (3,)])
def test_identity(self):
-
f = io.StringIO()
sbf = lldb.SBFile(f)
self.assertTrue(f is sbf.GetFile())
@@ -810,22 +787,15 @@ def test_set_filehandle_none(self):
self.dbg.SetOutputFileHandle(None, False)
self.dbg.SetErrorFileHandle(None, False)
sbf = self.dbg.GetOutputFile()
- if sys.version_info.major >= 3:
- # python 2 lacks PyFile_FromFd, so GetFile() will
- # have to duplicate the file descriptor and make a FILE*
- # in order to convert a NativeFile it back to a python
- # file.
- self.assertEqual(sbf.GetFile().fileno(), 1)
+ self.assertEqual(sbf.GetFile().fileno(), 1)
sbf = self.dbg.GetErrorFile()
- if sys.version_info.major >= 3:
- self.assertEqual(sbf.GetFile().fileno(), 2)
+ self.assertEqual(sbf.GetFile().fileno(), 2)
with open(self.out_filename, 'r') as f:
status = self.dbg.SetInputFile(f)
self.assertSuccess(status)
self.dbg.SetInputFileHandle(None, False)
sbf = self.dbg.GetInputFile()
- if sys.version_info.major >= 3:
- self.assertEqual(sbf.GetFile().fileno(), 0)
+ self.assertEqual(sbf.GetFile().fileno(), 0)
def test_sbstream(self):
diff --git a/lldb/test/API/terminal/TestSTTYBeforeAndAfter.py b/lldb/test/API/terminal/TestSTTYBeforeAndAfter.py
index 8fdb8b0108067..348cdcb026293 100644
--- a/lldb/test/API/terminal/TestSTTYBeforeAndAfter.py
+++ b/lldb/test/API/terminal/TestSTTYBeforeAndAfter.py
@@ -7,6 +7,7 @@
import lldb
import six
+import sys
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
@@ -41,11 +42,7 @@ def test_stty_dash_a_before_and_afetr_invoking_lldb_command(self):
lldb_prompt = "(lldb) "
# So that the child gets torn down after the test.
- import sys
- if sys.version_info.major == 3:
- self.child = pexpect.spawnu('expect')
- else:
- self.child = pexpect.spawn('expect')
+ self.child = pexpect.spawnu('expect')
child = self.child
child.expect(expect_prompt)
More information about the lldb-commits
mailing list