Skip to content

[lldb-dap] Test gardening, enabling tests and improving doc comments. #140777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/packages/Python/lldbsuite/test/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
# A plugin whose tests will be enabled, like intel-pt.
enabled_plugins = []

# the build type of lldb
# Typical values include Debug, Release, RelWithDebInfo and MinSizeRel
cmake_build_type = None

def shouldSkipBecauseOfCategories(test_categories):
if use_categories:
Expand Down
13 changes: 13 additions & 0 deletions lldb/packages/Python/lldbsuite/test/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# System modules
from functools import wraps
from typing import Optional
from packaging import version
import ctypes
import locale
Expand Down Expand Up @@ -1102,3 +1103,15 @@ def is_feature_enabled():
return "%s is not supported on this system." % feature

return skipTestIfFn(is_feature_enabled)


def skipIfBuildType(types: list[str]):
"""Skip tests if built in a specific CMAKE_BUILD_TYPE.

Supported types include 'Release', 'RelWithDebInfo', 'Debug', 'MinSizeRel'.
"""
types = [name.lower() for name in types]
return unittest.skipIf(
configuration.cmake_build_type.lower() in types,
"skip on {} build type(s)".format(", ".join(types)),
)
1 change: 1 addition & 0 deletions lldb/packages/Python/lldbsuite/test/dotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def parseOptionsAndInitTestdirs():
configuration.libcxx_include_dir = args.libcxx_include_dir
configuration.libcxx_include_target_dir = args.libcxx_include_target_dir
configuration.libcxx_library_dir = args.libcxx_library_dir
configuration.cmake_build_type = args.cmake_build_type.lower()

if args.channels:
lldbtest_config.channels = args.channels
Expand Down
6 changes: 6 additions & 0 deletions lldb/packages/Python/lldbsuite/test/dotest_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ def create_parser():
metavar="platform-available-ports",
help="Ports available for connection to a lldb server on the remote platform",
)
group.add_argument(
"--cmake-build-type",
dest="cmake_build_type",
metavar="cmake-build-type",
help="Specifies the build type on single-configuration",
)

