diff options
Diffstat (limited to 'pjlib/src/pjlib-test/ioq_udp.c')
-rw-r--r-- | pjlib/src/pjlib-test/ioq_udp.c | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/pjlib/src/pjlib-test/ioq_udp.c b/pjlib/src/pjlib-test/ioq_udp.c index 1bbe494f..e7e1ae52 100644 --- a/pjlib/src/pjlib-test/ioq_udp.c +++ b/pjlib/src/pjlib-test/ioq_udp.c @@ -125,7 +125,7 @@ static pj_ioqueue_callback test_cb = * To test that the basic IOQueue functionality works. It will just exchange * data between two sockets. */ -static int compliance_test(void) +static int compliance_test(pj_bool_t allow_concur) { pj_sock_t ssock=-1, csock=-1; pj_sockaddr_in addr, dst_addr; @@ -178,6 +178,13 @@ static int compliance_test(void) status=-20; goto on_error; } + // Set concurrency + TRACE_("set concurrency..."); + rc = pj_ioqueue_set_default_concurrency(ioque, allow_concur); + if (rc != PJ_SUCCESS) { + status=-21; goto on_error; + } + // Register server and client socket. // We put this after inactivity socket, hopefully this can represent the // worst waiting time. @@ -351,7 +358,7 @@ static void on_read_complete(pj_ioqueue_key_t *key, * Check if callback is still called after socket has been unregistered or * closed. */ -static int unregister_test(void) +static int unregister_test(pj_bool_t allow_concur) { enum { RPORT = 50000, SPORT = 50001 }; pj_pool_t *pool; @@ -381,6 +388,13 @@ static int unregister_test(void) return -110; } + // Set concurrency + TRACE_("set concurrency..."); + status = pj_ioqueue_set_default_concurrency(ioqueue, allow_concur); + if (status != PJ_SUCCESS) { + return -112; + } + /* Create sender socket */ status = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, SPORT, &ssock); if (status != PJ_SUCCESS) { @@ -512,7 +526,7 @@ static int unregister_test(void) * This will just test registering PJ_IOQUEUE_MAX_HANDLES count * of sockets to the ioqueue. */ -static int many_handles_test(void) +static int many_handles_test(pj_bool_t allow_concur) { enum { MAX = PJ_IOQUEUE_MAX_HANDLES }; pj_pool_t *pool; @@ -539,6 +553,12 @@ static int many_handles_test(void) return -10; } + // Set concurrency + rc = pj_ioqueue_set_default_concurrency(ioqueue, allow_concur); + if (rc != PJ_SUCCESS) { + return -11; + } + /* Register as many sockets. */ for (count=0; count<MAX; ++count) { sock[count] = PJ_INVALID_SOCKET; @@ -600,7 +620,8 @@ static int many_handles_test(void) /* * Benchmarking IOQueue */ -static int bench_test(int bufsize, int inactive_sock_count) +static int bench_test(pj_bool_t allow_concur, int bufsize, + int inactive_sock_count) { pj_sock_t ssock=-1, csock=-1; pj_sockaddr_in addr; @@ -651,6 +672,13 @@ static int bench_test(int bufsize, int inactive_sock_count) goto on_error; } + // Set concurrency + rc = pj_ioqueue_set_default_concurrency(ioque, allow_concur); + if (rc != PJ_SUCCESS) { + app_perror("...error: pj_ioqueue_set_default_concurrency()", rc); + goto on_error; + } + // Allocate inactive sockets, and bind them to some arbitrary address. // Then register them to the I/O queue, and start a read operation. inactive_sock = (pj_sock_t*)pj_pool_alloc(pool, @@ -839,27 +867,29 @@ on_error: return -1; } -int udp_ioqueue_test() +static int udp_ioqueue_test_imp(pj_bool_t allow_concur) { int status; int bufsize, sock_count; + PJ_LOG(3,(THIS_FILE, "..testing with concurency=%d", allow_concur)); + //goto pass1; PJ_LOG(3, (THIS_FILE, "...compliance test (%s)", pj_ioqueue_name())); - if ((status=compliance_test()) != 0) { + if ((status=compliance_test(allow_concur)) != 0) { return status; } PJ_LOG(3, (THIS_FILE, "....compliance test ok")); PJ_LOG(3, (THIS_FILE, "...unregister test (%s)", pj_ioqueue_name())); - if ((status=unregister_test()) != 0) { + if ((status=unregister_test(allow_concur)) != 0) { return status; } PJ_LOG(3, (THIS_FILE, "....unregister test ok")); - if ((status=many_handles_test()) != 0) { + if ((status=many_handles_test(allow_concur)) != 0) { return status; } @@ -879,7 +909,7 @@ int udp_ioqueue_test() //goto pass2; for (bufsize=BUF_MIN_SIZE; bufsize <= BUF_MAX_SIZE; bufsize *= 2) { - if ((status=bench_test(bufsize, SOCK_INACTIVE_MIN)) != 0) + if ((status=bench_test(allow_concur, bufsize, SOCK_INACTIVE_MIN)) != 0) return status; } //pass2: @@ -889,12 +919,27 @@ int udp_ioqueue_test() sock_count *= 2) { //PJ_LOG(3,(THIS_FILE, "...testing with %d fds", sock_count)); - if ((status=bench_test(bufsize, sock_count-2)) != 0) + if ((status=bench_test(allow_concur, bufsize, sock_count-2)) != 0) return status; } return 0; } +int udp_ioqueue_test() +{ + int rc; + + rc = udp_ioqueue_test_imp(PJ_TRUE); + if (rc != 0) + return rc; + + rc = udp_ioqueue_test_imp(PJ_FALSE); + if (rc != 0) + return rc; + + return 0; +} + #else /* To prevent warning about "translation unit is empty" * when this test is disabled. |