Files
libfaketime/test/pidtest.sh
Daniel Kahn Gillmor 2ca0b719e3 test getpid() against library with constructor that calls it
This is an attempt to ensure that an external library invocation of
getpid doesn't trigger a crash (e.g. #295) or an infinite loop
(e.g. #297).
2021-02-24 11:15:31 -05:00

27 lines
797 B
Bash
Executable File

#!/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
printf 'testing shared object with getpid() in library constructor\n'
LD_LIBRARY_PATH=. ./use_lib_getpid
printf 'now with LD_PRELOAD and FAKETIME_FAKEPID\n'
FAKETIME_FAKEPID=25 LD_PRELOAD="$FTPL" LD_LIBRARY_PATH=. ./use_lib_getpid
printf 'now with LD_PRELOAD without FAKETIME_FAKEPID\n'
LD_PRELOAD="$FTPL" LD_LIBRARY_PATH=. ./use_lib_getpid