1
/* $Id: transport_loop_test.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#define THIS_FILE "transport_loop_test.c"
27
static int datagram_loop_test()
30
pjsip_transport *loop;
35
int rtt[LOOP], min_rtt;
37
PJ_LOG(3,(THIS_FILE, "testing datagram loop transport"));
39
/* Test acquire transport. */
40
status = pjsip_endpt_acquire_transport( endpt, PJSIP_TRANSPORT_LOOP_DGRAM,
41
&addr, sizeof(addr), NULL, &loop);
42
if (status != PJ_SUCCESS) {
43
app_perror(" error: loop transport is not configured", status);
47
/* Get initial reference counter */
48
ref_cnt = pj_atomic_get(loop->ref_cnt);
50
/* Test basic transport attributes */
51
status = generic_transport_test(loop);
52
if (status != PJ_SUCCESS)
55
/* Basic transport's send/receive loopback test. */
56
for (i=0; i<LOOP; ++i) {
57
status = transport_send_recv_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop,
58
"sip:bob@130.0.0.1;transport=loop-dgram",
65
for (i=0; i<LOOP; ++i)
66
if (rtt[i] < min_rtt) min_rtt = rtt[i];
68
report_ival("loop-rtt-usec", min_rtt, "usec",
69
"Best Loopback transport round trip time, in microseconds "
70
"(time from sending request until response is received. "
71
"Tests were performed on local machine only)");
74
/* Multi-threaded round-trip test. */
75
status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop,
76
"sip:bob@130.0.0.1;transport=loop-dgram",
82
PJ_LOG(3,(THIS_FILE, " error: %d packet(s) was lost", pkt_lost));
87
PJ_LOG(3,(THIS_FILE," setting network delay to 10 ms"));
88
pjsip_loop_set_delay(loop, 10);
90
/* Multi-threaded round-trip test. */
91
status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop,
92
"sip:bob@130.0.0.1;transport=loop-dgram",
98
PJ_LOG(3,(THIS_FILE, " error: %d packet(s) was lost", pkt_lost));
103
pjsip_loop_set_delay(loop, 0);
105
/* Check reference counter. */
106
if (pj_atomic_get(loop->ref_cnt) != ref_cnt) {
107
PJ_LOG(3,(THIS_FILE, " error: ref counter is not %d (%d)",
108
ref_cnt, pj_atomic_get(loop->ref_cnt)));
112
/* Decrement reference. */
113
pjsip_transport_dec_ref(loop);
118
int transport_loop_test(void)
122
status = datagram_loop_test();