summaryrefslogtreecommitdiff
path: root/tests/pjsua/mod_call.py
blob: c725f2108b636aee8b3e4841d2209e4dbc00804a (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# $Id: mod_call.py 2078 2008-06-27 21:12:12Z nanang $
import time
import imp
import sys
import inc_const as const
from inc_cfg import *

# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])

# Check media flow between ua1 and ua2
def check_media(ua1, ua2):
	ua1.send("#")
	ua1.expect("#")
	ua1.send("1122")
	ua2.expect(const.RX_DTMF + "1")
	ua2.expect(const.RX_DTMF + "1")
	ua2.expect(const.RX_DTMF + "2")
	ua2.expect(const.RX_DTMF + "2")


# Test body function
def test_func(t):
	callee = t.process[0]
	caller = t.process[1]

	# if have_reg then wait for couple of seconds for PUBLISH
	# to complete (just in case pUBLISH is used)
	if callee.inst_param.have_reg:
		time.sleep(1)
	if caller.inst_param.have_reg:
		time.sleep(1)

	# Caller making call
	caller.send("m")
	caller.send(t.inst_params[0].uri)
	caller.expect(const.STATE_CALLING)
	
	# Callee waits for call and answers with 180/Ringing
	time.sleep(0.2)
	callee.expect(const.EVENT_INCOMING_CALL)
	callee.send("a")
	callee.send("180")
	callee.expect("SIP/2.0 180")
	caller.expect("SIP/2.0 180")

	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Callee answers with 200/OK
	callee.send("a")
	callee.send("200")

	# Wait until call is connected in both endpoints
	time.sleep(0.2)
	caller.expect(const.STATE_CONFIRMED)
	callee.expect(const.STATE_CONFIRMED)

	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()
	time.sleep(0.1)
	caller.sync_stdout()
	callee.sync_stdout()

	# Test that media is okay
	time.sleep(0.3)
	check_media(caller, callee)
	check_media(callee, caller)

	# Hold call by caller
	caller.send("H")
	caller.expect("INVITE sip:")
	callee.expect("INVITE sip:")
	caller.expect(const.MEDIA_HOLD)
	callee.expect(const.MEDIA_HOLD)
	
	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Release hold
	time.sleep(0.5)
	caller.send("v")
	caller.expect("INVITE sip:")
	callee.expect("INVITE sip:")
	caller.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold")
	callee.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold")

	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Test that media is okay
	check_media(caller, callee)
	check_media(callee, caller)

	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Hold call by callee
	callee.send("H")
	callee.expect("INVITE sip:")
	caller.expect("INVITE sip:")
	caller.expect(const.MEDIA_HOLD)
	callee.expect(const.MEDIA_HOLD)
	
	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Release hold
	time.sleep(0.1)
	callee.send("v")
	callee.expect("INVITE sip:")
	caller.expect("INVITE sip:")
	callee.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold")
	caller.expect(const.MEDIA_ACTIVE, title="waiting for media active after call hold")

	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Test that media is okay
	# Wait for some time for ICE negotiation
	time.sleep(0.6)
	check_media(caller, callee)
	check_media(callee, caller)

	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# UPDATE (by caller)
	caller.send("U")
	#caller.sync_stdout()
	callee.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE")
	caller.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE")
	
	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Test that media is okay
	time.sleep(0.1)
	check_media(caller, callee)
	check_media(callee, caller)

	# UPDATE (by callee)
	callee.send("U")
	callee.expect("UPDATE sip:")
	caller.expect("UPDATE sip:")
	caller.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE")
	callee.expect(const.MEDIA_ACTIVE, title="waiting for media active with UPDATE")
	
	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Test that media is okay
	time.sleep(0.1)
	check_media(caller, callee)
	check_media(callee, caller)

	# Synchronize stdout
	caller.sync_stdout()
	callee.sync_stdout()

	# Set codecs in both caller and callee so that there is
	# no common codec between them.
	# In caller we only enable PCMU, in callee we only enable PCMA
	caller.send("Cp")
	caller.expect("Enter codec")
	caller.send("* 0")
	caller.send("Cp")
	caller.expect("Enter codec")
	caller.send("pcmu 120")
	
	callee.send("Cp")
	callee.expect("Enter codec")
	callee.send("* 0")
	callee.send("Cp")
	callee.expect("Enter codec")
	callee.send("pcma 120")

	# Test when UPDATE fails (by callee)
	callee.send("U")
	caller.expect("SIP/2.0 488")
	callee.expect("SIP/2.0 488")
	callee.sync_stdout()
	caller.sync_stdout()
	
	# Test that media is still okay
	time.sleep(0.1)
	check_media(caller, callee)
	check_media(callee, caller)

	# Test when UPDATE fails (by caller)
	caller.send("U")
	caller.expect("UPDATE sip:")
	callee.expect("UPDATE sip:")
	callee.expect("SIP/2.0 488")
	caller.expect("SIP/2.0 488")
	caller.sync_stdout()
	callee.sync_stdout()
	
	# Test that media is still okay
	time.sleep(0.1)
	check_media(callee, caller)
	check_media(caller, callee)

	# Hangup call
	time.sleep(0.1)
	caller.send("h")

	# Wait until calls are cleared in both endpoints
	caller.expect(const.STATE_DISCONNECTED)
	callee.expect(const.STATE_DISCONNECTED)
	

# Here where it all comes together
test = cfg_file.test_param
test.test_func = test_func