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