-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[lldb] Fix TestModuleLoadedNotifys API test to work correctly on most of Linux targets #94672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Fix TestModuleLoadedNotifys API test to work correctly on most of Linux targets #94672
Conversation
… of Linux targets. The different build configuration and target Linux system can load a different number of .so libraries (2 and more). As example, Linux x86_64 host shows the following loaded modules: ``` Loaded files: ld-linux-x86-64.so.2 Loaded files: [vdso] Loaded files: a.out Loaded files: libstdc++.so.6, libm.so.6, libgcc_s.so.1, libc.so.6 ``` avg_solibs_added_per_event = 1.75 But Linux Aarch64 (remote target) with statically linked C++ library (clang) shows: ``` Loaded files: ld-2.31.so Loaded files: [vdso] Loaded files: a.out Loaded files: libm.so.6, libc.so.6 ``` avg_solibs_added_per_event = 1.25 Increase precision by 1 digit to fix the test.
@llvm/pr-subscribers-lldb Author: Dmitry Vasilyev (slydiman) ChangesThe different build configuration and target Linux system can load a different number of .so libraries (2 and more). As example, Linux x86_64 host shows the following loaded modules:
avg_solibs_added_per_event = 1.75 But Linux Aarch64 (remote target) with statically linked C++ library (clang) shows:
avg_solibs_added_per_event = 1.25 Increase precision by 1 digit to fix the test. Full diff: https://github.com/llvm/llvm-project/pull/94672.diff 1 Files Affected:
diff --git a/lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py b/lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
index abf761fb3420b..28a1026ae4fcc 100644
--- a/lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
+++ b/lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
@@ -118,6 +118,6 @@ def test_launch_notifications(self):
# On Linux we get events for ld.so, [vdso], the binary and then all libraries.
avg_solibs_added_per_event = round(
- float(total_solibs_added) / float(total_modules_added_events)
+ 10.0 * float(total_solibs_added) / float(total_modules_added_events)
)
- self.assertGreater(avg_solibs_added_per_event, 1)
+ self.assertGreater(avg_solibs_added_per_event, 10)
|
@@ -118,6 +118,6 @@ def test_launch_notifications(self): | |||
# On Linux we get events for ld.so, [vdso], the binary and then all libraries. | |||
|
|||
avg_solibs_added_per_event = round( | |||
float(total_solibs_added) / float(total_modules_added_events) | |||
10.0 * float(total_solibs_added) / float(total_modules_added_events) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't really call it "number of libraries per event" anymore if you multiply by ten. It's more like number of decilibraries/event :P. Maybe you could just remove the round call, and compare to 1.0, but I'm wondering if this is even the right metric for the test. Since what we're trying to check is that we don't send these notifications one by one, I think some check like "number of events with more than one module" or "number of total events" (or both) would be better. @jasonmolenda, what do you think?
Also, this test is very unhermetic in the sense that it depends on the environment to provide enough shared libraries to measure. In the extreme case we could have a totally statically linked binary and zero shared libraries. So, another way to make this test be more resilient is to introduce a couple of shared libraries of our own, so that we can be sure there is something to measure. You could copy the pattern from TestLoadUnload.py to link a bunch of shared libraries to this binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't really call it "number of libraries per event" anymore if you multiply by ten.
I have updated the patch.
Maybe you could just remove the round call, and compare to 1.0
No, because assertGreater() expects int parameters.
Also, this test is very unhermetic
Right, and it seems that the behavior on Darwin is very different. I'd just check min_modules_per_event >= 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, another way to make this test be more resilient is to introduce a couple of shared libraries of our own
The patch is updated this way. Please review. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't really call it "number of libraries per event" anymore if you multiply by ten.
I have updated the patch.
Maybe you could just remove the round call, and compare to 1.0
No, because assertGreater() expects int parameters.
That's strange because assertGreater(47.0001, 47.0000)
works just fine for me. So does assertLessEqual(set(["a", "b"]), set(["a", "b"]))
.
Could it be that you're still running on the version of lldb that has the ancient checked in copy of unittest
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked the documentation for assertGreater() trying to figure out the purpose of round() usage in the original code. But it does not matter anymore, since the patch has been significantly refactored.
✅ With the latest revision this PR passed the C/C++ code formatter. |
0aec72a
to
d7832a1
Compare
d7832a1
to
60671ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff, just a couple of details
ext = "so" | ||
if self.platformIsDarwin(): | ||
ext = "dylib" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to get this as self.platformContext.shlib_extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
int a_init() { return 234; } | ||
|
||
int a_global = a_init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just delete all of this stuff, as it's not relevant for what we're testing. (the a_function
-> b_function
dep is marginally interesting, as it creates a more interesting dependency graph).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
include Makefile.rules | ||
CXX_SOURCES := main.cpp | ||
LD_EXTRAS := -L. -lloadunload_d -lloadunload_c -lloadunload_a -lloadunload_b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename the modules to something else (even a simple liba
is probably fine).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
self.assertGreaterEqual( | ||
len(set(max_solib_chunk_per_event).intersection(expected_solibs)), | ||
len(expected_solibs), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be assertLessEqual(set(expected_solibs), set(max_solib_chunk_per_event))
(with the advantage being that you'd bet a better error message than 3 is not less than 4
when it fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
… of Linux targets (llvm#94672) The different build configuration and target Linux system can load a different number of .so libraries. Add and check own libraries.
The different build configuration and target Linux system can load a different number of .so libraries (2 and more). As example, Linux x86_64 host shows the following loaded modules:
avg_solibs_added_per_event = 1.75
But Linux Aarch64 (remote target) with statically linked C++ library (clang) shows:
avg_solibs_added_per_event = 1.25
Increase precision by 1 digit to fix the test.