|
8 | 8 |
|
9 | 9 |
|
10 | 10 | 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 | + |
11 | 30 | @skipIfWindows |
12 | 31 | 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 | + """ |
13 | 36 | program = self.getBuildArtifact("a.out") |
14 | 37 | self.build_and_launch(program) |
| 38 | + # We can analyze the order of events after the process exits. |
15 | 39 | self.continue_to_exit() |
16 | 40 |
|
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) |
29 | 43 |
|
30 | 44 | self.assertIn( |
31 | 45 | "new", |
32 | | - [e["body"]["reason"] for e in a_out_events], |
| 46 | + self.module_reasons(a_out_events), |
33 | 47 | "Expected a.out to load during the debug session.", |
34 | 48 | ) |
35 | 49 |
|
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) |
48 | 54 | self.assertEqual( |
49 | | - [e["body"]["reason"] for e in libother_events], |
| 55 | + self.module_reasons(libother_events), |
50 | 56 | ["new", "removed"], |
51 | 57 | "Expected libother to be loaded then unloaded during the debug session.", |
52 | 58 | ) |
0 commit comments