1 # loadlibrary.at -- test loadlibrary functionality -*- Autotest -*-
3 # Copyright (C) 2010 Free Software Foundation, Inc.
4 # This file is part of GNU Libtool.
6 # GNU Libtool is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
11 # GNU Libtool is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Libtool; see the file COPYING. If not, a copy
18 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
19 # or obtained by writing to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 AT_SETUP([loadlibrary error messages])
24 AT_KEYWORDS([libltdl])
26 eval "`$LIBTOOL --config | $EGREP '^(objdir)='`"
33 standard_error_message(const char *error)
37 for (error_number = 0; error_number < LT_ERROR_MAX; ++error_number)
39 lt_dlseterror (error_number);
40 if (error == lt_dlerror ())
46 lt_dlseterror (LT_ERROR_UNKNOWN);
51 main (int argc, char* argv[])
54 lt_dlhandle module = NULL;
55 const lt_dlvtable *loadlibrary;
56 const lt_dlvtable *preopen;
57 lt_dlloader loader = NULL;
59 const lt_dlvtable *vtable;
65 fprintf (stderr, "usage: %s plugin [symbol]\n", argv[0]);
71 loadlibrary = lt_dlloader_find ("lt_loadlibrary");
74 /* Skip if the loadlibrary loader isn't supported */
75 printf ("loadlibrary loader not found\n");
80 preopen = lt_dlloader_find ("lt_preopen");
83 printf ("preopen loader not found\n");
88 /* Remove all loaders except the preopen and loadlibrary loaders. */
89 while (next = lt_dlloader_next (loader))
91 if (lt_dlloader_get (next) == loadlibrary)
97 if (lt_dlloader_get (next) == preopen)
103 lt_dlloader_remove (lt_dlloader_get (next)->name);
106 module = lt_dlopen (argv[1]);
107 error = lt_dlerror ();
111 printf ("lt_dlopen: success!\n");
115 /* But failure was the desired result... */
116 printf ("expected failure\n");
123 /* Didn't expect failure... */
124 printf ("lt_dlopen: failure: %s\n", error);
128 else if (standard_error_message (error))
130 /* Expected custom error message... */
131 printf ("lt_dlopen: standard error (bad): %s\n", error);
137 printf ("lt_dlopen: custom error (good): %s\n", error);
141 symbol = lt_dlsym (module, argv[2]);
142 error = lt_dlerror ();
146 printf ("lt_dlsym: success!\n");
148 else if (standard_error_message (error))
150 /* Expected custom failure message... */
151 printf ("lt_dlsym: standard error (bad): %s\n", error);
156 printf ("lt_dlsym: custom error (good): %s\n", error);
212 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
213 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
215 # Skip this test when called from:
216 # make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
217 AT_CHECK([case $LIBLTDL in #(
218 */_inst/lib/*) test -f $LIBLTDL || (exit 77) ;;
221 CPPFLAGS="$LTDLINCL $CPPFLAGS"
225 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c main.c], [], [ignore], [ignore])
226 for file in foomod.c bardep.c barmod.c; do
227 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file],
228 [], [ignore], [ignore])
230 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o foomod.la ]dnl
231 [-rpath $libdir -module -avoid-version -no-undefined ]dnl
233 [], [ignore], [ignore])
234 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libbardep.la ]dnl
235 [-rpath $libdir -avoid-version -no-undefined ]dnl
237 [], [ignore], [ignore])
238 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o barmod.la ]dnl
239 [-rpath $libdir -module -avoid-version -no-undefined ]dnl
240 [barmod.lo ./libbardep.la],
241 [], [ignore], [ignore])
243 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT ]dnl
244 [main.$OBJEXT $LIBLTDL],
245 [], [ignore], [ignore])
248 AT_CHECK([test -n "$dlname" || (exit 77)])
250 LT_AT_EXEC_CHECK([./main], [], [ignore], [ignore], [./foomod.la no_symbol])
252 # chmod -x doesn't appear to work in MSYS, and Wine can load no-exec dlls.
253 dnl chmod -x $objdir/$dlname
254 dnl LT_AT_EXEC_CHECK([./main], [], [ignore], [ignore], [./foomod.la])
256 rm -f $objdir/$dlname
257 LT_AT_EXEC_CHECK([./main], [], [ignore], [ignore], [./foomod.la])
259 LT_AT_EXEC_CHECK([./main], [], [ignore], [ignore], [./barmod.la no_symbol])
262 # chmod -x doesn't appear to work in MSYS, and Wine can load no-exec dlls.
263 dnl chmod -x $objdir/$dlname
264 dnl LT_AT_EXEC_CHECK([./main], [], [ignore], [ignore], [./barmod.la])
266 rm -f $objdir/$dlname
267 LT_AT_EXEC_CHECK([./main], [], [ignore], [ignore], [./barmod.la])