Skip to content

[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

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

slydiman
Copy link
Contributor

@slydiman slydiman commented Jun 6, 2024

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.

… 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.
@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2024

@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/94672.diff

1 Files Affected:

  • (modified) lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py (+2-2)
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)

@labath labath requested a review from jasonmolenda June 7, 2024 06:50
@@ -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)
Copy link
Collaborator

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.

Copy link
Contributor Author

@slydiman slydiman Jun 7, 2024

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@labath

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@slydiman slydiman requested a review from labath June 8, 2024 08:55
Copy link

github-actions bot commented Jun 8, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@slydiman slydiman force-pushed the fix-lldb-TestModuleLoadedNotifys branch 3 times, most recently from 0aec72a to d7832a1 Compare June 8, 2024 09:15
@slydiman slydiman force-pushed the fix-lldb-TestModuleLoadedNotifys branch from d7832a1 to 60671ec Compare June 8, 2024 09:19
Copy link
Collaborator

@labath labath left a 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

Comment on lines 43 to 45
ext = "so"
if self.platformIsDarwin():
ext = "dylib"
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 3 to 5
int a_init() { return 234; }

int a_global = a_init();
Copy link
Collaborator

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).

Copy link
Contributor Author

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
Copy link
Collaborator

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 157 to 159
self.assertGreaterEqual(
len(set(max_solib_chunk_per_event).intersection(expected_solibs)),
len(expected_solibs),
Copy link
Collaborator

@labath labath Jun 10, 2024

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@slydiman slydiman merged commit 3e39328 into llvm:main Jun 10, 2024
5 checks passed
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Jun 12, 2024
… 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.
@HerrCai0907 HerrCai0907 mentioned this pull request Jun 13, 2024
@slydiman slydiman deleted the fix-lldb-TestModuleLoadedNotifys branch July 25, 2024 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants