diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 00:55:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 00:55:53 +0000 |
commit | 3d0386f27ca66379acf50199e1d1298386eeeeb8 (patch) | |
tree | f87bd4a126b3a843858eb447e8fd5893c3ee3882 /tests/deckard/contrib/libfaketime/test/functests/test_walkone.sh | |
parent | Initial commit. (diff) | |
download | knot-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/test_walkone.sh')
-rwxr-xr-x | tests/deckard/contrib/libfaketime/test/functests/test_walkone.sh | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/deckard/contrib/libfaketime/test/functests/test_walkone.sh b/tests/deckard/contrib/libfaketime/test/functests/test_walkone.sh new file mode 100755 index 0000000..b27df9a --- /dev/null +++ b/tests/deckard/contrib/libfaketime/test/functests/test_walkone.sh @@ -0,0 +1,67 @@ +# walking-1 test. +# sourced in from testframe.sh. +# +# this script defines a suite of functional tests +# that verifies the correct operation of libfaketime +# with the date command. + +run() +{ + init + + for i in $(range 0 30); do + run_testcase test_with_i $i + done +} + +# ----- support routines +init() +{ + typeset testsuite="$1" + PLATFORM=$(platform) + if [ -z "$PLATFORM" ]; then + echo "$testsuite: unknown platform! quitting" + return 1 + fi + echo "# PLATFORM=$PLATFORM" + return 0 +} + + +# run date cmd under faketime, print time in secs +fakedate() +{ + # + # let the time format be raw seconds since Epoch + # for both input to libfaketime, and output of the date cmd. + # + typeset fmt='%s' + export FAKETIME_FMT=$fmt + fakecmd "$1" date +$fmt +} + +# +# compute x**n. +# use only the shell, in case we need to run on machines +# without bc, dc, perl, etc. +# +pow() +{ + typeset x="$1" n="$2" + typeset r=1 + typeset i=0 + while ((i < n)); do + ((r = r*x)) + ((i++)) + done + echo $r +} + +# run a fakedate test with a given time t +test_with_i() +{ + typeset i="$1" + typeset t=$(pow 2 $i) + + asserteq $(fakedate $t) $t "(secs since Epoch)" +} |