diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-01-07 18:44:25 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-01-07 18:44:25 +0000 |
commit | 57b75697969b3cfd0cc5fe6ca3c98b38acc16608 (patch) | |
tree | bca6c76392e15dcc6447919313eadf835138269d /pjsip/src/test-pjsip | |
parent | 9b1fe4bbb2a30ea94d3ff33989341c656936d930 (diff) |
Added test functions for UAC transaction
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@109 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/test-pjsip')
-rw-r--r-- | pjsip/src/test-pjsip/msg_logger.c | 102 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/msg_test.c | 42 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/test.c | 66 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/test.h | 8 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/transport_loop_test.c | 76 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/transport_test.c | 171 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/transport_udp_test.c | 13 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/tsx_basic_test.c | 147 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/tsx_uac_test.c | 788 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/txdata_test.c | 35 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/uri_test.c | 69 |
11 files changed, 1261 insertions, 256 deletions
diff --git a/pjsip/src/test-pjsip/msg_logger.c b/pjsip/src/test-pjsip/msg_logger.c new file mode 100644 index 00000000..faa36b53 --- /dev/null +++ b/pjsip/src/test-pjsip/msg_logger.c @@ -0,0 +1,102 @@ +/* $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> + +#define THIS_FILE "msg_logger.c" + +static pj_bool_t msg_log_enabled; + +static pj_bool_t on_rx_msg(pjsip_rx_data *rdata) +{ + if (msg_log_enabled) { + PJ_LOG(4,(THIS_FILE, "RX %d bytes %s from %s:%d:\n" + "%s\n" + "--end msg--", + rdata->msg_info.len, + pjsip_rx_data_get_info(rdata), + rdata->pkt_info.src_name, + rdata->pkt_info.src_port, + rdata->msg_info.msg_buf)); + } + + return PJ_FALSE; +} + +static pj_status_t on_tx_msg(pjsip_tx_data *tdata) +{ + if (msg_log_enabled) { + PJ_LOG(4,(THIS_FILE, "TX %d bytes %s to %s:%d:\n" + "%s\n" + "--end msg--", + (tdata->buf.cur - tdata->buf.start), + pjsip_tx_data_get_info(tdata), + tdata->tp_info.dst_name, + tdata->tp_info.dst_port, + tdata->buf.start)); + } + return PJ_SUCCESS; +} + + +/* Message logger module. */ +static pjsip_module mod_msg_logger = +{ + NULL, NULL, /* prev and next */ + { "mod-msg-logger", 14}, /* Name. */ + -1, /* Id */ + PJSIP_MOD_PRIORITY_TRANSPORT_LAYER-1,/* Priority */ + NULL, /* User data. */ + 0, /* Number of methods supported (=0). */ + { 0 }, /* Array of methods (none) */ + NULL, /* load() */ + NULL, /* start() */ + NULL, /* stop() */ + NULL, /* unload() */ + &on_rx_msg, /* on_rx_request() */ + &on_rx_msg, /* on_rx_response() */ + &on_tx_msg, /* on_tx_request() */ + &on_tx_msg, /* on_tx_response() */ + NULL, /* on_tsx_state() */ +}; + +int init_msg_logger(void) +{ + pj_status_t status; + + if (mod_msg_logger.id != -1) + return 0; + + status = pjsip_endpt_register_module(endpt, &mod_msg_logger); + if (status != PJ_SUCCESS) { + app_perror(" error registering module", status); + return -10; + } + + return 0; +} + +int msg_logger_set_enabled(pj_bool_t enabled) +{ + int val = msg_log_enabled; + msg_log_enabled = enabled; + return val; +} + diff --git a/pjsip/src/test-pjsip/msg_test.c b/pjsip/src/test-pjsip/msg_test.c index 11a69b43..f49f1256 100644 --- a/pjsip/src/test-pjsip/msg_test.c +++ b/pjsip/src/test-pjsip/msg_test.c @@ -23,6 +23,7 @@ #define POOL_SIZE 8000 #define LOOP 10000 #define AVERAGE_MSG_LEN 800 +#define THIS_FILE "msg_test.c" static pjsip_msg *create_msg0(pj_pool_t *pool); static pjsip_msg *create_msg1(pj_pool_t *pool); @@ -142,7 +143,7 @@ static pj_status_t test_entry( pj_pool_t *pool, struct test_msg *entry ) } } if (msg_size != entry->len) { - PJ_LOG(3,("", " error: size mismatch")); + PJ_LOG(3,(THIS_FILE, " error: size mismatch")); return -6; } pj_get_timestamp(&t2); @@ -162,7 +163,7 @@ parse_msg: if (entry->expected_status != STATUS_SYNTAX_ERROR) { status = -10; if (err_list.next != &err_list) { - PJ_LOG(3,("", " Syntax error in line %d col %d", + PJ_LOG(3,(THIS_FILE, " Syntax error in line %d col %d", err_list.next->line, err_list.next->col)); } goto on_return; @@ -207,14 +208,14 @@ parse_msg: } } else { if (parsed_msg->line.status.code != ref_msg->line.status.code) { - PJ_LOG(3,("", " error: status code mismatch")); + PJ_LOG(3,(THIS_FILE, " error: status code mismatch")); status = -32; goto on_return; } if (pj_strcmp(&parsed_msg->line.status.reason, &ref_msg->line.status.reason) != 0) { - PJ_LOG(3,("", " error: status text mismatch")); + PJ_LOG(3,(THIS_FILE, " error: status text mismatch")); status = -33; goto on_return; } @@ -243,7 +244,7 @@ parse_msg: if (pj_strcmp(&str1, &str2) != 0) { status = -60; - PJ_LOG(3,("", " error: header string mismatch:\n" + PJ_LOG(3,(THIS_FILE, " error: header string mismatch:\n" " h1='%s'\n" " h2='%s'\n", str1.ptr, str2.ptr)); @@ -683,7 +684,7 @@ int msg_test(void) pj_time_val elapsed; pj_highprec_t avg_detect, avg_parse, avg_print, kbytes; - PJ_LOG(3,("", " simple test..")); + PJ_LOG(3,(THIS_FILE, " simple test..")); 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] ); @@ -693,7 +694,7 @@ int msg_test(void) return status; } - PJ_LOG(3,("", " benchmarking..")); + PJ_LOG(3,(THIS_FILE, " benchmarking..")); detect_len = parse_len = print_len = 0; zero.u64 = detect_time.u64 = parse_time.u64 = print_time.u64 = 0; @@ -717,10 +718,11 @@ int msg_test(void) pj_highprec_div(avg_detect, detect_len); avg_detect = 1000000 / avg_detect; - PJ_LOG(3,("", " %u.%u MB detected in %d.%03ds (avg=%d msg detection/sec)", - (unsigned)(detect_len/1000000), (unsigned)kbytes, - elapsed.sec, elapsed.msec, - (unsigned)avg_detect)); + PJ_LOG(3,(THIS_FILE, + " %u.%u MB detected in %d.%03ds (avg=%d msg detection/sec)", + (unsigned)(detect_len/1000000), (unsigned)kbytes, + elapsed.sec, elapsed.msec, + (unsigned)avg_detect)); kbytes = parse_len; pj_highprec_mod(kbytes, 1000000); @@ -731,10 +733,11 @@ int msg_test(void) pj_highprec_div(avg_parse, parse_len); avg_parse = 1000000 / avg_parse; - PJ_LOG(3,("", " %u.%u MB parsed in %d.%03ds (avg=%d msg parsing/sec)", - (unsigned)(parse_len/1000000), (unsigned)kbytes, - elapsed.sec, elapsed.msec, - (unsigned)avg_parse)); + PJ_LOG(3,(THIS_FILE, + " %u.%u MB parsed in %d.%03ds (avg=%d msg parsing/sec)", + (unsigned)(parse_len/1000000), (unsigned)kbytes, + elapsed.sec, elapsed.msec, + (unsigned)avg_parse)); kbytes = print_len; pj_highprec_mod(kbytes, 1000000); @@ -745,10 +748,11 @@ int msg_test(void) pj_highprec_div(avg_print, print_len); avg_print = 1000000 / avg_print; - PJ_LOG(3,("", " %u.%u MB printed in %d.%03ds (avg=%d msg print/sec)", - (unsigned)(print_len/1000000), (unsigned)kbytes, - elapsed.sec, elapsed.msec, - (unsigned)avg_print)); + PJ_LOG(3,(THIS_FILE, + " %u.%u MB printed in %d.%03ds (avg=%d msg print/sec)", + (unsigned)(print_len/1000000), (unsigned)kbytes, + elapsed.sec, elapsed.msec, + (unsigned)avg_print)); return status; } diff --git a/pjsip/src/test-pjsip/test.c b/pjsip/src/test-pjsip/test.c index fbb72917..fdc6a7d8 100644 --- a/pjsip/src/test-pjsip/test.c +++ b/pjsip/src/test-pjsip/test.c @@ -22,10 +22,12 @@ #include <pjlib.h> #include <pjsip_core.h> +#define THIS_FILE "test.c" + #define DO_TEST(test) do { \ - PJ_LOG(3, ("test", "Running %s...", #test)); \ + PJ_LOG(3, (THIS_FILE, "Running %s...", #test)); \ rc = test; \ - PJ_LOG(3, ("test", \ + PJ_LOG(3, (THIS_FILE, \ "%s(%d)", \ (rc ? "..ERROR" : "..success"), rc)); \ if (rc!=0) goto on_return; \ @@ -42,8 +44,28 @@ void app_perror(const char *msg, pj_status_t rc) PJ_CHECK_STACK(); pjsip_strerror(rc, errbuf, sizeof(errbuf)); - PJ_LOG(3,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf)); + PJ_LOG(3,(THIS_FILE, "%s: [pj_status_t=%d] %s", msg, rc, errbuf)); + +} + +void flush_events(unsigned duration) +{ + pj_time_val stop_time; + + pj_gettimeofday(&stop_time); + stop_time.msec += duration; + pj_time_val_normalize(&stop_time); + + /* Process all events for the specified duration. */ + for (;;) { + pj_time_val timeout = {0, 1}, now; + + pjsip_endpt_handle_events(endpt, &timeout); + pj_gettimeofday(&now); + if (PJ_TIME_VAL_GTE(now, stop_time)) + break; + } } pj_status_t register_static_modules(pj_size_t *count, pjsip_module **modules) @@ -59,9 +81,11 @@ int test_main(void) const char *filename; int line; - pj_log_set_level(3); + pj_log_set_level(5); + /* pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC); + */ if ((rc=pj_init()) != PJ_SUCCESS) { app_perror("pj_init", rc); @@ -79,30 +103,50 @@ int test_main(void) return rc; } - PJ_LOG(3,("","")); + PJ_LOG(3,(THIS_FILE,"")); + + /* Init logger module. */ + init_msg_logger(); + msg_logger_set_enabled(1); + + /* Start transaction layer module. */ + rc = pjsip_tsx_layer_init(endpt); + if (rc != PJ_SUCCESS) { + app_perror(" Error initializing transaction module", rc); + goto on_return; + } + + /* Create loop transport. */ + rc = pjsip_loop_start(endpt, NULL); + if (rc != PJ_SUCCESS) { + app_perror(" error: unable to create datagram loop transport", + rc); + goto on_return; + } //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()); + //DO_TEST(transport_loop_test()); + //DO_TEST(tsx_basic_test()); + DO_TEST(tsx_uac_test()); on_return: pjsip_endpt_destroy(endpt); pj_caching_pool_destroy(&caching_pool); - PJ_LOG(3,("test", "")); + PJ_LOG(3,(THIS_FILE, "")); pj_thread_get_stack_info(pj_thread_this(), &filename, &line); - PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u", + PJ_LOG(3,(THIS_FILE, "Stack max usage: %u, deepest: %s:%u", pj_thread_get_stack_max_usage(pj_thread_this()), filename, line)); if (rc == 0) - PJ_LOG(3,("test", "Looks like everything is okay!..")); + PJ_LOG(3,(THIS_FILE, "Looks like everything is okay!..")); else - PJ_LOG(3,("test", "Test completed with error(s)")); + PJ_LOG(3,(THIS_FILE, "Test completed with error(s)")); return 0; } diff --git a/pjsip/src/test-pjsip/test.h b/pjsip/src/test-pjsip/test.h index db12e390..2012781c 100644 --- a/pjsip/src/test-pjsip/test.h +++ b/pjsip/src/test-pjsip/test.h @@ -32,6 +32,7 @@ int msg_test(void); int txdata_test(void); int transport_udp_test(void); int transport_loop_test(void); +int tsx_basic_test(void); int tsx_uac_test(void); /* Transport test helpers (transport_test.c). */ @@ -41,13 +42,16 @@ int transport_send_recv_test( pjsip_transport_type_e tp_type, char *target_url ); int transport_rt_test( pjsip_transport_type_e tp_type, pjsip_transport *ref_tp, - char *target_url ); + char *target_url, + int *pkt_lost); /* Test main entry */ int test_main(void); /* Test utilities. */ void app_perror(const char *msg, pj_status_t status); - +int init_msg_logger(void); +int msg_logger_set_enabled(pj_bool_t enabled); +void flush_events(unsigned duration); #endif /* __TEST_H__ */ diff --git a/pjsip/src/test-pjsip/transport_loop_test.c b/pjsip/src/test-pjsip/transport_loop_test.c index 467f327f..f4e6bb3c 100644 --- a/pjsip/src/test-pjsip/transport_loop_test.c +++ b/pjsip/src/test-pjsip/transport_loop_test.c @@ -21,40 +21,25 @@ #include <pjsip_core.h> #include <pjlib.h> +#define THIS_FILE "transport_loop_test.c" + static int datagram_loop_test() { - pjsip_transport *loop, *tp; - pj_str_t s; - int i, log_level; + pjsip_transport *loop; + int i, pkt_lost; 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); + PJ_LOG(3,(THIS_FILE, "testing datagram loop transport")); /* Test acquire transport. */ status = pjsip_endpt_acquire_transport( endpt, PJSIP_TRANSPORT_LOOP_DGRAM, - &addr, sizeof(addr), &tp); + &addr, sizeof(addr), &loop); if (status != PJ_SUCCESS) { - app_perror(" error: unable to acquire transport", status); + app_perror(" error: loop transport is not configured", 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) @@ -68,45 +53,40 @@ static int datagram_loop_test() 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"); + status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop, + "sip:bob@130.0.0.1;transport=loop-dgram", + &pkt_lost); if (status != 0) return status; + if (pkt_lost != 0) { + PJ_LOG(3,(THIS_FILE, " error: %d packet(s) was lost", pkt_lost)); + return -40; + } - /* 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); + /* Put delay. */ + PJ_LOG(3,(THIS_FILE," setting network delay to 10 ms")); + pjsip_loop_set_delay(loop, 10); /* Multi-threaded round-trip test. */ - status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, tp, - "sip:bob@130.0.0.1;transport=loop-dgram"); + status = transport_rt_test(PJSIP_TRANSPORT_LOOP_DGRAM, loop, + "sip:bob@130.0.0.1;transport=loop-dgram", + &pkt_lost); if (status != 0) return status; - /* Restore log level. */ - pj_log_set_level(log_level); + if (pkt_lost != 0) { + PJ_LOG(3,(THIS_FILE, " error: %d packet(s) was lost", pkt_lost)); + return -50; + } + + /* Restore delay. */ + pjsip_loop_set_delay(loop, 0); /* Check that reference counter is one. */ if (pj_atomic_get(loop->ref_cnt) != 1) { - return -30; + return -50; } /* Decrement reference. */ diff --git a/pjsip/src/test-pjsip/transport_test.c b/pjsip/src/test-pjsip/transport_test.c index 76b6bb9e..b57fedbf 100644 --- a/pjsip/src/test-pjsip/transport_test.c +++ b/pjsip/src/test-pjsip/transport_test.c @@ -21,6 +21,8 @@ #include <pjsip_core.h> #include <pjlib.h> +#define THIS_FILE "transport_test.c" + /////////////////////////////////////////////////////////////////////////////// /* * Generic testing for transport, to make sure that basic @@ -28,7 +30,7 @@ */ int generic_transport_test(pjsip_transport *tp) { - PJ_LOG(3,("", " structure test...")); + PJ_LOG(3,(THIS_FILE, " structure test...")); /* Check that local address name is valid. */ { @@ -37,7 +39,7 @@ int generic_transport_test(pjsip_transport *tp) /* Note: inet_aton() returns non-zero if addr is valid! */ if (pj_inet_aton(&tp->local_name.host, &addr) != 0) { if (addr.s_addr==PJ_INADDR_ANY || addr.s_addr==PJ_INADDR_NONE) { - PJ_LOG(3,("", " Error: invalid address name")); + PJ_LOG(3,(THIS_FILE, " Error: invalid address name")); return -420; } } else { @@ -121,13 +123,6 @@ static pj_bool_t my_on_rx_request(pjsip_rx_data *rdata) pjsip_response_addr res_addr; pj_status_t status; - PJ_LOG(4,("test", "Received %d bytes request: --begin-\n" - "%s\n" - "--end--", - rdata->msg_info.len, - rdata->msg_info.msg_buf)); - - status = pjsip_endpt_create_response( endpt, rdata, 200, NULL, &tdata); if (status != PJ_SUCCESS) { recv_status = status; @@ -155,12 +150,6 @@ static pj_bool_t my_on_rx_request(pjsip_rx_data *rdata) static pj_bool_t my_on_rx_response(pjsip_rx_data *rdata) { if (pj_strcmp2(&rdata->msg_info.call_id, CALL_ID_HDR) == 0) { - PJ_LOG(4,("test", "Received %d bytes response: --begin-\n" - "%s\n" - "--end--", - rdata->msg_info.len, - rdata->msg_info.msg_buf)); - pj_get_timestamp(&my_recv_time); recv_status = PJ_SUCCESS; return PJ_TRUE; @@ -189,13 +178,14 @@ int transport_send_recv_test( pjsip_transport_type_e tp_type, pjsip_transport *ref_tp, char *target_url ) { + pj_bool_t msg_log_enabled; pj_status_t status; pj_str_t target, from, to, contact, call_id, body; pjsip_method method; pjsip_tx_data *tdata; pj_time_val timeout; - PJ_LOG(3,("", " single message round-trip test...")); + PJ_LOG(3,(THIS_FILE, " single message round-trip test...")); /* Register out test module to receive the message (if necessary). */ if (my_module.id == -1) { @@ -206,6 +196,9 @@ int transport_send_recv_test( pjsip_transport_type_e tp_type, } } + /* Disable message logging. */ + msg_log_enabled = msg_logger_set_enabled(0); + /* Create a request message. */ target = pj_str(target_url); from = pj_str(FROM_HDR); @@ -249,7 +242,7 @@ int transport_send_recv_test( pjsip_transport_type_e tp_type, pj_gettimeofday(&now); if (PJ_TIME_VAL_GTE(now, timeout)) { - PJ_LOG(3,("", " error: timeout in send/recv test")); + PJ_LOG(3,(THIS_FILE, " error: timeout in send/recv test")); status = -540; goto on_return; } @@ -278,9 +271,12 @@ int transport_send_recv_test( pjsip_transport_type_e tp_type, if (status == PJ_SUCCESS) { unsigned usec_rt; usec_rt = pj_elapsed_usec(&my_send_time, &my_recv_time); - PJ_LOG(3,("", " round-trip = %d usec", usec_rt)); + PJ_LOG(3,(THIS_FILE, " round-trip = %d usec", usec_rt)); } + /* Restore message logging. */ + msg_logger_set_enabled(msg_log_enabled); + status = PJ_SUCCESS; on_return: @@ -327,6 +323,9 @@ static struct pj_timestamp total_rt_time; int sent_request_count, recv_response_count; pj_str_t call_id; + pj_timer_entry timeout_timer; + pj_timer_entry tx_timer; + pj_mutex_t *mutex; } rt_test_data[16]; static char rt_target_uri[64]; @@ -371,6 +370,9 @@ static pj_status_t rt_send_request(int thread_id) pj_status_t status; pj_str_t target, from, to, contact, call_id; pjsip_tx_data *tdata; + pj_time_val timeout_delay; + + pj_mutex_lock(rt_test_data[thread_id].mutex); /* Create a request message. */ target = pj_str(rt_target_uri); @@ -384,7 +386,8 @@ static pj_status_t rt_send_request(int thread_id) &contact, &call_id, -1, NULL, &tdata ); if (status != PJ_SUCCESS) { - app_perror(" error: unable to create request", status); + app_perror(" error: unable to create request", status); + pj_mutex_unlock(rt_test_data[thread_id].mutex); return -610; } @@ -395,14 +398,25 @@ static pj_status_t rt_send_request(int thread_id) status = pjsip_endpt_send_request_stateless( endpt, tdata, NULL, NULL); if (status != PJ_SUCCESS) { /* Immediate error! */ - app_perror(" error: send request", status); + app_perror(" error: send request", status); pjsip_tx_data_dec_ref(tdata); + pj_mutex_unlock(rt_test_data[thread_id].mutex); return -620; } /* Update counter. */ rt_test_data[thread_id].sent_request_count++; + /* Set timeout timer. */ + if (rt_test_data[thread_id].timeout_timer.user_data != NULL) { + pjsip_endpt_cancel_timer(endpt, &rt_test_data[thread_id].timeout_timer); + } + timeout_delay.sec = 100; timeout_delay.msec = 0; + rt_test_data[thread_id].timeout_timer.user_data = (void*)1; + pjsip_endpt_schedule_timer(endpt, &rt_test_data[thread_id].timeout_timer, + &timeout_delay); + + pj_mutex_unlock(rt_test_data[thread_id].mutex); return PJ_SUCCESS; } @@ -413,6 +427,11 @@ static pj_bool_t rt_on_rx_response(pjsip_rx_data *rdata) int thread_id = (*pos - '0'); pj_timestamp recv_time; + pj_mutex_lock(rt_test_data[thread_id].mutex); + + /* Stop timer. */ + pjsip_endpt_cancel_timer(endpt, &rt_test_data[thread_id].timeout_timer); + /* Update counter and end-time. */ rt_test_data[thread_id].recv_response_count++; pj_get_timestamp(&recv_time); @@ -420,14 +439,55 @@ static pj_bool_t rt_on_rx_response(pjsip_rx_data *rdata) pj_sub_timestamp(&recv_time, &rt_test_data[thread_id].send_time); pj_add_timestamp(&rt_test_data[thread_id].total_rt_time, &recv_time); - if (!rt_stop) - rt_send_request(thread_id); + if (!rt_stop) { + pj_time_val tx_delay = { 0, 0 }; + pj_assert(rt_test_data[thread_id].tx_timer.user_data == NULL); + rt_test_data[thread_id].tx_timer.user_data = (void*)1; + pjsip_endpt_schedule_timer(endpt, &rt_test_data[thread_id].tx_timer, + &tx_delay); + } + + pj_mutex_unlock(rt_test_data[thread_id].mutex); + return PJ_TRUE; } return PJ_FALSE; } -static int rt_thread(void *arg) +static void rt_timeout_timer( pj_timer_heap_t *timer_heap, + struct pj_timer_entry *entry ) +{ + pj_mutex_lock(rt_test_data[entry->id].mutex); + + PJ_UNUSED_ARG(timer_heap); + PJ_LOG(3,(THIS_FILE, " timeout waiting for response")); + rt_test_data[entry->id].timeout_timer.user_data = NULL; + + if (rt_test_data[entry->id].tx_timer.user_data == NULL) { + pj_time_val delay = { 0, 0 }; + rt_test_data[entry->id].tx_timer.user_data = (void*)1; + pjsip_endpt_schedule_timer(endpt, &rt_test_data[entry->id].tx_timer, + &delay); + } + + pj_mutex_unlock(rt_test_data[entry->id].mutex); +} + +static void rt_tx_timer( pj_timer_heap_t *timer_heap, + struct pj_timer_entry *entry ) +{ + pj_mutex_lock(rt_test_data[entry->id].mutex); + + PJ_UNUSED_ARG(timer_heap); + pj_assert(rt_test_data[entry->id].tx_timer.user_data != NULL); + rt_test_data[entry->id].tx_timer.user_data = NULL; + rt_send_request(entry->id); + + pj_mutex_unlock(rt_test_data[entry->id].mutex); +} + + +static int rt_worker_thread(void *arg) { int i, thread_id = (int)arg; pj_time_val poll_delay = { 0, 10 }; @@ -435,10 +495,6 @@ static int rt_thread(void *arg) /* Sleep to allow main threads to run. */ pj_thread_sleep(10); - /* Send the first request. */ - if (rt_send_request(thread_id) != PJ_SUCCESS) - return -1; - while (!rt_stop) { pjsip_endpt_handle_events(endpt, &poll_delay); } @@ -452,13 +508,14 @@ static int rt_thread(void *arg) int transport_rt_test( pjsip_transport_type_e tp_type, pjsip_transport *ref_tp, - char *target_url ) + char *target_url, + int *lost) { enum { THREADS = 4, INTERVAL = 10 }; int i; pj_status_t status; pj_pool_t *pool; - pj_bool_t is_reliable; + pj_bool_t logger_enabled; pj_timestamp zero_time, total_time; unsigned usec_rt; @@ -466,11 +523,13 @@ int transport_rt_test( pjsip_transport_type_e tp_type, unsigned total_recv; - PJ_LOG(3,("", " multithreaded round-trip test (%d threads)...", + PJ_LOG(3,(THIS_FILE, " multithreaded round-trip test (%d threads)...", THREADS)); - PJ_LOG(3,("", " this will take approx %d seconds, please wait..", INTERVAL)); + PJ_LOG(3,(THIS_FILE, " this will take approx %d seconds, please wait..", + INTERVAL)); - is_reliable = (pjsip_transport_get_flag_from_type(tp_type) & PJSIP_TRANSPORT_RELIABLE); + /* Make sure msg logger is disabled. */ + logger_enabled = msg_logger_set_enabled(0); /* Register module (if not yet registered) */ if (rt_module.id == -1) { @@ -498,14 +557,27 @@ int transport_rt_test( pjsip_transport_type_e tp_type, pj_memset(&rt_test_data[i], 0, sizeof(rt_test_data[i])); + /* Init timer entry */ + rt_test_data[i].tx_timer.id = i; + rt_test_data[i].tx_timer.cb = &rt_tx_timer; + rt_test_data[i].timeout_timer.id = i; + rt_test_data[i].timeout_timer.cb = &rt_timeout_timer; + /* Generate Call-ID for each thread. */ rt_test_data[i].call_id.ptr = pj_pool_alloc(pool, rt_call_id.slen+1); pj_strcpy(&rt_test_data[i].call_id, &rt_call_id); buf[0] = '0' + i; pj_strcat(&rt_test_data[i].call_id, &str_id); + /* Init mutex. */ + status = pj_mutex_create_recursive(pool, "rt", &rt_test_data[i].mutex); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create mutex", status); + return -615; + } + /* Create thread, suspended. */ - status = pj_thread_create(pool, "rttest%p", &rt_thread, (void*)i, 0, + status = pj_thread_create(pool, "rttest%p", &rt_worker_thread, (void*)i, 0, PJ_THREAD_SUSPENDED, &rt_test_data[i].thread); if (status != PJ_SUCCESS) { app_perror(" error: unable to create thread", status); @@ -515,7 +587,12 @@ int transport_rt_test( pjsip_transport_type_e tp_type, /* Start threads! */ for (i=0; i<THREADS; ++i) { + pj_time_val delay = {0,0}; pj_thread_resume(rt_test_data[i].thread); + + /* Schedule first message transmissions. */ + rt_test_data[i].tx_timer.user_data = (void*)1; + pjsip_endpt_schedule_timer(endpt, &rt_test_data[i].tx_timer, &delay); } /* Sleep for some time. */ @@ -530,6 +607,12 @@ int transport_rt_test( pjsip_transport_type_e tp_type, pj_thread_destroy(rt_test_data[i].thread); } + /* Destroy rt_test_data */ + for (i=0; i<THREADS; ++i) { + pj_mutex_destroy(rt_test_data[i].mutex); + pjsip_endpt_cancel_timer(endpt, &rt_test_data[i].timeout_timer); + } + /* Gather statistics. */ pj_memset(&total_time, 0, sizeof(total_time)); pj_memset(&zero_time, 0, sizeof(zero_time)); @@ -546,19 +629,19 @@ int transport_rt_test( pjsip_transport_type_e tp_type, else total_time.u64 = 0; usec_rt = pj_elapsed_usec(&zero_time, &total_time); - PJ_LOG(3,("", " done.")); - PJ_LOG(3,("", " total %d messages sent", total_sent)); - if (total_sent-total_recv) - PJ_LOG(2,("", " total %d messages LOST", total_sent-total_recv)); - else - PJ_LOG(3,("", " no message was lost")); - PJ_LOG(3,("", " average round-trip=%d usec", usec_rt)); + PJ_LOG(3,(THIS_FILE, " done.")); + PJ_LOG(3,(THIS_FILE, " total %d messages sent", total_sent)); + PJ_LOG(3,(THIS_FILE, " average round-trip=%d usec", usec_rt)); pjsip_endpt_release_pool(endpt, pool); - if (is_reliable && (total_sent != total_recv)) { - PJ_LOG(3,("", " error: %d messages lost", total_sent-total_recv)); - return -650; - } + *lost = total_sent-total_recv; + + /* Flush events. */ + flush_events(500); + + /* Restore msg logger. */ + msg_logger_set_enabled(logger_enabled); + return 0; } diff --git a/pjsip/src/test-pjsip/transport_udp_test.c b/pjsip/src/test-pjsip/transport_udp_test.c index 0fdbddae..ebc0557d 100644 --- a/pjsip/src/test-pjsip/transport_udp_test.c +++ b/pjsip/src/test-pjsip/transport_udp_test.c @@ -21,6 +21,8 @@ #include <pjsip_core.h> #include <pjlib.h> +#define THIS_FILE "transport_udp_test.c" + /* * UDP transport test. @@ -32,7 +34,7 @@ int transport_udp_test(void) pj_sockaddr_in addr, rem_addr; pj_str_t s; pj_status_t status; - int i; + int i, pkt_lost; pj_sockaddr_in_init(&addr, NULL, TEST_UDP_PORT); @@ -84,10 +86,14 @@ int transport_udp_test(void) /* Multi-threaded round-trip test. */ status = transport_rt_test(PJSIP_TRANSPORT_UDP, tp, - "sip:alice@127.0.0.1:"TEST_UDP_PORT_STR); + "sip:alice@127.0.0.1:"TEST_UDP_PORT_STR, + &pkt_lost); if (status != 0) return status; + if (pkt_lost != 0) + PJ_LOG(3,(THIS_FILE, " note: %d packet(s) was lost", pkt_lost)); + /* Check again that reference counter is 1. */ if (pj_atomic_get(udp_tp->ref_cnt) != 1) return -80; @@ -100,6 +106,9 @@ int transport_udp_test(void) if (status != PJ_SUCCESS) return -90; + /* Flush events. */ + PJ_LOG(3,(THIS_FILE, " Flushing events, 1 second...")); + flush_events(1000); /* Done */ return 0; diff --git a/pjsip/src/test-pjsip/tsx_basic_test.c b/pjsip/src/test-pjsip/tsx_basic_test.c new file mode 100644 index 00000000..1db86f8d --- /dev/null +++ b/pjsip/src/test-pjsip/tsx_basic_test.c @@ -0,0 +1,147 @@ +/* $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> + +#define THIS_FILE "tsx_basic_test.c" + +/* Test transaction layer. */ +static int tsx_layer_test(void) +{ + pj_str_t target, from, tsx_key; + pjsip_tx_data *tdata; + pjsip_transaction *tsx, *found; + pj_status_t status; + + PJ_LOG(3,(THIS_FILE, " transaction layer test")); + + target = pj_str("sip:alice@localhost"); + from = pj_str("sip:bob@localhost"); + + status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target, + &from, &target, NULL, NULL, -1, NULL, + &tdata); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create request", status); + return -110; + } + + status = pjsip_tsx_create_uac(NULL, tdata, &tsx); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create transaction", status); + return -120; + } + + pj_strdup(tdata->pool, &tsx_key, &tsx->transaction_key); + + found = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_FALSE); + if (found != tsx) { + return -130; + } + + pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); + flush_events(500); + + if (pjsip_tx_data_dec_ref(tdata) != PJSIP_EBUFDESTROYED) { + return -140; + } + + return 0; +} + +/* Double terminate test. */ +static int double_terminate(void) +{ + pj_str_t target, from, tsx_key; + pjsip_tx_data *tdata; + pjsip_transaction *tsx; + pj_status_t status; + + PJ_LOG(3,(THIS_FILE, " double terminate test")); + + target = pj_str("sip:alice@localhost;transport=loop-dgram"); + from = pj_str("sip:bob@localhost"); + + /* Create request. */ + status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target, + &from, &target, NULL, NULL, -1, NULL, + &tdata); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create request", status); + return -10; + } + + /* Create transaction. */ + status = pjsip_tsx_create_uac(NULL, tdata, &tsx); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create transaction", status); + return -20; + } + + /* Save transaction key for later. */ + pj_strdup_with_null(tdata->pool, &tsx_key, &tsx->transaction_key); + + /* Add reference to transmit buffer (tsx_send_msg() will dec txdata). */ + pjsip_tx_data_add_ref(tdata); + + /* Send message to start timeout timer. */ + status = pjsip_tsx_send_msg(tsx, NULL); + + /* Terminate transaction. */ + status = pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to terminate transaction", status); + return -30; + } + + tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE); + if (tsx) { + /* Terminate transaction again. */ + pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to terminate transaction", status); + return -40; + } + pj_mutex_unlock(tsx->mutex); + } + + flush_events(500); + if (pjsip_tx_data_dec_ref(tdata) != PJSIP_EBUFDESTROYED) { + return -50; + } + + return PJ_SUCCESS; +} + +int tsx_basic_test(void) +{ + int status; + + status = tsx_layer_test(); + if (status != 0) + return status; + + status = double_terminate(); + if (status != 0) + return status; + + return 0; +} diff --git a/pjsip/src/test-pjsip/tsx_uac_test.c b/pjsip/src/test-pjsip/tsx_uac_test.c index 24af41e9..cf40e5d5 100644 --- a/pjsip/src/test-pjsip/tsx_uac_test.c +++ b/pjsip/src/test-pjsip/tsx_uac_test.c @@ -21,17 +21,77 @@ #include <pjsip_core.h> #include <pjlib.h> +#define THIS_FILE "tsx_uac_test.c" + + /***************************************************************************** ** - ** UAC basic retransmission and timeout test. + ** UAC tests. ** - ** This will test the retransmission of the UAC transaction. Remote will not - ** answer the transaction, so the transaction should fail. + ** This file performs various tests for UAC transactions. Each test will have + ** a different Via branch param so that message receiver module and + ** transaction user module can identify which test is being carried out. + ** + ** TEST1_BRANCH_ID + ** Perform basic retransmission and timeout test. Message receiver will + ** verify that retransmission is received at correct time. + ** This test verifies the following requirements: + ** - retransmit timer doubles for INVITE + ** - retransmit timer doubles and caps off for non-INVITE + ** - retransmit timer timer is precise + ** - correct timeout and retransmission count + ** Requirements not tested: + ** - retransmit timer only starts after resolving has completed. + ** + ** TEST2_BRANCH_ID + ** Test scenario where resolver is unable to resolve destination host. + ** + ** TEST3_BRANCH_ID + ** Test scenario where transaction is terminated while resolver is still + ** running. + ** + ** TEST4_BRANCH_ID + ** Test scenario where transport failed after several retransmissions. + ** + ** TEST5_BRANCH_ID + ** Test scenario where transaction is terminated by user after several + ** retransmissions. ** + ** TEST6_BRANCH_ID + ** Test successfull non-INVITE transaction. + ** It tests the following requirements: + ** - transaction correctly moves to COMPLETED state. + ** - retransmission must cease. + ** - tx_data must be maintained until state is terminated. + ** + ** TEST7_BRANCH_ID + ** Test successfull non-INVITE transaction, with provisional response. + ** + ** TEST8_BRANCH_ID + ** Test failed INVITE transaction (e.g. ACK must be received) + ** + ** TEST9_BRANCH_ID + ** Test failed INVITE transaction with provisional response. + ** + ** ***************************************************************************** */ -static char *CALL_ID1 = "UAC-Tsx-Basic-Test1"; +static char *TEST1_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test1"; +static char *TEST2_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test2"; +static char *TEST3_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test3"; +static char *TEST4_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test4"; +static char *TEST5_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test5"; +static char *TEST6_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test6"; +static char *TEST7_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test7"; +static char *TEST8_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test8"; +static char *TEST9_BRANCH_ID = PJSIP_RFC3261_BRANCH_ID "-Test9"; + +#define TEST1_ALLOWED_DIFF (150) +#define TEST4_RETRANSMIT_CNT 3 +#define TEST5_RETRANSMIT_CNT 3 + + 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); @@ -51,6 +111,8 @@ static pjsip_module tsx_user = NULL, /* unload() */ NULL, /* on_rx_request() */ NULL, /* on_rx_response() */ + NULL, /* on_tx_request() */ + NULL, /* on_tx_response() */ &tsx_user_on_tsx_state, /* on_tsx_state() */ }; @@ -70,39 +132,205 @@ static pjsip_module msg_receiver = NULL, /* unload() */ &msg_receiver_on_rx_request, /* on_rx_request() */ NULL, /* on_rx_response() */ + NULL, /* on_tx_request() */ + NULL, /* on_tx_response() */ NULL, /* on_tsx_state() */ }; -/* Static vars. */ +/* Static vars, which will be reset on each test. */ static int recv_count; static pj_time_val recv_last; static pj_bool_t test_complete; +/* Loop transport instance. */ +static pjsip_transport *loop; + +/* + * This is the handler to receive state changed notification from the + * transaction. It is used to verify that the transaction behaves according + * to the test scenario. + */ 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; + if (pj_strcmp2(&tsx->branch, TEST1_BRANCH_ID)==0) { + /* + * Transaction with TEST1_BRANCH_ID should terminate with transaction + * timeout status. + */ + if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + if (test_complete == 0) + test_complete = 1; + + /* Test the status code. */ + if (tsx->status_code != PJSIP_SC_TSX_TIMEOUT) { + PJ_LOG(3,(THIS_FILE, + " error: status code is %d instead of %d", + tsx->status_code, PJSIP_SC_TSX_TIMEOUT)); + test_complete = -710; + } + } + + } else if (pj_strcmp2(&tsx->branch, TEST2_BRANCH_ID)==0) { + /* + * Transaction with TEST2_BRANCH_ID should terminate with transport error. + */ + if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + /* Test the status code. */ + if (tsx->status_code != PJSIP_SC_TSX_TRANSPORT_ERROR) { + PJ_LOG(3,(THIS_FILE, + " error: status code is %d instead of %d", + tsx->status_code, PJSIP_SC_TSX_TRANSPORT_ERROR)); + test_complete = -720; + } + + if (test_complete == 0) + test_complete = 1; + } + + } else if (pj_strcmp2(&tsx->branch, TEST3_BRANCH_ID)==0) { + /* + * This test terminates the transaction while resolver is still + * running. + */ + if (tsx->state == PJSIP_TSX_STATE_CALLING) { + + /* Terminate the transaction. */ + pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); + + } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + /* Check if status code is correct. */ + if (tsx->status_code != PJSIP_SC_REQUEST_TERMINATED) { + PJ_LOG(3,(THIS_FILE, + " error: status code is %d instead of %d", + tsx->status_code, PJSIP_SC_REQUEST_TERMINATED)); + test_complete = -730; + } + + if (test_complete == 0) + test_complete = 1; + + } + + } else if (pj_strcmp2(&tsx->branch, TEST4_BRANCH_ID)==0) { + /* + * This test simulates transport failure after several + * retransmissions. + */ + if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + /* Status code must be transport error. */ + if (tsx->status_code != PJSIP_SC_TSX_TRANSPORT_ERROR) { + PJ_LOG(3,(THIS_FILE, + " error: status code is %d instead of %d", + tsx->status_code, PJSIP_SC_TSX_TRANSPORT_ERROR)); + test_complete = -730; + } + + /* Must have correct retransmission count. */ + if (tsx->retransmit_count != TEST4_RETRANSMIT_CNT) { + PJ_LOG(3,(THIS_FILE, + " error: retransmit cnt is %d instead of %d", + tsx->retransmit_count, TEST4_RETRANSMIT_CNT)); + test_complete = -731; + } + + if (test_complete == 0) + test_complete = 1; + } + + + } else if (pj_strcmp2(&tsx->branch, TEST5_BRANCH_ID)==0) { + /* + * This test simulates transport failure after several + * retransmissions. + */ + if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { + + /* Status code must be PJSIP_SC_REQUEST_TERMINATED. */ + if (tsx->status_code != PJSIP_SC_REQUEST_TERMINATED) { + PJ_LOG(3,(THIS_FILE, + " error: status code is %d instead of %d", + tsx->status_code, PJSIP_SC_REQUEST_TERMINATED)); + test_complete = -733; + } + + /* Must have correct retransmission count. */ + if (tsx->retransmit_count != TEST5_RETRANSMIT_CNT) { + PJ_LOG(3,(THIS_FILE, + " error: retransmit cnt is %d instead of %d", + tsx->retransmit_count, TEST5_RETRANSMIT_CNT)); + test_complete = -734; + } + + if (test_complete == 0) + test_complete = 1; + } + + + } else if (pj_strcmp2(&tsx->branch, TEST6_BRANCH_ID)==0) { + /* + * Successfull non-INVITE transaction. + */ + if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { + + /* Status code must be 202. */ + if (tsx->status_code != 202) { + PJ_LOG(3,(THIS_FILE, + " error: status code is %d instead of %d", + tsx->status_code, 202)); + test_complete = -736; + } + + /* Must have correct retransmission count. */ + if (tsx->retransmit_count != 0) { + PJ_LOG(3,(THIS_FILE, + " error: retransmit cnt is %d instead of %d", + tsx->retransmit_count, 0)); + test_complete = -737; + } + + /* Must still keep last_tx */ + if (tsx->last_tx == NULL) { + PJ_LOG(3,(THIS_FILE, + " error: transaction lost last_tx")); + test_complete = -738; + } + + if (test_complete == 0) { + test_complete = 1; + pjsip_tsx_terminate(tsx, 202); + } + } + } } #define DIFF(a,b) ((a<b) ? (b-a) : (a-b)) +/* + * This is the handler to receive message for this test. It is used to + * control and verify the behavior of the message transmitted by the + * transaction. + */ static pj_bool_t msg_receiver_on_rx_request(pjsip_rx_data *rdata) { - if (pj_strcmp2(&rdata->msg_info.call_id, CALL_ID1) == 0) { + if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST1_BRANCH_ID) == 0) { /* - * The CALL_ID1 test performs the verifications for transaction + * The TEST1_BRANCH_ID 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")); + PJ_LOG(4,(THIS_FILE, " 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", + PJ_LOG(3,(THIS_FILE, " error: received unexpected method %.*s", msg->line.req.method.name.slen, msg->line.req.method.name.ptr)); test_complete = -600; @@ -111,12 +339,15 @@ static pj_bool_t msg_receiver_on_rx_request(pjsip_rx_data *rdata) if (recv_count == 0) { recv_count++; - pj_gettimeofday(&recv_last); + //pj_gettimeofday(&recv_last); + recv_last = rdata->pkt_info.timestamp; } else { pj_time_val now; unsigned msec_expected, msec_elapsed; + int max_received; - pj_gettimeofday(&now); + //pj_gettimeofday(&now); + now = rdata->pkt_info.timestamp; PJ_TIME_VAL_SUB(now, recv_last); msec_elapsed = now.sec*1000 + now.msec; @@ -126,63 +357,165 @@ static pj_bool_t msg_receiver_on_rx_request(pjsip_rx_data *rdata) if (msg->line.req.method.id != PJSIP_INVITE_METHOD) { if (msec_expected > PJSIP_T2_TIMEOUT) msec_expected = PJSIP_T2_TIMEOUT; + max_received = 11; + } else { + max_received = 7; } - 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)); + if (DIFF(msec_expected, msec_elapsed) > TEST1_ALLOWED_DIFF) { + PJ_LOG(3,(THIS_FILE, + " error: expecting retransmission no. %d 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)); + + if (recv_count > max_received) { + PJ_LOG(3,(THIS_FILE, + " error: too many messages (%d) received", + recv_count)); test_complete = -620; } - pj_gettimeofday(&recv_last); + //pj_gettimeofday(&recv_last); + recv_last = rdata->pkt_info.timestamp; + } + return PJ_TRUE; + + } else + if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST4_BRANCH_ID) == 0) { + /* + * The TEST4_BRANCH_ID test simulates transport failure after several + * retransmissions. + */ + recv_count++; + + if (recv_count == TEST4_RETRANSMIT_CNT) { + /* Simulate transport failure. */ + pjsip_loop_set_failure(loop, 2, NULL); + + } else if (recv_count > TEST4_RETRANSMIT_CNT) { + PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", + recv_count)); + test_complete = -631; + } + + return PJ_TRUE; + + + } else + if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST5_BRANCH_ID) == 0) { + /* + * The TEST5_BRANCH_ID test simulates user terminating the transaction + * after several retransmissions. + */ + recv_count++; + + if (recv_count == TEST5_RETRANSMIT_CNT+1) { + pj_str_t key; + pjsip_transaction *tsx; + + pjsip_tsx_create_key( rdata->tp_info.pool, &key, PJSIP_ROLE_UAC, + &rdata->msg_info.msg->line.req.method, rdata); + tsx = pjsip_tsx_layer_find_tsx(&key, PJ_TRUE); + if (tsx) { + pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); + pj_mutex_unlock(tsx->mutex); + } else { + PJ_LOG(3,(THIS_FILE, " error: uac transaction not found!")); + test_complete = -633; + } + + } else if (recv_count > TEST5_RETRANSMIT_CNT+1) { + PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", + recv_count)); + test_complete = -634; + } + + return PJ_TRUE; + + } else + if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST6_BRANCH_ID) == 0) { + /* + * The TEST5_BRANCH_ID test successfull non-INVITE transaction. + */ + pjsip_tx_data *tdata; + pjsip_response_addr res_addr; + pj_status_t status; + + recv_count++; + + if (recv_count > 1) { + PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", + recv_count)); + test_complete = -635; + } + + status = pjsip_endpt_create_response(endpt, rdata, 202, NULL, &tdata); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to create response", status); + test_complete = -636; + } + + status = pjsip_get_response_addr(tdata->pool, rdata, &res_addr); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to get response addr", status); + test_complete = -637; } + + status = pjsip_endpt_send_response(endpt, &res_addr, tdata, NULL,NULL); + if (status != PJ_SUCCESS) { + app_perror(" error: unable to send response", status); + test_complete = -638; + pjsip_tx_data_dec_ref(tdata); + } + 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. - ** - ***************************************************************************** +/* + * The generic test framework, used by most of the tests. */ -static int tsx_uac_retransmit_test(const pjsip_method *method) +static int perform_tsx_test(int dummy, char *target_uri, char *from_uri, + char *branch_param, int test_time, + const pjsip_method *method) { pjsip_tx_data *tdata; pjsip_transaction *tsx; - char buf[80]; - pj_str_t target, from, call_id, tsx_key; + pj_str_t target, from, tsx_key; + pjsip_via_hdr *via; pj_time_val timeout; pj_status_t status; - PJ_LOG(3,("", " basic uac retransmission and timeout test")); + PJ_LOG(3,(THIS_FILE, + " please standby, this will take at most %d seconds..", + test_time)); - 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); + /* Reset test. */ + recv_count = 0; + test_complete = 0; + + /* Init headers. */ + target = pj_str(target_uri); + from = pj_str(from_uri); /* Create request. */ status = pjsip_endpt_create_request( endpt, method, &target, - &from, &target, NULL, &call_id, -1, + &from, &target, NULL, NULL, -1, NULL, &tdata); if (status != PJ_SUCCESS) { app_perror(" Error: unable to create request", status); - return -500; + return -100; } + /* Set the branch param for test 1. */ + via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); + via->branch_param = pj_str(branch_param); + /* Add additional reference to tdata to prevent transaction from * deleting it. */ @@ -192,7 +525,8 @@ static int tsx_uac_retransmit_test(const pjsip_method *method) status = pjsip_tsx_create_uac( &tsx_user, tdata, &tsx); if (status != PJ_SUCCESS) { app_perror(" Error: unable to create UAC transaction", status); - return -510; + pjsip_tx_data_dec_ref(tdata); + return -110; } /* Get transaction key. */ @@ -200,42 +534,65 @@ static int tsx_uac_retransmit_test(const pjsip_method *method) /* Send the message. */ status = pjsip_tsx_send_msg(tsx, NULL); - if (status != PJ_SUCCESS) { - app_perror(" Error: unable to send request", status); - return -520; - } + // Ignore send result. Some tests do deliberately triggers error + // when sending message. + //if (status != PJ_SUCCESS) { + // app_perror(" Error: unable to send request", status); + // pjsip_tx_data_dec_ref(tdata); + // return -120; + //} + /* Set test completion time. */ pj_gettimeofday(&timeout); - timeout.sec += 33; + timeout.sec += test_time; /* Wait until test complete. */ while (!test_complete) { - pj_time_val now; + pj_time_val now, poll_delay = {0, 10}; - pjsip_endpt_handle_events(endpt, NULL); + pjsip_endpt_handle_events(endpt, &poll_delay); pj_gettimeofday(&now); if (now.sec > timeout.sec) { - PJ_LOG(3,("", " Error: test has timed out")); - return -530; + PJ_LOG(3,(THIS_FILE, " Error: test has timed out")); + pjsip_tx_data_dec_ref(tdata); + return -130; } } - if (status < 0) + if (status < 0) { + pjsip_tx_data_dec_ref(tdata); return status; + } + + if (test_complete < 0) { + tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE); + if (tsx) { + pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); + pj_mutex_unlock(tsx->mutex); + flush_events(1000); + } + pjsip_tx_data_dec_ref(tdata); + return test_complete; + } + + /* Allow transaction to destroy itself */ + flush_events(500); /* 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; + PJ_LOG(3,(THIS_FILE, " Error: transaction has not been destroyed")); + pjsip_tx_data_dec_ref(tdata); + return -140; } /* Check tdata reference counter. */ if (pj_atomic_get(tdata->ref_cnt) != 1) { - PJ_LOG(3,("", " Error: tdata reference counter is %d", + PJ_LOG(3,(THIS_FILE, " Error: tdata reference counter is %d", pj_atomic_get(tdata->ref_cnt))); - return -550; + pjsip_tx_data_dec_ref(tdata); + return -150; } /* Destroy txdata */ @@ -246,38 +603,280 @@ static int tsx_uac_retransmit_test(const pjsip_method *method) /***************************************************************************** ** - ** UAC Transaction Test. + ** TEST1_BRANCH_ID: 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 Via branch prm + ** TEST1_BRANCH_ID will be used for this test. ** ***************************************************************************** */ -int tsx_uac_test(void) +static int tsx_uac_retransmit_test(void) { - pj_sockaddr_in addr; - pj_str_t tmp; - pjsip_transport *tp; + int status, enabled; + int i; + struct { + const pjsip_method *method; + unsigned delay; + } sub_test[] = + { + { &pjsip_invite_method, 0}, + { &pjsip_invite_method, TEST1_ALLOWED_DIFF*2}, + { &pjsip_options_method, 0}, + { &pjsip_options_method, TEST1_ALLOWED_DIFF*2} + }; + + PJ_LOG(3,(THIS_FILE, " test1: basic uac retransmit and timeout test")); + + + /* For this test. message printing shound be disabled because it makes + * incorrect timing. + */ + enabled = msg_logger_set_enabled(0); + + for (i=0; i<PJ_ARRAY_SIZE(sub_test); ++i) { + + PJ_LOG(3,(THIS_FILE, + " variant %c: %s with %d ms network delay", + ('a' + i), + sub_test[i].method->name.ptr, + sub_test[i].delay)); + + /* Configure transport */ + pjsip_loop_set_failure(loop, 0, NULL); + pjsip_loop_set_recv_delay(loop, sub_test[i].delay, NULL); + + /* Do the test. */ + status = perform_tsx_test(-500, "sip:bob@127.0.0.1;transport=loop-dgram", + "sip:alice@127.0.0.1;transport=loop-dgram", + TEST1_BRANCH_ID, + 35, sub_test[i].method); + if (status != 0) + break; + } + + /* Restore transport. */ + pjsip_loop_set_recv_delay(loop, 0, NULL); + + /* Restore msg logger. */ + msg_logger_set_enabled(enabled); + + /* Done. */ + return status; +} + +/***************************************************************************** + ** + ** TEST2_BRANCH_ID: UAC resolve error test. + ** + ** Test the scenario where destination host is unresolvable. There are + ** two variants: + ** (a) resolver returns immediate error + ** (b) resolver returns error via the callback. + ** + ***************************************************************************** + */ +static int tsx_resolve_error_test(void) +{ + int status; + + PJ_LOG(3,(THIS_FILE, " test2: resolve error test")); + + /* + * Variant (a): immediate resolve error. + */ + PJ_LOG(3,(THIS_FILE, " variant a: immediate resolving error")); + + status = perform_tsx_test(-800, + "sip:bob@unresolved-host;transport=loop-dgram", + "sip:alice@127.0.0.1;transport=loop-dgram", + TEST2_BRANCH_ID, 10, + &pjsip_options_method); + if (status != 0) + return status; + + /* + * Variant (b): error via callback. + */ + PJ_LOG(3,(THIS_FILE, " variant b: error via callback")); + + /* Set loop transport to return delayed error. */ + pjsip_loop_set_failure(loop, 2, NULL); + pjsip_loop_set_send_callback_delay(loop, 10, NULL); + + status = perform_tsx_test(-800, "sip:bob@127.0.0.1;transport=loop-dgram", + "sip:alice@127.0.0.1;transport=loop-dgram", + TEST2_BRANCH_ID, 2, + &pjsip_options_method); + if (status != 0) + return status; + + /* Restore loop transport settings. */ + pjsip_loop_set_failure(loop, 0, NULL); + pjsip_loop_set_send_callback_delay(loop, 0, NULL); + + return status; +} + + +/***************************************************************************** + ** + ** TEST3_BRANCH_ID: UAC terminate while resolving test. + ** + ** Terminate the transaction while resolver is still running. + ** + ***************************************************************************** + */ +static int tsx_terminate_resolving_test(void) +{ + unsigned prev_delay; pj_status_t status; - pj_sockaddr_in_init(&addr, pj_cstr(&tmp, "127.0.0.1"), TEST_UDP_PORT); + PJ_LOG(3,(THIS_FILE, " test3: terminate while resolving test")); - /* 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); + /* Configure transport delay. */ + pjsip_loop_set_send_callback_delay(loop, 100, &prev_delay); + + /* Start the test. */ + status = perform_tsx_test(-900, "sip:127.0.0.1;transport=loop-dgram", + "sip:127.0.0.1;transport=loop-dgram", + TEST3_BRANCH_ID, 2, &pjsip_options_method); + + /* Restore delay. */ + pjsip_loop_set_send_callback_delay(loop, prev_delay, NULL); + + return status; +} + + +/***************************************************************************** + ** + ** TEST4_BRANCH_ID: Transport failed after several retransmissions + ** + ** There are two variants of this test: (a) failure occurs immediately when + ** transaction calls pjsip_transport_send() or (b) failure is reported via + ** transport callback. + ** + ***************************************************************************** + */ +static int tsx_retransmit_fail_test(void) +{ + int i; + unsigned delay[] = {0, 10}; + pj_status_t status; + + PJ_LOG(3,(THIS_FILE, + " test4: transport fails after several retransmissions test")); + + + for (i=0; i<PJ_ARRAY_SIZE(delay); ++i) { + + PJ_LOG(3,(THIS_FILE, + " variant %c: transport delay %d ms", ('a'+i), delay[i])); + + /* Configure transport delay. */ + pjsip_loop_set_send_callback_delay(loop, delay[i], NULL); + + /* Restore transport failure mode. */ + pjsip_loop_set_failure(loop, 0, 0); + + /* Start the test. */ + status = perform_tsx_test(-1000, "sip:127.0.0.1;transport=loop-dgram", + "sip:127.0.0.1;transport=loop-dgram", + TEST4_BRANCH_ID, 6, &pjsip_options_method); + + if (status != 0) + break; + + } + + /* Restore delay. */ + pjsip_loop_set_send_callback_delay(loop, 0, NULL); + + /* Restore transport failure mode. */ + pjsip_loop_set_failure(loop, 0, 0); + + return status; +} + + +/***************************************************************************** + ** + ** TEST5_BRANCH_ID: Terminate transaction after several retransmissions + ** + ***************************************************************************** + */ +static int tsx_terminate_after_retransmit_test(void) +{ + int status; + + PJ_LOG(3,(THIS_FILE, " test5: terminate after retransmissions")); + + /* Do the test. */ + status = perform_tsx_test(-1100, "sip:bob@127.0.0.1;transport=loop-dgram", + "sip:alice@127.0.0.1;transport=loop-dgram", + TEST5_BRANCH_ID, + 6, &pjsip_options_method); + + /* Done. */ + return status; +} + + +/***************************************************************************** + ** + ** TEST6_BRANCH_ID: Successfull non-invite transaction + ** + ***************************************************************************** + */ +static int tsx_successfull_non_invite_test(void) +{ + int i, status; + unsigned delay[] = { 1, 200 }; + + PJ_LOG(3,(THIS_FILE, " test6: successfull non-invite transaction")); + + /* Do the test. */ + for (i=0; i<PJ_ARRAY_SIZE(delay); ++i) { + + PJ_LOG(3,(THIS_FILE, " variant %c: with %d ms transport delay", + ('a'+i), delay[i])); + + pjsip_loop_set_delay(loop, delay[i]); + + status = perform_tsx_test(-1200, + "sip:bob@127.0.0.1;transport=loop-dgram", + "sip:alice@127.0.0.1;transport=loop-dgram", + TEST6_BRANCH_ID, + 2, &pjsip_options_method); + if (status != 0) + return status; } - /* Start transaction layer module. */ - status = pjsip_tsx_layer_init(endpt); + pjsip_loop_set_delay(loop, 0); + + /* Done. */ + return status; +} + + +/***************************************************************************** + ** + ** UAC Transaction Test. + ** + ***************************************************************************** + */ +int tsx_uac_test(void) +{ + pj_sockaddr_in addr; + pj_status_t status; + + /* Check if loop transport is configured. */ + status = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_LOOP_DGRAM, + &addr, sizeof(addr), &loop); if (status != PJ_SUCCESS) { - app_perror(" Error initializing transaction module", status); - return -20; + PJ_LOG(3,(THIS_FILE, " Error: loop transport is not configured!")); + return -10; } /* Register modules. */ @@ -289,18 +888,43 @@ int tsx_uac_test(void) status = pjsip_endpt_register_module(endpt, &msg_receiver); if (status != PJ_SUCCESS) { app_perror(" Error: unable to register module", status); - return -30; + return -40; } - /* Basic retransmit and timeout test for INVITE. */ - status = tsx_uac_retransmit_test(&pjsip_invite_method); +#if 0 + /* TEST1_BRANCH_ID: Basic retransmit and timeout test. */ + status = tsx_uac_retransmit_test(); + if (status != 0) + return status; + + /* TEST2_BRANCH_ID: Resolve error test. */ + status = tsx_resolve_error_test(); if (status != 0) return status; - /* Basic retransmit and timeout test for non-INVITE. */ - status = tsx_uac_retransmit_test(&pjsip_options_method); + /* TEST3_BRANCH_ID: UAC terminate while resolving test. */ + status = tsx_terminate_resolving_test(); if (status != 0) return status; + /* TEST4_BRANCH_ID: Transport failed after several retransmissions */ + status = tsx_retransmit_fail_test(); + if (status != 0) + return status; + + /* TEST5_BRANCH_ID: Terminate transaction after several retransmissions */ + status = tsx_terminate_after_retransmit_test(); + if (status != 0) + return status; +#endif + + /* TEST6_BRANCH_ID: Successfull non-invite transaction */ + status = tsx_successfull_non_invite_test(); + if (status != 0) + return status; + + + pjsip_transport_dec_ref(loop); return 0; } + diff --git a/pjsip/src/test-pjsip/txdata_test.c b/pjsip/src/test-pjsip/txdata_test.c index 08cad024..b740c6fe 100644 --- a/pjsip/src/test-pjsip/txdata_test.c +++ b/pjsip/src/test-pjsip/txdata_test.c @@ -23,6 +23,9 @@ #define HFIND(msg,h,H) ((pjsip_##h##_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_##H, NULL)) +#define THIS_FILE "txdata_test.c" + + /* * This tests various core message creation functions. */ @@ -50,12 +53,12 @@ int txdata_test(void) /* Buffer must be invalid. */ if (pjsip_tx_data_is_valid(invite) != 0) { - PJ_LOG(3,("", " error: buffer must be invalid")); + PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid")); return -14; } /* Reference counter must be set to 1. */ if (pj_atomic_get(invite->ref_cnt) != 1) { - PJ_LOG(3,("", " error: invalid reference counter")); + PJ_LOG(3,(THIS_FILE, " error: invalid reference counter")); return -15; } /* Check message type. */ @@ -102,12 +105,12 @@ int txdata_test(void) /* Buffer must be invalid. */ if (pjsip_tx_data_is_valid(invite2) != 0) { - PJ_LOG(3,("", " error: buffer must be invalid")); + PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid")); return -34; } /* Reference counter must be set to 1. */ if (pj_atomic_get(invite2->ref_cnt) != 1) { - PJ_LOG(3,("", " error: invalid reference counter")); + PJ_LOG(3,(THIS_FILE, " error: invalid reference counter")); return -35; } /* Check message type. */ @@ -141,7 +144,7 @@ int txdata_test(void) /* Done checking invite2. We can delete this. */ if (pjsip_tx_data_dec_ref(invite2) != PJSIP_EBUFDESTROYED) { - PJ_LOG(3,("", " error: request buffer not destroyed!")); + PJ_LOG(3,(THIS_FILE, " error: request buffer not destroyed!")); return -49; } @@ -172,12 +175,12 @@ int txdata_test(void) /* Buffer must be invalid. */ if (pjsip_tx_data_is_valid(response) != 0) { - PJ_LOG(3,("", " error: buffer must be invalid")); + PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid")); return -54; } /* Check reference counter. */ if (pj_atomic_get(response->ref_cnt) != 1) { - PJ_LOG(3,("", " error: invalid ref count in response")); + PJ_LOG(3,(THIS_FILE, " error: invalid ref count in response")); return -55; } /* Check message type. */ @@ -214,12 +217,12 @@ int txdata_test(void) /* Buffer must be invalid. */ if (pjsip_tx_data_is_valid(cancel) != 0) { - PJ_LOG(3,("", " error: buffer must be invalid")); + PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid")); return -84; } /* Check reference counter. */ if (pj_atomic_get(cancel->ref_cnt) != 1) { - PJ_LOG(3,("", " error: invalid ref count in CANCEL request")); + PJ_LOG(3,(THIS_FILE, " error: invalid ref count in CANCEL request")); return -85; } /* Check message type. */ @@ -247,7 +250,7 @@ int txdata_test(void) /* Done checking CANCEL request. */ if (pjsip_tx_data_dec_ref(cancel) != PJSIP_EBUFDESTROYED) { - PJ_LOG(3,("", " error: response buffer not destroyed!")); + PJ_LOG(3,(THIS_FILE, " error: response buffer not destroyed!")); return -99; } @@ -259,17 +262,17 @@ int txdata_test(void) /* Create ACK request */ status = pjsip_endpt_create_ack( endpt, invite, &dummy_rdata, &ack ); if (status != PJ_SUCCESS) { - PJ_LOG(3,("", " error: unable to create ACK")); + PJ_LOG(3,(THIS_FILE, " error: unable to create ACK")); return -100; } /* Buffer must be invalid. */ if (pjsip_tx_data_is_valid(ack) != 0) { - PJ_LOG(3,("", " error: buffer must be invalid")); + PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid")); return -104; } /* Check reference counter. */ if (pj_atomic_get(ack->ref_cnt) != 1) { - PJ_LOG(3,("", " error: invalid ref count in ACK request")); + PJ_LOG(3,(THIS_FILE, " error: invalid ref count in ACK request")); return -105; } /* Check message type. */ @@ -298,19 +301,19 @@ int txdata_test(void) /* Done checking invite message. */ if (pjsip_tx_data_dec_ref(invite) != PJSIP_EBUFDESTROYED) { - PJ_LOG(3,("", " error: response buffer not destroyed!")); + PJ_LOG(3,(THIS_FILE, " error: response buffer not destroyed!")); return -120; } /* Done checking response message. */ if (pjsip_tx_data_dec_ref(response) != PJSIP_EBUFDESTROYED) { - PJ_LOG(3,("", " error: response buffer not destroyed!")); + PJ_LOG(3,(THIS_FILE, " error: response buffer not destroyed!")); return -130; } /* Done checking ack message. */ if (pjsip_tx_data_dec_ref(ack) != PJSIP_EBUFDESTROYED) { - PJ_LOG(3,("", " error: response buffer not destroyed!")); + PJ_LOG(3,(THIS_FILE, " error: response buffer not destroyed!")); return -140; } diff --git a/pjsip/src/test-pjsip/uri_test.c b/pjsip/src/test-pjsip/uri_test.c index de9604bf..46edd66a 100644 --- a/pjsip/src/test-pjsip/uri_test.c +++ b/pjsip/src/test-pjsip/uri_test.c @@ -20,6 +20,8 @@ #include <pjsip_core.h> #include <pjlib.h> +#define THIS_FILE "uri_test.c" + #define ALPHANUM "abcdefghijklmnopqrstuvwxyz" \ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ @@ -692,9 +694,9 @@ static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry) */ status = entry->status==ERR_SYNTAX_ERR ? PJ_SUCCESS : -10; if (status != 0) { - PJ_LOG(3,("", " uri parse error!\n" - " uri='%s'\n", - entry->str)); + PJ_LOG(3,(THIS_FILE, " uri parse error!\n" + " uri='%s'\n", + entry->str)); } goto on_return; } @@ -738,10 +740,10 @@ static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry) /* Not equal. See if this is the expected status. */ status = entry->status==ERR_NOT_EQUAL ? PJ_SUCCESS : -40; if (status != 0) { - PJ_LOG(3,("", " uri comparison mismatch, status=%d:\n" - " uri1='%s'\n" - " uri2='%s'", - status, s1.ptr, s2.ptr)); + PJ_LOG(3,(THIS_FILE, " uri comparison mismatch, status=%d:\n" + " uri1='%s'\n" + " uri2='%s'", + status, s1.ptr, s2.ptr)); } goto on_return; @@ -762,19 +764,19 @@ static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry) if (entry->printed) { if (pj_strcmp2(&s1, entry->printed) != 0) { /* Not equal. */ - PJ_LOG(3,("", " uri print mismatch:\n" - " printed='%s'\n" - " expectd='%s'", - s1.ptr, entry->printed)); + PJ_LOG(3,(THIS_FILE, " uri print mismatch:\n" + " printed='%s'\n" + " expectd='%s'", + s1.ptr, entry->printed)); status = -60; } } else { if (pj_strcmp(&s1, &s2) != 0) { /* Not equal. */ - PJ_LOG(3,("", " uri print mismatch:\n" - " uri1='%s'\n" - " uri2='%s'", - s1.ptr, s2.ptr)); + PJ_LOG(3,(THIS_FILE, " uri print mismatch:\n" + " uri1='%s'\n" + " uri2='%s'", + s1.ptr, s2.ptr)); status = -70; } } @@ -794,19 +796,19 @@ int uri_test() zero.u32.hi = zero.u32.lo = 0; - PJ_LOG(3,("", " simple test")); + PJ_LOG(3,(THIS_FILE, " simple test")); pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE); for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) { status = do_uri_test(pool, &uri_test_array[i]); if (status != PJ_SUCCESS) { - PJ_LOG(3,("uri_test", " error %d when testing entry %d", + PJ_LOG(3,(THIS_FILE, " error %d when testing entry %d", status, i)); goto on_return; } } pjsip_endpt_release_pool(endpt, pool); - PJ_LOG(3,("", " benchmarking...")); + PJ_LOG(3,(THIS_FILE, " benchmarking...")); parse_len = print_len = cmp_len = 0; parse_time.u32.hi = parse_time.u32.lo = 0; print_time.u32.hi = print_time.u32.lo = 0; @@ -816,7 +818,7 @@ int uri_test() for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) { status = do_uri_test(pool, &uri_test_array[i]); if (status != PJ_SUCCESS) { - PJ_LOG(3,("uri_test", " error %d when testing entry %d", + PJ_LOG(3,(THIS_FILE, " error %d when testing entry %d", status, i)); pjsip_endpt_release_pool(endpt, pool); goto on_return; @@ -834,10 +836,11 @@ int uri_test() pj_highprec_div(avg_parse, parse_len); avg_parse = 1000000 / avg_parse; - PJ_LOG(3,("", " %u.%u MB of urls parsed in %d.%03ds (avg=%d urls/sec)", - (unsigned)(parse_len/1000000), (unsigned)kbytes, - elapsed.sec, elapsed.msec, - (unsigned)avg_parse)); + PJ_LOG(3,(THIS_FILE, + " %u.%u MB of urls parsed in %d.%03ds (avg=%d urls/sec)", + (unsigned)(parse_len/1000000), (unsigned)kbytes, + elapsed.sec, elapsed.msec, + (unsigned)avg_parse)); kbytes = print_len; pj_highprec_mod(kbytes, 1000000); @@ -848,10 +851,11 @@ int uri_test() pj_highprec_div(avg_print, parse_len); avg_print = 1000000 / avg_print; - PJ_LOG(3,("", " %u.%u MB of urls printed in %d.%03ds (avg=%d urls/sec)", - (unsigned)(print_len/1000000), (unsigned)kbytes, - elapsed.sec, elapsed.msec, - (unsigned)avg_print)); + PJ_LOG(3,(THIS_FILE, + " %u.%u MB of urls printed in %d.%03ds (avg=%d urls/sec)", + (unsigned)(print_len/1000000), (unsigned)kbytes, + elapsed.sec, elapsed.msec, + (unsigned)avg_print)); kbytes = cmp_len; pj_highprec_mod(kbytes, 1000000); @@ -862,12 +866,13 @@ int uri_test() pj_highprec_div(avg_cmp, cmp_len); avg_cmp = 1000000 / avg_cmp; - PJ_LOG(3,("", " %u.%u MB of urls compared in %d.%03ds (avg=%d urls/sec)", - (unsigned)(cmp_len/1000000), (unsigned)kbytes, - elapsed.sec, elapsed.msec, - (unsigned)avg_cmp)); + PJ_LOG(3,(THIS_FILE, + " %u.%u MB of urls compared in %d.%03ds (avg=%d urls/sec)", + (unsigned)(cmp_len/1000000), (unsigned)kbytes, + elapsed.sec, elapsed.msec, + (unsigned)avg_cmp)); - PJ_LOG(3,("", " multithreaded test")); + PJ_LOG(3,(THIS_FILE, " multithreaded test")); on_return: |