xref: /freebsd/contrib/ntp/sntp/libevent/test/test.sh (revision a466cc55373fc3cf86837f09da729535b57e69a1)
1#!/bin/sh
2
3BACKENDS="EVPORT KQUEUE EPOLL DEVPOLL POLL SELECT WIN32"
4TESTS="test-eof test-closed test-weof test-time test-changelist test-fdleak"
5FAILED=no
6TEST_OUTPUT_FILE=${TEST_OUTPUT_FILE:-/dev/null}
7REGRESS_ARGS=${REGRESS_ARGS:-}
8
9# /bin/echo is a little more likely to support -n than sh's builtin echo,
10# printf is even more likely
11if test "`printf %s hello 2>&1`" = "hello"
12then
13	ECHO_N="printf %s"
14else
15	if test -x /bin/echo
16	then
17		ECHO_N="/bin/echo -n"
18	else
19		ECHO_N="echo -n"
20	fi
21fi
22
23if test "$TEST_OUTPUT_FILE" != "/dev/null"
24then
25	touch "$TEST_OUTPUT_FILE" || exit 1
26fi
27
28TEST_DIR=.
29TEST_SRC_DIR=.
30
31T=`echo "$0" | sed -e 's/test.sh$//'`
32if test -x "$T/test-init"
33then
34	TEST_DIR="$T"
35elif test -x "./test/test-init"
36then
37        TEST_DIR="./test"
38fi
39if test -f "$T/check-dumpevents.py"
40then
41	TEST_SRC_DIR="$T"
42elif test -f "./test/check-dumpevents.py"
43then
44        TEST_SRC_DIR="./test"
45fi
46
47setup () {
48	for i in $BACKENDS; do
49		eval "EVENT_NO$i=yes; export EVENT_NO$i"
50	done
51	unset EVENT_EPOLL_USE_CHANGELIST
52	unset EVENT_PRECISE_TIMER
53}
54
55announce () {
56	echo "$@"
57	echo "$@" >>"$TEST_OUTPUT_FILE"
58}
59
60announce_n () {
61	$ECHO_N "$@"
62	echo "$@" >>"$TEST_OUTPUT_FILE"
63}
64
65
66run_tests () {
67	if $TEST_DIR/test-init 2>>"$TEST_OUTPUT_FILE" ;
68	then
69		true
70	else
71		announce Skipping test
72		return
73	fi
74	for i in $TESTS; do
75		announce_n " $i: "
76		if $TEST_DIR/$i >>"$TEST_OUTPUT_FILE" ;
77		then
78			announce OKAY ;
79		else
80			announce FAILED ;
81			FAILED=yes
82		fi
83	done
84	announce_n " test-dumpevents: "
85	if python -c 'import sys; assert(sys.version_info >= (2, 4))' 2>/dev/null && test -f $TEST_SRC_DIR/check-dumpevents.py; then
86	    if $TEST_DIR/test-dumpevents | $TEST_SRC_DIR/check-dumpevents.py >> "$TEST_OUTPUT_FILE" ;
87	    then
88	        announce OKAY ;
89	    else
90	        announce FAILED ;
91	    fi
92	else
93	    # no python
94	    if $TEST_DIR/test-dumpevents >/dev/null; then
95	        announce "OKAY (output not checked)" ;
96	    else
97	        announce "FAILED (output not checked)" ;
98	    fi
99	fi
100
101	test -x $TEST_DIR/regress || return
102	announce_n " regress: "
103	if test "$TEST_OUTPUT_FILE" = "/dev/null" ;
104	then
105		$TEST_DIR/regress --quiet $REGRESS_ARGS
106	else
107		$TEST_DIR/regress $REGRESS_ARGS >>"$TEST_OUTPUT_FILE"
108	fi
109	if test "$?" = "0" ;
110	then
111		announce OKAY ;
112	else
113		announce FAILED ;
114		FAILED=yes
115	fi
116
117	announce_n " regress_debug: "
118	if test "$TEST_OUTPUT_FILE" = "/dev/null" ;
119	then
120		EVENT_DEBUG_MODE=1 $TEST_DIR/regress --quiet $REGRESS_ARGS
121	else
122		EVENT_DEBUG_MODE=1 $TEST_DIR/regress $REGRESS_ARGS >>"$TEST_OUTPUT_FILE"
123	fi
124	if test "$?" = "0" ;
125	then
126		announce OKAY ;
127	else
128		announce FAILED ;
129		FAILED=yes
130	fi
131}
132
133do_test() {
134	setup
135	announce "$1 $2"
136	unset EVENT_NO$1
137	if test "$2" = "(changelist)" ; then
138	    EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST
139	elif test "$2" = "(timerfd)" ; then
140	    EVENT_PRECISE_TIMER=1; export EVENT_PRECISE_TIMER
141	elif test "$2" = "(timerfd+changelist)" ; then
142	    EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST
143	    EVENT_PRECISE_TIMER=1; export EVENT_PRECISE_TIMER
144        fi
145
146	run_tests
147}
148
149usage()
150{
151	cat <<EOL
152  -b   - specify backends
153  -t   - run timerfd test
154  -c   - run changelist test
155  -T   - run timerfd+changelist test
156EOL
157}
158main()
159{
160	backends=$BACKENDS
161	timerfd=0
162	changelist=0
163	timerfd_changelist=0
164
165	while getopts "b:tcT" c; do
166		case "$c" in
167			b) backends="$OPTARG";;
168			t) timerfd=1;;
169			c) changelist=1;;
170			T) timerfd_changelist=1;;
171			?*) usage && exit 1;;
172		esac
173	done
174
175	announce "Running tests:"
176
177	[ $timerfd -eq 0 ] || do_test EPOLL "(timerfd)"
178	[ $changelist -eq 0 ] || do_test EPOLL "(changelist)"
179	[ $timerfd_changelist -eq 0 ] || do_test EPOLL "(timerfd+changelist)"
180	for i in $backends; do
181		do_test $i
182	done
183
184	if test "$FAILED" = "yes"; then
185		exit 1
186	fi
187}
188main "$@"
189