diff options
author | Karel Zak | 2007-03-14 14:10:18 +0100 |
---|---|---|
committer | Karel Zak | 2007-03-14 14:10:18 +0100 |
commit | 82640b11ba9fbb36e8d39c2a05671ef5f8011b68 (patch) | |
tree | 9b45cf0b2a10f10e1d2fd8a1575e74e36312d22d /tests/helpers | |
parent | build-sys: remove aclocal.m4 from SCM (diff) | |
download | kernel-qcow2-util-linux-82640b11ba9fbb36e8d39c2a05671ef5f8011b68.tar.gz kernel-qcow2-util-linux-82640b11ba9fbb36e8d39c2a05671ef5f8011b68.tar.xz kernel-qcow2-util-linux-82640b11ba9fbb36e8d39c2a05671ef5f8011b68.zip |
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 <kzak@redhat.com>
Diffstat (limited to 'tests/helpers')
-rw-r--r-- | tests/helpers/Makefile.am | 8 | ||||
-rw-r--r-- | tests/helpers/libpreload-time.c | 26 |
2 files changed, 33 insertions, 1 deletions
diff --git a/tests/helpers/Makefile.am b/tests/helpers/Makefile.am index 13eaae1e9..6c514e7c7 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 000000000..e69795098 --- /dev/null +++ b/tests/helpers/libpreload-time.c @@ -0,0 +1,26 @@ + +#include <stdio.h> +#include <ctype.h> +#include <stdlib.h> +#include <time.h> +#include <sys/time.h> + +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; +} |