From 8853afb50994232af8351a9b05cdc1937a9824b8 Mon Sep 17 00:00:00 2001 From: Wolfgang Hommel Date: Thu, 4 Feb 2021 21:30:01 +0100 Subject: [PATCH] Added optional FAKETIME_TESTLIB environment variable for make test (#288) --- README.packagers | 4 ++++ test/functests/common.inc | 3 ++- test/test.sh | 34 ++++++++++++++++++---------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/README.packagers b/README.packagers index d2ef290..60ffe02 100644 --- a/README.packagers +++ b/README.packagers @@ -14,6 +14,10 @@ src/Makefile, but sane defaults for stable operations have been chosen. Currently, libfaketime does not use autotools yet, so there is _no_ ./configure step, but "make" and "make test" will work as expected. +For "make test", an optional environment variable FAKETIME_TESTLIB can +be set, pointing to the path and filename of the libfaketime library +to be used for tests; the default is "../src/libfaketime.so.1". + However, one problem makes it somewhat difficult to get libfaketime working on different platforms: diff --git a/test/functests/common.inc b/test/functests/common.inc index d184ae2..1a91cf4 100644 --- a/test/functests/common.inc +++ b/test/functests/common.inc @@ -39,7 +39,8 @@ sunos_fakecmd() linuxlike_fakecmd() { typeset timestring="$1"; shift - typeset fakelib=../src/libfaketime.so.1 + FTPL="${FAKETIME_TESTLIB:-../src/libfaketime.so.1}" + typeset fakelib="$FTPL" export LD_PRELOAD=$fakelib FAKETIME="$timestring" \ "$@" diff --git a/test/test.sh b/test/test.sh index d707f8d..35f2a52 100755 --- a/test/test.sh +++ b/test/test.sh @@ -1,14 +1,16 @@ #!/bin/sh +FTPL="${FAKETIME_TESTLIB:-../src/libfaketime.so.1}" + if [ -f /etc/faketimerc ] ; then echo "Running the test program with your system-wide default in /etc/faketimerc" - echo "\$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest" - LD_PRELOAD=../src/libfaketime.so.1 ./timetest + echo "\$ LD_PRELOAD=$FTPL ./timetest" + LD_PRELOAD="$FTPL" ./timetest echo else echo "Running the test program with no faked time specified" - echo "\$ LD_PRELOAD=../src/libfaketime.so.1 ./timetest" - LD_PRELOAD=../src/libfaketime.so.1 ./timetest + echo "\$ LD_PRELOAD=$FTPL ./timetest" + LD_PRELOAD="$FTPL" ./timetest echo fi @@ -16,48 +18,48 @@ echo "========================================================================== echo echo "Running the test program with absolute date 2003-01-01 10:00:05 specified" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"2003-01-01 10:00:05\" ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="2003-01-01 10:00:05" ./timetest +echo "\$ LD_PRELOAD=$FTPL FAKETIME=\"2003-01-01 10:00:05\" ./timetest" +LD_PRELOAD="$FTPL" FAKETIME="2003-01-01 10:00:05" ./timetest echo echo "=============================================================================" echo echo "Running the test program with START date @2005-03-29 14:14:14 specified" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"@2005-03-29 14:14:14\" ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="@2005-03-29 14:14:14" ./timetest +echo "\$ LD_PRELOAD=$FTPL FAKETIME=\"@2005-03-29 14:14:14\" ./timetest" +LD_PRELOAD="$FTPL" FAKETIME="@2005-03-29 14:14:14" ./timetest echo echo "=============================================================================" echo echo "Running the test program with 10 days negative offset specified" -echo "LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-10d\" ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-10d" ./timetest +echo "LD_PRELOAD=$FTPL FAKETIME=\"-10d\" ./timetest" +LD_PRELOAD="$FTPL" FAKETIME="-10d" ./timetest echo echo "=============================================================================" echo echo "Running the test program with 10 days negative offset specified, and FAKE_STAT disabled" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-10d" NO_FAKE_STAT=1 ./timetest +echo "\$ LD_PRELOAD=$FTPL FAKETIME=\"-10d\" NO_FAKE_STAT=1 ./timetest" +LD_PRELOAD="$FTPL" FAKETIME="-10d" NO_FAKE_STAT=1 ./timetest echo echo "=============================================================================" echo echo "Running the test program with 10 days positive offset specified, and speed-up factor" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"+10d x1\" ./timetest" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="+10d x1" NO_FAKE_STAT=1 ./timetest +echo "\$ LD_PRELOAD=$FTPL FAKETIME=\"+10d x1\" ./timetest" +LD_PRELOAD="$FTPL" FAKETIME="+10d x1" NO_FAKE_STAT=1 ./timetest echo echo "=============================================================================" echo echo "Running the 'date' command with 15 days negative offset specified" -echo "\$ LD_PRELOAD=../src/libfaketime.so.1 FAKETIME=\"-15d\" date" -LD_PRELOAD=../src/libfaketime.so.1 FAKETIME="-15d" date +echo "\$ LD_PRELOAD=$FTPL FAKETIME=\"-15d\" date" +LD_PRELOAD="$FTPL" FAKETIME="-15d" date echo echo "============================================================================="