blob: 351fb7b68817a160865a44a17b7055ae64becf60 [file] [log] [blame]
Benny Prijonofa73e3e2006-01-05 23:35:46 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "test.h"
Benny Prijono40f2f642006-01-30 18:40:05 +000021#include <pjsip.h>
Benny Prijonofa73e3e2006-01-05 23:35:46 +000022#include <pjlib.h>
23
Benny Prijono85598d92006-01-07 18:44:25 +000024#define THIS_FILE "transport_loop_test.c"
25
Benny Prijonofa73e3e2006-01-05 23:35:46 +000026static int datagram_loop_test()
27{
Benny Prijono85598d92006-01-07 18:44:25 +000028 pjsip_transport *loop;
29 int i, pkt_lost;
Benny Prijonofa73e3e2006-01-05 23:35:46 +000030 pj_sockaddr_in addr;
31 pj_status_t status;
32
Benny Prijono85598d92006-01-07 18:44:25 +000033 PJ_LOG(3,(THIS_FILE, "testing datagram loop transport"));
Benny Prijonofa73e3e2006-01-05 23:35:46 +000034
35 /* Test acquire transport. */
36 status = pjsip_endpt_acquire_transport( endpt, PJSIP_TRANSPORT_LOOP_DGRAM,
Benny Prijono85598d92006-01-07 18:44:25 +000037 &addr, sizeof(addr), &loop);
Benny Prijonofa73e3e2006-01-05 23:35:46 +000038 if (status != PJ_SUCCESS) {
Benny Prijono85598d92006-01-07 18:44:25 +000039 app_perror(" error: loop transport is not configured", status);
Benny Prijonofa73e3e2006-01-05 23:35:46 +000040 return -20;
41 }
42
Benny Prijonofa73e3e2006-01-05 23:35:46 +000043 /* Test basic transport attributes */
44 status = generic_transport_test(loop);
45 if (status != PJ_SUCCESS)
46 return status;
47
48 /* Basic transport's send/receive loopback test. */
49 for (i=0; i<2; ++i) {
50 status = transport_send_recv_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop,
51 "sip:bob@130.0.0.1;transport=loop-dgram");
52 if (status != 0)
53 return status;
54 }
55
Benny Prijono85598d92006-01-07 18:44:25 +000056 /* Multi-threaded round-trip test. */
57 status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop,
58 "sip:bob@130.0.0.1;transport=loop-dgram",
59 &pkt_lost);
60 if (status != 0)
61 return status;
62
63 if (pkt_lost != 0) {
64 PJ_LOG(3,(THIS_FILE, " error: %d packet(s) was lost", pkt_lost));
65 return -40;
66 }
Benny Prijonofa73e3e2006-01-05 23:35:46 +000067
68 /* Put delay. */
Benny Prijono85598d92006-01-07 18:44:25 +000069 PJ_LOG(3,(THIS_FILE," setting network delay to 10 ms"));
70 pjsip_loop_set_delay(loop, 10);
Benny Prijonofa73e3e2006-01-05 23:35:46 +000071
72 /* Multi-threaded round-trip test. */
Benny Prijono85598d92006-01-07 18:44:25 +000073 status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop,
74 "sip:bob@130.0.0.1;transport=loop-dgram",
75 &pkt_lost);
Benny Prijonofa73e3e2006-01-05 23:35:46 +000076 if (status != 0)
77 return status;
78
Benny Prijono85598d92006-01-07 18:44:25 +000079 if (pkt_lost != 0) {
80 PJ_LOG(3,(THIS_FILE, " error: %d packet(s) was lost", pkt_lost));
81 return -50;
82 }
Benny Prijonofa73e3e2006-01-05 23:35:46 +000083
Benny Prijono85598d92006-01-07 18:44:25 +000084 /* Restore delay. */
85 pjsip_loop_set_delay(loop, 0);
Benny Prijonofa73e3e2006-01-05 23:35:46 +000086
87 /* Check that reference counter is one. */
88 if (pj_atomic_get(loop->ref_cnt) != 1) {
Benny Prijono85598d92006-01-07 18:44:25 +000089 return -50;
Benny Prijonofa73e3e2006-01-05 23:35:46 +000090 }
91
92 /* Decrement reference. */
93 pjsip_transport_dec_ref(loop);
94
95 return 0;
96}
97
98int transport_loop_test(void)
99{
100 int status;
101
102 status = datagram_loop_test();
103 if (status != 0)
104 return status;
105
106 return 0;
107}