Skip to content

Commit

Permalink
Remove Python 2 checks from the test suite
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JDevlieghere committed Apr 27, 2022
1 parent 9053767 commit 0e9af88
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 96 deletions.
31 changes: 11 additions & 20 deletions lldb/test/API/functionalities/step_scripted/TestStepScripted.py
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())

Expand All @@ -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)
Expand All @@ -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)





10 changes: 0 additions & 10 deletions lldb/test/API/lldbtest.py
Expand Up @@ -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 different 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:
Expand Down
10 changes: 3 additions & 7 deletions lldb/test/API/macosx/nslog/TestDarwinNSLogOutput.py
Expand Up @@ -10,6 +10,7 @@
import lldb
import platform
import re
import sys

from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
Expand Down Expand Up @@ -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.
Expand Down
Expand Up @@ -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])

Expand Down
58 changes: 14 additions & 44 deletions lldb/test/API/python_api/file_handle/TestFileHandle.py
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 2 additions & 5 deletions lldb/test/API/terminal/TestSTTYBeforeAndAfter.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0e9af88

Please sign in to comment.