1 | #!/usr/bin/env bash |
---|
2 | |
---|
3 | start_skyped() |
---|
4 | { |
---|
5 | python ../skyped.py "$@" > skypedtest.pid |
---|
6 | while true |
---|
7 | do |
---|
8 | [ -e skypedtest.pid ] || break |
---|
9 | pid=$(sed 's/.*: //' skypedtest.pid) |
---|
10 | if [ -n "$(ps -p $pid -o pid=)" ]; then |
---|
11 | sleep 5 |
---|
12 | else |
---|
13 | start_skyped "$@" |
---|
14 | break |
---|
15 | fi |
---|
16 | done |
---|
17 | } |
---|
18 | |
---|
19 | BITLBEE=$1 |
---|
20 | typeset -ix PORT=`echo $2 | egrep '^[0-9]{1,5}$'` |
---|
21 | SCRIPT=$3 |
---|
22 | shift 3 |
---|
23 | |
---|
24 | [ -n "$SCRIPT" -a -n "$BITLBEE" -a -e "$SCRIPT" -a "$PORT" -ne 0 ] || { echo Syntax: `basename "$0"` bitlbee-executable listening-port test-script test-script-args; exit 1; } |
---|
25 | |
---|
26 | # Create or empty test dir |
---|
27 | mkdir livetest 2>/dev/null || rm livetest/bitlbeetest*.xml bitlbeetest.pid 2>/dev/null |
---|
28 | |
---|
29 | # Run the bee |
---|
30 | echo Running bitlbee... |
---|
31 | $VALGRIND $BITLBEE -n -c bitlbee.conf -d livetest/ -D -P bitlbeetest.pid -p $PORT 2>bitlbee.log & |
---|
32 | sleep 2 |
---|
33 | |
---|
34 | # Check if it's really running |
---|
35 | kill -0 `cat bitlbeetest.pid 2>/dev/null ` 2>/dev/null || { echo Failed to run bitlbee daemon on port $PORT; exit 1; } |
---|
36 | |
---|
37 | if [ -z "$TUNNELED_MODE" ]; then |
---|
38 | # Set up skyped |
---|
39 | |
---|
40 | rm -rf etc |
---|
41 | mkdir etc |
---|
42 | cd etc |
---|
43 | cp ../../skyped.cnf . |
---|
44 | cp ~/.skyped/skyped.cert.pem . |
---|
45 | cp ~/.skyped/skyped.key.pem . |
---|
46 | cd .. |
---|
47 | echo "[skyped]" > skyped.conf |
---|
48 | echo "username = $TEST_SKYPE_ID" >> skyped.conf |
---|
49 | SHA1=`which sha1sum` |
---|
50 | if [ -z "$SHA1" ]; then |
---|
51 | SHA1=`which sha1` |
---|
52 | fi |
---|
53 | if [ -z "$SHA1" ]; then |
---|
54 | echo Test failed |
---|
55 | echo "(Can't compute password for skyped.conf)" |
---|
56 | exit 77 |
---|
57 | fi |
---|
58 | echo "password = $(echo -n $TEST_SKYPE_PASSWORD|$SHA1|sed 's/ *-$//')" >> skyped.conf |
---|
59 | # we use ~ here to test that resolve that syntax works |
---|
60 | echo "cert = $(pwd|sed "s|$HOME|~|")/etc/skyped.cert.pem" >> skyped.conf |
---|
61 | echo "key = $(pwd|sed "s|$HOME|~|")/etc/skyped.key.pem" >> skyped.conf |
---|
62 | echo "port = 2727" >> skyped.conf |
---|
63 | |
---|
64 | # Run skyped |
---|
65 | start_skyped -c skyped.conf -l skypedtest.log & |
---|
66 | sleep 2 |
---|
67 | fi |
---|
68 | |
---|
69 | if [ "$TUNNELED_MODE" = "yes" ]; then |
---|
70 | rm -f tunnel.pid |
---|
71 | if [ -n "$TUNNEL_SCRIPT" ]; then |
---|
72 | $TUNNEL_SCRIPT & |
---|
73 | echo $! > tunnel.pid |
---|
74 | sleep 5 |
---|
75 | fi |
---|
76 | fi |
---|
77 | |
---|
78 | # Run the test |
---|
79 | echo Running test script... |
---|
80 | "$SCRIPT" $* |
---|
81 | RET=$? |
---|
82 | |
---|
83 | if [ -z "$TUNNELED_MODE" ]; then |
---|
84 | # skyped runs on another host: no means to kill it |
---|
85 | # Kill skyped |
---|
86 | killall -TERM skype |
---|
87 | if [ -f skypedtest.pid ]; then |
---|
88 | pid=$(sed 's/.*: //' skypedtest.pid) |
---|
89 | rm skypedtest.pid |
---|
90 | [ -n "$(ps -p $pid -o pid=)" ] && kill -TERM $pid |
---|
91 | fi |
---|
92 | fi |
---|
93 | |
---|
94 | if [ "$TUNNELED_MODE" = "yes" ]; then |
---|
95 | if [ -n "$TUNNEL_SCRIPT" ]; then |
---|
96 | cat tunnel.pid >> /tmp/tunnel.pid |
---|
97 | kill `cat tunnel.pid` |
---|
98 | rm -f tunnel.pid |
---|
99 | fi |
---|
100 | fi |
---|
101 | |
---|
102 | # Kill bee |
---|
103 | echo Killing bitlbee... |
---|
104 | kill `cat bitlbeetest.pid` |
---|
105 | |
---|
106 | if [ "$TUNNELED_MODE" = "yes" ]; then |
---|
107 | # give the skyped a chance to timeout |
---|
108 | sleep 30 |
---|
109 | fi |
---|
110 | |
---|
111 | # Return test result |
---|
112 | [ $RET -eq 0 ] && echo Test passed |
---|
113 | [ $RET -ne 0 ] && echo Test failed |
---|
114 | [ $RET -eq 22 ] && echo '(timed out)' |
---|
115 | [ $RET -eq 66 ] && echo '(environment variables missing)' |
---|
116 | exit $RET |
---|