diff options
author | Wolfgang Hommel <wolfcw@users.noreply.github.com> | 2021-02-25 06:15:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-25 06:15:42 +0100 |
commit | 3668fd9b0f7427de5c7b3c87c4c2b340aa18f67d (patch) | |
tree | 4d73f0ee3313e14035b5cd532d97acf323e51d6b /test | |
parent | a8283c646d43518b7c8d9cd90ce8f627edd76a9e (diff) | |
parent | 811283e683cd244ae14e77cd85a2c7d4266478eb (diff) | |
download | libfaketime-3668fd9b0f7427de5c7b3c87c4c2b340aa18f67d.tar.gz |
Merge pull request #302 from dkg/syscall-interception
Intercept syscall
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 3 | ||||
-rw-r--r-- | test/syscall_test.c | 11 | ||||
-rwxr-xr-x | test/syscalltest.sh | 29 |
3 files changed, 43 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile index 8f56489..fbbcde3 100644 --- a/test/Makefile +++ b/test/Makefile @@ -31,6 +31,9 @@ randomtest: getrandom_test use_lib_random librandom.so getpidtest: use_lib_getpid libgetpid.so ./pidtest.sh +syscalltest: syscall_test + ./syscalltest.sh + lib%.o: lib%.c ${CC} -c -o $@ -fpic ${CFLAGS} $< diff --git a/test/syscall_test.c b/test/syscall_test.c new file mode 100644 index 0000000..cf9f9f9 --- /dev/null +++ b/test/syscall_test.c @@ -0,0 +1,11 @@ +#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 new file mode 100755 index 0000000..0b5a4cf --- /dev/null +++ b/test/syscalltest.sh @@ -0,0 +1,29 @@ +#!/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 |