Summary: A lot of our tests do 'self.assertTrue(error.Success()'. The problem with that is that when this fails, it produces a completely useless error message (False is not True) and the most important piece of information -- the actual error message -- is completely hidden. Sometimes we mitigate that by including the error message in the "msg" argument, but this has two additional problems: - as the msg argument is evaluated unconditionally, one needs to be careful to not trigger an exception when the operation was actually successful. - it requires more typing, which means we often don't do it assertSuccess solves these problems by taking the entire SBError object as an argument. If the operation was unsuccessful, it can format a reasonable error message itself. The function still accepts a "msg" argument, which can include any additional context, but this context now does not need to include the error message. To demonstrate usage, I replace a number of existing assertTrue assertions with the new function. As this process is not easily automatable, I have just manually updated a representative sample. In some cases, I did not update the code to use assertSuccess, but I went for even higher-level assertion apis (runCmd, expect_expr), as these are even shorter, and can produce even better failure messages. Reviewers: teemperor, JDevlieghere Subscribers: arphaman, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D82759
101 lines
3.6 KiB
Python
101 lines
3.6 KiB
Python
"""
|
|
Test target commands: target.auto-install-main-executable.
|
|
"""
|
|
|
|
import time
|
|
import gdbremote_testcase
|
|
|
|
from lldbsuite.test.decorators import *
|
|
from lldbsuite.test.lldbtest import *
|
|
from lldbsuite.test import lldbutil
|
|
|
|
|
|
class TestAutoInstallMainExecutable(gdbremote_testcase.GdbRemoteTestCaseBase):
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
@llgs_test
|
|
@no_debug_info_test
|
|
@skipIf(remote=False)
|
|
@expectedFailureAll(hostoslist=["windows"], triple='.*-android')
|
|
def test_target_auto_install_main_executable(self):
|
|
self.build()
|
|
self.init_llgs_test(False)
|
|
|
|
# Manually install the modified binary.
|
|
working_dir = lldb.remote_platform.GetWorkingDirectory()
|
|
src_device = lldb.SBFileSpec(self.getBuildArtifact("a.device.out"))
|
|
dest = lldb.SBFileSpec(os.path.join(working_dir, "a.out"))
|
|
err = lldb.remote_platform.Put(src_device, dest)
|
|
if err.Fail():
|
|
raise RuntimeError(
|
|
"Unable copy '%s' to '%s'.\n>>> %s" %
|
|
(src_device.GetFilename(), working_dir, err.GetCString()))
|
|
|
|
m = re.search("^(.*)://([^/]*):(.*)$", configuration.lldb_platform_url)
|
|
protocol = m.group(1)
|
|
hostname = m.group(2)
|
|
hostport = int(m.group(3))
|
|
listen_url = "*:"+str(hostport+1)
|
|
|
|
commandline_args = [
|
|
"platform",
|
|
"--listen",
|
|
listen_url,
|
|
"--server"
|
|
]
|
|
|
|
self.spawnSubprocess(
|
|
self.debug_monitor_exe,
|
|
commandline_args,
|
|
install_remote=False)
|
|
self.addTearDownHook(self.cleanupSubprocesses)
|
|
|
|
# Wait for the new process gets ready.
|
|
time.sleep(0.1)
|
|
|
|
self.dbg.SetAsync(False)
|
|
|
|
new_platform = lldb.SBPlatform(lldb.remote_platform.GetName())
|
|
self.dbg.SetSelectedPlatform(new_platform)
|
|
|
|
connect_url = "%s://%s:%s" % (protocol, hostname, str(hostport+1))
|
|
|
|
# Test the default setting.
|
|
self.expect("settings show target.auto-install-main-executable",
|
|
substrs=["target.auto-install-main-executable (boolean) = true"],
|
|
msg="Default settings for target.auto-install-main-executable failed.")
|
|
|
|
# Disable the auto install.
|
|
self.runCmd("settings set target.auto-install-main-executable false")
|
|
self.expect("settings show target.auto-install-main-executable",
|
|
substrs=["target.auto-install-main-executable (boolean) = false"])
|
|
|
|
self.runCmd("platform select %s"%configuration.lldb_platform_name)
|
|
self.runCmd("platform connect %s" % (connect_url))
|
|
|
|
# Create the target with the original file.
|
|
self.runCmd("target create --remote-file %s %s "%
|
|
(os.path.join(working_dir,dest.GetFilename()),
|
|
self.getBuildArtifact("a.out")))
|
|
|
|
target = new_debugger.GetSelectedTarget()
|
|
breakpoint = target.BreakpointCreateByName("main")
|
|
|
|
launch_info = lldb.SBLaunchInfo(None)
|
|
error = lldb.SBError()
|
|
process = target.Launch(launch_info, error)
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
|
|
|
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
|
|
self.assertTrue(
|
|
thread.IsValid(),
|
|
"There should be a thread stopped due to breakpoint")
|
|
|
|
frame = thread.GetFrameAtIndex(0)
|
|
self.assertEqual(frame.GetFunction().GetName(), "main")
|
|
|
|
self.expect("target variable build", substrs=['"device"'],
|
|
msg="Magic in the binary is wrong")
|
|
|
|
process.Continue()
|