complex_sip_case_tester.c 14 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
	liblinphone_tester - liblinphone test suite
	Copyright (C) 2015  Belledonne Communications SARL

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


20
#include "linphone/core.h"
jehan's avatar
jehan committed
21
#include "liblinphone_tester.h"
22
#include "linphone/lpconfig.h"
jehan's avatar
jehan committed
23 24
#include "private.h"

25

26
#if HAVE_SIPP
27 28
void check_rtcp(LinphoneCall *call) {
	MSTimeSpec ts;
29
	LinphoneCallStats *audio_stats, *video_stats;
30

31 32
	linphone_call_ref(call);
	liblinphone_tester_clock_start(&ts);
33

34
	do {
35 36 37
		audio_stats = linphone_call_get_audio_stats(call);
		video_stats = linphone_call_get_video_stats(call);
		if (linphone_call_stats_get_round_trip_delay(audio_stats) > 0.0 && (!linphone_call_log_video_enabled(linphone_call_get_call_log(call)) || linphone_call_stats_get_round_trip_delay(video_stats) > 0.0)) {
38 39
			break;
		}
40 41
		linphone_call_stats_unref(audio_stats);
		if (video_stats) linphone_call_stats_unref(video_stats);
42
		wait_for_until(linphone_call_get_core(call), NULL, NULL, 0, 20); /*just to sleep while iterating*/
43
	} while (!liblinphone_tester_clock_elapsed(&ts, 15000));
44

45 46
	audio_stats = linphone_call_get_audio_stats(call);
	BC_ASSERT_GREATER(linphone_call_stats_get_round_trip_delay(audio_stats), 0.0, float, "%f");
47
	if (linphone_call_log_video_enabled(linphone_call_get_call_log(call))) {
48 49 50
		video_stats = linphone_call_get_video_stats(call);
		BC_ASSERT_GREATER(linphone_call_stats_get_round_trip_delay(video_stats), 0.0, float, "%f");
		linphone_call_stats_unref(video_stats);
51
	}
52
	linphone_call_stats_unref(audio_stats);
53

54 55
	linphone_call_unref(call);
}
jehan's avatar
jehan committed
56

57
FILE *sip_start(const char *senario, const char* dest_username, const char *passwd, LinphoneAddress* dest_addres) {
jehan's avatar
jehan committed
58 59 60
	char *dest;
	char *command;
	FILE *file;
61

jehan's avatar
jehan committed
62 63 64 65
	if (linphone_address_get_port(dest_addres)>0)
		dest = ms_strdup_printf("%s:%i",linphone_address_get_domain(dest_addres),linphone_address_get_port(dest_addres));
	else
		dest = ms_strdup_printf("%s",linphone_address_get_domain(dest_addres));
66
	//until errors logs are handled correctly and stop breaks output, they will be DISABLED
67 68 69 70
	command = ms_strdup_printf(SIPP_COMMAND" -sf %s -s %s %s -trace_err -trace_msg -rtp_echo -m 1 -d 1000 -ap %s 2>/dev/null",senario
								,dest_username
								,dest
								,(passwd?passwd:"none"));
71

72
	ms_message("Starting sipp command [%s]",command);
jehan's avatar
jehan committed
73 74 75 76 77
	file = popen(command, "r");
	ms_free(command);
	ms_free(dest);
	return file;
}
78

79

80 81 82 83 84
static FILE *sip_start_recv(const char *senario) {
	char *command;
	FILE *file;

	//until errors logs are handled correctly and stop breaks output, they will be DISABLED
85
	command = ms_strdup_printf(SIPP_COMMAND" -sf %s -trace_err -trace_msg -rtp_echo -m 1 -d 1000 2>/dev/null",senario);
86

87
	ms_message("Starting sipp command [%s]",command);
88 89 90 91
	file = popen(command, "r");
	ms_free(command);
	return file;
}
92

93
static void dest_server_server_resolved(void *data, const char *name, struct addrinfo *ai_list, uint32_t ttl) {
jehan's avatar
jehan committed
94
	*(struct addrinfo **)data =ai_list;
Simon Morlat's avatar
Simon Morlat committed
95 96
}

