complex_sip_case_tester.c 14.2 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"
Benjamin REIS's avatar
Benjamin REIS committed
23
#include "tester_utils.h"
jehan's avatar
jehan committed
24

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
	int port = linphone_address_get_port(source);
	LinphoneAddress * dest;
Benjamin REIS's avatar
Benjamin REIS committed
103

104
	sal_resolve_a(linphone_core_get_sal(mgr->lc)
105 106 107
	 ,linphone_address_get_domain(source)
	 ,linphone_address_get_port(source)
	 ,AF_INET
108
	 ,dest_server_server_resolved
109
	 ,&addrinfo);
Benjamin REIS's avatar
Benjamin REIS committed
110

111
	 dest=linphone_address_new(NULL);
Benjamin REIS's avatar
Benjamin REIS committed
112

113
	 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
	 linphone_address_set_domain(dest, ipstring);
	 if (port > 0)
		linphone_address_set_port(dest, port);
Benjamin REIS's avatar
Benjamin REIS committed
121

122 123 124 125 126 127
	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 145 146 147 148
		if (linphone_core_get_current_call(mgr->lc)) {
			linphone_call_accept(linphone_core_get_current_call(mgr->lc));
			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));
		}
jehan's avatar
jehan committed
149
		pclose(sipp_out);
jehan's avatar
jehan committed
150
	}
jehan's avatar
jehan committed
151
	linphone_core_manager_destroy(mgr);
jehan's avatar
jehan committed
152 153
}

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

161 162 163 164 165 166
	/*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);
167

168
	linphone_core_iterate(mgr->lc);
169

170
	scen = bc_tester_res("sipp/call_with_audio_mline_before_video_in_sdp.xml");
171

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

	if (sipp_out) {
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1));
176
		call = linphone_core_get_current_call(mgr->lc);
177 178
		BC_ASSERT_PTR_NOT_NULL(call);
		if (call) {
179
			linphone_call_accept(call);
180
			BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 1));
181 182 183
			BC_ASSERT_EQUAL(_linphone_call_get_main_audio_stream_index(call), 0, int, "%d");
			BC_ASSERT_EQUAL(_linphone_call_get_main_video_stream_index(call), 1, int, "%d");
			BC_ASSERT_TRUE(_linphone_call_get_main_text_stream_index(call) > 1);
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 223 224
			BC_ASSERT_EQUAL(_linphone_call_get_main_audio_stream_index(call), 1, int, "%d");
			BC_ASSERT_EQUAL(_linphone_call_get_main_video_stream_index(call), 0, int, "%d");
			BC_ASSERT_TRUE(_linphone_call_get_main_text_stream_index(call) > 1);
225 226 227 228
			BC_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(call)));

			check_rtcp(call);
		}
229

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

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

243 244 245 246 247 248
	/*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);
249

250
	linphone_core_iterate(mgr->lc);
251

252
	scen = bc_tester_res("sipp/call_with_multiple_audio_mline_in_sdp.xml");
253

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

	if (sipp_out) {
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1));
258
		call = linphone_core_get_current_call(mgr->lc);
259 260
		BC_ASSERT_PTR_NOT_NULL(call);
		if (call) {
261
			linphone_call_accept(call);
262
			BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 1));
263 264 265
			BC_ASSERT_EQUAL(_linphone_call_get_main_audio_stream_index(call), 0, int, "%d");
			BC_ASSERT_EQUAL(_linphone_call_get_main_video_stream_index(call), 2, int, "%d");
			BC_ASSERT_TRUE(_linphone_call_get_main_text_stream_index(call) > 2);
266 267 268 269
			BC_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(call)));

			check_rtcp(call);
		}
270

271 272 273 274 275 276
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1));
		pclose(sipp_out);
	}
	linphone_core_manager_destroy(mgr);
}

277
static void call_with_multiple_video_mline_in_sdp(void) {
278 279 280 281 282
	LinphoneCoreManager *mgr;
	char *identity_char;
	char *scen;
	FILE * sipp_out;
	LinphoneCall *call = NULL;
283

284 285 286 287 288 289
	/*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);
290

291
	linphone_core_iterate(mgr->lc);
292

293
	scen = bc_tester_res("sipp/call_with_multiple_video_mline_in_sdp.xml");
294

295
	sipp_out = sip_start(scen, linphone_address_get_username(mgr->identity), NULL, mgr->identity);
296 297 298

	if (sipp_out) {
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallIncomingReceived, 1));
299
		call = linphone_core_get_current_call(mgr->lc);
300 301
		BC_ASSERT_PTR_NOT_NULL(call);
		if (call) {
302
			linphone_call_accept(call);
303
			BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallStreamsRunning, 1));
304 305 306
			BC_ASSERT_EQUAL(_linphone_call_get_main_audio_stream_index(call), 0, int, "%d");
			BC_ASSERT_EQUAL(_linphone_call_get_main_video_stream_index(call), 1, int, "%d");
			BC_ASSERT_TRUE(_linphone_call_get_main_text_stream_index(call) > 3);
307 308 309 310
			BC_ASSERT_TRUE(linphone_call_log_video_enabled(linphone_call_get_call_log(call)));

			check_rtcp(call);
		}
311

312 313 314 315 316 317
		BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1));
		pclose(sipp_out);
	}
	linphone_core_manager_destroy(mgr);
}

318

319
static void call_invite_200ok_without_contact_header(void) {
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
	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));
345 346 347 348
		/*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");
349
		linphone_call_terminate(call);
350 351
		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));
352 353 354 355
		pclose(sipp_out);
	}
	linphone_core_manager_destroy(mgr);
}
356

357

jehan's avatar
jehan committed
358
static test_t tests[] = {
359 360 361 362 363 364
	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
365
};
366
#endif
jehan's avatar
jehan committed
367

jehan's avatar
jehan committed
368
test_suite_t complex_sip_call_test_suite = {
369
	"Complex SIP Case",
Sylvain Berfini's avatar
Sylvain Berfini committed
370 371 372
	NULL,
	NULL,
	liblinphone_tester_before_each,
373
	liblinphone_tester_after_each,
374
#if HAVE_SIPP
jehan's avatar
jehan committed
375 376
	sizeof(tests) / sizeof(tests[0]),
	tests
377 378 379 380
#else
	0,
	NULL
#endif
jehan's avatar
jehan committed
381
};