summaryrefslogtreecommitdiff
path: root/pjsip/src/test-pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-01-05 23:35:46 +0000
committerBenny Prijono <bennylp@teluu.com>2006-01-05 23:35:46 +0000
commit67d6a30732fd1e1fae2f98f646d97356b2eaa8c9 (patch)
tree599de20e4a6554656db42030cdce7c1f2ccdb655 /pjsip/src/test-pjsip
parent944562492d0c16b9e44ec4e1cc97657846d82cd0 (diff)
Added loop transport to test transaction
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@107 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/test-pjsip')
-rw-r--r--pjsip/src/test-pjsip/msg_test.c32
-rw-r--r--pjsip/src/test-pjsip/test.c10
-rw-r--r--pjsip/src/test-pjsip/test.h9
-rw-r--r--pjsip/src/test-pjsip/transport_loop_test.c127
-rw-r--r--pjsip/src/test-pjsip/transport_test.c33
-rw-r--r--pjsip/src/test-pjsip/transport_udp_test.c12
-rw-r--r--pjsip/src/test-pjsip/tsx_uac_test.c306
-rw-r--r--pjsip/src/test-pjsip/uri_test.c6
8 files changed, 497 insertions, 38 deletions
diff --git a/pjsip/src/test-pjsip/msg_test.c b/pjsip/src/test-pjsip/msg_test.c
index e3702713..11a69b43 100644
--- a/pjsip/src/test-pjsip/msg_test.c
+++ b/pjsip/src/test-pjsip/msg_test.c
@@ -47,7 +47,7 @@ struct test_msg
{
/* 'Normal' message with all headers. */
"INVITE sip:user@foo SIP/2.0\n"
- "From: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=1234578901234567890\r"
+ "From: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=123457890123456\r"
"To: Fellow User <sip:user@foo.bar.domain.com>\r\n"
"Call-ID: 12345678901234567890@bar\r\n"
"Content-Length: 0\r\n"
@@ -57,15 +57,16 @@ struct test_msg
"Content-Type: text/html ; charset=ISO-8859-4\r"
"Route: <sip:bigbox3.site3.atlanta.com;lr>,\r\n"
" <sip:server10.biloxi.com;lr>\r"
- "Record-Route: <sip:server10.biloxi.com>,\r\n"
+ "Record-Route: <sip:server10.biloxi.com>,\r\n" /* multiple routes+folding*/
" <sip:bigbox3.site3.atlanta.com;lr>\n"
- "Via: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1\n"
- "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\n"
+ "Via: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c230\n"
+ "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\n" /* folding. */
" ;received=192.0.2.1\r\n"
"Via: SIP/2.0/UDP 10.2.1.1, SIP/2.0/TCP 192.168.1.1\n"
"Organization: \r"
"Max-Forwards: 70\n"
- "X-Header: \r\n"
+ "X-Header: \r\n" /* empty header */
+ "P-Associated-URI:\r\n" /* empty header without space */
"\r\n",
&create_msg0,
PJ_SUCCESS
@@ -351,10 +352,10 @@ static pjsip_msg *create_msg0(pj_pool_t *pool)
pj_strdup2(pool, &url->user, "user");
pj_strdup2(pool, &url->host, "foo");
- /* "From: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=1234578901234567890\r" */
+ /* "From: Hi I'm Joe <sip:joe.user@bar.otherdomain.com>;tag=123457890123456\r" */
fromto = pjsip_from_hdr_create(pool);
pjsip_msg_add_hdr(msg, (pjsip_hdr*)fromto);
- pj_strdup2(pool, &fromto->tag, "1234578901234567890");
+ pj_strdup2(pool, &fromto->tag, "123457890123456");
name_addr = pjsip_name_addr_create(pool);
fromto->uri = (pjsip_uri*)name_addr;
pj_strdup2(pool, &name_addr->display, "Hi I'm Joe");
@@ -462,12 +463,12 @@ static pjsip_msg *create_msg0(pj_pool_t *pool)
pj_strdup2(pool, &url->host, "bigbox3.site3.atlanta.com");
url->lr_param = 1;
- /* "Via: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c2312983.1\n" */
+ /* "Via: SIP/2.0/SCTP bigbox3.site3.atlanta.com;branch=z9hG4bK77ef4c230\n" */
via = pjsip_via_hdr_create(pool);
pjsip_msg_add_hdr(msg, (pjsip_hdr*)via);
pj_strdup2(pool, &via->transport, "SCTP");
pj_strdup2(pool, &via->sent_by.host, "bigbox3.site3.atlanta.com");
- pj_strdup2(pool, &via->branch_param, "z9hG4bK77ef4c2312983.1");
+ pj_strdup2(pool, &via->branch_param, "z9hG4bK77ef4c230");
/* "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\n"
" ;received=192.0.2.1\r\n" */
@@ -518,6 +519,15 @@ static pjsip_msg *create_msg0(pj_pool_t *pool)
str.slen = 0;
generic->hvalue = str;
+ /* P-Associated-URI:\r\n */
+ str.ptr = "P-Associated-URI";
+ str.slen = 16;
+ generic = pjsip_generic_string_hdr_create(pool, &str);
+ pjsip_msg_add_hdr(msg, (pjsip_hdr*)generic);
+ str.ptr = NULL;
+ str.slen = 0;
+ generic->hvalue = str;
+
return msg;
}
@@ -677,7 +687,7 @@ int msg_test(void)
for (i=0; i<PJ_ARRAY_SIZE(test_array); ++i) {
pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE);
status = test_entry( pool, &test_array[i] );
- pjsip_endpt_destroy_pool(endpt, pool);
+ pjsip_endpt_release_pool(endpt, pool);
if (status != PJ_SUCCESS)
return status;
@@ -691,7 +701,7 @@ int msg_test(void)
for (i=0; i<PJ_ARRAY_SIZE(test_array); ++i) {
pool = pjsip_endpt_create_pool(endpt, NULL, POOL_SIZE, POOL_SIZE);
status = test_entry( pool, &test_array[i] );
- pjsip_endpt_destroy_pool(endpt, pool);
+ pjsip_endpt_release_pool(endpt, pool);
if (status != PJ_SUCCESS)
return status;
diff --git a/pjsip/src/test-pjsip/test.c b/pjsip/src/test-pjsip/test.c
index a8f339c8..fbb72917 100644
--- a/pjsip/src/test-pjsip/test.c
+++ b/pjsip/src/test-pjsip/test.c
@@ -81,10 +81,12 @@ int test_main(void)
PJ_LOG(3,("",""));
- DO_TEST(uri_test());
- DO_TEST(msg_test());
- DO_TEST(txdata_test());
- DO_TEST(transport_udp_test());
+ //DO_TEST(uri_test());
+ //DO_TEST(msg_test());
+ //DO_TEST(txdata_test());
+ //DO_TEST(transport_udp_test());
+ DO_TEST(transport_loop_test());
+ //DO_TEST(tsx_uac_test());
on_return:
diff --git a/pjsip/src/test-pjsip/test.h b/pjsip/src/test-pjsip/test.h
index 686dea07..db12e390 100644
--- a/pjsip/src/test-pjsip/test.h
+++ b/pjsip/src/test-pjsip/test.h
@@ -23,22 +23,25 @@
extern pjsip_endpoint *endpt;
-#define TEST_UDP_PORT 15060
+#define TEST_UDP_PORT 15060
+#define TEST_UDP_PORT_STR "15060"
/* The tests */
int uri_test(void);
int msg_test(void);
int txdata_test(void);
int transport_udp_test(void);
+int transport_loop_test(void);
+int tsx_uac_test(void);
/* Transport test helpers (transport_test.c). */
int generic_transport_test(pjsip_transport *tp);
int transport_send_recv_test( pjsip_transport_type_e tp_type,
pjsip_transport *ref_tp,
- const pj_sockaddr_in *rem_addr );
+ char *target_url );
int transport_rt_test( pjsip_transport_type_e tp_type,
pjsip_transport *ref_tp,
- const pj_sockaddr_in *rem_addr );
+ char *target_url );
/* Test main entry */
int test_main(void);
diff --git a/pjsip/src/test-pjsip/transport_loop_test.c b/pjsip/src/test-pjsip/transport_loop_test.c
new file mode 100644
index 00000000..467f327f
--- /dev/null
+++ b/pjsip/src/test-pjsip/transport_loop_test.c
@@ -0,0 +1,127 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "test.h"
+#include <pjsip_core.h>
+#include <pjlib.h>
+
+static int datagram_loop_test()
+{
+ pjsip_transport *loop, *tp;
+ pj_str_t s;
+ int i, log_level;
+ pj_sockaddr_in addr;
+ pj_status_t status;
+
+ PJ_LOG(3,("", "testing datagram loop transport"));
+
+ /* Create loop transport. */
+ status = pjsip_loop_start(endpt, &loop);
+ if (status != PJ_SUCCESS) {
+ app_perror(" error: unable to create datagram loop transport",
+ status);
+ return -10;
+ }
+
+ /* Create dummy address. */
+ pj_sockaddr_in_init(&addr, pj_cstr(&s, "130.0.0.1"), TEST_UDP_PORT);
+
+ /* Test acquire transport. */
+ status = pjsip_endpt_acquire_transport( endpt, PJSIP_TRANSPORT_LOOP_DGRAM,
+ &addr, sizeof(addr), &tp);
+ if (status != PJ_SUCCESS) {
+ app_perror(" error: unable to acquire transport", status);
+ return -20;
+ }
+
+ /* Check that this is the right transport. */
+ if (tp != loop) {
+ return -30;
+ }
+
+ /* Test basic transport attributes */
+ status = generic_transport_test(loop);
+ if (status != PJ_SUCCESS)
+ return status;
+
+ /* Basic transport's send/receive loopback test. */
+ for (i=0; i<2; ++i) {
+ status = transport_send_recv_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop,
+ "sip:bob@130.0.0.1;transport=loop-dgram");
+ if (status != 0)
+ return status;
+ }
+
+ /* For multithreaded round-trip test to work, delay must be set
+ * (otherwise functions will be called recursively until no memory is
+ * left in the system)
+ */
+
+ /* Put delay. */
+ pjsip_loop_set_delay(loop, 1, NULL);
+
+ /* Multi-threaded round-trip test. */
+ status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, tp,
+ "sip:bob@130.0.0.1;transport=loop-dgram");
+ if (status != 0)
+ return status;
+
+
+ /* Next test will test without delay.
+ * This will stress-test the system.
+ */
+ PJ_LOG(3,(""," performing another multithreaded round-trip test..."));
+
+ /* Remove delay. */
+ pjsip_loop_set_delay(loop, 0, NULL);
+
+ /* Ignore errors. */
+ log_level = pj_log_get_level();
+ pj_log_set_level(2);
+
+ /* Multi-threaded round-trip test. */
+ status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, tp,
+ "sip:bob@130.0.0.1;transport=loop-dgram");
+ if (status != 0)
+ return status;
+
+ /* Restore log level. */
+ pj_log_set_level(log_level);
+
+ /* Check that reference counter is one. */
+ if (pj_atomic_get(loop->ref_cnt) != 1) {
+ return -30;
+ }
+
+ /* Decrement reference. */
+ pjsip_transport_dec_ref(loop);
+
+ return 0;
+}
+
+int transport_loop_test(void)
+{
+ int status;
+
+ status = datagram_loop_test();
+ if (status != 0)
+ return status;
+
+ return 0;
+}
diff --git a/pjsip/src/test-pjsip/transport_test.c b/pjsip/src/test-pjsip/transport_test.c
index 0d54d42d..76b6bb9e 100644
--- a/pjsip/src/test-pjsip/transport_test.c
+++ b/pjsip/src/test-pjsip/transport_test.c
@@ -75,7 +75,6 @@ int generic_transport_test(pjsip_transport *tp)
* before we continue with more complicated tests.
*/
#define FROM_HDR "Bob <sip:bob@example.com>"
-#define TO_HDR "Alice <sip:alice@example.com>"
#define CONTACT_HDR "Bob <sip:bob@127.0.0.1>"
#define CALL_ID_HDR "SendRecv-Test"
#define CSEQ_VALUE 100
@@ -108,7 +107,7 @@ static pjsip_module my_module =
NULL, /* unload() */
&my_on_rx_request, /* on_rx_request() */
&my_on_rx_response, /* on_rx_response() */
- NULL, /* tsx_handler() */
+ NULL, /* on_tsx_state() */
};
@@ -188,10 +187,9 @@ static void send_msg_callback(pjsip_send_state *stateless_data,
/* Test that we receive loopback message. */
int transport_send_recv_test( pjsip_transport_type_e tp_type,
pjsip_transport *ref_tp,
- const pj_sockaddr_in *rem_addr )
+ char *target_url )
{
pj_status_t status;
- char target_buf[80];
pj_str_t target, from, to, contact, call_id, body;
pjsip_method method;
pjsip_tx_data *tdata;
@@ -209,11 +207,9 @@ int transport_send_recv_test( pjsip_transport_type_e tp_type,
}
/* Create a request message. */
- pj_sprintf(target_buf, "sip:%s:%d", pj_inet_ntoa(rem_addr->sin_addr),
- pj_ntohs(rem_addr->sin_port));
- target = pj_str(target_buf);
+ target = pj_str(target_url);
from = pj_str(FROM_HDR);
- to = pj_str(TO_HDR);
+ to = pj_str(target_url);
contact = pj_str(CONTACT_HDR);
call_id = pj_str(CALL_ID_HDR);
body = pj_str(BODY);
@@ -333,7 +329,7 @@ static struct
pj_str_t call_id;
} rt_test_data[16];
-static char rt_target_uri[32];
+static char rt_target_uri[64];
static pj_bool_t rt_stop;
static pj_str_t rt_call_id;
@@ -349,15 +345,18 @@ static pj_bool_t rt_on_rx_request(pjsip_rx_data *rdata)
status = pjsip_endpt_create_response( endpt, rdata, 200, NULL, &tdata);
if (status != PJ_SUCCESS) {
+ app_perror(" error creating response", status);
return PJ_TRUE;
}
status = pjsip_get_response_addr( tdata->pool, rdata, &res_addr);
if (status != PJ_SUCCESS) {
+ app_perror(" error in get response address", status);
pjsip_tx_data_dec_ref(tdata);
return PJ_TRUE;
}
status = pjsip_endpt_send_response( endpt, &res_addr, tdata, NULL, NULL);
if (status != PJ_SUCCESS) {
+ app_perror(" error sending response", status);
pjsip_tx_data_dec_ref(tdata);
return PJ_TRUE;
}
@@ -376,7 +375,7 @@ static pj_status_t rt_send_request(int thread_id)
/* Create a request message. */
target = pj_str(rt_target_uri);
from = pj_str(FROM_HDR);
- to = pj_str(TO_HDR);
+ to = pj_str(rt_target_uri);
contact = pj_str(CONTACT_HDR);
call_id = rt_test_data[thread_id].call_id;
@@ -430,7 +429,7 @@ static pj_bool_t rt_on_rx_response(pjsip_rx_data *rdata)
static int rt_thread(void *arg)
{
- int thread_id = (int)arg;
+ int i, thread_id = (int)arg;
pj_time_val poll_delay = { 0, 10 };
/* Sleep to allow main threads to run. */
@@ -443,12 +442,17 @@ static int rt_thread(void *arg)
while (!rt_stop) {
pjsip_endpt_handle_events(endpt, &poll_delay);
}
+
+ /* Exhaust responses. */
+ for (i=0; i<100; ++i)
+ pjsip_endpt_handle_events(endpt, &poll_delay);
+
return 0;
}
int transport_rt_test( pjsip_transport_type_e tp_type,
pjsip_transport *ref_tp,
- const pj_sockaddr_in *rem_addr )
+ char *target_url )
{
enum { THREADS = 4, INTERVAL = 10 };
int i;
@@ -483,8 +487,7 @@ int transport_rt_test( pjsip_transport_type_e tp_type,
return -610;
/* Initialize static test data. */
- pj_sprintf(rt_target_uri, "sip:%s:%d", pj_inet_ntoa(rem_addr->sin_addr),
- pj_ntohs(rem_addr->sin_port));
+ pj_native_strcpy(rt_target_uri, target_url);
rt_call_id = pj_str("RT-Call-Id/");
rt_stop = PJ_FALSE;
@@ -551,7 +554,7 @@ int transport_rt_test( pjsip_transport_type_e tp_type,
PJ_LOG(3,("", " no message was lost"));
PJ_LOG(3,("", " average round-trip=%d usec", usec_rt));
- pjsip_endpt_destroy_pool(endpt, pool);
+ pjsip_endpt_release_pool(endpt, pool);
if (is_reliable && (total_sent != total_recv)) {
PJ_LOG(3,("", " error: %d messages lost", total_sent-total_recv));
diff --git a/pjsip/src/test-pjsip/transport_udp_test.c b/pjsip/src/test-pjsip/transport_udp_test.c
index 1af74ed0..0fdbddae 100644
--- a/pjsip/src/test-pjsip/transport_udp_test.c
+++ b/pjsip/src/test-pjsip/transport_udp_test.c
@@ -76,13 +76,15 @@ int transport_udp_test(void)
/* Basic transport's send/receive loopback test. */
pj_sockaddr_in_init(&rem_addr, pj_cstr(&s, "127.0.0.1"), TEST_UDP_PORT);
for (i=0; i<SEND_RECV_LOOP; ++i) {
- status = transport_send_recv_test(PJSIP_TRANSPORT_UDP, tp, &rem_addr);
+ status = transport_send_recv_test(PJSIP_TRANSPORT_UDP, tp,
+ "sip:alice@127.0.0.1:"TEST_UDP_PORT_STR);
if (status != 0)
return status;
}
/* Multi-threaded round-trip test. */
- status = transport_rt_test(PJSIP_TRANSPORT_UDP, tp, &rem_addr);
+ status = transport_rt_test(PJSIP_TRANSPORT_UDP, tp,
+ "sip:alice@127.0.0.1:"TEST_UDP_PORT_STR);
if (status != 0)
return status;
@@ -93,6 +95,12 @@ int transport_udp_test(void)
/* Destroy this transport. */
pjsip_transport_dec_ref(udp_tp);
+ /* Force destroy this transport. */
+ status = pjsip_transport_unregister( pjsip_endpt_get_tpmgr(endpt), udp_tp);
+ if (status != PJ_SUCCESS)
+ return -90;
+
+
/* Done */
return 0;
}
diff --git a/pjsip/src/test-pjsip/tsx_uac_test.c b/pjsip/src/test-pjsip/tsx_uac_test.c
new file mode 100644
index 00000000..24af41e9
--- /dev/null
+++ b/pjsip/src/test-pjsip/tsx_uac_test.c
@@ -0,0 +1,306 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "test.h"
+#include <pjsip_core.h>
+#include <pjlib.h>
+
+/*****************************************************************************
+ **
+ ** UAC basic retransmission and timeout test.
+ **
+ ** This will test the retransmission of the UAC transaction. Remote will not
+ ** answer the transaction, so the transaction should fail.
+ **
+ *****************************************************************************
+ */
+
+static char *CALL_ID1 = "UAC-Tsx-Basic-Test1";
+static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e);
+static pj_bool_t msg_receiver_on_rx_request(pjsip_rx_data *rdata);
+
+/* UAC transaction user module. */
+static pjsip_module tsx_user =
+{
+ NULL, NULL, /* prev and next */
+ { "Tsx-User", 8}, /* Name. */
+ -1, /* Id */
+ PJSIP_MOD_PRIORITY_APPLICATION-1, /* Priority */
+ NULL, /* User data. */
+ 0, /* Number of methods supported (=0). */
+ { 0 }, /* Array of methods (none) */
+ NULL, /* load() */
+ NULL, /* start() */
+ NULL, /* stop() */
+ NULL, /* unload() */
+ NULL, /* on_rx_request() */
+ NULL, /* on_rx_response() */
+ &tsx_user_on_tsx_state, /* on_tsx_state() */
+};
+
+/* Module to receive the loop-backed request. */
+static pjsip_module msg_receiver =
+{
+ NULL, NULL, /* prev and next */
+ { "Test", 4}, /* Name. */
+ -1, /* Id */
+ PJSIP_MOD_PRIORITY_APPLICATION-1, /* Priority */
+ NULL, /* User data. */
+ 0, /* Number of methods supported (=0). */
+ { 0 }, /* Array of methods (none) */
+ NULL, /* load() */
+ NULL, /* start() */
+ NULL, /* stop() */
+ NULL, /* unload() */
+ &msg_receiver_on_rx_request, /* on_rx_request() */
+ NULL, /* on_rx_response() */
+ NULL, /* on_tsx_state() */
+};
+
+/* Static vars. */
+static int recv_count;
+static pj_time_val recv_last;
+static pj_bool_t test_complete;
+
+static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e)
+{
+ if (tsx->state == PJSIP_TSX_STATE_TERMINATED && test_complete==0)
+ test_complete = 1;
+}
+
+#define DIFF(a,b) ((a<b) ? (b-a) : (a-b))
+
+static pj_bool_t msg_receiver_on_rx_request(pjsip_rx_data *rdata)
+{
+ if (pj_strcmp2(&rdata->msg_info.call_id, CALL_ID1) == 0) {
+ /*
+ * The CALL_ID1 test performs the verifications for transaction
+ * retransmission mechanism. It will not answer the incoming request
+ * with any response.
+ */
+ pjsip_msg *msg = rdata->msg_info.msg;
+
+ PJ_LOG(4,("", " received request"));
+
+ /* Only wants to take INVITE or OPTIONS method. */
+ if (msg->line.req.method.id != PJSIP_INVITE_METHOD &&
+ msg->line.req.method.id != PJSIP_OPTIONS_METHOD)
+ {
+ PJ_LOG(3,("", " error: received unexpected method %.*s",
+ msg->line.req.method.name.slen,
+ msg->line.req.method.name.ptr));
+ test_complete = -600;
+ return PJ_TRUE;
+ }
+
+ if (recv_count == 0) {
+ recv_count++;
+ pj_gettimeofday(&recv_last);
+ } else {
+ pj_time_val now;
+ unsigned msec_expected, msec_elapsed;
+
+ pj_gettimeofday(&now);
+ PJ_TIME_VAL_SUB(now, recv_last);
+ msec_elapsed = now.sec*1000 + now.msec;
+
+ ++recv_count;
+ msec_expected = (1<<(recv_count-2))*PJSIP_T1_TIMEOUT;
+
+ if (msg->line.req.method.id != PJSIP_INVITE_METHOD) {
+ if (msec_expected > PJSIP_T2_TIMEOUT)
+ msec_expected = PJSIP_T2_TIMEOUT;
+ }
+
+ if (DIFF(msec_expected, msec_elapsed) > 100) {
+ PJ_LOG(3,(""," error: expecting %d-th retransmission in %d "
+ "ms, received in %d ms",
+ recv_count-1, msec_expected, msec_elapsed));
+ test_complete = -610;
+ }
+
+ if (recv_count > 7) {
+ PJ_LOG(3,("", " error: too many messages (%d) received",
+ recv_count));
+ test_complete = -620;
+ }
+
+ pj_gettimeofday(&recv_last);
+ }
+ return PJ_TRUE;
+ }
+ return PJ_FALSE;
+}
+
+/*****************************************************************************
+ **
+ ** UAC basic retransmission and timeout test.
+ **
+ ** This will test the retransmission of the UAC transaction. Remote will not
+ ** answer the transaction, so the transaction should fail. The Call-ID
+ ** CALL_ID1 will be used for this test.
+ **
+ *****************************************************************************
+ */
+static int tsx_uac_retransmit_test(const pjsip_method *method)
+{
+ pjsip_tx_data *tdata;
+ pjsip_transaction *tsx;
+ char buf[80];
+ pj_str_t target, from, call_id, tsx_key;
+ pj_time_val timeout;
+ pj_status_t status;
+
+ PJ_LOG(3,("", " basic uac retransmission and timeout test"));
+
+ pj_sprintf(buf, "sip:alice@127.0.0.1:%d", TEST_UDP_PORT);
+ target = pj_str(buf);
+ from = pj_str("sip:bob@127.0.0.1");
+ call_id = pj_str(CALL_ID1);
+
+ /* Create request. */
+ status = pjsip_endpt_create_request( endpt, method, &target,
+ &from, &target, NULL, &call_id, -1,
+ NULL, &tdata);
+ if (status != PJ_SUCCESS) {
+ app_perror(" Error: unable to create request", status);
+ return -500;
+ }
+
+ /* Add additional reference to tdata to prevent transaction from
+ * deleting it.
+ */
+ pjsip_tx_data_add_ref(tdata);
+
+ /* Create transaction. */
+ status = pjsip_tsx_create_uac( &tsx_user, tdata, &tsx);
+ if (status != PJ_SUCCESS) {
+ app_perror(" Error: unable to create UAC transaction", status);
+ return -510;
+ }
+
+ /* Get transaction key. */
+ pj_strdup(tdata->pool, &tsx_key, &tsx->transaction_key);
+
+ /* Send the message. */
+ status = pjsip_tsx_send_msg(tsx, NULL);
+ if (status != PJ_SUCCESS) {
+ app_perror(" Error: unable to send request", status);
+ return -520;
+ }
+
+ /* Set test completion time. */
+ pj_gettimeofday(&timeout);
+ timeout.sec += 33;
+
+ /* Wait until test complete. */
+ while (!test_complete) {
+ pj_time_val now;
+
+ pjsip_endpt_handle_events(endpt, NULL);
+
+ pj_gettimeofday(&now);
+ if (now.sec > timeout.sec) {
+ PJ_LOG(3,("", " Error: test has timed out"));
+ return -530;
+ }
+ }
+
+ if (status < 0)
+ return status;
+
+ /* Make sure transaction has been destroyed. */
+ if (pjsip_tsx_layer_find_tsx(&tsx_key, PJ_FALSE) != NULL) {
+ PJ_LOG(3,("", " Error: transaction has not been destroyed"));
+ return -540;
+ }
+
+ /* Check tdata reference counter. */
+ if (pj_atomic_get(tdata->ref_cnt) != 1) {
+ PJ_LOG(3,("", " Error: tdata reference counter is %d",
+ pj_atomic_get(tdata->ref_cnt)));
+ return -550;
+ }
+
+ /* Destroy txdata */
+ pjsip_tx_data_dec_ref(tdata);
+
+ return PJ_SUCCESS;
+}
+
+/*****************************************************************************
+ **
+ ** UAC Transaction Test.
+ **
+ *****************************************************************************
+ */
+int tsx_uac_test(void)
+{
+ pj_sockaddr_in addr;
+ pj_str_t tmp;
+ pjsip_transport *tp;
+ pj_status_t status;
+
+ pj_sockaddr_in_init(&addr, pj_cstr(&tmp, "127.0.0.1"), TEST_UDP_PORT);
+
+ /* Start UDP transport if necessary. */
+ if (pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_UDP, &addr,
+ sizeof(addr), &tp) != PJ_SUCCESS)
+ {
+ addr.sin_addr.s_addr = 0;
+ status = pjsip_udp_transport_start( endpt, &addr, NULL, 1, NULL);
+ if (status != PJ_SUCCESS) {
+ app_perror(" Error: unable to start UDP transport", status);
+ return -10;
+ }
+ } else {
+ pjsip_transport_dec_ref(tp);
+ }
+
+ /* Start transaction layer module. */
+ status = pjsip_tsx_layer_init(endpt);
+ if (status != PJ_SUCCESS) {
+ app_perror(" Error initializing transaction module", status);
+ return -20;
+ }
+
+ /* Register modules. */
+ status = pjsip_endpt_register_module(endpt, &tsx_user);
+ if (status != PJ_SUCCESS) {
+ app_perror(" Error: unable to register module", status);
+ return -30;
+ }
+ status = pjsip_endpt_register_module(endpt, &msg_receiver);
+ if (status != PJ_SUCCESS) {
+ app_perror(" Error: unable to register module", status);
+ return -30;
+ }
+
+ /* Basic retransmit and timeout test for INVITE. */
+ status = tsx_uac_retransmit_test(&pjsip_invite_method);
+ if (status != 0)
+ return status;
+
+ /* Basic retransmit and timeout test for non-INVITE. */
+ status = tsx_uac_retransmit_test(&pjsip_options_method);
+ if (status != 0)
+ return status;
+
+ return 0;
+}
diff --git a/pjsip/src/test-pjsip/uri_test.c b/pjsip/src/test-pjsip/uri_test.c
index 647397a2..de9604bf 100644
--- a/pjsip/src/test-pjsip/uri_test.c
+++ b/pjsip/src/test-pjsip/uri_test.c
@@ -804,7 +804,7 @@ int uri_test()
goto on_return;
}
}
- pjsip_endpt_destroy_pool(endpt, pool);
+ pjsip_endpt_release_pool(endpt, pool);
PJ_LOG(3,("", " benchmarking..."));
parse_len = print_len = cmp_len = 0;
@@ -818,11 +818,11 @@ int uri_test()
if (status != PJ_SUCCESS) {
PJ_LOG(3,("uri_test", " error %d when testing entry %d",
status, i));
- pjsip_endpt_destroy_pool(endpt, pool);
+ pjsip_endpt_release_pool(endpt, pool);
goto on_return;
}
}
- pjsip_endpt_destroy_pool(endpt, pool);
+ pjsip_endpt_release_pool(endpt, pool);
}
kbytes = parse_len;