xref: /freebsd/contrib/ntp/sntp/libevent/test/test.sh (revision 2b15cb3d)
1*2b15cb3dSCy Schubert#!/bin/sh
2*2b15cb3dSCy Schubert
3*2b15cb3dSCy SchubertBACKENDS="EVPORT KQUEUE EPOLL DEVPOLL POLL SELECT WIN32"
4*2b15cb3dSCy SchubertTESTS="test-eof test-closed test-weof test-time test-changelist test-fdleak"
5*2b15cb3dSCy SchubertFAILED=no
6*2b15cb3dSCy SchubertTEST_OUTPUT_FILE=${TEST_OUTPUT_FILE:-/dev/null}
7*2b15cb3dSCy SchubertREGRESS_ARGS=${REGRESS_ARGS:-}
8*2b15cb3dSCy Schubert
9*2b15cb3dSCy Schubert# /bin/echo is a little more likely to support -n than sh's builtin echo,
10*2b15cb3dSCy Schubert# printf is even more likely
11*2b15cb3dSCy Schubertif test "`printf %s hello 2>&1`" = "hello"
12*2b15cb3dSCy Schubertthen
13*2b15cb3dSCy Schubert	ECHO_N="printf %s"
14*2b15cb3dSCy Schubertelse
15*2b15cb3dSCy Schubert	if test -x /bin/echo
16*2b15cb3dSCy Schubert	then
17*2b15cb3dSCy Schubert		ECHO_N="/bin/echo -n"
18*2b15cb3dSCy Schubert	else
19*2b15cb3dSCy Schubert		ECHO_N="echo -n"
20*2b15cb3dSCy Schubert	fi
21*2b15cb3dSCy Schubertfi
22*2b15cb3dSCy Schubert
23*2b15cb3dSCy Schubertif test "$TEST_OUTPUT_FILE" != "/dev/null"
24*2b15cb3dSCy Schubertthen
25*2b15cb3dSCy Schubert	touch "$TEST_OUTPUT_FILE" || exit 1
26*2b15cb3dSCy Schubertfi
27*2b15cb3dSCy Schubert
28*2b15cb3dSCy SchubertTEST_DIR=.
29*2b15cb3dSCy SchubertTEST_SRC_DIR=.
30*2b15cb3dSCy Schubert
31*2b15cb3dSCy SchubertT=`echo "$0" | sed -e 's/test.sh$//' | sed -e 's/test-script.sh//' `
32*2b15cb3dSCy Schubertif test -x "$T/test-init"
33*2b15cb3dSCy Schubertthen
34*2b15cb3dSCy Schubert	TEST_DIR="$T"
35*2b15cb3dSCy Schubertelif test -x "./test/test-init"
36*2b15cb3dSCy Schubertthen
37*2b15cb3dSCy Schubert        TEST_DIR="./test"
38*2b15cb3dSCy Schubertfi
39*2b15cb3dSCy Schubertif test -f "$T/check-dumpevents.py"
40*2b15cb3dSCy Schubertthen
41*2b15cb3dSCy Schubert	TEST_SRC_DIR="$T"
42*2b15cb3dSCy Schubertelif test -f "./test/check-dumpevents.py"
43*2b15cb3dSCy Schubertthen
44*2b15cb3dSCy Schubert        TEST_SRC_DIR="./test"
45*2b15cb3dSCy Schubertfi
46*2b15cb3dSCy Schubert
47*2b15cb3dSCy Schubertsetup () {
48*2b15cb3dSCy Schubert	for i in $BACKENDS; do
49*2b15cb3dSCy Schubert		eval "EVENT_NO$i=yes; export EVENT_NO$i"
50*2b15cb3dSCy Schubert	done
51*2b15cb3dSCy Schubert	unset EVENT_EPOLL_USE_CHANGELIST
52*2b15cb3dSCy Schubert	unset EVENT_PRECISE_TIMER
53*2b15cb3dSCy Schubert}
54*2b15cb3dSCy Schubert
55*2b15cb3dSCy Schubertannounce () {
56*2b15cb3dSCy Schubert	echo "$@"
57*2b15cb3dSCy Schubert	echo "$@" >>"$TEST_OUTPUT_FILE"
58*2b15cb3dSCy Schubert}
59*2b15cb3dSCy Schubert
60*2b15cb3dSCy Schubertannounce_n () {
61*2b15cb3dSCy Schubert	$ECHO_N "$@"
62*2b15cb3dSCy Schubert	echo "$@" >>"$TEST_OUTPUT_FILE"
63*2b15cb3dSCy Schubert}
64*2b15cb3dSCy Schubert
65*2b15cb3dSCy Schubert
66*2b15cb3dSCy Schubertrun_tests () {
67*2b15cb3dSCy Schubert	if $TEST_DIR/test-init 2>>"$TEST_OUTPUT_FILE" ;
68*2b15cb3dSCy Schubert	then
69*2b15cb3dSCy Schubert		true
70*2b15cb3dSCy Schubert	else
71*2b15cb3dSCy Schubert		announce Skipping test
72*2b15cb3dSCy Schubert		return
73*2b15cb3dSCy Schubert	fi
74*2b15cb3dSCy Schubert	for i in $TESTS; do
75*2b15cb3dSCy Schubert		announce_n " $i: "
76*2b15cb3dSCy Schubert		if $TEST_DIR/$i >>"$TEST_OUTPUT_FILE" ;
77*2b15cb3dSCy Schubert		then
78*2b15cb3dSCy Schubert			announce OKAY ;
79*2b15cb3dSCy Schubert		else
80*2b15cb3dSCy Schubert			announce FAILED ;
81*2b15cb3dSCy Schubert			FAILED=yes
82*2b15cb3dSCy Schubert		fi
83*2b15cb3dSCy Schubert	done
84*2b15cb3dSCy Schubert	announce_n " test-dumpevents: "
85*2b15cb3dSCy Schubert	if python2 -c 'import sys; assert(sys.version_info >= (2, 4))' 2>/dev/null && test -f $TEST_SRC_DIR/check-dumpevents.py; then
86*2b15cb3dSCy Schubert	    if $TEST_DIR/test-dumpevents | python2 $TEST_SRC_DIR/check-dumpevents.py >> "$TEST_OUTPUT_FILE" ;
87*2b15cb3dSCy Schubert	    then
88*2b15cb3dSCy Schubert	        announce OKAY ;
89*2b15cb3dSCy Schubert	    else
90*2b15cb3dSCy Schubert	        announce FAILED ;
91*2b15cb3dSCy Schubert	    fi
92*2b15cb3dSCy Schubert	else
93*2b15cb3dSCy Schubert	    # no python
94*2b15cb3dSCy Schubert	    if $TEST_DIR/test-dumpevents >/dev/null; then
95*2b15cb3dSCy Schubert	        announce "OKAY (output not checked)" ;
96*2b15cb3dSCy Schubert	    else
97*2b15cb3dSCy Schubert	        announce "FAILED (output not checked)" ;
98*2b15cb3dSCy Schubert	    fi
99*2b15cb3dSCy Schubert	fi
100*2b15cb3dSCy Schubert	test -x $TEST_DIR/regress || return
101*2b15cb3dSCy Schubert	announce_n " regress: "
102*2b15cb3dSCy Schubert	if test "$TEST_OUTPUT_FILE" = "/dev/null" ;
103*2b15cb3dSCy Schubert	then
104*2b15cb3dSCy Schubert		$TEST_DIR/regress --quiet $REGRESS_ARGS
105*2b15cb3dSCy Schubert	else
106*2b15cb3dSCy Schubert		$TEST_DIR/regress $REGRESS_ARGS >>"$TEST_OUTPUT_FILE"
107*2b15cb3dSCy Schubert	fi
108*2b15cb3dSCy Schubert	if test "$?" = "0" ;
109*2b15cb3dSCy Schubert	then
110*2b15cb3dSCy Schubert		announce OKAY ;
111*2b15cb3dSCy Schubert	else
112*2b15cb3dSCy Schubert		announce FAILED ;
113*2b15cb3dSCy Schubert		FAILED=yes
114*2b15cb3dSCy Schubert	fi
115*2b15cb3dSCy Schubert}
116*2b15cb3dSCy Schubert
117*2b15cb3dSCy Schubertdo_test() {
118*2b15cb3dSCy Schubert	setup
119*2b15cb3dSCy Schubert	announce "$1 $2"
120*2b15cb3dSCy Schubert	unset EVENT_NO$1
121*2b15cb3dSCy Schubert	if test "$2" = "(changelist)" ; then
122*2b15cb3dSCy Schubert	    EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST
123*2b15cb3dSCy Schubert	elif test "$2" = "(timerfd)" ; then
124*2b15cb3dSCy Schubert	    EVENT_PRECISE_TIMER=1; export EVENT_PRECISE_TIMER
125*2b15cb3dSCy Schubert	elif test "$2" = "(timerfd+changelist)" ; then
126*2b15cb3dSCy Schubert	    EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST
127*2b15cb3dSCy Schubert	    EVENT_PRECISE_TIMER=1; export EVENT_PRECISE_TIMER
128*2b15cb3dSCy Schubert        fi
129*2b15cb3dSCy Schubert
130*2b15cb3dSCy Schubert	run_tests
131*2b15cb3dSCy Schubert}
132*2b15cb3dSCy Schubert
133*2b15cb3dSCy Schubertannounce "Running tests:"
134*2b15cb3dSCy Schubert
135*2b15cb3dSCy Schubertdo_test EPOLL "(timerfd)"
136*2b15cb3dSCy Schubertdo_test EPOLL "(changelist)"
137*2b15cb3dSCy Schubertdo_test EPOLL "(timerfd+changelist)"
138*2b15cb3dSCy Schubertfor i in $BACKENDS; do
139*2b15cb3dSCy Schubert	do_test $i
140*2b15cb3dSCy Schubertdone
141*2b15cb3dSCy Schubert
142*2b15cb3dSCy Schubertif test "$FAILED" = "yes"; then
143*2b15cb3dSCy Schubert	exit 1
144*2b15cb3dSCy Schubertfi
145