Skip to content

Commit b3f9fa6

Browse files
committed
Rename timeoutval to DEFAULT_TIMEOUT and adjust the kwargs separator.
1 parent d229f34 commit b3f9fa6

File tree

8 files changed

+81
-86
lines changed

8 files changed

+81
-86
lines changed

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

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -590,33 +590,30 @@ def replay_packets(self, replay_file_path):
590590

591591
def request_attach(
592592
self,
593-
/,
594-
program=None,
595-
pid=None,
596-
waitFor=None,
597-
trace=None,
598-
initCommands=None,
599-
preRunCommands=None,
600-
stopCommands=None,
601-
exitCommands=None,
602-
attachCommands=None,
603-
terminateCommands=None,
604-
coreFile=None,
593+
*,
594+
program: Optional[str] = None,
595+
pid: Optional[int] = None,
596+
waitFor=False,
597+
initCommands: Optional[list[str]] = None,
598+
preRunCommands: Optional[list[str]] = None,
599+
attachCommands: Optional[list[str]] = None,
600+
postRunCommands: Optional[list[str]] = None,
601+
stopCommands: Optional[list[str]] = None,
602+
exitCommands: Optional[list[str]] = None,
603+
terminateCommands: Optional[list[str]] = None,
604+
coreFile: Optional[str] = None,
605605
stopOnAttach=True,
606-
postRunCommands=None,
607-
sourceMap=None,
608-
gdbRemotePort=None,
609-
gdbRemoteHostname=None,
606+
sourceMap: Optional[Union[list[tuple[str, str]], dict[str, str]]] = None,
607+
gdbRemotePort: Optional[int] = None,
608+
gdbRemoteHostname: Optional[str] = None,
610609
):
611610
args_dict = {}
612611
if pid is not None:
613612
args_dict["pid"] = pid
614613
if program is not None:
615614
args_dict["program"] = program
616-
if waitFor is not None:
615+
if waitFor:
617616
args_dict["waitFor"] = waitFor
618-
if trace:
619-
args_dict["trace"] = trace
620617
args_dict["initCommands"] = self.init_commands
621618
if initCommands:
622619
args_dict["initCommands"].extend(initCommands)
@@ -822,33 +819,32 @@ def request_initialize(self, sourceInitFile=False):
822819

