summaryrefslogtreecommitdiffstats
path: root/tests/deckard/contrib/libfaketime/test/functests/common.inc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:55:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:55:53 +0000
commit3d0386f27ca66379acf50199e1d1298386eeeeb8 (patch)
treef87bd4a126b3a843858eb447e8fd5893c3ee3882 /tests/deckard/contrib/libfaketime/test/functests/common.inc
parentInitial commit. (diff)
downloadknot-resolver-upstream.tar.xz
knot-resolver-upstream.zip
Adding upstream version 3.2.1.upstream/3.2.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/deckard/contrib/libfaketime/test/functests/common.inc')
-rw-r--r--tests/deckard/contrib/libfaketime/test/functests/common.inc63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/deckard/contrib/libfaketime/test/functests/common.inc b/tests/deckard/contrib/libfaketime/test/functests/common.inc
new file mode 100644
index 0000000..d184ae2
--- /dev/null
+++ b/tests/deckard/contrib/libfaketime/test/functests/common.inc
@@ -0,0 +1,63 @@
+# libfaketime-specific common support routines for tests
+
+# say which *_fakecmd wrapper to use
+platform()
+{
+ # may want to expand the pattern for linuxlike
+ typeset out=$(uname)
+ case "$out" in
+ *Darwin*) echo "mac" ;;
+ *Linux*) echo "linuxlike" ;;
+ GNU|GNU/kFreeBSD) echo "linuxlike" ;;
+ *SunOS*) echo "sunos" ;;
+ *) echo 1>&2 unsupported platform, uname=\"$out\" ;;
+ esac
+}
+
+# run faked command on a mac
+# UNTESTED
+mac_fakecmd()
+{
+ typeset timestring="$1"; shift
+ typeset fakelib=../src/libfaketime.1.dylib
+ export DYLD_INSERT_LIBRARIES=$fakelib
+ export DYLD_FORCE_FLAT_NAMESPACE=1
+ FAKETIME="$timestring" \
+ "$@"
+}
+
+sunos_fakecmd()
+{
+ typeset timestring="$1"; shift
+ typeset fakelib=../src/libfaketime.so.1
+ export LD_PRELOAD=$fakelib
+ FAKETIME="$timestring" \
+ "$@"
+}
+
+# run faked command on linuxlike OS
+linuxlike_fakecmd()
+{
+ typeset timestring="$1"; shift
+ typeset fakelib=../src/libfaketime.so.1
+ export LD_PRELOAD=$fakelib
+ FAKETIME="$timestring" \
+ "$@"
+}
+
+# run a command with libfaketime using the given timestring
+fakecmd()
+{
+ ${PLATFORM}_fakecmd "$@"
+}
+
+# generate a sequence of numbers from a to b
+range()
+{
+ typeset a=$1 b=$2
+ typeset i=$a
+ while ((i <= b)); do
+ echo $i
+ ((i = i+1))
+ done
+}