mirror of
https://github.com/libevent/libevent.git
synced 2025-01-20 05:02:55 +08:00
26c75828b7
The epoll interface ordinarily gives us one-millisecond precision, so on Linux it makes perfect sense to use the CLOCK_MONOTONIC_COARSE timer. But when the user has set the new PRECISE_TIMER flag for an event_base (either by the EVENT_BASE_FLAG_PRECISE_TIMER flag, or by the EVENT_PRECISE_TIMER environment variable), they presumably want finer granularity. On not-too-old Linuxes, we can achieve this using the Timerfd mechanism, which accepts nanosecond granularity and understands posix clocks. It's a little more expensive than just calling epoll_wait(), so we won't do it by default.
138 lines
2.7 KiB
Bash
Executable File
138 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
BACKENDS="EVPORT KQUEUE EPOLL DEVPOLL POLL SELECT WIN32"
|
|
TESTS="test-eof test-weof test-time test-changelist test-fdleak"
|
|
FAILED=no
|
|
TEST_OUTPUT_FILE=${TEST_OUTPUT_FILE:-/dev/null}
|
|
|
|
# /bin/echo is a little more likely to support -n than sh's builtin echo,
|
|
# printf is even more likely
|
|
if test "`printf %s hello 2>&1`" = "hello"
|
|
then
|
|
ECHO_N="printf %s"
|
|
else
|
|
if test -x /bin/echo
|
|
then
|
|
ECHO_N="/bin/echo -n"
|
|
else
|
|
ECHO_N="echo -n"
|
|
fi
|
|
fi
|
|
|
|
if test "$TEST_OUTPUT_FILE" != "/dev/null"
|
|
then
|
|
touch "$TEST_OUTPUT_FILE" || exit 1
|
|
fi
|
|
|
|
TEST_DIR=.
|
|
TEST_SRC_DIR=.
|
|
|
|
T=`echo "$0" | sed -e 's/test.sh$//'`
|
|
if test -x "$T/test-init"
|
|
then
|
|
TEST_DIR="$T"
|
|
fi
|
|
if test -e "$T/check-dumpevents.py"
|
|
then
|
|
TEST_SRC_DIR="$T"
|
|
fi
|
|
|
|
setup () {
|
|
for i in $BACKENDS; do
|
|
eval "EVENT_NO$i=yes; export EVENT_NO$i"
|
|
done
|
|
unset EVENT_EPOLL_USE_CHANGELIST
|
|
unset EVENT_PRECISE_TIMER
|
|
}
|
|
|
|
announce () {
|
|
echo "$@"
|
|
echo "$@" >>"$TEST_OUTPUT_FILE"
|
|
}
|
|
|
|
announce_n () {
|
|
$ECHO_N "$@"
|
|
echo "$@" >>"$TEST_OUTPUT_FILE"
|
|
}
|
|
|
|
|
|
run_tests () {
|
|
if $TEST_DIR/test-init 2>>"$TEST_OUTPUT_FILE" ;
|
|
then
|
|
true
|
|
else
|
|
announce Skipping test
|
|
return
|
|
fi
|
|
for i in $TESTS; do
|
|
announce_n " $i: "
|
|
if $TEST_DIR/$i >>"$TEST_OUTPUT_FILE" ;
|
|
then
|
|
announce OKAY ;
|
|
else
|
|
announce FAILED ;
|
|
FAILED=yes
|
|
fi
|
|
done
|
|
announce_n " test-dumpevents: "
|
|
if python -c 'import sys; assert(sys.version_info >= (2, 4))' 2>/dev/null; then
|
|
if $TEST_DIR/test-dumpevents | python $TEST_SRC_DIR/check-dumpevents.py >> "$TEST_OUTPUT_FILE" ;
|
|
then
|
|
announce OKAY ;
|
|
else
|
|
announce FAILED ;
|
|
fi
|
|
else
|
|
# no python
|
|
if $TEST_DIR/test-dumpevents >/dev/null; then
|
|
announce "OKAY (output not checked)" ;
|
|
else
|
|
announce "FAILED (output not checked)" ;
|
|
fi
|
|
fi
|
|
test -x $TEST_DIR/regress || return
|
|
announce_n " regress: "
|
|
if test "$TEST_OUTPUT_FILE" = "/dev/null" ;
|
|
then
|
|
$TEST_DIR/regress --quiet
|
|
else
|
|
$TEST_DIR/regress >>"$TEST_OUTPUT_FILE"
|
|
fi
|
|
if test "$?" = "0" ;
|
|
then
|
|
announce OKAY ;
|
|
else
|
|
announce FAILED ;
|
|
FAILED=yes
|
|
fi
|
|
}
|
|
|
|
do_test() {
|
|
setup
|
|
announce "$1 $2"
|
|
unset EVENT_NO$1
|
|
if test "$2" = "(changelist)" ; then
|
|
EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST
|
|
elif test "$2" = "(timerfd)" ; then
|
|
EVENT_PRECISE_TIMER=1; export EVENT_PRECISE_TIMER
|
|
elif test "$2" = "(timerfd+changelist)" ; then
|
|
EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST
|
|
EVENT_PRECISE_TIMER=1; export EVENT_PRECISE_TIMER
|
|
fi
|
|
|
|
run_tests
|
|
}
|
|
|
|
announce "Running tests:"
|
|
|
|
do_test EPOLL "(timerfd)"
|
|
do_test EPOLL "(changelist)"
|
|
do_test EPOLL "(timerfd+changelist)"
|
|
for i in $BACKENDS; do
|
|
do_test $i
|
|
done
|
|
|
|
if test "$FAILED" = "yes"; then
|
|
exit 1
|
|
fi
|