1 # resident.at -- test resident modules -*- Autotest -*-
3 # Copyright (C) 2010-2019, 2021-2024 Free Software Foundation, Inc.
5 # This file is part of GNU Libtool.
7 # GNU Libtool is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of
10 # the License, or (at your option) any later version.
12 # GNU Libtool is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Libtool; see the file COPYING. If not, a copy
19 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
20 # or obtained by writing to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 # Ensure resident modules are not unloaded at program exit:
25 # they need to be able to invoke atexit handlers.
27 AT_SETUP([resident modules])
28 AT_KEYWORDS([libltdl])
35 main (int argc, char* argv[])
38 lt_dlhandle plugin_handle;
41 LTDL_SET_PRELOADED_SYMBOLS();
45 fprintf (stderr, "usage: %s plugin\n", argv[0]);
50 if (lt_dladvise_init (&advise) != 0
51 || lt_dladvise_ext (&advise) != 0
52 || lt_dladvise_resident (&advise) != 0)
54 printf ("advise failure: %s\n", lt_dlerror ());
59 plugin_handle = lt_dlopenadvise (argv[1], advise);
60 if (NULL != plugin_handle)
63 printf ("plugin opened successfully!\n");
64 pf = (int (*) (void)) lt_dlsym (plugin_handle, "setup_plugin");
69 printf ("dlsym failure: %s\n", lt_dlerror ());
72 if (!lt_dlisresident (plugin_handle))
74 printf ("module wrongly not marked resident\n");
77 if (lt_dlclose (plugin_handle) != 0)
79 printf ("close failure (expected): %s\n", lt_dlerror ());
83 printf ("wrongly closed resident module\n");
89 printf ("plugin failed to open: %s\n", lt_dlerror ());
92 if (lt_dladvise_destroy (&advise) != 0)
94 printf ("advise destroy failure: %s\n", lt_dlerror ());
104 [[#include <stdlib.h>
110 puts ("called from atexit handler");
123 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
124 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
126 # Skip this test when called from:
127 # make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
128 AT_CHECK([case $LIBLTDL in #(
129 */_inst/lib/*) test -f "$LIBLTDL" || (exit 77) ;;
132 CPPFLAGS="$LTDLINCL $CPPFLAGS"
133 LDFLAGS="$LDFLAGS -no-undefined"
137 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c main.c], [], [ignore], [ignore])
138 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c plugin.c],
139 [], [ignore], [ignore])
140 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o plugin.la -rpath $libdir ]dnl
141 [-module -avoid-version plugin.lo], [], [ignore], [ignore])
142 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT ]dnl
143 [-dlopen plugin.la $LIBLTDL],
144 [], [ignore], [ignore])
145 LT_AT_EXEC_CHECK([./main], [], [stdout], [ignore], [./plugin.la])
146 AT_CHECK([$GREP 'called from atexit handler' stdout], [], [ignore])