summaryrefslogtreecommitdiff
path: root/protocols/Telegram/libevent/test/test.sh
blob: b73c1adced674a20e8f047ce7fb7a1abf9da3a21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/sh

BACKENDS="EVPORT KQUEUE EPOLL DEVPOLL POLL SELECT WIN32"
TESTS="test-eof test-closed test-weof test-time test-changelist test-fdleak"
FAILED=no
TEST_OUTPUT_FILE=${TEST_OUTPUT_FILE:-/dev/null}
REGRESS_ARGS=${REGRESS_ARGS:-}

# /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$//' | sed -e 's/test-script.sh//' `
if test -x "$T/test-init"
then
	TEST_DIR="$T"
elif test -x "./test/test-init"
then
        TEST_DIR="./test"
fi
if test -f "$T/check-dumpevents.py"
then
	TEST_SRC_DIR="$T"
elif test -f "./test/check-dumpevents.py"
then
        TEST_SRC_DIR="./test"
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 python2 -c 'import sys; assert(sys.version_info >= (2, 4))' 2>/dev/null && test -f $TEST_SRC_DIR/check-dumpevents.py; then
	    if $TEST_DIR/test-dumpevents | python2 $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 $REGRESS_ARGS
	else
		$TEST_DIR/regress $REGRESS_ARGS >>"$TEST_OUTPUT_FILE"
	fi
	if test "$?" = "0" ;
	then
		announce OKAY ;
	else
		announce FAILED ;
		FAILED=yes
	fi

	announce_n " regress_debug: "
	if test "$TEST_OUTPUT_FILE" = "/dev/null" ;
	then
		EVENT_DEBUG_MODE=1 $TEST_DIR/regress --quiet $REGRESS_ARGS
	else
		EVENT_DEBUG_MODE=1 $TEST_DIR/regress $REGRESS_ARGS >>"$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