ltmain.in: Use func_warning for all warnings
[libtool.git] / tests / resident.at
blob392bb4578772268a7707734fb82cc80e402ec897
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.
22 ####
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])
30 AT_DATA([main.c],
31 [[#include <ltdl.h>
32 #include <stdio.h>
34 int
35 main (int argc, char* argv[])
37   int err = 0;
38   lt_dlhandle plugin_handle;
39   lt_dladvise advise;
41   LTDL_SET_PRELOADED_SYMBOLS();
43   if (argc < 2)
44     {
45       fprintf (stderr, "usage: %s plugin\n", argv[0]);
46       return 1;
47     }
49   lt_dlinit ();
50   if (lt_dladvise_init (&advise) != 0
51       || lt_dladvise_ext (&advise) != 0
52       || lt_dladvise_resident (&advise) != 0)
53     {
54       printf ("advise failure: %s\n", lt_dlerror ());
55       err = 1;
56     }
57   else
58     {
59       plugin_handle = lt_dlopenadvise (argv[1], advise);
60       if (NULL != plugin_handle)
61         {
62           int (*pf) (void);
63           printf ("plugin opened successfully!\n");
64           pf = (int (*) (void)) lt_dlsym (plugin_handle, "setup_plugin");
65           if (pf)
66             pf ();
67           else
68             {
69               printf ("dlsym failure: %s\n", lt_dlerror ());
70               err = 1;
71             }
72           if (!lt_dlisresident (plugin_handle))
73             {
74               printf ("module wrongly not marked resident\n");
75               err = 1;
76             }
77           if (lt_dlclose (plugin_handle) != 0)
78             {
79               printf ("close failure (expected): %s\n", lt_dlerror ());
80             }
81           else
82             {
83               printf ("wrongly closed resident module\n");
84               err = 1;
85             }
86         }
87       else
88         {
89           printf ("plugin failed to open: %s\n", lt_dlerror ());
90           err = 1;
91         }
92       if (lt_dladvise_destroy (&advise) != 0)
93         {
94           printf ("advise destroy failure: %s\n", lt_dlerror ());
95           err = 1;
96         }
97     }
98   lt_dlexit ();
99   return err;
103 AT_DATA([plugin.c],
104 [[#include <stdlib.h>
105 #include <stdio.h>
107 void
108 bye (void)
110   puts ("called from atexit handler");
113 #ifdef __cplusplus
114 extern "C"
115 #endif
117 setup_plugin (void)
119   atexit (bye);
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) ;;
130 esac], [], [ignore])
132 CPPFLAGS="$LTDLINCL $CPPFLAGS"
133 LDFLAGS="$LDFLAGS -no-undefined"
134 inst=`pwd`/inst
135 libdir=$inst/lib
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])
148 AT_CLEANUP