823820
def request_launch(
824821
self,
825-
program: Optional[str],
826-
/,
822+
program: str,
823+
*,
827824
args: Optional[list[str]] = None,
828-
cwd=None,
829-
env=None,
825+
cwd: Optional[str] = None,
826+
env: Optional[dict[str, str]] = None,
830827
stopOnEntry=True,
831828
disableASLR=True,
832829
disableSTDIO=False,
833830
shellExpandArguments=False,
834-
trace=False,
835-
initCommands=None,
836-
preRunCommands=None,
837-
stopCommands=None,
838-
exitCommands=None,
839-
terminateCommands=None,
840-
sourcePath=None,
841-
debuggerRoot=None,
842-
launchCommands=None,
843-
sourceMap=None,
844831
runInTerminal=False,
845-
postRunCommands=None,
846832
enableAutoVariableSummaries=False,
847833
displayExtendedBacktrace=False,
848834
enableSyntheticChildDebugging=False,
849-
commandEscapePrefix=None,
850-
customFrameFormat=None,
851-
customThreadFormat=None,
835+
initCommands: Optional[list[str]] = None,
836+
preRunCommands: Optional[list[str]] = None,
837+
launchCommands: Optional[list[str]] = None,
838+
postRunCommands: Optional[list[str]] = None,
839+
stopCommands: Optional[list[str]] = None,
840+
exitCommands: Optional[list[str]] = None,
841+
terminateCommands: Optional[list[str]] = None,
842+
sourceMap: Optional[Union[list[tuple[str, str]], dict[str, str]]] = None,
843+
sourcePath: Optional[str] = None,
844+
debuggerRoot: Optional[str] = None,
845+
commandEscapePrefix: Optional[str] = None,
846+
customFrameFormat: Optional[str] = None,
847+
customThreadFormat: Optional[str] = None,
852848
):
853849
args_dict = {"program": program}
854850
if args:
@@ -863,8 +859,6 @@ def request_launch(
863859
args_dict["disableSTDIO"] = disableSTDIO
864860
if shellExpandArguments:
865861
args_dict["shellExpandArguments"] = shellExpandArguments
866-
if trace:
867-
args_dict["trace"] = trace
868862
args_dict["initCommands"] = self.init_commands
869863
if initCommands:
870864
args_dict["initCommands"].extend(initCommands)
@@ -1271,7 +1265,7 @@ def __init__(
12711265
@classmethod
12721266
def launch(
12731267
cls,
1274-
/,
1268+
*,
12751269
executable: str,
12761270
env: Optional[dict[str, str]] = None,
12771271
log_file: Optional[TextIO] = None,

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

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import time
3+
from typing import Optional
34
import uuid
45

56
import dap_server
@@ -11,10 +12,14 @@
1112
class DAPTestCaseBase(TestBase):
1213
# set timeout based on whether ASAN was enabled or not. Increase
1314
# timeout by a factor of 10 if ASAN is enabled.
14-
timeoutval = 10 * (10 if ("ASAN_OPTIONS" in os.environ) else 1)
15+
DEFAULT_TIMEOUT = 10 * (10 if ("ASAN_OPTIONS" in os.environ) else 1)
1516
NO_DEBUG_INFO_TESTCASE = True
1617

17-
def create_debug_adapter(self, lldbDAPEnv=None, connection=None):
18+
def create_debug_adapter(
19+
self,
20+
lldbDAPEnv: Optional[dict[str, str]] = None,
21+
connection: Optional[str] = None,
22+
):
1823
"""Create the Visual Studio Code debug adapter"""
1924
self.assertTrue(
2025
is_exe(self.lldbDAPExec), "lldb-dap must exist and be executable"
@@ -28,7 +33,11 @@ def create_debug_adapter(self, lldbDAPEnv=None, connection=None):
2833
env=lldbDAPEnv,
2934
)
3035

31-
def build_and_create_debug_adapter(self, lldbDAPEnv=None, dictionary=None):
36+
def build_and_create_debug_adapter(
37+
self,
38+
lldbDAPEnv: Optional[dict[str, str]] = None,
39+
dictionary: Optional[dict] = None,
40+
):
3241
self.build(dictionary=dictionary)
3342
self.create_debug_adapter(lldbDAPEnv)
3443

@@ -78,7 +87,7 @@ def waitUntil(self, condition_callback):
7887
time.sleep(0.5)
7988
return False
8089

81-
def verify_breakpoint_hit(self, breakpoint_ids, timeout=timeoutval):
90+
def verify_breakpoint_hit(self, breakpoint_ids, timeout=DEFAULT_TIMEOUT):
8291
"""Wait for the process we are debugging to stop, and verify we hit
8392
any breakpoint location in the "breakpoint_ids" array.
8493
"breakpoint_ids" should be a list of breakpoint ID strings
@@ -112,7 +121,7 @@ def verify_breakpoint_hit(self, breakpoint_ids, timeout=timeoutval):
112121
return
113122
self.assertTrue(False, f"breakpoint not hit, stopped_events={stopped_events}")
114123

115-
def verify_stop_exception_info(self, expected_description, timeout=timeoutval):
124+
def verify_stop_exception_info(self, expected_description, timeout=DEFAULT_TIMEOUT):
116125
"""Wait for the process we are debugging to stop, and verify the stop
117126
reason is 'exception' and that the description matches
118127
'expected_description'
@@ -267,7 +276,7 @@ def stepIn(
267276
targetId=None,
268277
waitForStop=True,
269278
granularity="statement",
270-
timeout=timeoutval,
279+
timeout=DEFAULT_TIMEOUT,
271280
):
272281
response = self.dap_server.request_stepIn(
273282
threadId=threadId, targetId=targetId, granularity=granularity
@@ -282,40 +291,40 @@ def stepOver(
282291
threadId=None,
283292
waitForStop=True,
284293
granularity="statement",
285-
timeout=timeoutval,
294+
timeout=DEFAULT_TIMEOUT,
286295
):
287296
self.dap_server.request_next(threadId=threadId, granularity=granularity)
288297
if waitForStop:
289298
return self.dap_server.wait_for_stopped(timeout)
290299
return None
291300

292-
def stepOut(self, threadId=None, waitForStop=True, timeout=timeoutval):
301+
def stepOut(self, threadId=None, waitForStop=True, timeout=DEFAULT_TIMEOUT):
293302
self.dap_server.request_stepOut(threadId=threadId)
294303
if waitForStop:
295304
return self.dap_server.wait_for_stopped(timeout)
296305
return None
297306

298-
def verify_continue(self):
307+
def do_continue(self): # `continue` is a keyword.
299308
resp = self.dap_server.request_continue()
300309
self.assertTrue(resp["success"], f"continue request failed: {resp}")
301310

302-
def continue_to_next_stop(self, timeout=timeoutval):
303-
self.verify_continue()
311+
def continue_to_next_stop(self, timeout=DEFAULT_TIMEOUT):
312+
self.do_continue()
304313
return self.dap_server.wait_for_stopped(timeout)
305314

306-
def continue_to_breakpoints(self, breakpoint_ids, timeout=timeoutval):
307-
self.verify_continue()
315+
def continue_to_breakpoints(self, breakpoint_ids, timeout=DEFAULT_TIMEOUT):
316+
self.do_continue()
308317
self.verify_breakpoint_hit(breakpoint_ids, timeout)
309318

310-
def continue_to_exception_breakpoint(self, filter_label, timeout=timeoutval):
311-
self.verify_continue()
319+
def continue_to_exception_breakpoint(self, filter_label, timeout=DEFAULT_TIMEOUT):
320+
self.do_continue()
312321
self.assertTrue(
313322
self.verify_stop_exception_info(filter_label, timeout),
314323
'verify we got "%s"' % (filter_label),
315324
)
316325

317-
def continue_to_exit(self, exitCode=0, timeout=timeoutval):
318-
self.verify_continue()
326+
def continue_to_exit(self, exitCode=0, timeout=DEFAULT_TIMEOUT):
327+
self.do_continue()
319328
stopped_events = self.dap_server.wait_for_stopped(timeout)
320329
self.assertEqual(
321330
len(stopped_events), 1, "stopped_events = {}".format(stopped_events)
@@ -344,14 +353,14 @@ def disassemble(self, threadId=None, frameIndex=None):
344353

345354
def attach(
346355
self,
347-
/,
356+
*,
348357
stopOnAttach=True,
349358
disconnectAutomatically=True,
350359
sourceInitFile=False,
351360
expectFailure=False,
352361
sourceBreakpoints=None,
353362
functionBreakpoints=None,
354-
timeout=timeoutval,
363+
timeout=DEFAULT_TIMEOUT,
355364
**kwargs,
356365
):
357366
"""Build the default Makefile target, create the DAP debug adapter,
@@ -404,14 +413,14 @@ def cleanup():
404413
def launch(
405414
self,
406415
program=None,
407-
/,
416+
*,
408417
sourceInitFile=False,
409418
disconnectAutomatically=True,
410419
sourceBreakpoints=None,
411420
functionBreakpoints=None,
412421
expectFailure=False,
413422
stopOnEntry=True,
414-
timeout=timeoutval,
423+
timeout=DEFAULT_TIMEOUT,
415424
**kwargs,
416425
):
417426
"""Sending launch request to dap"""
@@ -472,8 +481,8 @@ def cleanup():
472481
def build_and_launch(
473482
self,
474483
program,
475-
/,
476-
lldbDAPEnv=None,
484+
*,
485+
lldbDAPEnv: Optional[dict[str, str]] = None,
477486
**kwargs,
478487
):
479488
"""Build the default Makefile target, create the DAP debug adapter,

lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22
Test lldb-dap attach request
33
"""
44

5-
import dap_server
65
from lldbsuite.test.decorators import *
76
from lldbsuite.test.lldbtest import *
87
from lldbsuite.test import lldbutil
98
import lldbdap_testcase
10-
import os
11-
import shutil
129
import subprocess
13-
import tempfile
1410
import threading
1511
import time
1612

1713

1814
def spawn_and_wait(program, delay):
19-
print("spawn_and_wait started...", time.time())
2015
if delay:
2116
time.sleep(delay)
22-
print("starting process... ", time.time())
2317
process = subprocess.Popen(
2418
[program], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
2519
)
@@ -40,7 +34,7 @@ def set_and_hit_breakpoint(self, continueToExit=True):
4034
# accordingly.
4135
timeout_offset = 10
4236
self.continue_to_breakpoints(
43-
breakpoint_ids, timeout=timeout_offset + self.timeoutval
37+
breakpoint_ids, timeout=timeout_offset + self.DEFAULT_TIMEOUT
4438
)
4539
if continueToExit:
4640
self.continue_to_exit()
@@ -165,7 +159,7 @@ def test_commands(self):
165159
# Continue after launch and hit the "pause()" call and stop the target.
166160
# Get output from the console. This should contain both the
167161
# "stopCommands" that were run after we stop.
168-
self.verify_continue()
162+
self.do_continue()
169163
time.sleep(0.5)
170164
self.dap_server.request_pause()
171165
self.dap_server.wait_for_stopped()

lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_pending_request(self):
5151
blocking_seq = self.async_blocking_request(duration=1.0)
5252
# Use a longer timeout to ensure we catch if the request was interrupted
5353
# properly.
54-
pending_seq = self.async_blocking_request(duration=self.timeoutval / 2)
54+
pending_seq = self.async_blocking_request(duration=self.DEFAULT_TIMEOUT / 2)
5555
cancel_seq = self.async_cancel(requestId=pending_seq)
5656

5757
blocking_resp = self.dap_server.recv_packet(filter_type=["response"])
@@ -78,10 +78,10 @@ def test_inflight_request(self):
7878
program = self.getBuildArtifact("a.out")
7979
self.build_and_launch(program, stopOnEntry=True)
8080

81-
blocking_seq = self.async_blocking_request(duration=self.timeoutval / 2)
81+
blocking_seq = self.async_blocking_request(duration=self.DEFAULT_TIMEOUT / 2)
8282
# Wait for the sleep to start to cancel the inflight request.
8383
self.collect_console(
84-
timeout_secs=self.timeoutval,
84+
timeout_secs=self.DEFAULT_TIMEOUT,
8585
pattern="starting sleep",
8686
)
8787
cancel_seq = self.async_cancel(requestId=blocking_seq)

lldb/test/API/tools/lldb-dap/console/TestDAP_console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_diagnositcs(self):
177177
)
178178

179179
diagnostics = self.collect_important(
180-
timeout_secs=self.timeoutval, pattern="minidump file"
180+
timeout_secs=self.DEFAULT_TIMEOUT, pattern="minidump file"
181181
)
182182

183183
self.assertIn(

lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_stopped_description(self):
1616
"""
1717
program = self.getBuildArtifact("a.out")
1818
self.build_and_launch(program)
19-
self.verify_continue()
19+
self.do_continue()
2020

2121
self.assertTrue(self.verify_stop_exception_info("signal SIGABRT"))
2222
exceptionInfo = self.get_exceptionInfo()

0 commit comments

Comments
 (0)