97
LinphoneAddress * linphone_core_manager_resolve(LinphoneCoreManager *mgr, const LinphoneAddress *source) {
jehan's avatar
jehan committed
98 99 100
	struct addrinfo *addrinfo = NULL;
	char ipstring [INET6_ADDRSTRLEN];
	int err;
101 102 103 104 105 106 107
	int port = linphone_address_get_port(source);
	LinphoneAddress * dest;
	
	sal_resolve_a(	mgr->lc->sal
	 ,linphone_address_get_domain(source)
	 ,linphone_address_get_port(source)
	 ,AF_INET
108
	 ,dest_server_server_resolved
109 110 111 112 113
	 ,&addrinfo);
	
	 dest=linphone_address_new(NULL);
	 
	 wait_for(mgr->lc, mgr->lc, (int*)&addrinfo, 1);
114
	 err=bctbx_getnameinfo((struct sockaddr*)addrinfo->ai_addr,addrinfo->ai_addrlen,ipstring,INET6_ADDRSTRLEN,NULL,0,NI_NUMERICHOST);
Simon Morlat's avatar
Simon Morlat committed
115 116 117
	 if (err !=0 ){
		 ms_error("linphone_core_manager_resolve(): getnameinfo error %s", gai_strerror(err));
	 }
118 119 120 121 122 123 124 125 126 127
	 linphone_address_set_domain(dest, ipstring);
	 if (port > 0)
		linphone_address_set_port(dest, port);
	
	return dest;
}


static void sip_update_within_icoming_reinvite_with_no_sdp(void) {
	LinphoneCoreManager *mgr;
jehan's avatar
jehan committed
128
	char *identity_char;
jehan's avatar
jehan committed
129 130
	char *scen;
	FILE * sipp_out;
131

jehan's avatar
jehan committed
132 133 134 135 136 137 138
	/*currently we use direct connection because sipp do not properly set ACK request uri*/
	mgr= linphone_core_manager_new2( "empty_rc", FALSE);
	mgr->identity= linphone_core_get_primary_contact_parsed(mgr->lc);
	linphone_address_set_username(mgr->identity,"marie");
	identity_char=linphone_address_as_string(mgr->identity);
	linphone_core_set_primary_contact(mgr->lc,identity_char);
	linphone_core_iterate(mgr->lc);
jehan's avatar
jehan committed
139
	scen = bc_tester_res("sipp/sip_update_within_icoming_reinvite_with_no_sdp.xml");
140
	sipp_out = sip_start(scen, linphone_address_get_username(mgr->identity),NULL, mgr->identity);
jehan's avatar
jehan committed
141 142

	if (sipp_out) {
jehan's avatar
jehan committed
143
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1));
144
		linphone_call_accept(linphone_core_get_current_call(mgr->lc));
jehan's avatar
jehan committed
145 146 147
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 2));
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1));
		pclose(sipp_out);
jehan's avatar
jehan committed
148
	}
jehan's avatar
jehan committed
149
	linphone_core_manager_destroy(mgr);
jehan's avatar
jehan committed
150 151
}

152
static void call_with_audio_mline_before_video_in_sdp(void) {
153 154 155 156 157
	LinphoneCoreManager *mgr;
	char *identity_char;
	char *scen;
	FILE * sipp_out;
	LinphoneCall *call = NULL;
158

159 160 161 162 163 164
	/*currently we use direct connection because sipp do not properly set ACK request uri*/
	mgr= linphone_core_manager_new2( "empty_rc", FALSE);
	mgr->identity = linphone_core_get_primary_contact_parsed(mgr->lc);
	linphone_address_set_username(mgr->identity,"marie");
	identity_char = linphone_address_as_string(mgr->identity);
	linphone_core_set_primary_contact(mgr->lc,identity_char);
165

166
	linphone_core_iterate(mgr->lc);
167

168
	scen = bc_tester_res("sipp/call_with_audio_mline_before_video_in_sdp.xml");
169

170
	sipp_out = sip_start(scen, linphone_address_get_username(mgr->identity), NULL,  mgr->identity);
171 172 173

	if (sipp_out) {
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1));
174
		call = linphone_core_get_current_call(mgr->lc);
175 176
		BC_ASSERT_PTR_NOT_NULL(call);
		if (call) {
177
			linphone_call_accept(call);
178
			BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 1));
179
#if 0
180 181 182
			BC_ASSERT_EQUAL(call->main_audio_stream_index, 0, int, "%d");
			BC_ASSERT_EQUAL(call->main_video_stream_index, 1, int, "%d");
			BC_ASSERT_TRUE(call->main_text_stream_index > 1);
183
#endif
184 185 186 187
			BC_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(call)));

			check_rtcp(call);
		}
188

189 190 191 192 193 194
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1));
		pclose(sipp_out);
	}
	linphone_core_manager_destroy(mgr);
}

195
static void call_with_video_mline_before_audio_in_sdp(void) {
196 197 198 199 200
	LinphoneCoreManager *mgr;
	char *identity_char;
	char *scen;
	FILE * sipp_out;
	LinphoneCall *call = NULL;
201

202 203
	/*currently we use direct connection because sipp do not properly set ACK request uri*/
	mgr= linphone_core_manager_new2( "empty_rc", FALSE);
204
	mgr->identity = linphone_core_get_primary_contact_parsed(mgr->lc);
205
	linphone_address_set_username(mgr->identity,"marie");
206
	identity_char = linphone_address_as_string(mgr->identity);
207
	linphone_core_set_primary_contact(mgr->lc,identity_char);
208

209
	linphone_core_iterate(mgr->lc);
210

211
	scen = bc_tester_res("sipp/call_with_video_mline_before_audio_in_sdp.xml");
212

213
	sipp_out = sip_start(scen, linphone_address_get_username(mgr->identity), NULL, mgr->identity);
214 215 216

	if (sipp_out) {
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1));
217
		call = linphone_core_get_current_call(mgr->lc);
218 219
		BC_ASSERT_PTR_NOT_NULL(call);
		if (call) {
220
			linphone_call_accept(call);
221
			BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 1));
222
#if 0
223 224 225
			BC_ASSERT_EQUAL(call->main_audio_stream_index, 1, int, "%d");
			BC_ASSERT_EQUAL(call->main_video_stream_index, 0, int, "%d");
			BC_ASSERT_TRUE(call->main_text_stream_index > 1);
226
#endif
227 228 229 230
			BC_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(call)));

			check_rtcp(call);
		}
231

232 233 234 235 236 237
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1));
		pclose(sipp_out);
	}
	linphone_core_manager_destroy(mgr);
}

238
static void call_with_multiple_audio_mline_in_sdp(void) {
239 240 241 242 243
	LinphoneCoreManager *mgr;
	char *identity_char;
	char *scen;
	FILE * sipp_out;
	LinphoneCall *call = NULL;
244

245 246 247 248 249 250
	/*currently we use direct connection because sipp do not properly set ACK request uri*/
	mgr= linphone_core_manager_new2( "empty_rc", FALSE);
	mgr->identity = linphone_core_get_primary_contact_parsed(mgr->lc);
	linphone_address_set_username(mgr->identity,"marie");
	identity_char = linphone_address_as_string(mgr->identity);
	linphone_core_set_primary_contact(mgr->lc,identity_char);
251

252
	linphone_core_iterate(mgr->lc);
253

254
	scen = bc_tester_res("sipp/call_with_multiple_audio_mline_in_sdp.xml");
255

256
	sipp_out = sip_start(scen, linphone_address_get_username(mgr->identity), NULL, mgr->identity);
257 258 259

	if (sipp_out) {
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1));
260
		call = linphone_core_get_current_call(mgr->lc);
261 262
		BC_ASSERT_PTR_NOT_NULL(call);
		if (call) {
263
			linphone_call_accept(call);
264
			BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 1));
265
#if 0
266 267 268
			BC_ASSERT_EQUAL(call->main_audio_stream_index, 0, int, "%d");
			BC_ASSERT_EQUAL(call->main_video_stream_index, 2, int, "%d");
			BC_ASSERT_TRUE(call->main_text_stream_index > 2);
269
#endif
270 271 272 273
			BC_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(call)));

			check_rtcp(call);
		}
274

275 276 277 278 279 280
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1));
		pclose(sipp_out);
	}
	linphone_core_manager_destroy(mgr);
}

281
static void call_with_multiple_video_mline_in_sdp(void) {
282 283 284 285 286
	LinphoneCoreManager *mgr;
	char *identity_char;
	char *scen;
	FILE * sipp_out;
	LinphoneCall *call = NULL;
287

288 289 290 291 292 293
	/*currently we use direct connection because sipp do not properly set ACK request uri*/
	mgr= linphone_core_manager_new2( "empty_rc", FALSE);
	mgr->identity = linphone_core_get_primary_contact_parsed(mgr->lc);
	linphone_address_set_username(mgr->identity,"marie");
	identity_char = linphone_address_as_string(mgr->identity);
	linphone_core_set_primary_contact(mgr->lc,identity_char);
294

295
	linphone_core_iterate(mgr->lc);
296

297
	scen = bc_tester_res("sipp/call_with_multiple_video_mline_in_sdp.xml");
298

299
	sipp_out = sip_start(scen, linphone_address_get_username(mgr->identity), NULL, mgr->identity);
300 301 302

	if (sipp_out) {
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1));
303
		call = linphone_core_get_current_call(mgr->lc);
304 305
		BC_ASSERT_PTR_NOT_NULL(call);
		if (call) {
306
			linphone_call_accept(call);
307
			BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 1));
308
#if 0
309 310 311
			BC_ASSERT_EQUAL(call->main_audio_stream_index, 0, int, "%d");
			BC_ASSERT_EQUAL(call->main_video_stream_index, 1, int, "%d");
			BC_ASSERT_TRUE(call->main_text_stream_index > 3);
312
#endif
313 314 315 316
			BC_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(call)));

			check_rtcp(call);
		}
317

318 319 320 321 322 323
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1));
		pclose(sipp_out);
	}
	linphone_core_manager_destroy(mgr);
}

324

325
static void call_invite_200ok_without_contact_header(void) {
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
	LinphoneCoreManager *mgr;
	char *identity_char;
	char *scen;
	FILE * sipp_out;
	LinphoneCall *call = NULL;

	/*currently we use direct connection because sipp do not properly set ACK request uri*/
	mgr= linphone_core_manager_new2("empty_rc", FALSE);
	mgr->identity = linphone_core_get_primary_contact_parsed(mgr->lc);
	linphone_address_set_username(mgr->identity,"marie");
	identity_char = linphone_address_as_string(mgr->identity);
	linphone_core_set_primary_contact(mgr->lc,identity_char);

	linphone_core_iterate(mgr->lc);

	scen = bc_tester_res("sipp/call_invite_200ok_without_contact_header.xml");

	sipp_out = sip_start_recv(scen);

	if (sipp_out) {
		call = linphone_core_invite(mgr->lc, "sipp@127.0.0.1");
		BC_ASSERT_PTR_NOT_NULL(call);
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallOutgoingInit, 1));
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallOutgoingProgress, 1));
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallOutgoingRinging, 1));
351 352 353 354
		/*assert that the call never gets connected nor terminated*/
		BC_ASSERT_FALSE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallConnected, 1));
		BC_ASSERT_EQUAL(mgr->stat.number_of_LinphoneCallEnd, 0, int, "%d");
		BC_ASSERT_EQUAL(mgr->stat.number_of_LinphoneCallError, 0, int, "%d");
355
		linphone_call_terminate(call);
356 357
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1));
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallReleased, 1));
358 359 360 361
		pclose(sipp_out);
	}
	linphone_core_manager_destroy(mgr);
}
362

363

jehan's avatar
jehan committed
364
static test_t tests[] = {
365 366 367 368 369 370
	TEST_NO_TAG("SIP UPDATE within incoming reinvite without sdp", sip_update_within_icoming_reinvite_with_no_sdp),
	TEST_NO_TAG("Call with audio mline before video in sdp", call_with_audio_mline_before_video_in_sdp),
	TEST_NO_TAG("Call with video mline before audio in sdp", call_with_video_mline_before_audio_in_sdp),
	TEST_NO_TAG("Call with multiple audio mline in sdp", call_with_multiple_audio_mline_in_sdp),
	TEST_NO_TAG("Call with multiple video mline in sdp", call_with_multiple_video_mline_in_sdp),
	TEST_NO_TAG("Call invite 200ok without contact header", call_invite_200ok_without_contact_header)
jehan's avatar
jehan committed
371
};
372
#endif
jehan's avatar
jehan committed
373

jehan's avatar
jehan committed
374
test_suite_t complex_sip_call_test_suite = {
375
	"Complex SIP Case",
Sylvain Berfini's avatar
Sylvain Berfini committed
376 377 378
	NULL,
	NULL,
	liblinphone_tester_before_each,
379
	liblinphone_tester_after_each,
380
#if HAVE_SIPP
jehan's avatar
jehan committed
381 382
	sizeof(tests) / sizeof(tests[0]),
	tests
383 384 385 386
#else
	0,
	NULL
#endif
jehan's avatar
jehan committed
387
};