source: tests/asterisktestlib @ 3b59591

Last change on this file since 3b59591 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 4.0 KB
Line 
1#!/bin/bash
2# (C)2009 DatuX - Released under GPL
3
4
5
6#voer asterisk commando uit via cli
7asterisk_cmd()
8{
9        CMD="asterisk -r -x '$1'"
10        VERIFYEXIT=0
11        sshtest         
12        return $?
13}
14
15asterisk_errorcheck()
16{
17        DESCRIPTION1="check op fouten in logs.."
18        CMD="
19        cat /var/log/asterisk/full |
20                egrep '(WARNING|ERROR|abandoning)' |
21                grep -v 'chan_misdn'    |               # voor het testen zonder isdn kaart
22                grep -v 'app_queue.*fullname' |         # dit field word dor asterisk genegeerd maar is nodig voor asterisk_gui
23                grep -v 'Failed to write frame' |       # gebeurd na opnemen voicemail
24                grep -v 'Unable to write frame to channel' |    # gebeurd bij meetme wel eens
25                grep -v 'Channel .SIP/105-.* sent into invalid extension' | #ook voicemail
26                grep -v 'No SMDI interfaces' | # res_smdi is nodig voor voicemail, maar klaagt over interfaces
27                grep -v 'ast_expr2.fl:' |               # asterisk_gui configureeerd FOLLOW_ME variabelle niet in extensions.conf
28                grep -v 'app_fax is untested' |
29                grep -v 'app_voicemail.c: maxsilence'           
30
31        "
32        VERIFYNEGATIVE=".*"
33        sshtest || exit 1
34}
35
36#send a pjsua command
37pjsua_cmd()
38{
39        echo "pjsua: Sending command '$1'"
40        echo "$1" >> pjsua.in
41}
42
43#wait for specific pjsua output text
44LINES=1
45pjsua_wait()
46{
47        #DEBUG:
48        asterisk_errorcheck
49
50        COUNT=$TIMEOUT
51        while true; do
52                echo "pjsua: Waiting for '$1'..."
53                if tail -n +"$LINES" pjsua.log | egrep -i "$1"; then
54                    echo "pjsua: Found '$1'";
55                    LINES=`cat pjsua.log|wc -l`
56                    (( LINES++ ))
57                    return 0
58                fi
59                (( COUNT-- ))
60                if [ "$COUNT" == "0" ]; then
61                        echo "pjsua: Not found '$1'"
62                        LINES=`cat pjsua.log|wc -l`
63                        (( LINES++ ))
64                        return 1
65                fi
66                pjsua_cmd ""
67                sleep 1;
68        done
69}
70
71#restart pjsua. use this to reset everything
72#WARNING: patch./pjsip/include/pjsua-lib/pjsua.h by setting PJSUA_MAX_ACC to 10000 !
73pjsua_restart()
74{
75        trap "kill -9 %1" 0
76
77        ####restart pjsua sip client
78        killall -9 pjsua
79        sleep 1
80        echo -n > pjsua.in
81        echo -n > pjsua.log
82
83        tail -s .1 -f pjsua.in | pjsua --app-log-level=3 $PJSUA_OPTS | egrep --line-buffered '(pjsua)' | tee pjsua.log &
84#       tail -s .1 -f pjsua.in | pjsua --app-log-level=3 | tee pjsua.log &
85
86        #wait for init
87        pjsua_wait "initialized" || exit 1
88}
89
90
91## De pjsua_... zijn de VAGE lowlevel functies om met pjsua te communiceren.
92## De sip_... functies zijn DUIDELIJKE wrappers om standaard dingen te doen, die je in testcases gebruikt. (bellen ophangen etc)
93
94#register new sip account
95sip_register()
96{
97        info "sip: Registering $1@$IP (password test)"
98        pjsua_cmd "+a"
99        pjsua_cmd "sip:$1@$IP"
100        pjsua_cmd "sip:$1@$IP"
101        pjsua_cmd "*"
102        pjsua_cmd "$1"
103        pjsua_cmd "test" #password moet altijd 'test' zijn!
104 
105        if ! [ "$NOWAIT" ]; then
106                pjsua_wait "$1@$IP.*registration success"
107                return $?
108        fi
109        NOWAIT=
110        return 0
111}
112
113sip_call()
114{
115        info "sip: Calling $1"
116        pjsua_cmd "]"
117        pjsua_cmd "m"
118        pjsua_cmd "sip:$1@$IP"
119
120        pjsua_wait "changed to CALLING"
121        return $?
122}
123
124sip_waitanswer()
125{
126        info "sip: Wait until call is answered"
127        pjsua_wait "changed to CONFIRMED"
128        return $?
129}
130
131sip_waithangup()
132{
133        info "sip: Wait until call is ended"
134        pjsua_wait "is DISCONNECTED"
135        return $?
136}
137
138
139sip_hangup()
140{
141        info "sip: Hang up all calls"
142        pjsua_cmd "ha"
143        sip_waithangup
144        return $?
145}
146
147sip_answer()
148{
149        info "sip: Answer call"
150        OLDTIMEOUT=$TIMEOUT
151        TIMEOUT=1
152        COUNT=10
153        #find the call..
154        while ! sip_waitanswer; do
155                pjsua_cmd "]"
156                pjsua_cmd ""
157                pjsua_cmd "a"
158                pjsua_cmd "200"
159                sleep 1
160                (( COUNT-- ))
161                [ "$COUNT" == 0 ] && return 1
162        done
163
164        TIMEOUT=$OLDTIMEOUT
165
166        return $?
167}
168
169sip_transfer()
170{
171        info "sip: Transferring call to $1"
172        pjsua_cmd "x"
173        pjsua_cmd "sip:$1@$IP"
174        pjsua_wait "transfered successfully"
175        return $?
176}
177
178sip_hold()
179{
180        info "sip: Holding call"
181        pjsua_cmd "H"
182        pjsua_wait "is suspended"
183        return $?
184}
185
186sip_unhold()
187{
188        info "sip: Un-hold call"
189        pjsua_cmd "v"
190        pjsua_wait "Media for call.*active"
191        return $?
192}
193
194sip_dtmf()
195{
196        #ALS DIT NIET WERKT, HEB JE EEN FIREWALL ISSUE MET SYN3 BAK - ZET FIREWALL HELEMAAL OPEN
197        info "sip: Sending DTMF: $1"
198        pjsua_cmd "#"
199        pjsua_cmd "$1"
200        sleep 2 # give asterisk time to react
201        return $?
202}
203
204#6 seconds of sounds
205makesound()
206{
207        #mplayer  /usr/kde/3.5/share/sounds/KDE_Startup_3.ogg || exit 1
208        echo "MAKE SOUND!!!!"
209        sleep 6
210}
211
Note: See TracBrowser for help on using the repository browser.