Files
clang-p2996/lldb/test/API/functionalities/jitloader_gdb/TestJITLoaderGDB.py
Jordan Rupprecht 5b386158aa [lldb][test] Switch LLDB API tests from vendored unittest2 to unittest (#79945)
This removes the dependency LLDB API tests have on
lldb/third_party/Python/module/unittest2, and instead uses the standard
one provided by Python.

This does not actually remove the vendored dep yet, nor update the docs.
I'll do both those once this sticks.

Non-trivial changes to call out:
- expected failures (i.e. "bugnumber") don't have a reason anymore, so
those params were removed
- `assertItemsEqual` is now called `assertCountEqual`
- When a test is marked xfail, our copy of unittest2 considers failures
during teardown to be OK, but modern unittest does not. See
TestThreadLocal.py. (Very likely could be a real bug/leak).
- Our copy of unittest2 was patched to print all test results, even ones
that don't happen, e.g. `(5 passes, 0 failures, 1 errors, 0 skipped,
...)`, but standard unittest prints a terser message that omits test
result types that didn't happen, e.g. `OK (skipped=1)`. Our lit
integration parses this stderr and needs to be updated w/ that
expectation.

I tested this w/ `ninja check-lldb-api` on Linux. There's a good chance
non-Linux tests have similar quirks, but I'm not able to uncover those.
2024-02-13 16:19:41 -06:00

111 lines
3.8 KiB
Python

"""Test for the JITLoaderGDB interface"""
import unittest
import os
import lldb
from lldbsuite.test import lldbutil
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
class JITLoaderGDBTestCase(TestBase):
@skipTestIfFn(
lambda: "Skipped because the test crashes the test runner",
bugnumber="llvm.org/pr24702",
)
@unittest.expectedFailure # llvm.org/pr24702
def test_bogus_values(self):
"""Test that we handle inferior misusing the GDB JIT interface"""
self.build()
exe = self.getBuildArtifact("a.out")
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Launch the process, do not stop at entry point.
process = target.LaunchSimple(None, None, self.get_process_working_directory())
self.assertTrue(process, PROCESS_IS_VALID)
# The inferior will now pass bogus values over the interface. Make sure
# we don't crash.
self.assertState(process.GetState(), lldb.eStateExited)
self.assertEqual(process.GetExitStatus(), 0)
def gen_log_file(self):
logfile = self.getBuildArtifact(
"jitintgdb-{}.txt".format(self.getArchitecture())
)
def cleanup():
if os.path.exists(logfile):
os.unlink(logfile)
self.addTearDownHook(cleanup)
return logfile
def test_jit_int_default(self):
self.expect(
"settings show plugin.jit-loader.gdb.enable",
substrs=["plugin.jit-loader.gdb.enable (enum) = default"],
)
@skipIfWindows # This test fails on Windows during C code build
def test_jit_int_on(self):
"""Tests interface with 'enable' settings 'on'"""
self.build()
exe = self.getBuildArtifact("simple")
logfile = self.gen_log_file()
self.runCmd("log enable -f %s lldb jit" % (logfile))
self.runCmd("settings set plugin.jit-loader.gdb.enable on")
def cleanup():
self.runCmd("log disable lldb")
self.runCmd("settings set plugin.jit-loader.gdb.enable default")
self.addTearDownHook(cleanup)
# Launch the process.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
process = target.LaunchSimple(None, None, self.get_process_working_directory())
self.assertTrue(process, PROCESS_IS_VALID)
self.assertState(process.GetState(), lldb.eStateExited)
self.assertEqual(process.GetExitStatus(), 0)
self.assertTrue(os.path.exists(logfile))
logcontent = open(logfile).read()
self.assertIn("SetJITBreakpoint setting JIT breakpoint", logcontent)
@skipIfWindows # This test fails on Windows during C code build
def test_jit_int_off(self):
"""Tests interface with 'enable' settings 'off'"""
self.build()
exe = self.getBuildArtifact("simple")
logfile = self.gen_log_file()
self.runCmd("log enable -f %s lldb jit" % (logfile))
self.runCmd("settings set plugin.jit-loader.gdb.enable off")
def cleanup():
self.runCmd("log disable lldb")
self.runCmd("settings set plugin.jit-loader.gdb.enable default")
self.addTearDownHook(cleanup)
# Launch the process.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
process = target.LaunchSimple(None, None, self.get_process_working_directory())
self.assertTrue(process, PROCESS_IS_VALID)
self.assertState(process.GetState(), lldb.eStateExited)
self.assertEqual(process.GetExitStatus(), 0)
self.assertTrue(os.path.exists(logfile))
logcontent = open(logfile).read()
self.assertNotIn("SetJITBreakpoint setting JIT breakpoint", logcontent)