Skip to content

examples/sotest: Check that a library can be opened twice - #3691

Open
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:dlopen-refcount-test
Open

examples/sotest: Check that a library can be opened twice#3691
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:dlopen-refcount-test

Conversation

@casaroli

@casaroli casaroli commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Depends-on: apache/nuttx#19639

Summary

dlopen() of an already loaded library used to fail, so nothing exercised what happens when two callers hold the same object.

This opens the library a second time, checks the same handle comes back, closes one of the two handles and checks the library is still usable through the other.

Testing

Without apache/nuttx#19639 the second dlopen() returns NULL and this test reports it.

Run on lm3s6965-ek under QEMU with CONFIG_EXAMPLES_SOTEST, CONFIG_ELF, CONFIG_LIBC_ELF and CONFIG_LIBC_DLFCN.

Without apache/nuttx#19639:

ERROR: dlopen(/mnt/sotest/romfs/sotest) failed on an already loaded library

With it:

testfunc3: Let's talk again very soon
   caller: Yes, don't be a stranger!
testfunc1: Hello, everyone!
   caller: Yes, don't be a stranger!
module_uninitialize

The repeated testfunc1 is the library still working after one of the two handles was closed, and module_uninitialize is it unloading once the last one went.

dlopen() of an already loaded library used to fail, so nothing exercised
what happens when two callers hold the same object.

Open the library a second time, check the same handle comes back, close
one of the two and check the library is still usable through the other.

Needs the counterpart change in nuttx; without it the second dlopen()
returns NULL and this reports it.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @casaroli :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants