From 34bfccb439053c82df4b0aa81c4c938bad469758 Mon Sep 17 00:00:00 2001 From: Sears Russell Date: Sun, 13 Mar 2005 02:24:01 +0000 Subject: [PATCH] Portability fixes for FreeBSD and Mac OS. Check broke compatibility w/ old versions; added #ifdef so that both versions of check will work. --- benchmarks/berkeleyDB/Makefile.am | 2 +- benchmarks/linearHashNTAWriteRequests.c | 4 +- configure.in | 36 ++++- m4/check.m4 | 9 ++ m4/db.m4 | 186 ++++++++++++++++++++++++ test/Makefile.am | 6 +- test/check_includes.h | 5 + test/dfa/Makefile.am | 4 +- test/lladd/Makefile.am | 6 +- test/lladd/check_operations.c | 2 + 10 files changed, 244 insertions(+), 16 deletions(-) create mode 100644 m4/db.m4 diff --git a/benchmarks/berkeleyDB/Makefile.am b/benchmarks/berkeleyDB/Makefile.am index 43f59b3..e25448b 100644 --- a/benchmarks/berkeleyDB/Makefile.am +++ b/benchmarks/berkeleyDB/Makefile.am @@ -1,3 +1,3 @@ LDADD=-ldb -lpthread -bin_PROGRAMS=transapp bdbRaw bdbHash bdbHashThreaded +bin_PROGRAMS=transapp bdbRaw bdbHash bdbHashThreaded bdbHashWriteRequests AM_CFLAGS=-g diff --git a/benchmarks/linearHashNTAWriteRequests.c b/benchmarks/linearHashNTAWriteRequests.c index 9be0249..aca474e 100644 --- a/benchmarks/linearHashNTAWriteRequests.c +++ b/benchmarks/linearHashNTAWriteRequests.c @@ -102,6 +102,9 @@ static void * go (void * arg_ptr) { ThashInsert(xid, hash, (byte*)&j, sizeof(int), (byte*)&j, sizeof(int)); + Tcommit(xid); // used to be outside of loop! + + gettimeofday(&endtime_tv, NULL); endtime.tv_sec = endtime_tv.tv_sec; @@ -132,7 +135,6 @@ static void * go (void * arg_ptr) { } - Tcommit(xid); /* for(j = k * count; j < (k+1) *(count) ; j++) { int tmp = -100; diff --git a/configure.in b/configure.in index db38a30..fe1d30d 100644 --- a/configure.in +++ b/configure.in @@ -24,10 +24,10 @@ AC_PROG_RANLIB # [have_check="no"]) #AM_CONDITIONAL(HAVE_CHECK, test x"$have_check", "xyes") -AM_PATH_CHECK(,[have_check=true], - AC_MSG_WARN([Check not found; cannot run unit tests!]) - [have_check=false]) -AM_CONDITIONAL(HAVE_CHECK, test x$have_check = xtrue) +#AM_PATH_CHECK(,[have_check=true], +# AC_MSG_WARN([Check not found; cannot run unit tests!]) +# [have_check=false]) +#AM_CONDITIONAL(HAVE_CHECK, test x$have_check = xtrue) ## alas, it won't link if this is put in here.. instead, it's linked in manually in the test directory... @@ -67,10 +67,34 @@ if test "$db_cv_open_o_direct" = "yes"; then AH_TEMPLATE(HAVE_O_DIRECT, [Define to 1 if you have the O_DIRECT flag.]) fi +AC_CONFIG_DB + +AC_CHECK_LIB([check], [suite_create], , AC_MSG_WARN([Check not found; cannot run unit tests!])) + +## This perl script thing is a total hack, but we need to define HAVE_LIBCHECK +## inside of an AM_CONDITIONAL to get conditional compilation to work. +AM_CONDITIONAL(HAVE_LIBCHECK, echo $LIBS | [ +perl -ne 'if($_=~/-lcheck/) + { print qq(Check found, make check will run full test suite. +); exit 0; } else { print qq( +-------------------------------- +Check not found! Most tests will be skipped by make check! + + +-------------------------------- +); exit 1; }']) + +#have_libcheck", "xyes") +#AC_CHECK_LIB([check], +# [suite_create], AC_MSG_WARN([Check not found; cannot run unit tests!] +# have_check=yes, +# AC_MSG_WARN([Check not found; cannot run unit tests!])) +#AM_CONDITIONAL(HAVE_CHECK, test x"$have_check", "xyes") +#AC_CHECK_FUNC([tcase_set_timeout]) +#AM_CONDITIONAL(HAVE_CHECK, test xyes, xyes) AC_CHECK_LIB([m], [sqrt]) -AC_CHECK_LIB([db], [db_open]) AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([confuse], [cfg_set_validate_func]) # Checks for header files. @@ -92,7 +116,7 @@ AC_FUNC_MALLOC AC_FUNC_MEMCMP AC_FUNC_REALLOC AC_FUNC_STAT -AC_CHECK_FUNCS([bzero fdatasync getcwd gettimeofday inet_ntoa localtime_r memmove memset mkdir powl posix_memalign socket sqrt strchr strdup strerror strrchr strstr strtoul]) +AC_CHECK_FUNCS([bzero fdatasync getcwd gettimeofday inet_ntoa localtime_r memmove memset mkdir powl posix_memalign socket sqrt strchr strdup strerror strrchr strstr strtoul tcase_set_timeout]) #AC_CONFIG_LIBMYSQLD diff --git a/m4/check.m4 b/m4/check.m4 index a2e0812..e7bf57b 100644 --- a/m4/check.m4 +++ b/m4/check.m4 @@ -88,6 +88,13 @@ int main () if test "x$no_check" = x ; then AC_MSG_RESULT(yes) +# echo "checking for tcase_set_timeout in check" +# AC_TRY_LINK([#include ], +# [ Suite *s = suite_create("foo"); TCase *tc = tcase_create("bar"); tcase_set_timeout(tc, 0) ], +# [ echo tcase_set_timeout found. ], +# [ echo tcase_set_timeout not found. This is harmless. +# +# ] ifelse([$2], , :, [$2]) else AC_MSG_RESULT(no) @@ -130,4 +137,6 @@ int main () rm -f conf.check-test fi + + ]) diff --git a/m4/db.m4 b/m4/db.m4 new file mode 100644 index 0000000..8a1fd6b --- /dev/null +++ b/m4/db.m4 @@ -0,0 +1,186 @@ +dnl +dnl Autoconf support for finding Berkeley DB +dnl + +AC_DEFUN([AC_DB_HELP], [ +cat <: + +# cd /build_unix +# ../dist/configure --enable-cxx +# make +# make install + +EOF + +]) + +dnl +dnl Main macro for finding a usable db installation +dnl +AC_DEFUN([AC_CONFIG_DB], [ + ac_dbvers='4.3 4.2' + ac_dbdir='yes' + + AC_ARG_WITH(db, + AC_HELP_STRING([--with-db=DIR], + [location of a Berkeley DB installation (default system)]), + ac_dbdir=$withval) + + AC_ARG_WITH(dbver, + AC_HELP_STRING([--with-dbver=VERSION], + Berkeley DB versions to try (default 4.3 or 4.2)), + ac_dbvers=$withval) + + dnl + dnl First make sure we even want it + dnl + if test x$ac_dbdir = xno ; then + DB_ENABLED=0 + else + DB_ENABLED=1 + + dnl + dnl Now check if we have a cached value, and if not, find it. + dnl + if test ! x$dtn_cv_path_db_h = x ; then + echo "checking for Berkeley DB installation... (cached) $dtn_cv_path_db_h/db_cxx.h, $dtn_cv_path_db_lib -l$dtn_cv_lib_db" + else + AC_FIND_DB + fi + + if test ! $dtn_cv_path_db_h = /usr/include ; then + CPPFLAGS="$CPPFLAGS -I$dtn_cv_path_db_h" + fi + + if test ! $dtn_cv_path_db_lib = /usr/lib ; then + LDFLAGS="$LDFLAGS -L$dtn_cv_path_db_lib" + fi + + LIBS="$LIBS -l$dtn_cv_lib_db" + + fi # DB_ENABLED + + AC_SUBST(DB_ENABLED) +]) + +dnl +dnl Find db +dnl +AC_DEFUN([AC_FIND_DB], [ + dtn_cv_path_db_h= + dtn_cv_path_db_lib= + dtn_cv_lib_db= + + ac_save_CPPFLAGS="$CPPFLAGS" + ac_save_LDFLAGS="$LDFLAGS" + ac_save_LIBS="$LIBS" + + AC_LANG_PUSH(C++) + + for ac_dbver in $ac_dbvers ; do + + ac_dbver_major=`echo $ac_dbver | cut -d . -f1` + ac_dbver_minor=`echo $ac_dbver | cut -d . -f2` + + if test ! x"$ac_dbdir" = x"yes" ; then + ac_dbincdirs=$ac_dbdir/include + else + ac_dbincdirs="/usr/include /usr/local/include/db4" + ac_dbincdirs="$ac_dbincdirs /usr/include/db$ac_dbver" + ac_dbincdirs="$ac_dbincdirs /usr/local/BerkeleyDB.$ac_dbver/include" + fi + + if test ! x"$ac_dbdir" = x"yes" ; then + ac_dblibdirs="$ac_dbdir/lib" + else + ac_dblibdirs="/usr/lib /usr/local/lib" + ac_dblibdirs="$ac_dblibdirs /usr/local/BerkeleyDB.$ac_dbver/lib" + fi + + for ac_dbincdir in $ac_dbincdirs; do + CPPFLAGS="$ac_save_CPPFLAGS -I$ac_dbincdir" + LDFLAGS="$ac_save_LDFLAGS" + LIBS="$ac_save_LIBS" + + dnl + dnl First check the version in the header file. If there's a match, + dnl fall through to the other check to make sure it links. + dnl If not, then we can break out of the two inner loops. + dnl + AC_MSG_CHECKING([for Berkeley DB header (version $ac_dbver) in $ac_dbincdir]) + AC_LINK_IFELSE( + AC_LANG_PROGRAM( + [ + #include + + #if (DB_VERSION_MAJOR != ${ac_dbver_major}) || \ + (DB_VERSION_MINOR != ${ac_dbver_minor}) + #error "incorrect version" + #endif + ], + + [ + ]), + [ + AC_MSG_RESULT([yes]) + ], + [ + AC_MSG_RESULT([no]) + continue + ]) + + for ac_dblibdir in $ac_dblibdirs; do + for ac_dblib in db_cxx-$ac_dbver; do + + LDFLAGS="$ac_save_LDFLAGS -L$ac_dblibdir" + LIBS="$ac_save_LIBS -l$ac_dblib" + + AC_MSG_CHECKING([for Berkeley DB library in $ac_dblibdir, -l$ac_dblib]) + AC_LINK_IFELSE( + AC_LANG_PROGRAM( + [ + #include + ], + + [ + DB *db; + db_create(&db, NULL, 0); + ]), + + [ + AC_MSG_RESULT([yes]) + dtn_cv_path_db_h=$ac_dbincdir + dtn_cv_path_db_lib=$ac_dblibdir + dtn_cv_lib_db=$ac_dblib + break 4 + ], + [ + AC_MSG_RESULT([no]) + ]) + done + done + done + done + + AC_LANG_POP(C++) + + CPPFLAGS="$ac_save_CPPFLAGS" + LDFLAGS="$ac_save_LDFLAGS" + LIBS="$ac_save_LIBS" + + if test x$dtn_cv_path_db_h = x ; then + AC_DB_HELP + AC_MSG_ERROR([can't find usable Berkeley DB installation]) + fi +]) diff --git a/test/Makefile.am b/test/Makefile.am index 7a84a86..5dbcd37 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,11 +1,11 @@ SUBDIRS = lladd monotree messages dfa 2pc cht pobj -INCLUDES = @CHECK_CFLAGS@ -if HAVE_CHECK +#INCLUDES = @CHECK_CFLAGS@ +if HAVE_LIBCHECK TESTS = check_check else TESTS = endif noinst_PROGRAMS = $(TESTS) check_check_SOURCES = check_check.c -check_check_LDADD = @CHECK_LIBS@ +#check_check_LDADD = @CHECK_LIBS@ CLEANFILES = check_check.log diff --git a/test/check_includes.h b/test/check_includes.h index 2678e78..8ca2db6 100644 --- a/test/check_includes.h +++ b/test/check_includes.h @@ -1,4 +1,9 @@ #include +#include + +#ifndef HAVE_TCASE_SET_TIMEOUT +#define tcase_set_timeout(x, y) 0 +#endif void setup (void) { remove("logfile.txt"); diff --git a/test/dfa/Makefile.am b/test/dfa/Makefile.am index 1e76e08..a87460d 100644 --- a/test/dfa/Makefile.am +++ b/test/dfa/Makefile.am @@ -1,7 +1,7 @@ -LDADD= @CHECK_LIBS@ $(top_builddir)/src/libdfa/libdfa.a $(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/pbl/libpbl.a $(top_builddir)/src/libdfa/librw.a -lconfuse +LDADD= $(top_builddir)/src/libdfa/libdfa.a $(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/pbl/libpbl.a $(top_builddir)/src/libdfa/librw.a -lconfuse bin_PROGRAMS=ping_pong_dfa fork_bomb star AM_FLAGS= -g -Wall -pedantic -std=c99 -if HAVE_CHECK +if HAVE_LIBCHECK TESTS = check_networksetup ping_pong_dfa else TESTS = diff --git a/test/lladd/Makefile.am b/test/lladd/Makefile.am index f6538c5..dc52f4f 100644 --- a/test/lladd/Makefile.am +++ b/test/lladd/Makefile.am @@ -1,5 +1,5 @@ - INCLUDES = @CHECK_CFLAGS@ -if HAVE_CHECK +# INCLUDES = @CHECK_CFLAGS@ +if HAVE_LIBCHECK ## Had to disable check_lht because lht needs to be rewritten. TESTS = check_logEntry check_logWriter check_page check_operations check_transactional2 check_recovery check_blobRecovery check_bufferManager check_indirect check_pageOperations check_linearHash check_logicalLinearHash check_header check_linkedListNTA check_linearHashNTA check_pageOrientedList check_lockManager check_compensations check_errorHandling check_ringbuffer check_iterator #check_lladdhash @@ -7,6 +7,6 @@ else TESTS = endif noinst_PROGRAMS = $(TESTS) -LDADD = @CHECK_LIBS@ $(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/pbl/libpbl.a $(top_builddir)/src/libdfa/librw.a #-lefence +LDADD = $(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/pbl/libpbl.a $(top_builddir)/src/libdfa/librw.a #-lefence CLEANFILES = check_lht.log check_logEntry.log storefile.txt logfile.txt blob0_file.txt blob1_file.txt check_blobRecovery.log check_logWriter.log check_operations.log check_recovery.log check_transactional2.log check_page.log check_bufferManager.log check_indirect.log check_bufferMananger.log check_lladdhash.log check_pageOperations.log check_linearhash.log check_linkedListNTA.log check_linearHashNTA.log check_pageOrientedListNTA.log check_lockManager.log check_compensations.log check_errorhandling.log check_header.logg check_iterator.log check_linearHash.log check_ringbuffer.log AM_CFLAGS= -g -Wall -pedantic -std=gnu99 diff --git a/test/lladd/check_operations.c b/test/lladd/check_operations.c index 53075df..c194f1d 100644 --- a/test/lladd/check_operations.c +++ b/test/lladd/check_operations.c @@ -625,7 +625,9 @@ START_TEST(operation_array_list) { Suite * check_suite(void) { Suite *s = suite_create("operations"); /* Begin a new test */ + TCase *tc = tcase_create("operations_simple"); + tcase_set_timeout(tc, 0); // disable timeouts /* Sub tests are added, one per line, here */ tcase_add_test(tc, operation_physical_do_undo);