diff -ur libdbi-drivers/configure.in libdbi-drivers-with-dlopen-check/configure.in --- libdbi-drivers/configure.in 2010-07-19 14:49:13.000000000 -0700 +++ libdbi-drivers-with-dlopen-check/configure.in 2010-11-29 16:19:12.904052001 -0800 @@ -175,6 +175,8 @@ if test "$ac_libdbi" = "YES"; then LIBADD_LIBDBI="-no-undefined -ldbi" + LIBDBI_TEST="test_libdbi.sh" + AC_SUBST(LIBDBI_TEST) else LIBADD_LIBDBI="-no-undefined" @@ -219,6 +221,9 @@ AC_SUBST(LIBADD_LIBDBI) + LIBDBI_LIBDIR="$ac_dbi_libdir" + AC_SUBST(LIBDBI_LIBDIR) + fi dnl ============================== @@ -246,6 +251,7 @@ tests/Makefile tests/cgreen/Makefile tests/test_dbi.cfg + tests/plugin_settings.sh ]) dnl doc/Makefile diff -Nur libdbi-drivers/tests/Makefile.am libdbi-drivers-with-dlopen-check/tests/Makefile.am --- libdbi-drivers/tests/Makefile.am 2010-09-04 07:23:12.000000000 -0700 +++ libdbi-drivers-with-dlopen-check/tests/Makefile.am 2010-11-29 16:40:49.344052001 -0800 @@ -4,15 +4,21 @@ SUBDIRS = cgreen -TESTS = @MYSQL_TEST@ @PGSQL_TEST@ @SQLITE_TEST@ @SQLITE3_TEST@ @MSQL_TEST@ @ORACLE_TEST@ @FIREBIRD_TEST@ @FREETDS_TEST@ @INGRES_TEST@ @DB2_TEST@ -check_PROGRAMS = test_dbi +TESTS = @MYSQL_TEST@ @PGSQL_TEST@ @SQLITE_TEST@ @SQLITE3_TEST@ @MSQL_TEST@ @ORACLE_TEST@ @FIREBIRD_TEST@ @FREETDS_TEST@ @INGRES_TEST@ @DB2_TEST@ @LIBDBI_TEST@ +check_PROGRAMS = test_dbi test_dbi_dlopen +check_LTLIBRARIES = libtest_dbi_plugin.la test_dbi_SOURCES = test_dbi.c -test_dbi_LDADD = $(top_srcdir)/tests/cgreen/libcgreen.a -L@libdir@ -lm -ldbi +test_dbi_LDADD = $(top_srcdir)/tests/cgreen/libcgreen.a -L@libdir@ -lm @LIBADD_LIBDBI@ +test_dbi_dlopen_SOURCES = test_dbi_dlopen.c +test_dbi_dlopen_LDFLAGS = -ldl +libtest_dbi_plugin_la_SOURCES = test_dbi_plugin.c +libtest_dbi_plugin_la_LIBADD = @LIBADD_LIBDBI@ +libtest_dbi_plugin_la_LDFLAGS = -module -rpath /nowhere INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/include -I$(top_srcdir)/tests/cgreen/include -I@includedir@ CFLAGS = -DDBI_DRIVER_DIR=\"@driverdir@\" -g -AM_CPPFLAGS = -DDBDIR=\"@dbi_dbdir@\" +AM_CPPFLAGS = -DDBDIR=\"@dbi_dbdir@\" @DBI_INCLUDE@ -EXTRA_DIST = test_mysql.sh test_pgsql.sh test_sqlite.sh test_sqlite3.sh test_msql.sh test_oracle.sh test_firebird.sh test_freetds.sh test_ingres.sh test_db2.sh +EXTRA_DIST = test_mysql.sh test_pgsql.sh test_sqlite.sh test_sqlite3.sh test_msql.sh test_oracle.sh test_firebird.sh test_freetds.sh test_ingres.sh test_db2.sh test_libdbi.sh debug: $(MAKE) all CFLAGS="@DEBUG@" diff -Nur libdbi-drivers/tests/plugin_settings.sh.in libdbi-drivers-with-dlopen-check/tests/plugin_settings.sh.in --- libdbi-drivers/tests/plugin_settings.sh.in 1969-12-31 16:00:00.000000000 -0800 +++ libdbi-drivers-with-dlopen-check/tests/plugin_settings.sh.in 2010-11-29 15:46:33.404052001 -0800 @@ -0,0 +1 @@ +LIBDBI_LIBDIR=@LIBDBI_LIBDIR@ diff -Nur libdbi-drivers/tests/test_dbi_dlopen.c libdbi-drivers-with-dlopen-check/tests/test_dbi_dlopen.c --- libdbi-drivers/tests/test_dbi_dlopen.c 1969-12-31 16:00:00.000000000 -0800 +++ libdbi-drivers-with-dlopen-check/tests/test_dbi_dlopen.c 2010-11-29 16:36:51.644052001 -0800 @@ -0,0 +1,78 @@ +/* + test_dbi_dlopen - test program for dlopening and then loading drivers + + Copyright (C) 2010 Canonical, Ltd. All Rights Reserved + Author: Clint Byrum + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 2.1 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 Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with this program. If not, see . +*/ + +#include +#include + +void usage(char *prog); + +void usage(char *prog) +{ + fprintf(stderr, "usage: %s G(for global)|N(for noglobal) /path/to/lib/dbd\n",prog); +} + +int main(int argc, char **argv) +{ + void *handle; + if (argc < 3) + { + usage(argv[0]); + return 1; + } + if (argv[1][0] == 'G') + { + handle = dlopen("./.libs/libtest_dbi_plugin.so", RTLD_NOW|RTLD_GLOBAL); + } + else if (argv[1][0] == 'N') + { + handle = dlopen("./.libs/libtest_dbi_plugin.so", RTLD_NOW); + } else { + usage(argv[0]); + return 1; + } + + if (!handle) + { + printf("Failed to load test_dbi_plugin.so"); + return 1; + } + + int (*init_db)(char *); + char *error; + + //return test_main(argc,argv); + *(void **) (&init_db) = dlsym(handle, "init_db"); + + if ((error = dlerror()) != NULL) { + fprintf(stderr, "%s\n", error); + return 1; + } + + int ndrivers = (*init_db)(argv[2]); + + if (ndrivers < 1) + { + fprintf(stderr, "Either you have no drivers in %s , or there was a problem loading them.\n",argv[2]); + return 1; + } + + fprintf(stdout,"num drivers = %d\n", (*init_db)(argv[2])); + return 0; +} diff -Nur libdbi-drivers/tests/test_dbi_plugin.c libdbi-drivers-with-dlopen-check/tests/test_dbi_plugin.c --- libdbi-drivers/tests/test_dbi_plugin.c 1969-12-31 16:00:00.000000000 -0800 +++ libdbi-drivers-with-dlopen-check/tests/test_dbi_plugin.c 2010-11-29 15:20:23.314052001 -0800 @@ -0,0 +1,27 @@ +/* + test_dbi_plugin - lodable test library that uses drivers + + Copyright (C) 2010 Canonical, Ltd. All Rights Reserved + Author: Clint Byrum + + This library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser Public License as published by + the Free Software Foundation, either version 2.1 of the License, or + (at your option) any later version. + + This library 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 Lesser Public License for more details. + + You should have received a copy of the GNU Lesser Public License + along with this library. If not, see . +*/ +#include + +int init_db(char *dir); + +int init_db(char *dir) +{ + return dbi_initialize(dir); +} diff -Nur libdbi-drivers/tests/test_libdbi.sh libdbi-drivers-with-dlopen-check/tests/test_libdbi.sh --- libdbi-drivers/tests/test_libdbi.sh 1969-12-31 16:00:00.000000000 -0800 +++ libdbi-drivers-with-dlopen-check/tests/test_libdbi.sh 2010-11-29 15:46:46.604052001 -0800 @@ -0,0 +1,27 @@ +#!/bin/sh +# This script calls test_dbi_dlopen which simulates using drivers from +# a plugin that is dlopened. + +homedir=`dirname $0` + +set -e + +rm -rf .plugins +mkdir .plugins + +olddir=`pwd` +cd .. +rootdir=`pwd` +for f in `find drivers -name 'libdbd*.so'` ; do + ln -vs $rootdir/$f $olddir/.plugins +done +cd $olddir + +. $homedir/plugin_settings.sh + +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${LIBDBI_LIBDIR} + +$homedir/test_dbi_dlopen G .plugins +$homedir/test_dbi_dlopen N .plugins || echo Failure is ok. + +rm -rf .plugins