summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2021-02-24 15:58:54 -0500
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>2021-02-24 15:58:54 -0500
commit20e74b1b02290656ff42e3074e3b31ef9e2dbaa6 (patch)
tree1fe2d18b4569bf4cb55fa3bfbab3ffcdc44a3023 /test
parent00d6edf90cfb397d37b0107113fefa444a2a0a76 (diff)
downloadlibfaketime-20e74b1b02290656ff42e3074e3b31ef9e2dbaa6.tar.gz
clean up randomtest.sh, make more flexible
Diffstat (limited to 'test')
-rwxr-xr-xtest/randomtest.sh58
1 files changed, 31 insertions, 27 deletions
diff --git a/test/randomtest.sh b/test/randomtest.sh
index 4290ec6..6f8d124 100755
--- a/test/randomtest.sh
+++ b/test/randomtest.sh
@@ -5,30 +5,34 @@ FTPL="${FAKETIME_TESTLIB:-../src/libfaketime.so.1}"
set -e
error=0
-./getrandom_test > run-base
-LD_PRELOAD="$FTPL" ./getrandom_test > run0
-FAKERANDOM_SEED=0x12345678DEADBEEF LD_PRELOAD="$FTPL" ./getrandom_test > run1
-FAKERANDOM_SEED=0x12345678DEADBEEF LD_PRELOAD="$FTPL" ./getrandom_test > run2
-FAKERANDOM_SEED=0x0000000000000000 LD_PRELOAD="$FTPL" ./getrandom_test > run3
-
-if diff -u run-base run0 > /dev/null; then
- error=1
- printf >&2 'test run without the LD_PRELOAD matches a run without LD_PRELOAD\n'
-fi
-
-if diff -u run0 run1 > /dev/null; then
- error=2
- printf >&2 'test run without a seed produced the same data as a run with a seed!\n'
-fi
-if ! diff -u run1 run2; then
- error=3
- printf >&2 'test runs with identical seeds differed!\n'
-fi
-if diff -u run2 run3 >/dev/null; then
- error=4
- printf >&2 'test runs with different seeds produced the same data!\n'
-fi
+for iface in getrandom; do
+ printf "Testing %s() interception...\n" "$iface"
+
+ "./${iface}_test" > "${iface}.alone"
+ LD_PRELOAD="$FTPL" "./${iface}_test" > "${iface}.preload"
+ FAKERANDOM_SEED=0x12345678DEADBEEF LD_PRELOAD="$FTPL" "./${iface}_test" > "${iface}.preload.seed0"
+ FAKERANDOM_SEED=0x12345678DEADBEEF LD_PRELOAD="$FTPL" "./${iface}_test" > "${iface}.preload.seed1"
+ FAKERANDOM_SEED=0x0000000000000000 LD_PRELOAD="$FTPL" "./${iface}_test" > "${iface}.preload.seed2"
+
+ if diff -u "${iface}.alone" "${iface}.preload" > /dev/null; then
+ error=1
+ printf >&2 '%s() without the LD_PRELOAD matches a run without LD_PRELOAD\n' "$iface"
+ fi
+ if diff -u "${iface}.preload" "${iface}.preload.seed0" > /dev/null; then
+ error=2
+ printf >&2 '%s() without a seed produced the same data as a run with a seed!\n' "$iface"
+ fi
+ if ! diff -u "${iface}.preload.seed0" "${iface}.preload.seed1"; then
+ error=3
+ printf >&2 '%s() with identical seeds differed!\n' "$iface"
+ fi
+ if diff -u "${iface}.preload.seed1" "${iface}.preload.seed2" >/dev/null; then
+ error=4
+ printf >&2 '%s() with different seeds produced the same data!\n' "$iface"
+ fi
+ rm -f "${iface}.alone" "${iface}.preload" "${iface}.preload.seed0" "${iface}.preload.seed1" "${iface}.preload.seed2"
+done
printf 'testing shared object with getrandom() in library constructor\n'
LD_LIBRARY_PATH=. ./use_lib_random
@@ -39,15 +43,15 @@ printf 'now with LD_PRELOAD without FAKERANDOM_SEED\n'
LD_PRELOAD="$FTPL" LD_LIBRARY_PATH=. ./use_lib_random
-FAKERANDOM_SEED=0xDEADBEEFDEADBEEF LD_PRELOAD="$FTPL" ./repeat_random 3 5 > run4
-FAKERANDOM_SEED=0xDEADBEEFDEADBEEF LD_PRELOAD="$FTPL" ./repeat_random 5 3 > run5
+FAKERANDOM_SEED=0xDEADBEEFDEADBEEF LD_PRELOAD="$FTPL" ./repeat_random 3 5 > repeat3x5
+FAKERANDOM_SEED=0xDEADBEEFDEADBEEF LD_PRELOAD="$FTPL" ./repeat_random 5 3 > repeat5x3
-if ! diff -u run4 run5; then
+if ! diff -u repeat3x5 repeat5x3; then
error=5
printf >&2 '5 calls of getrandom(3) did not produce the same stream as 3 calls of getrandom(5)\n'
fi
-rm -f run-base run0 run1 run2 run3 run4 run5
+rm -f repeat3x5 repeat5x3
if [ 0 = $error ]; then
printf 'getrandom interception test successful.\n'