Skip to content

Commit b185ae3

Browse files
committed
Add api tests
1 parent 3e927b0 commit b185ae3

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,7 @@ def launch(
15281528
env: Optional[dict[str, str]] = None,
15291529
log_file: Optional[TextIO] = None,
15301530
connection: Optional[str] = None,
1531+
connection_timeout: Optional[int] = None,
15311532
) -> tuple[subprocess.Popen, Optional[str]]:
15321533
adapter_env = os.environ.copy()
15331534
if env is not None:
@@ -1541,6 +1542,10 @@ def launch(
15411542
args.append("--connection")
15421543
args.append(connection)
15431544

1545+
if connection_timeout is not None:
1546+
args.append("--connection-timeout")
1547+
args.append(str(connection_timeout))
1548+
15441549
process = subprocess.Popen(
15451550
args,
15461551
stdin=subprocess.PIPE,

lldb/test/API/tools/lldb-dap/server/TestDAP_server.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import signal
77
import tempfile
8+
import time
89

910
import dap_server
1011
from lldbsuite.test.decorators import *
@@ -13,22 +14,28 @@
1314

1415

1516
class TestDAP_server(lldbdap_testcase.DAPTestCaseBase):
16-
def start_server(self, connection):
17+
def start_server(
18+
self, connection, connection_timeout=None, wait_seconds_for_termination=None
19+
):
1720
log_file_path = self.getBuildArtifact("dap.txt")
1821
(process, connection) = dap_server.DebugAdapterServer.launch(
1922
executable=self.lldbDAPExec,
2023
connection=connection,
24+
connection_timeout=connection_timeout,
2125
log_file=log_file_path,
2226
)
2327

2428
def cleanup():
25-
process.terminate()
29+
if wait_seconds_for_termination is not None:
30+
process.wait(wait_seconds_for_termination)
31+
else:
32+
process.terminate()
2633

2734
self.addTearDownHook(cleanup)
2835

2936
return (process, connection)
3037

31-
def run_debug_session(self, connection, name):
38+
def run_debug_session(self, connection, name, sleep_seconds_in_middle=None):
3239
self.dap_server = dap_server.DebugAdapterServer(
3340
connection=connection,
3441
)
@@ -41,6 +48,8 @@ def run_debug_session(self, connection, name):
4148
args=[name],
4249
disconnectAutomatically=False,
4350
)
51+
if sleep_seconds_in_middle is not None:
52+
time.sleep(sleep_seconds_in_middle)
4453
self.set_source_breakpoints(source, [breakpoint_line])
4554
self.continue_to_next_stop()
4655
self.continue_to_exit()
@@ -108,3 +117,47 @@ def test_server_interrupt(self):
108117
self.dap_server.exit_status,
109118
"Process exited before interrupting lldb-dap server",
110119
)
120+
121+
@skipIfWindows
122+
def test_connection_timeout_at_server_start(self):
123+
"""
124+
Test launching lldb-dap in server mode with connection timeout and waiting for it to terminate automatically when no client connects.
125+
"""
126+
self.build()
127+
self.start_server(
128+
connection="listen://localhost:0",
129+
connection_timeout=1,
130+
wait_seconds_for_termination=2,
131+
)
132+
133+
@skipIfWindows
134+
def test_connection_timeout_long_debug_session(self):
135+
"""
136+
Test launching lldb-dap in server mode with connection timeout and terminating the server after the a long debug session.
137+
"""
138+
self.build()
139+
(_, connection) = self.start_server(
140+
connection="listen://localhost:0",
141+
connection_timeout=1,
142+
wait_seconds_for_termination=2,
143+
)
144+
# The connection timeout should not cut off the debug session
145+
self.run_debug_session(connection, "Alice", 1.5)
146+
147+
@skipIfWindows
148+
def test_connection_timeout_multiple_sessions(self):
149+
"""
150+
Test launching lldb-dap in server mode with connection timeout and terminating the server after the last debug session.
151+
"""
152+
self.build()
153+
(_, connection) = self.start_server(
154+
connection="listen://localhost:0",
155+
connection_timeout=1,
156+
wait_seconds_for_termination=2,
157+
)
158+
time.sleep(0.5)
159+
# Should be able to connect to the server.
160+
self.run_debug_session(connection, "Alice")
161+
time.sleep(0.5)
162+
# Should be able to connect to the server, because it's still within the connection timeout.
163+
self.run_debug_session(connection, "Bob")

0 commit comments

Comments
 (0)