Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / lt_dlopen.at
1 # lt_dlopen.at -- test libltdl functionality                -*- Autotest -*-
2 #
3 #   Copyright (C) 2009 Free Software Foundation, Inc.
4 #   This file is part of GNU Libtool.
5 #
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.
10 #
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.
15 #
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.
21 ####
22
23 AT_SETUP([lt_dlopen error messages])
24 AT_KEYWORDS([libltdl])
25
26 # The bug is not fixed:
27 AT_XFAIL_IF([:])
28
29 # This test only works if the system allows undefined symbols.
30 eval `$LIBTOOL --config | grep '^allow_undefined_flag='`
31 AT_CHECK([test unsupported != "$allow_undefined_flag" || exit 77])
32
33 AT_DATA([main.c],
34 [[#include <ltdl.h>
35 #include <stdio.h>
36
37 int
38 main (int argc, char* argv[])
39 {
40   int err = 0;
41   lt_dlhandle plugin_handle;
42
43   if (argc < 2)
44     {
45       fprintf (stderr, "usage: %s plugin\n", argv[0]);
46       return 1;
47     }
48
49   lt_dlinit ();
50   plugin_handle = lt_dlopenext (argv[1]);
51   if (NULL != plugin_handle)
52     {
53       printf ("plugin opened successfully!\n");
54       lt_dlclose (plugin_handle);
55     }
56   else
57     {
58       printf ("plugin failed to open: %s\n", lt_dlerror());
59       err = 1;
60     }
61   lt_dlexit ();
62   return err;
63 }
64 ]])
65
66 AT_DATA([good-plugin.c],
67 [[int foo;
68 int *i = &foo;
69 ]])
70
71 AT_DATA([missing-symbol-plugin.c],
72 [[/* On systems that allow undefined symbols, this will compile,
73      but the symbol "foo" won't be found at runtime */
74 extern int foo;
75 int *i = &foo;
76 ]])
77
78 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
79 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
80
81 CPPFLAGS="$LTDLINCL $CPPFLAGS"
82 inst=`pwd`/inst
83 libdir=$inst/lib
84
85 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c main.c], [], [ignore], [ignore])
86 for file in good-plugin.c missing-symbol-plugin.c; do
87   AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file],
88            [], [ignore], [ignore])
89 done
90 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o good-plugin.la -rpath $libdir ]dnl
91          [-module -avoid-version good-plugin.lo], [], [ignore], [ignore])
92 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o missing-symbol-plugin.la -rpath $libdir]dnl
93          [-module -avoid-version missing-symbol-plugin.lo], [], [ignore], [ignore])
94
95 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT ]dnl
96          [-dlopen good-plugin.la -dlopen missing-symbol-plugin.la $LIBLTDL],
97          [], [ignore], [ignore])
98
99 LT_AT_EXEC_CHECK([./main], [], [ignore], [ignore], [./good-plugin.la])
100 LT_AT_EXEC_CHECK([./main], [1], [ignore], [stderr], [./missing-symbol-plugin.la])
101 AT_CHECK([grep 'missing symbol' stderr], [], [ignore])
102
103 AT_CLEANUP