9
9
from lldbsuite .test import lldbutil
10
10
11
11
12
+ @skipUnlessPlatform (["linux" ] + lldbplatformutil .getDarwinOSTriples ())
12
13
class ModuleLoadedNotifysTestCase (TestBase ):
13
14
NO_DEBUG_INFO_TESTCASE = True
14
15
15
16
# At least DynamicLoaderDarwin and DynamicLoaderPOSIXDYLD should batch up
16
17
# notifications about newly added/removed libraries. Other DynamicLoaders may
17
18
# not be written this way.
18
- @skipUnlessPlatform (["linux" ] + lldbplatformutil .getDarwinOSTriples ())
19
19
def setUp (self ):
20
20
# Call super's setUp().
21
21
TestBase .setUp (self )
22
22
# Find the line number to break inside main().
23
23
self .line = line_number ("main.cpp" , "// breakpoint" )
24
24
25
+ def setup_test (self , solibs ):
26
+ if lldb .remote_platform :
27
+ path = lldb .remote_platform .GetWorkingDirectory ()
28
+ for f in solibs :
29
+ lldbutil .install_to_target (self , self .getBuildArtifact (f ))
30
+ else :
31
+ path = self .getBuildDir ()
32
+ if self .dylibPath in os .environ :
33
+ sep = self .platformContext .shlib_path_separator
34
+ path = os .environ [self .dylibPath ] + sep + path
35
+ self .runCmd (
36
+ "settings append target.env-vars '{}={}'" .format (self .dylibPath , path )
37
+ )
38
+ self .default_path = path
39
+
25
40
def test_launch_notifications (self ):
26
41
"""Test that lldb broadcasts newly loaded libraries in batches."""
42
+
43
+ ext = "so"
44
+ if self .platformIsDarwin ():
45
+ ext = "dylib"
46
+
47
+ expected_solibs = [
48
+ "libloadunload_a." + ext ,
49
+ "libloadunload_b." + ext ,
50
+ "libloadunload_c." + ext ,
51
+ "libloadunload_d." + ext ,
52
+ ]
53
+
27
54
self .build ()
55
+ self .setup_test (expected_solibs )
56
+
28
57
exe = self .getBuildArtifact ("a.out" )
29
58
self .dbg .SetAsync (False )
30
59
@@ -70,6 +99,8 @@ def test_launch_notifications(self):
70
99
total_modules_added_events = 0
71
100
total_modules_removed_events = 0
72
101
already_loaded_modules = []
102
+ max_solibs_per_event = 0
103
+ max_solib_chunk_per_event = []
73
104
while listener .GetNextEvent (event ):
74
105
if lldb .SBTarget .EventIsTargetEvent (event ):
75
106
if event .GetType () == lldb .SBTarget .eBroadcastBitModulesLoaded :
@@ -91,12 +122,17 @@ def test_launch_notifications(self):
91
122
"{} is already loaded" .format (module ),
92
123
)
93
124
already_loaded_modules .append (module )
94
- if self .TraceOn ():
95
- added_files .append (module .GetFileSpec ().GetFilename ())
125
+ added_files .append (module .GetFileSpec ().GetFilename ())
96
126
if self .TraceOn ():
97
127
# print all of the binaries that have been added
98
128
print ("Loaded files: %s" % (", " .join (added_files )))
99
129
130
+ # We will check the latest biggest chunk of loaded solibs.
131
+ # We expect all of our solibs in the last chunk of loaded modules.
132
+ if solib_count >= max_solibs_per_event :
133
+ max_solib_chunk_per_event = added_files .copy ()
134
+ max_solibs_per_event = solib_count
135
+
100
136
if event .GetType () == lldb .SBTarget .eBroadcastBitModulesUnloaded :
101
137
solib_count = lldb .SBTarget .GetNumModulesFromEvent (event )
102
138
total_modules_removed_events += 1
@@ -115,9 +151,10 @@ def test_launch_notifications(self):
115
151
# binaries in batches. Check that we got back more than 1 solib per event.
116
152
# In practice on Darwin today, we get back two events for a do-nothing c
117
153
# program: a.out and dyld, and then all the rest of the system libraries.
118
- # On Linux we get events for ld.so, [vdso], the binary and then all libraries.
119
-
120
- avg_solibs_added_per_event = float (total_solibs_added ) / float (
121
- total_modules_added_events
154
+ # On Linux we get events for ld.so, [vdso], the binary and then all libraries,
155
+ # but the different configurations could load a different number of .so modules
156
+ # per event.
157
+ self .assertGreaterEqual (
158
+ len (set (max_solib_chunk_per_event ).intersection (expected_solibs )),
159
+ len (expected_solibs ),
122
160
)
123
- self .assertGreater (round (10.0 * avg_solibs_added_per_event ), 10 )
0 commit comments