Files
clang-p2996/lldb/test/API/commands/platform/sdk/TestPlatformSDK.py
Pavel Labath 3ca7b2d03c Reapply "[lldb/test] Automatically find debug servers to test"
This reapplies 7df4eaaa93/D96202, which was reverted due to issues on
windows. These were caused by problems in the computation of the liblldb
directory, which was fixed by D96779.

The original commit message was:
Our test configuration logic assumes that the tests can be run either
with debugserver or with lldb-server. This is not entirely correct,
since lldb server has two "personalities" (platform server and debug
server) and debugserver is only a replacement for the latter.

A consequence of this is that it's not possible to test the platform
behavior of lldb-server on macos, as it is not possible to get a hold of
the lldb-server binary.

One solution to that would be to duplicate the server configuration
logic to be able to specify both executables. However, that seems
excessively redundant.

A well-behaved lldb should be able to find the debug server on its own,
and testing lldb with a different (lldb-|debug)server does not seem very
useful (even in the out-of-tree debugserver setup, we copy the server
into the build tree to make it appear "real").

Therefore, this patch deletes the configuration altogether and changes
the low-level server retrieval functions to be able to both lldb-server
and debugserver paths. They do this by consulting the "support
executable" directory of the lldb under test.

Differential Revision: https://reviews.llvm.org/D96202
2021-02-21 20:47:47 +01:00

117 lines
3.5 KiB
Python

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
from lldbgdbserverutils import get_debugserver_exe
import os
import platform
import shutil
import time
import socket
class PlatformSDKTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
# The port used by debugserver.
PORT = 54637
# The number of attempts.
ATTEMPTS = 10
# Time given to the binary to launch and to debugserver to attach to it for
# every attempt. We'll wait a maximum of 10 times 2 seconds while the
# inferior will wait 10 times 10 seconds.
TIMEOUT = 2
def no_debugserver(self):
if get_debugserver_exe() is None:
return 'no debugserver'
return None
def port_not_available(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if s.connect_ex(('127.0.0.1', self.PORT)) == 0:
return '{} not available'.format(self.PORT)
return None
@no_debug_info_test
@skipUnlessDarwin
@expectedFailureIfFn(no_debugserver)
@expectedFailureIfFn(port_not_available)
def test_macos_sdk(self):
self.build()
exe = self.getBuildArtifact('a.out')
token = self.getBuildArtifact('token')
# Remove the old token.
try:
os.remove(token)
except:
pass
# Create a fake 'SDK' directory.
test_home = os.path.join(self.getBuildDir(), 'fake_home.noindex')
macos_version = platform.mac_ver()[0]
sdk_dir = os.path.join(test_home, 'Library', 'Developer', 'Xcode',
'macOS DeviceSupport', macos_version)
symbols_dir = os.path.join(sdk_dir, 'Symbols')
lldbutil.mkdir_p(symbols_dir)
# Save the current home directory and restore it afterwards.
old_home = os.getenv('HOME')
def cleanup():
if not old_home:
del os.environ['HOME']
else:
os.environ['HOME'] = old_home
self.addTearDownHook(cleanup)
os.environ['HOME'] = test_home
# Launch our test binary.
inferior = self.spawnSubprocess(exe, [token])
pid = inferior.pid
# Wait for the binary to launch.
lldbutil.wait_for_file_on_target(self, token)
# Move the binary into the 'SDK'.
rel_exe_path = os.path.relpath(exe, '/')
exe_sdk_path = os.path.join(symbols_dir, rel_exe_path)
lldbutil.mkdir_p(os.path.dirname(exe_sdk_path))
shutil.move(exe, exe_sdk_path)
# Attach to it with debugserver.
debugserver = get_debugserver_exe()
debugserver_args = [
'localhost:{}'.format(self.PORT), '--attach={}'.format(pid)
]
self.spawnSubprocess(debugserver, debugserver_args)
# Select the platform.
self.expect('platform select remote-macosx', substrs=[sdk_dir])
# Connect to debugserver
interpreter = self.dbg.GetCommandInterpreter()
connected = False
for i in range(self.ATTEMPTS):
result = lldb.SBCommandReturnObject()
interpreter.HandleCommand('gdb-remote {}'.format(self.PORT),
result)
connected = result.Succeeded()
if connected:
break
time.sleep(self.TIMEOUT)
self.assertTrue(connected, "could not connect to debugserver")
# Make sure the image was loaded from the 'SDK'.
self.expect('image list', substrs=[exe_sdk_path])