diff options
author | Benny Prijono <bennylp@teluu.com> | 2005-11-07 18:14:08 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2005-11-07 18:14:08 +0000 |
commit | 8b3f0c56c5c885134f3865539a7257a7ebb90387 (patch) | |
tree | 0388183e5ca1c7973c0b830bdbd0bedd58a9c315 /pjlib/src/pjlib-test | |
parent | e25a988d098a075f5519090c24237c3b97bc1323 (diff) |
UDP echo testing in Linux
git-svn-id: http://svn.pjsip.org/repos/pjproject/main@19 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pjlib-test')
-rw-r--r-- | pjlib/src/pjlib-test/echo_clt.c | 14 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/test.c | 28 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/test.h | 26 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/udp_echo_srv_sync.c | 120 |
4 files changed, 101 insertions, 87 deletions
diff --git a/pjlib/src/pjlib-test/echo_clt.c b/pjlib/src/pjlib-test/echo_clt.c index 169b6dc2..737a1f59 100644 --- a/pjlib/src/pjlib-test/echo_clt.c +++ b/pjlib/src/pjlib-test/echo_clt.c @@ -41,6 +41,9 @@ static int echo_client_thread(void *arg) pj_sockaddr_in addr; pj_str_t s; pj_status_t rc; + pj_uint32_t buffer_id; + pj_uint32_t buffer_counter; + pj_uint32_t timeout_counter=0, invalid_counter=0; struct client *client = arg; pj_status_t last_recv_err = PJ_SUCCESS, last_send_err = PJ_SUCCESS; unsigned counter = 0; @@ -77,14 +80,24 @@ static int echo_client_thread(void *arg) //PJ_LOG(3,("", "...thread %p running", pj_thread_this())); + buffer_id = (pj_uint32_t) pj_thread_this(); + buffer_counter = 0; + + *(pj_uint32_t*)send_buf = buffer_id; + for (;;) { int rc; pj_ssize_t bytes; + pj_uint32_t *p_buffer_id, *p_buffer_counter; ++counter; + while (wait_socket(sock,0) > 0) + ; + /* Send a packet. */ bytes = BUF_SIZE; + *(pj_uint32_t*)(send_buf+4) = ++buffer_counter; rc = pj_sock_send(sock, send_buf, &bytes, 0); if (rc != PJ_SUCCESS || bytes != BUF_SIZE) { if (rc != last_send_err) { @@ -100,6 +113,7 @@ static int echo_client_thread(void *arg) if (rc == 0) { PJ_LOG(3,("", "...timeout")); bytes = 0; + timeout_counter++; } else if (rc < 0) { rc = pj_get_netos_error(); app_perror("...select() error", rc); diff --git a/pjlib/src/pjlib-test/test.c b/pjlib/src/pjlib-test/test.c index b65fa9e7..52ed0617 100644 --- a/pjlib/src/pjlib-test/test.c +++ b/pjlib/src/pjlib-test/test.c @@ -30,10 +30,10 @@ int test_inner(void) int rc = 0; mem = &caching_pool.factory; -
- pj_log_set_level(3);
- pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
- PJ_LOG_HAS_MICRO_SEC);
+ + pj_log_set_level(3); + pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | + PJ_LOG_HAS_MICRO_SEC); rc = pj_init(); if (rc != 0) { @@ -123,14 +123,14 @@ int test_inner(void) #if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST DO_TEST( tcp_ioqueue_test() ); #endif -
-#if INCLUDE_IOQUEUE_PERF_TEST
- DO_TEST( ioqueue_perf_test() );
-#endif
-
-#if INCLUDE_FILE_TEST
- DO_TEST( file_test() );
-#endif
+ +#if INCLUDE_IOQUEUE_PERF_TEST + DO_TEST( ioqueue_perf_test() ); +#endif + +#if INCLUDE_FILE_TEST + DO_TEST( file_test() ); +#endif #if INCLUDE_XML_TEST DO_TEST( xml_test() ); @@ -138,8 +138,8 @@ int test_inner(void) #if INCLUDE_ECHO_SERVER //echo_server(); - //echo_srv_sync();
- udp_echo_srv_ioqueue();
+ //echo_srv_sync(); + udp_echo_srv_ioqueue(); #elif INCLUDE_ECHO_CLIENT if (param_echo_sock_type == 0) diff --git a/pjlib/src/pjlib-test/test.h b/pjlib/src/pjlib-test/test.h index b16aff69..b6da599d 100644 --- a/pjlib/src/pjlib-test/test.h +++ b/pjlib/src/pjlib-test/test.h @@ -8,8 +8,8 @@ #define GROUP_LIBC 0 #define GROUP_OS 0 #define GROUP_DATA_STRUCTURE 0 -#define GROUP_NETWORK 0
-#define GROUP_FILE 1 +#define GROUP_NETWORK 0 +#define GROUP_FILE 0 #define GROUP_EXTRA 0 #define INCLUDE_ERRNO_TEST GROUP_LIBC @@ -31,16 +31,16 @@ #define INCLUDE_SOCK_PERF_TEST GROUP_NETWORK #define INCLUDE_SELECT_TEST GROUP_NETWORK #define INCLUDE_UDP_IOQUEUE_TEST GROUP_NETWORK -#define INCLUDE_TCP_IOQUEUE_TEST GROUP_NETWORK
-#define INCLUDE_IOQUEUE_PERF_TEST GROUP_NETWORK
+#define INCLUDE_TCP_IOQUEUE_TEST GROUP_NETWORK +#define INCLUDE_IOQUEUE_PERF_TEST GROUP_NETWORK #define INCLUDE_FILE_TEST GROUP_FILE #define INCLUDE_XML_TEST GROUP_EXTRA -#define INCLUDE_ECHO_SERVER 0 +#define INCLUDE_ECHO_SERVER 1 #define INCLUDE_ECHO_CLIENT 0 -
-#define ECHO_SERVER_MAX_THREADS 4 + +#define ECHO_SERVER_MAX_THREADS 2 #define ECHO_SERVER_START_PORT 65000 #define ECHO_SERVER_ADDRESS "compaq.home" #define ECHO_SERVER_DURATION_MSEC (60*60*1000) @@ -68,17 +68,17 @@ extern int sock_test(void); extern int sock_perf_test(void); extern int select_test(void); extern int udp_ioqueue_test(void); -extern int tcp_ioqueue_test(void);
-extern int ioqueue_perf_test(void);
+extern int tcp_ioqueue_test(void); +extern int ioqueue_perf_test(void); extern int file_test(void); extern int xml_test(void); extern int echo_server(void); extern int echo_client(int sock_type, const char *server, int port); -
-extern int echo_srv_sync(void);
-extern int udp_echo_srv_ioqueue(void);
-extern int echo_srv_common_loop(pj_atomic_t *bytes_counter);
+ +extern int echo_srv_sync(void); +extern int udp_echo_srv_ioqueue(void); +extern int echo_srv_common_loop(pj_atomic_t *bytes_counter); extern pj_pool_factory *mem; diff --git a/pjlib/src/pjlib-test/udp_echo_srv_sync.c b/pjlib/src/pjlib-test/udp_echo_srv_sync.c index 19ee702c..7f371709 100644 --- a/pjlib/src/pjlib-test/udp_echo_srv_sync.c +++ b/pjlib/src/pjlib-test/udp_echo_srv_sync.c @@ -3,7 +3,7 @@ #include "test.h" #include <pjlib.h> -static pj_atomic_t *total_bytes;
+static pj_atomic_t *total_bytes; static int worker_thread(void *arg) { @@ -47,7 +47,7 @@ int echo_srv_sync(void) pj_pool_t *pool; pj_sock_t sock; pj_thread_t *thread[ECHO_SERVER_MAX_THREADS]; - pj_status_t rc;
+ pj_status_t rc; int i; pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); @@ -60,7 +60,7 @@ int echo_srv_sync(void) return -6; } - rc = app_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, ECHO_SERVER_START_PORT, &sock); + rc = app_socket(PJ_AF_INET, PJ_SOCK_DGRAM,0, ECHO_SERVER_START_PORT, &sock); if (rc != PJ_SUCCESS) { app_perror("...socket error", rc); return -10; @@ -80,64 +80,64 @@ int echo_srv_sync(void) ECHO_SERVER_MAX_THREADS, ECHO_SERVER_START_PORT)); PJ_LOG(3,("", "...Press Ctrl-C to abort")); - echo_srv_common_loop(total_bytes);
+ echo_srv_common_loop(total_bytes); return 0; } -int echo_srv_common_loop(pj_atomic_t *bytes_counter)
-{
- pj_highprec_t last_received, avg_bw, highest_bw;
- pj_time_val last_print;
- unsigned count;
-
- last_received = 0;
- pj_gettimeofday(&last_print);
- avg_bw = highest_bw = 0;
- count = 0;
-
- for (;;) {
- pj_highprec_t received, cur_received, bw;
- unsigned msec;
- pj_time_val now, duration;
-
- pj_thread_sleep(1000);
-
- received = cur_received = pj_atomic_get(bytes_counter);
- cur_received = cur_received - last_received;
-
- pj_gettimeofday(&now);
- duration = now;
- PJ_TIME_VAL_SUB(duration, last_print);
- msec = PJ_TIME_VAL_MSEC(duration);
-
- bw = cur_received;
- pj_highprec_mul(bw, 1000);
- pj_highprec_div(bw, msec);
-
- last_print = now;
- last_received = received;
-
- avg_bw = avg_bw + bw;
- count++;
-
- PJ_LOG(3,("", "Synchronous UDP (%d threads): %u KB/s (avg=%u KB/s) %s",
- ECHO_SERVER_MAX_THREADS,
- (unsigned)(bw / 1000),
- (unsigned)(avg_bw / count / 1000),
- (count==20 ? "<ses avg>" : "")));
-
- if (count==20) {
- if (avg_bw/count > highest_bw)
- highest_bw = avg_bw/count;
-
- count = 0;
- avg_bw = 0;
-
- PJ_LOG(3,("", "Highest average bandwidth=%u KB/s",
- (unsigned)(highest_bw/1000)));
- }
- }
-}
-
-
+int echo_srv_common_loop(pj_atomic_t *bytes_counter) +{ + pj_highprec_t last_received, avg_bw, highest_bw; + pj_time_val last_print; + unsigned count; + + last_received = 0; + pj_gettimeofday(&last_print); + avg_bw = highest_bw = 0; + count = 0; + + for (;;) { + pj_highprec_t received, cur_received, bw; + unsigned msec; + pj_time_val now, duration; + + pj_thread_sleep(1000); + + received = cur_received = pj_atomic_get(bytes_counter); + cur_received = cur_received - last_received; + + pj_gettimeofday(&now); + duration = now; + PJ_TIME_VAL_SUB(duration, last_print); + msec = PJ_TIME_VAL_MSEC(duration); + + bw = cur_received; + pj_highprec_mul(bw, 1000); + pj_highprec_div(bw, msec); + + last_print = now; + last_received = received; + + avg_bw = avg_bw + bw; + count++; + + PJ_LOG(3,("", "Synchronous UDP (%d threads): %u KB/s (avg=%u KB/s) %s", + ECHO_SERVER_MAX_THREADS, + (unsigned)(bw / 1000), + (unsigned)(avg_bw / count / 1000), + (count==20 ? "<ses avg>" : ""))); + + if (count==20) { + if (avg_bw/count > highest_bw) + highest_bw = avg_bw/count; + + count = 0; + avg_bw = 0; + + PJ_LOG(3,("", "Highest average bandwidth=%u KB/s", + (unsigned)(highest_bw/1000))); + } + } +} + + |