f1c951267b4cb99e6b1c79bd281f83f7d96007d1
[platform/upstream/libnice.git] / stun / tests / check-bind.sh
1 #! /bin/sh
2
3 if test -n "${BUILT_WITH_MESON}"; then
4   STUNC=$1
5   STUND=$2
6 else
7   STUNC=../tools/stunbdc
8   STUND=../tools/stund
9 fi
10
11 cleanup() {
12   rm -f stund?.pid stund?.fail stunc?.log
13 }
14
15 trap cleanup EXIT
16
17 set -xe
18
19 # Dummy command line parsing tests
20 $STUNC -h
21 $STUNC -V
22 ! $STUNC server port dummy
23
24 # Timeout tests
25 ! $STUNC -4 127.0.0.1 1
26 ! $STUNC -6 ::1 1
27
28 # Allocate a likely unused port number
29 PORT=$((32768+$$))
30 if test $PORT -le 1024; then
31         PORT=$(($PORT+1024))
32 fi
33
34 echo "Using local UDP port number $PORT ..."
35
36 # Start the STUN test daemon if needed
37 cleanup()
38
39 for v in 4 6; do
40         (($SHELL -c "echo \$\$ > stund$v.pid ; exec $STUND -$v $PORT") || \
41                 touch stund$v.fail) &
42 done
43
44 # Run the test client
45 $STUNC -4 127.0.0.1 $PORT > stunc4.log || test -f stund4.fail
46 $STUNC -6 ::1 $PORT > stunc6.log || test -f stund6.fail
47
48 # Terminate the test daemon
49 for v in 4 6; do kill -INT $(cat stund$v.pid) || true; done
50 wait
51
52 # Check client results
53 if test -f stund4.fail; then exit 77; fi
54 grep -e "^Mapped address: 127.0.0.1" stunc4.log || exit 4
55
56 if test -f stund6.fail; then exit 77; fi
57 grep -e "^Mapped address: ::1" stunc6.log || exit 6