diff options
author | Benny Prijono <bennylp@teluu.com> | 2008-08-04 10:52:51 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2008-08-04 10:52:51 +0000 |
commit | 8a14826b0e6725b8c5eab7752fd30811510e8c24 (patch) | |
tree | 49af4efd31b12e5bca764254040e41b84de2ec92 /pjsip/src/test-pjsip | |
parent | f2b03bec9115d384456098eada81efc9707df24a (diff) |
Changed SIP transport to use active socket to fix ticket #579: "Data loss with TCP sockets (thanks Helmut Wolf for the report)". Also added SIP more TCP transport tests to reproduce the bug
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2188 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/test-pjsip')
-rw-r--r-- | pjsip/src/test-pjsip/transport_tcp_test.c | 6 | ||||
-rw-r--r-- | pjsip/src/test-pjsip/transport_test.c | 116 |
2 files changed, 121 insertions, 1 deletions
diff --git a/pjsip/src/test-pjsip/transport_tcp_test.c b/pjsip/src/test-pjsip/transport_tcp_test.c index 3594aff0..2a091caa 100644 --- a/pjsip/src/test-pjsip/transport_tcp_test.c +++ b/pjsip/src/test-pjsip/transport_tcp_test.c @@ -83,7 +83,11 @@ int transport_tcp_test(void) /* Check again that reference counter is 1. */ if (pj_atomic_get(tcp->ref_cnt) != 1) - return -70; + return -40; + + /* Load test */ + if (transport_load_test(url) != 0) + return -60; /* Basic transport's send/receive loopback test. */ for (i=0; i<SEND_RECV_LOOP; ++i) { diff --git a/pjsip/src/test-pjsip/transport_test.c b/pjsip/src/test-pjsip/transport_test.c index a283ec73..a7aa8905 100644 --- a/pjsip/src/test-pjsip/transport_test.c +++ b/pjsip/src/test-pjsip/transport_test.c @@ -641,3 +641,119 @@ int transport_rt_test( pjsip_transport_type_e tp_type, return 0; } + +/////////////////////////////////////////////////////////////////////////////// +/* + * Transport load testing + */ +static pj_bool_t load_on_rx_request(pjsip_rx_data *rdata); + +static struct mod_load_test +{ + pjsip_module mod; + pj_uint32_t next_seq; + pj_bool_t err; +} mod_load = +{ + { + NULL, NULL, /* prev and next */ + { "mod-load-test", 13}, /* Name. */ + -1, /* Id */ + PJSIP_MOD_PRIORITY_TSX_LAYER-1, /* Priority */ + NULL, /* load() */ + NULL, /* start() */ + NULL, /* stop() */ + NULL, /* unload() */ + &load_on_rx_request, /* on_rx_request() */ + NULL, /* on_rx_response() */ + NULL, /* tsx_handler() */ + } +}; + + +static pj_bool_t load_on_rx_request(pjsip_rx_data *rdata) +{ + if (rdata->msg_info.cseq->cseq != mod_load.next_seq) { + PJ_LOG(1,("THIS_FILE", " err: expecting cseq %u, got %u", + mod_load.next_seq, rdata->msg_info.cseq->cseq)); + mod_load.err = PJ_TRUE; + mod_load.next_seq = rdata->msg_info.cseq->cseq + 1; + } else + mod_load.next_seq++; + return PJ_TRUE; +} + +int transport_load_test(char *target_url) +{ + enum { COUNT = 2000 }; + unsigned i; + pj_status_t status; + + /* exhaust packets */ + do { + pj_time_val delay = {1, 0}; + i = 0; + pjsip_endpt_handle_events2(endpt, &delay, &i); + } while (i != 0); + + PJ_LOG(3,(THIS_FILE, " transport load test...")); + + if (mod_load.mod.id == -1) { + status = pjsip_endpt_register_module( endpt, &mod_load.mod); + if (status != PJ_SUCCESS) { + app_perror("error registering module", status); + return -1; + } + } + mod_load.err = PJ_FALSE; + mod_load.next_seq = 0; + + for (i=0; i<COUNT && !mod_load.err; ++i) { + pj_str_t target, from, call_id; + pjsip_tx_data *tdata; + + target = pj_str(target_url); + from = pj_str("<sip:user@host>"); + call_id = pj_str("thecallid"); + status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, + &target, &from, + &target, &from, &call_id, + i, NULL, &tdata ); + if (status != PJ_SUCCESS) { + app_perror("error creating request", status); + goto on_return; + } + + status = pjsip_endpt_send_request_stateless(endpt, tdata, NULL, NULL); + if (status != PJ_SUCCESS) { + app_perror("error sending request", status); + goto on_return; + } + } + + do { + pj_time_val delay = {1, 0}; + i = 0; + pjsip_endpt_handle_events2(endpt, &delay, &i); + } while (i != 0); + + if (mod_load.next_seq != COUNT) { + PJ_LOG(1,("THIS_FILE", " err: expecting %u msg, got only %u", + COUNT, mod_load.next_seq)); + status = -2; + goto on_return; + } + +on_return: + if (mod_load.mod.id != -1) { + pjsip_endpt_unregister_module( endpt, &mod_load.mod); + mod_load.mod.id = -1; + } + if (status != PJ_SUCCESS || mod_load.err) { + return -2; + } + PJ_LOG(3,(THIS_FILE, " success")); + return 0; +} + + |