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
+ expected_solibs = [
44
+ "lib_a." + self .platformContext .shlib_extension ,
45
+ "lib_b." + self .platformContext .shlib_extension ,
46
+ "lib_c." + self .platformContext .shlib_extension ,
47
+ "lib_d." + self .platformContext .shlib_extension ,
48
+ ]
49
+
27
50
self .build ()
51
+ self .setup_test (expected_solibs )
52
+
28
53
exe = self .getBuildArtifact ("a.out" )
29
54
self .dbg .SetAsync (False )
30
55
@@ -70,6 +95,8 @@ def test_launch_notifications(self):
70
95
total_modules_added_events = 0
71
96
total_modules_removed_events = 0
72
97
already_loaded_modules = []
98
+ max_solibs_per_event = 0
99
+ max_solib_chunk_per_event = []
73
100
while listener .GetNextEvent (event ):
74
101
if lldb .SBTarget .EventIsTargetEvent (event ):
75
102
if event .GetType () == lldb .SBTarget .eBroadcastBitModulesLoaded :
@@ -91,12 +118,17 @@ def test_launch_notifications(self):
91
118
"{} is already loaded" .format (module ),
92
119
)
93
120
already_loaded_modules .append (module )
94
- if self .TraceOn ():
95
- added_files .append (module .GetFileSpec ().GetFilename ())
121
+ added_files .append (module .GetFileSpec ().GetFilename ())
96
122
if self .TraceOn ():
97
123
# print all of the binaries that have been added
98
124
print ("Loaded files: %s" % (", " .join (added_files )))
99
125
126
+ # We will check the latest biggest chunk of loaded solibs.
127
+ # We expect all of our solibs in the last chunk of loaded modules.
128
+ if solib_count >= max_solibs_per_event :
129
+ max_solib_chunk_per_event = added_files .copy ()
130
+ max_solibs_per_event = solib_count
131
+
100
132
if event .GetType () == lldb .SBTarget .eBroadcastBitModulesUnloaded :
101
133
solib_count = lldb .SBTarget .GetNumModulesFromEvent (event )
102
134
total_modules_removed_events += 1
@@ -115,9 +147,7 @@ def test_launch_notifications(self):
115
147
# binaries in batches. Check that we got back more than 1 solib per event.
116
148
# In practice on Darwin today, we get back two events for a do-nothing c
117
149
# 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 = round (
121
- float (total_solibs_added ) / float (total_modules_added_events )
122
- )
123
- self .assertGreater (avg_solibs_added_per_event , 1 )
150
+ # On Linux we get events for ld.so, [vdso], the binary and then all libraries,
151
+ # but the different configurations could load a different number of .so modules
152
+ # per event.
153
+ self .assertLessEqual (set (expected_solibs ), set (max_solib_chunk_per_event ))
0 commit comments