From: Luca Boccassi <[email protected]> Provides unit tests for new sd-dlopen module. --- modules/sd-dlopen-tests | 19 +++++++++++++++ tests/test-sd-dlopen-disabled.c | 41 +++++++++++++++++++++++++++++++++ tests/test-sd-dlopen.c | 36 +++++++++++++++++++++++++++++ tests/test-sd-dlopen.sh | 21 +++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 modules/sd-dlopen-tests create mode 100644 tests/test-sd-dlopen-disabled.c create mode 100644 tests/test-sd-dlopen.c create mode 100755 tests/test-sd-dlopen.sh
diff --git a/modules/sd-dlopen-tests b/modules/sd-dlopen-tests new file mode 100644 index 0000000000..fdbd652755 --- /dev/null +++ b/modules/sd-dlopen-tests @@ -0,0 +1,19 @@ +Files: +tests/test-sd-dlopen.c +tests/test-sd-dlopen-disabled.c +tests/test-sd-dlopen.sh + +Depends-on: +test-framework-sh + +configure.ac: +AC_CHECK_TOOL([OBJDUMP], [objdump], [false]) +SD_DLOPEN_SUPPORTED=$gl_cv_asm_ifndef_endif_balign +AC_SUBST([SD_DLOPEN_SUPPORTED]) + +Makefile.am: +TESTS_ENVIRONMENT += \ + OBJDUMP='$(OBJDUMP)' \ + SD_DLOPEN_SUPPORTED='$(SD_DLOPEN_SUPPORTED)' +TESTS += test-sd-dlopen test-sd-dlopen-disabled test-sd-dlopen.sh +check_PROGRAMS += test-sd-dlopen test-sd-dlopen-disabled diff --git a/tests/test-sd-dlopen-disabled.c b/tests/test-sd-dlopen-disabled.c new file mode 100644 index 0000000000..a23d3cd6d6 --- /dev/null +++ b/tests/test-sd-dlopen-disabled.c @@ -0,0 +1,41 @@ +/* Test the disabled sd-dlopen macros. + Copyright 2026 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +#undef HAVE_ASM_IFNDEF_ENDIF_BALIGN + +#include "sd-dlopen.h" + +#ifdef _SD_ELF_NOTE_DLOPEN +# error "sd-dlopen implementation enabled without assembler support" +#endif + +SD_ELF_NOTE_DLOPEN ("test", + "Test optional dependency", + SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, + "libtest.so.1"); + +int +main (void) +{ + SD_ELF_NOTE_DLOPEN_ANCHORED (test_required, + "test", + "Test required dependency", + SD_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED, + "libtest.so.1"); + return 0; +} diff --git a/tests/test-sd-dlopen.c b/tests/test-sd-dlopen.c new file mode 100644 index 0000000000..1faaa36c2c --- /dev/null +++ b/tests/test-sd-dlopen.c @@ -0,0 +1,36 @@ +/* Test of sd-dlopen module. + Copyright 2026 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +#include "sd-dlopen.h" + +SD_ELF_NOTE_DLOPEN ("test", + "Test optional dependency", + SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, + "libtest.so.1"); + +int +main (void) +{ + SD_ELF_NOTE_DLOPEN_ANCHORED (test_required, + "test", + "Test required dependency", + SD_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED, + "libtest.so.1"); + + return SD_ELF_NOTE_DLOPEN_TYPE != 0x407c0c0a; +} diff --git a/tests/test-sd-dlopen.sh b/tests/test-sd-dlopen.sh new file mode 100755 index 0000000000..36dd3baae2 --- /dev/null +++ b/tests/test-sd-dlopen.sh @@ -0,0 +1,21 @@ +#!/bin/sh +. "${srcdir=.}/init.sh" + +test "$SD_DLOPEN_SUPPORTED" = yes \ + || skip_ ".note.dlopen is not supported" +test "$OBJDUMP" != false \ + || skip_ "objdump is not available" + +program="$initial_cwd_/test-sd-dlopen${EXEEXT}" +LC_ALL=C "$OBJDUMP" -h "$program" > sections \ + || skip_ "objdump cannot read the test executable" +grep '[.]note[.]dlopen' sections > /dev/null \ + || fail_ ".note.dlopen section is missing" + +LC_ALL=C "$OBJDUMP" -s -j .note.dlopen "$program" > contents \ + || fail_ "cannot dump the .note.dlopen section" +vendor_count=$(grep -c '46444f00' contents) +test "$vendor_count" = 2 \ + || fail_ "expected two FDO dlopen notes, found $vendor_count" + +Exit 0 -- 2.47.3
