From 82640b11ba9fbb36e8d39c2a05671ef5f8011b68 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 14 Mar 2007 14:10:18 +0100 Subject: [PATCH] tests: add library for LD_PRELOAD to manipulate with time() in tests The cal command generates output that depends on time(). For reliable regression tests we need to use still same time. It seems that LD_PRELOAD is pretty simple way. Signed-off-by: Karel Zak --- .gitignore | 1 + autogen.sh | 9 ++++++++- config.h.in | 3 +++ configure.ac | 1 + tests/helpers/Makefile.am | 8 +++++++- tests/helpers/libpreload-time.c | 26 ++++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/helpers/libpreload-time.c diff --git a/.gitignore b/.gitignore index 88822ba1..c1259240 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ compile depcomp install-sh missing +ltmain.sh diff --git a/autogen.sh b/autogen.sh index ffd8de95..d730a96a 100755 --- a/autogen.sh +++ b/autogen.sh @@ -44,7 +44,13 @@ DIE=0 echo "or see http://www.gnu.org/software/autoheader" DIE=1 } - +(libtool --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have libtool installed to generate util-linux build-system." + echo "Download the appropriate package for your distribution," + echo "or see http://www.gnu.org/software/libtool" + DIE=1 +} if test "$DIE" -eq 1; then exit 1 fi @@ -55,6 +61,7 @@ test -f mount/mount.c || { } autopoint --force +libtoolize --copy --force aclocal -I m4 automake --add-missing autoconf diff --git a/config.h.in b/config.h.in index 807cecfd..987945f4 100644 --- a/config.h.in +++ b/config.h.in @@ -8,6 +8,9 @@ */ #undef HAVE_DCGETTEXT +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ #undef HAVE_FSEEKO diff --git a/configure.ac b/configure.ac index 95690ddf..66e88df8 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,7 @@ AC_PREFIX_DEFAULT(/) AC_PROG_CC_STDC AC_PROG_RANLIB +AC_PROG_LIBTOOL AC_PATH_PROG(PERL, perl) diff --git a/tests/helpers/Makefile.am b/tests/helpers/Makefile.am index 13eaae1e..6c514e7c 100644 --- a/tests/helpers/Makefile.am +++ b/tests/helpers/Makefile.am @@ -1,5 +1,11 @@ include $(top_srcdir)/config/include-Makefile.am noinst_PROGRAMS = mnt_test_sysinfo +mnt_test_sysinfo_SOURCES = mnt_test_sysinfo.c + + +noinst_LTLIBRARIES = libpreload-time.la + +libpreload_time_la_SOURCES = libpreload-time.c +libpreload_time_la_LDFLAGS = -shared -rpath `pwd` -avoid-version -mnt_test_sysinfo_SOURCES = mnt_test_sysinfo.c diff --git a/tests/helpers/libpreload-time.c b/tests/helpers/libpreload-time.c new file mode 100644 index 00000000..e6979509 --- /dev/null +++ b/tests/helpers/libpreload-time.c @@ -0,0 +1,26 @@ + +#include +#include +#include +#include +#include + +time_t +time(time_t *t) +{ + time_t tt = 0; + char *e = getenv("TEST_TIME"); + + if (e && isdigit((unsigned char) *e)) + tt = atol(e); + else { + struct timeval tv; + + if (gettimeofday(&tv, NULL) == 0) + tt = tv.tv_sec; + } + if (t) + *t = tt; + + return tt; +} -- 2.39.5