Skip to content

Commit 389e425

Browse files
committed
Adding helpers to the module event test to improve readability.
1 parent 565bfd7 commit 389e425

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

lldb/test/API/tools/lldb-dap/module-event/TestDAP_module_event.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,51 @@
88

99

1010
class TestDAP_module_event(lldbdap_testcase.DAPTestCaseBase):
11+
def lookup_module_id(self, name):
12+
"""Returns the identifier for the first module event starting with the given name."""
13+
for event in self.dap_server.module_events:
14+
if self.get_dict_value(event, ["body", "module", "name"]).startswith(name):
15+
return self.get_dict_value(event, ["body", "module", "id"])
16+
self.fail(f"No module events matching name={name}")
17+
18+
def module_events(self, id):
19+
"""Finds all module events by identifier."""
20+
return [
21+
event
22+
for event in self.dap_server.module_events
23+
if self.get_dict_value(event, ["body", "module", "id"]) == id
24+
]
25+
26+
def module_reasons(self, events):
27+
"""Returns the list of 'reason' values from the given events."""
28+
return [event["body"]["reason"] for event in events]
29+
1130
@skipIfWindows
1231
def test_module_event(self):
32+
"""
33+
Test that module events are fired on target load and when the list of
34+
dynamic libraries updates while running.
35+
"""
1336
program = self.getBuildArtifact("a.out")
1437
self.build_and_launch(program)
38+
# We can analyze the order of events after the process exits.
1539
self.continue_to_exit()
1640

17-
# Module 'remove' events will only contain the 'id' not the 'name',
18-
# first lookup the module id to find all the events.
19-
a_out_id = next(
20-
e
21-
for e in self.dap_server.module_events
22-
if e["body"]["module"]["name"] == "a.out"
23-
)["body"]["module"]["id"]
24-
a_out_events = [
25-
e
26-
for e in self.dap_server.module_events
27-
if e["body"]["module"]["id"] == a_out_id
28-
]
41+
a_out_id = self.lookup_module_id("a.out")
42+
a_out_events = self.module_events(id=a_out_id)
2943

3044
self.assertIn(
3145
"new",
32-
[e["body"]["reason"] for e in a_out_events],
46+
self.module_reasons(a_out_events),
3347
"Expected a.out to load during the debug session.",
3448
)
3549

36-
libother_id = next(
37-
e
38-
for e in self.dap_server.module_events
39-
if e["body"]["module"]["name"].startswith("libother.")
40-
)["body"]["module"]["id"]
41-
libother_events = [
42-
e
43-
for e in self.dap_server.module_events
44-
if e["body"]["module"]["id"] == libother_id
45-
]
46-
47-
self.assertTrue(libother_events, "Expected libother to produce module events.")
50+
libother_id = self.lookup_module_id(
51+
"libother." # libother.so or libother.dylib based on OS.
52+
)
53+
libother_events = self.module_events(id=libother_id)
4854
self.assertEqual(
49-
[e["body"]["reason"] for e in libother_events],
55+
self.module_reasons(libother_events),
5056
["new", "removed"],
5157
"Expected libother to be loaded then unloaded during the debug session.",
5258
)

0 commit comments

Comments
 (0)