# Test-suite behaviour
group = parser.add_argument_group("Runtime behaviour options")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def __init__(
self.output: dict[str, list[str]] = {}
self.configuration_done_sent = False
self.initialized = False
self.terminated = False
self.frame_scopes = {}
self.init_commands = init_commands

Expand Down Expand Up @@ -271,6 +272,10 @@ def _handle_recv_packet(self, packet: Optional[ProtocolMessage]) -> bool:
# When a new process is attached or launched, remember the
# details that are available in the body of the event
self.process_event_body = body
elif event == "terminated":
# If we get the 'terminated' event then lldb-dap has exited
# itself.
self.terminated = True
elif event == "exited":
# Process exited, mark the status to indicate the process is not
# alive.
Expand Down Expand Up @@ -388,7 +393,7 @@ def send_recv(self, command):
if response_or_request["command"] == "runInTerminal":
subprocess.Popen(
response_or_request["arguments"]["args"],
env=response_or_request["arguments"]["env"],
env=response_or_request["arguments"].get("env", {}),
)
self.send_packet(
{
Expand Down Expand Up @@ -749,13 +754,11 @@ def request_restart(self, restartArguments=None):
# Caller must still call wait_for_stopped.
return response

def request_disconnect(self, terminateDebuggee=None):
args_dict = {}
if terminateDebuggee is not None:
if terminateDebuggee:
args_dict["terminateDebuggee"] = True
else:
args_dict["terminateDebuggee"] = False
def request_disconnect(self, terminateDebuggee=False, suspendDebuggee=False):
args_dict = {
"terminateDebuggee": terminateDebuggee,
"suspendDebuggee": suspendDebuggee,
}
command_dict = {
"command": "disconnect",
"type": "request",
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ def delete_module_cache(path):
if is_configured("lldb_framework_dir"):
dotest_cmd += ["--framework", config.lldb_framework_dir]

if is_configured("cmake_build_type"):
dotest_cmd += ["--cmake-build-type", config.cmake_build_type]

if "lldb-simulator-ios" in config.available_features:
dotest_cmd += ["--apple-sdk", "iphonesimulator", "--platform-name", "ios-simulator"]
elif "lldb-simulator-watchos" in config.available_features:
Expand Down
1 change: 1 addition & 0 deletions lldb/test/API/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ config.has_libcxx = @LLDB_HAS_LIBCXX@
config.libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
config.libcxx_include_dir = "@LIBCXX_GENERATED_INCLUDE_DIR@"
config.libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
config.cmake_build_type = "@CMAKE_BUILD_TYPE@"
# The API tests use their own module caches.
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-api")
Expand Down
61 changes: 26 additions & 35 deletions lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@
Test lldb-dap "port" configuration to "attach" request
"""

import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
from lldbsuite.test import lldbplatformutil
from lldbgdbserverutils import Pipe
import lldbdap_testcase
import os
import shutil
import subprocess
import tempfile
import threading
import sys
import socket
import lldb


@skip("https://github.com/llvm/llvm-project/issues/138803")
@skip(bugnumber="https://github.com/llvm/llvm-project/issues/138803")
class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase):
default_timeout = 20

def set_and_hit_breakpoint(self, continueToExit=True):
self.dap_server.wait_for_stopped()

Expand Down Expand Up @@ -50,7 +40,7 @@ def get_debug_server_command_line_args(self):
def get_debug_server_pipe(self):
pipe = Pipe(self.getBuildDir())
self.addTearDownHook(lambda: pipe.close())
pipe.finish_connection(self.default_timeout)
pipe.finish_connection(self.DEFAULT_TIMEOUT)
return pipe

@skipIfWindows
Expand All @@ -73,28 +63,33 @@ def test_by_port(self):
)

# Read the port number from the debug server pipe.
port = pipe.read(10, self.default_timeout)
port = pipe.read(10, self.DEFAULT_TIMEOUT)
# Trim null byte, convert to int
port = int(port[:-1])
self.assertIsNotNone(
port, " Failed to read the port number from debug server pipe"
)

self.attach(program=program, gdbRemotePort=port, sourceInitFile=True)
self.attach(
program=program,
gdbRemotePort=port,
sourceInitFile=True,
stopOnEntry=True,
)
self.set_and_hit_breakpoint(continueToExit=True)
self.process.terminate()

@skipIfWindows
@skipIfNetBSD
def test_by_port_and_pid(self):
def test_fails_if_both_port_and_pid_are_set(self):
"""
Tests attaching to a process by process ID and port number.
"""
program = self.build_and_create_debug_adapter_for_attach()

# It is not necessary to launch "lldb-server" to obtain the actual port and pid for attaching.
# However, when providing the port number and pid directly, "lldb-dap" throws an error message, which is expected.
# So, used random pid and port numbers here.
# It is not necessary to launch "lldb-server" to obtain the actual port
# and pid for attaching. However, when providing the port number and pid
# directly, "lldb-dap" throws an error message, which is expected. So,
# used random pid and port numbers here.

pid = 1354
port = 1234
Expand All @@ -106,10 +101,9 @@ def test_by_port_and_pid(self):
sourceInitFile=True,
expectFailure=True,
)
if not (response and response["success"]):
self.assertFalse(
response["success"], "The user can't specify both pid and port"
)
self.assertFalse(
response["success"], "The user can't specify both pid and port"
)

@skipIfWindows
@skipIfNetBSD
Expand All @@ -123,11 +117,10 @@ def test_by_invalid_port(self):
response = self.attach(
program=program, gdbRemotePort=port, sourceInitFile=True, expectFailure=True
)
if not (response and response["success"]):
self.assertFalse(
response["success"],
"The user can't attach with invalid port (%s)" % port,
)
self.assertFalse(
response["success"],
"The user can't attach with invalid port (%s)" % port,
)

@skipIfWindows
@skipIfNetBSD
Expand All @@ -147,9 +140,7 @@ def test_by_illegal_port(self):
response = self.attach(
program=program, gdbRemotePort=port, sourceInitFile=True, expectFailure=True
)
if not (response and response["success"]):
self.assertFalse(
response["success"],
"The user can't attach with illegal port (%s)" % port,
)
self.process.terminate()
self.assertFalse(
response["success"],
"The user can't attach with illegal port (%s)" % port,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import os


@skip("Temporarily disable the breakpoint tests")
class TestDAP_setBreakpoints(lldbdap_testcase.DAPTestCaseBase):
def setUp(self):
lldbdap_testcase.DAPTestCaseBase.setUp(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import lldbdap_testcase


@skip("Temporarily disable the breakpoint tests")
class TestDAP_setExceptionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
@skipIfWindows
def test_functionality(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import lldbdap_testcase


@skip("Temporarily disable the breakpoint tests")
class TestDAP_setFunctionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
@skipIfWindows
def test_set_and_clear(self):
Expand Down
2 changes: 0 additions & 2 deletions lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Test lldb-dap cancel request
"""

import time

from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
import lldbdap_testcase
Expand Down
25 changes: 11 additions & 14 deletions lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
"""
Test lldb-dap setBreakpoints request
Test lldb-dap console output
"""

import dap_server
import lldbdap_testcase
from lldbsuite.test import lldbutil
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *


def get_subprocess(root_process, process_name):
queue = [root_process]
while queue:
process = queue.pop()
if process.name() == process_name:
return process
queue.extend(process.children())

self.assertTrue(False, "No subprocess with name %s found" % process_name)
class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
def get_subprocess(self, root_process, process_name):
queue = [root_process]
while queue:
process = queue.pop()
if process.name() == process_name:
return process
queue.extend(process.children())

self.assertTrue(False, "No subprocess with name %s found" % process_name)

class TestDAP_console(lldbdap_testcase.DAPTestCaseBase):
def check_lldb_command(
self, lldb_command, contains_string, assert_msg, command_escape_prefix="`"
):
Expand Down Expand Up @@ -134,7 +131,7 @@ def test_exit_status_message_sigterm(self):
file=sys.stderr,
)
return
process = get_subprocess(psutil.Process(os.getpid()), process_name)
process = self.get_subprocess(psutil.Process(os.getpid()), process_name)
process.terminate()
process.wait()

Expand Down
2 changes: 0 additions & 2 deletions lldb/test/API/tools/lldb-dap/coreFile/TestDAP_coreFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
Test lldb-dap coreFile attaching
"""

import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import lldbdap_testcase
import os

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TestDAP_setDataBreakpoints(lldbdap_testcase.DAPTestCaseBase):
def setUp(self):
lldbdap_testcase.DAPTestCaseBase.setUp(self)
super().setUp()
self.accessTypes = ["read", "write", "readWrite"]

@skipIfWindows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
"""


import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import lldbdap_testcase
import os

Expand Down
4 changes: 1 addition & 3 deletions lldb/test/API/tools/lldb-dap/disassemble/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ int compare_ints(const void *a, const void *b) {
int arg1 = *(const int *)a;
int arg2 = *(const int *)b;

// breakpoint 1

if (arg1 < arg2)
if (arg1 < arg2) // breakpoint 1
return -1;
if (arg1 > arg2)
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""


import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import re

import lldbdap_testcase
from lldbsuite.test.decorators import skipIfWindows
from lldbsuite.test.lldbtest import line_number
Expand Down
Loading
Loading