diff options
author | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2021-02-25 21:51:46 -0500 |
---|---|---|
committer | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2021-02-25 23:17:25 -0500 |
commit | a5885f1479d482d201f5d2a400073d177eb8687d (patch) | |
tree | f298a50f5fdc2b3a3939a10fa0ebe76027a32593 | |
parent | 0872c6c0c08c2483cf2c06e3ce2400ea3fe17144 (diff) | |
download | libfaketime-a5885f1479d482d201f5d2a400073d177eb8687d.tar.gz |
Drop more duplicative tests
Now that we have the snippet-driven test_variable_data suite, most of
the other longer hand-written tests are duplicative.
-rw-r--r-- | test/Makefile | 9 | ||||
-rw-r--r-- | test/getentropy_test.c | 14 | ||||
-rw-r--r-- | test/getrandom_test.c | 29 | ||||
-rwxr-xr-x | test/pidtest.sh | 19 | ||||
-rwxr-xr-x | test/randomtest.sh | 28 | ||||
-rw-r--r-- | test/syscall_test.c | 11 | ||||
-rwxr-xr-x | test/syscalltest.sh | 29 |
7 files changed, 1 insertions, 138 deletions
diff --git a/test/Makefile b/test/Makefile index ee398dd..fc663c2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -28,16 +28,9 @@ functest: %_test: %_test.c ${CC} -o $@ ${CFLAGS} $< -randomtest: getrandom_test repeat_random getentropy_test +randomtest: repeat_random ./randomtest.sh -getpidtest: - ./pidtest.sh - -syscalltest: syscall_test - ./syscalltest.sh - - ## test variables test_variable_data: test_variable_data.sh $(foreach f,${EXPECTATIONS},run_${f}) diff --git a/test/getentropy_test.c b/test/getentropy_test.c deleted file mode 100644 index a3d02e6..0000000 --- a/test/getentropy_test.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <unistd.h> -#include <stdio.h> - -int main() { - unsigned char buf[16]; - if (getentropy(buf, sizeof(buf))) { - perror("failed to getentropy()"); - return 1; - } - for (size_t i = 0; i < sizeof(buf); i++) - printf("%02x", buf[i]); - printf("\n"); - return 0; -} diff --git a/test/getrandom_test.c b/test/getrandom_test.c deleted file mode 100644 index 8b134e3..0000000 --- a/test/getrandom_test.c +++ /dev/null @@ -1,29 +0,0 @@ -#include <stdio.h> -#include <sys/random.h> -#include <stdlib.h> - -int base() { - char *buf = calloc(100, 1); - size_t buflen = 100; - unsigned flags = GRND_NONBLOCK; - - fprintf(stdout, "Before getrandom:\n"); - for (size_t i=0; i < buflen; i++) { fprintf(stdout, "%hhu ", buf[i]); } - fprintf(stdout, "\n"); - - int result = getrandom(buf, buflen, flags); - fprintf(stdout, "getrandom() result: %d\n", result); - if (result == -1) perror("getrandom() unsuccessful"); - - - fprintf(stdout, "After getrandom:\n"); - for (size_t i=0; i < buflen; i++) { fprintf(stdout, "%hhu ", buf[i]); } - fprintf(stdout, "\n"); - - free(buf); - return 0; -} - -int main() { - return base() + base(); -} diff --git a/test/pidtest.sh b/test/pidtest.sh deleted file mode 100755 index 617bad8..0000000 --- a/test/pidtest.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -FTPL="${FAKETIME_TESTLIB:-../src/libfaketime.so.1}" - -set -e -run1=$(LD_PRELOAD="$FTPL" sh -c 'echo $$') -run2=$(LD_PRELOAD="$FTPL" sh -c 'echo $$') - -if [ $run1 = $run2 ]; then - printf >&2 'got the same pid twice in a row without setting FAKETIME_FAKEPID\n' - exit 1 -fi - -output=$(FAKETIME_FAKEPID=13 LD_PRELOAD="$FTPL" sh -c 'echo $$') - -if [ $output != 13 ]; then - printf >&2 'Failed to enforce a rigid response to getpid()\n' - exit 2 -fi diff --git a/test/randomtest.sh b/test/randomtest.sh index 052510b..6509c79 100755 --- a/test/randomtest.sh +++ b/test/randomtest.sh @@ -6,34 +6,6 @@ set -e error=0 -for iface in getrandom getentropy; 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 - FAKERANDOM_SEED=0xDEADBEEFDEADBEEF LD_PRELOAD="$FTPL" ./repeat_random 3 5 > repeat3x5 FAKERANDOM_SEED=0xDEADBEEFDEADBEEF LD_PRELOAD="$FTPL" ./repeat_random 5 3 > repeat5x3 diff --git a/test/syscall_test.c b/test/syscall_test.c deleted file mode 100644 index cf9f9f9..0000000 --- a/test/syscall_test.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <sys/syscall.h> - -int main() { - int d = 0; - long r = syscall(__NR_getrandom, &d, sizeof(d), 0); - printf("getrandom(%d, <ptr>, %zd, 0) returned %ld and yielded 0x%08x\n", - __NR_getrandom, sizeof(d), r, d); - return 0; -} diff --git a/test/syscalltest.sh b/test/syscalltest.sh deleted file mode 100755 index 0b5a4cf..0000000 --- a/test/syscalltest.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -FTPL="${FAKETIME_TESTLIB:-../src/libfaketime.so.1}" - -set -e - -error=0 -run0=$(./syscall_test) -run1=$(LD_PRELOAD="$FTPL" ./syscall_test) -run2=$(FAKERANDOM_SEED=0x0000000000000000 LD_PRELOAD="$FTPL" ./syscall_test) -run3=$(FAKERANDOM_SEED=0x0000000000000000 LD_PRELOAD="$FTPL" ./syscall_test) -run4=$(FAKERANDOM_SEED=0xDEADBEEFDEADBEEF LD_PRELOAD="$FTPL" ./syscall_test) - -if [ "$run0" = "$run1" ] ; then - error=1 - printf >&2 'test run without LD_PRELOAD matches run with LD_PRELOAD. This is very unlikely.\n' -fi -if [ "$run1" = "$run2" ] ; then - error=2 - printf >&2 'test with LD_PRELOAD but without FAKERANDOM_SEED matches run with LD_PRELOAD and FAKERANDOM_SEED. This is also very unlikely.\n' -fi -if [ "$run2" != "$run3" ]; then - error=1 - printf >&2 'test run with same seed produces different outputs.\n' -fi -if [ "$run3" = "$run4" ]; then - error=1 - printf >&2 'test runs with different seeds produce the same outputs.\n' -fi |