summaryrefslogtreecommitdiff
path: root/pjlib/src/pjlib-test
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-08 11:31:55 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-08 11:31:55 +0000
commit382afec4b07358dc2447ac9a098a273175c82543 (patch)
tree3ae0c15ccbe85f97f45a7fb5b74d9923f0e5a5cc /pjlib/src/pjlib-test
parentfdf37ce8250927f2395a375e58fabbe4c646c1fa (diff)
Initial configuration for pjlib-util
git-svn-id: http://svn.pjsip.org/repos/pjproject/main@32 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pjlib-test')
-rw-r--r--pjlib/src/pjlib-test/file.c7
-rw-r--r--pjlib/src/pjlib-test/ioq_perf.c2
-rw-r--r--pjlib/src/pjlib-test/ioq_tcp.c142
-rw-r--r--pjlib/src/pjlib-test/ioq_udp.c72
-rw-r--r--pjlib/src/pjlib-test/test.c4
-rw-r--r--pjlib/src/pjlib-test/test.h3
6 files changed, 114 insertions, 116 deletions
diff --git a/pjlib/src/pjlib-test/file.c b/pjlib/src/pjlib-test/file.c
index aa863506..b3ab6e32 100644
--- a/pjlib/src/pjlib-test/file.c
+++ b/pjlib/src/pjlib-test/file.c
@@ -8,7 +8,8 @@
#define NEWNAME "testfil2.txt"
#define INCLUDE_FILE_TIME_TEST 0
-static char buffer[11] = "Hello world";
+static char buffer[11] = {'H', 'e', 'l', 'l', 'o', ' ',
+ 'W', 'o', 'r', 'l', 'd' };
int file_test(void)
{
@@ -112,7 +113,9 @@ int file_test(void)
read = 1;
status = pj_file_read(fd, &readbuf[size], &read);
if (status != PJ_SUCCESS) {
- app_perror("...file_read() error", status);
+ PJ_LOG(3,("", "...error reading file after %d bytes (error follows)",
+ size));
+ app_perror("...error", status);
return -110;
}
if (read == 0) {
diff --git a/pjlib/src/pjlib-test/ioq_perf.c b/pjlib/src/pjlib-test/ioq_perf.c
index a4ee005c..cfeaab76 100644
--- a/pjlib/src/pjlib-test/ioq_perf.c
+++ b/pjlib/src/pjlib-test/ioq_perf.c
@@ -440,7 +440,7 @@ int ioqueue_perf_test(void)
pj_size_t best_bandwidth;
int best_index = 0;
- PJ_LOG(3,(THIS_FILE, " Benchmarking ioqueue:"));
+ PJ_LOG(3,(THIS_FILE, " Benchmarking %s ioqueue:", pj_ioqueue_name()));
PJ_LOG(3,(THIS_FILE, " ==============================================="));
PJ_LOG(3,(THIS_FILE, " Type Threads Skt.Pairs Avg.Time Bandwidth"));
PJ_LOG(3,(THIS_FILE, " ==============================================="));
diff --git a/pjlib/src/pjlib-test/ioq_tcp.c b/pjlib/src/pjlib-test/ioq_tcp.c
index 14813c79..22827942 100644
--- a/pjlib/src/pjlib-test/ioq_tcp.c
+++ b/pjlib/src/pjlib-test/ioq_tcp.c
@@ -38,37 +38,37 @@ static pj_ssize_t callback_read_size,
static pj_ioqueue_key_t *callback_read_key,
*callback_write_key,
*callback_accept_key,
- *callback_connect_key;
-static pj_ioqueue_op_key_t *callback_read_op,
- *callback_write_op,
+ *callback_connect_key;
+static pj_ioqueue_op_key_t *callback_read_op,
+ *callback_write_op,
*callback_accept_op;
-static void on_ioqueue_read(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_read(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_read)
{
- callback_read_key = key;
+ callback_read_key = key;
callback_read_op = op_key;
callback_read_size = bytes_read;
}
-static void on_ioqueue_write(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_write(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_written)
{
- callback_write_key = key;
+ callback_write_key = key;
callback_write_op = op_key;
callback_write_size = bytes_written;
}
-static void on_ioqueue_accept(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_accept(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_sock_t sock,
int status)
{
PJ_UNUSED_ARG(sock);
- callback_accept_key = key;
+ callback_accept_key = key;
callback_accept_op = op_key;
callback_accept_status = status;
}
@@ -96,31 +96,31 @@ static int send_recv_test(pj_ioqueue_t *ioque,
pj_timestamp *t_elapsed)
{
pj_status_t status;
- pj_ssize_t bytes;
+ pj_ssize_t bytes;
pj_time_val timeout;
pj_timestamp t1, t2;
- int pending_op = 0;
+ int pending_op = 0;
pj_ioqueue_op_key_t read_op, write_op;
- // Start reading on the server side.
+ // Start reading on the server side.
bytes = bufsize;
status = pj_ioqueue_recv(skey, &read_op, recv_buf, &bytes, 0);
- if (status != PJ_SUCCESS && status != PJ_EPENDING) {
+ if (status != PJ_SUCCESS && status != PJ_EPENDING) {
app_perror("...pj_ioqueue_recv error", status);
return -100;
}
-
+
if (status == PJ_EPENDING)
- ++pending_op;
- else {
- /* Does not expect to return error or immediate data. */
- return -115;
+ ++pending_op;
+ else {
+ /* Does not expect to return error or immediate data. */
+ return -115;
}
// Randomize send buffer.
pj_create_random_string((char*)send_buf, bufsize);
- // Starts send on the client side.
+ // Starts send on the client side.
bytes = bufsize;
status = pj_ioqueue_send(ckey, &write_op, send_buf, &bytes, 0);
if (status != PJ_SUCCESS && bytes != PJ_EPENDING) {
@@ -135,12 +135,12 @@ static int send_recv_test(pj_ioqueue_t *ioque,
// Reset indicators
callback_read_size = callback_write_size = 0;
- callback_read_key = callback_write_key = NULL;
+ callback_read_key = callback_write_key = NULL;
callback_read_op = callback_write_op = NULL;
// Poll the queue until we've got completion event in the server side.
status = 0;
- while (pending_op > 0) {
+ while (pending_op > 0) {
timeout.sec = 1; timeout.msec = 0;
status = pj_ioqueue_poll(ioque, &timeout);
if (status > 0) {
@@ -148,32 +148,32 @@ static int send_recv_test(pj_ioqueue_t *ioque,
if (callback_read_size != bufsize)
return -160;
if (callback_read_key != skey)
- return -161;
- if (callback_read_op != &read_op)
+ return -161;
+ if (callback_read_op != &read_op)
return -162;
}
if (callback_write_size) {
if (callback_write_key != ckey)
- return -163;
- if (callback_write_op != &write_op)
+ return -163;
+ if (callback_write_op != &write_op)
return -164;
}
pending_op -= status;
- }
- if (status == 0) {
- PJ_LOG(3,("", "...error: timed out"));
+ }
+ if (status == 0) {
+ PJ_LOG(3,("", "...error: timed out"));
}
if (status < 0) {
return -170;
}
}
-
- // Pending op is zero.
- // Subsequent poll should yield zero too.
- timeout.sec = timeout.msec = 0;
- status = pj_ioqueue_poll(ioque, &timeout);
- if (status != 0)
- return -173;
+
+ // Pending op is zero.
+ // Subsequent poll should yield zero too.
+ timeout.sec = timeout.msec = 0;
+ status = pj_ioqueue_poll(ioque, &timeout);
+ if (status != 0)
+ return -173;
// End time.
pj_get_timestamp(&t2);
@@ -200,7 +200,7 @@ static int compliance_test_0(void)
pj_pool_t *pool = NULL;
char *send_buf, *recv_buf;
pj_ioqueue_t *ioque = NULL;
- pj_ioqueue_key_t *skey, *ckey0, *ckey1;
+ pj_ioqueue_key_t *skey, *ckey0, *ckey1;
pj_ioqueue_op_key_t accept_op;
int bufsize = BUF_MIN_SIZE;
pj_ssize_t status = -1;
@@ -265,7 +265,7 @@ static int compliance_test_0(void)
// Server socket accept()
client_addr_len = sizeof(pj_sockaddr_in);
- status = pj_ioqueue_accept(skey, &accept_op, &csock0,
+ status = pj_ioqueue_accept(skey, &accept_op, &csock0,
&client_addr, &rmt_addr, &client_addr_len);
if (status != PJ_EPENDING) {
app_perror("...ERROR in pj_ioqueue_accept()", rc);
@@ -297,7 +297,7 @@ static int compliance_test_0(void)
callback_read_key = callback_write_key =
callback_accept_key = callback_connect_key = NULL;
- callback_accept_op = callback_read_op = callback_write_op = NULL;
+ callback_accept_op = callback_read_op = callback_write_op = NULL;
while (pending_op) {
pj_time_val timeout = {1, 0};
@@ -310,10 +310,10 @@ static int compliance_test_0(void)
}
if (callback_accept_key != skey) {
status=-42; goto on_error;
- }
- if (callback_accept_op != &accept_op) {
- status=-43; goto on_error;
- }
+ }
+ if (callback_accept_op != &accept_op) {
+ status=-43; goto on_error;
+ }
callback_accept_status = -2;
}
@@ -323,7 +323,7 @@ static int compliance_test_0(void)
}
if (callback_connect_key != ckey1) {
status=-51; goto on_error;
- }
+ }
callback_connect_status = -2;
}
@@ -334,16 +334,16 @@ static int compliance_test_0(void)
}
}
}
-
- // There's no pending operation.
- // When we poll the ioqueue, there must not be events.
- if (pending_op == 0) {
- pj_time_val timeout = {1, 0};
- status = pj_ioqueue_poll(ioque, &timeout);
- if (status != 0) {
- status=-60; goto on_error;
- }
- }
+
+ // There's no pending operation.
+ // When we poll the ioqueue, there must not be events.
+ if (pending_op == 0) {
+ pj_time_val timeout = {1, 0};
+ status = pj_ioqueue_poll(ioque, &timeout);
+ if (status != 0) {
+ status=-60; goto on_error;
+ }
+ }
// Check accepted socket.
if (csock0 == PJ_INVALID_SOCKET) {
@@ -363,7 +363,7 @@ static int compliance_test_0(void)
// Test send and receive.
t_elapsed.u32.lo = 0;
- status = send_recv_test(ioque, ckey0, ckey1, send_buf,
+ status = send_recv_test(ioque, ckey0, ckey1, send_buf,
recv_buf, bufsize, &t_elapsed);
if (status != 0) {
goto on_error;
@@ -468,17 +468,17 @@ static int compliance_test_1(void)
}
}
}
-
- // There's no pending operation.
- // When we poll the ioqueue, there must not be events.
- if (pending_op == 0) {
- pj_time_val timeout = {1, 0};
- status = pj_ioqueue_poll(ioque, &timeout);
- if (status != 0) {
- status=-60; goto on_error;
- }
- }
-
+
+ // There's no pending operation.
+ // When we poll the ioqueue, there must not be events.
+ if (pending_op == 0) {
+ pj_time_val timeout = {1, 0};
+ status = pj_ioqueue_poll(ioque, &timeout);
+ if (status != 0) {
+ status=-60; goto on_error;
+ }
+ }
+
// Success
status = 0;
@@ -495,12 +495,14 @@ int tcp_ioqueue_test()
{
int status;
- PJ_LOG(3, (THIS_FILE, "..compliance test 0 (success scenario)"));
+ PJ_LOG(3, (THIS_FILE, "..%s compliance test 0 (success scenario)",
+ pj_ioqueue_name()));
if ((status=compliance_test_0()) != 0) {
PJ_LOG(1, (THIS_FILE, "....FAILED (status=%d)\n", status));
return status;
}
- PJ_LOG(3, (THIS_FILE, "..compliance test 1 (failed scenario)"));
+ PJ_LOG(3, (THIS_FILE, "..%s compliance test 1 (failed scenario)",
+ pj_ioqueue_name()));
if ((status=compliance_test_1()) != 0) {
PJ_LOG(1, (THIS_FILE, "....FAILED (status=%d)\n", status));
return status;
diff --git a/pjlib/src/pjlib-test/ioq_udp.c b/pjlib/src/pjlib-test/ioq_udp.c
index 6ee90e42..c6a5c5f0 100644
--- a/pjlib/src/pjlib-test/ioq_udp.c
+++ b/pjlib/src/pjlib-test/ioq_udp.c
@@ -42,34 +42,34 @@ static pj_ioqueue_key_t *callback_read_key,
*callback_write_key,
*callback_accept_key,
*callback_connect_key;
-static pj_ioqueue_op_key_t *callback_read_op,
- *callback_write_op,
- *callback_accept_op;
+static pj_ioqueue_op_key_t *callback_read_op,
+ *callback_write_op,
+ *callback_accept_op;
-static void on_ioqueue_read(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_read(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_read)
{
- callback_read_key = key;
+ callback_read_key = key;
callback_read_op = op_key;
callback_read_size = bytes_read;
}
-static void on_ioqueue_write(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_write(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_written)
{
- callback_write_key = key;
+ callback_write_key = key;
callback_write_op = op_key;
callback_write_size = bytes_written;
}
-static void on_ioqueue_accept(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_accept(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_sock_t sock, int status)
{
PJ_UNUSED_ARG(sock);
- callback_accept_key = key;
+ callback_accept_key = key;
callback_accept_op = op_key;
callback_accept_status = status;
}
@@ -107,7 +107,7 @@ static int compliance_test(void)
pj_pool_t *pool = NULL;
char *send_buf, *recv_buf;
pj_ioqueue_t *ioque = NULL;
- pj_ioqueue_key_t *skey, *ckey;
+ pj_ioqueue_key_t *skey, *ckey;
pj_ioqueue_op_key_t read_op, write_op;
int bufsize = BUF_MIN_SIZE;
pj_ssize_t bytes, status = -1;
@@ -183,11 +183,11 @@ static int compliance_test(void)
// Register reading from ioqueue.
TRACE_("start recvfrom...");
- addrlen = sizeof(addr);
+ addrlen = sizeof(addr);
bytes = bufsize;
rc = pj_ioqueue_recvfrom(skey, &read_op, recv_buf, &bytes, 0,
&addr, &addrlen);
- if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
+ if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
app_perror("...error: pj_ioqueue_recvfrom", rc);
status=-28; goto on_error;
} else if (rc == PJ_EPENDING) {
@@ -201,11 +201,11 @@ static int compliance_test(void)
}
// Write must return the number of bytes.
- TRACE_("start sendto...");
+ TRACE_("start sendto...");
bytes = bufsize;
rc = pj_ioqueue_sendto(ckey, &write_op, send_buf, &bytes, 0, &addr,
sizeof(addr));
- if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
+ if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
app_perror("...error: pj_ioqueue_sendto", rc);
status=-30; goto on_error;
} else if (rc == PJ_EPENDING) {
@@ -223,7 +223,7 @@ static int compliance_test(void)
callback_accept_status = callback_connect_status = -2;
callback_read_key = callback_write_key =
callback_accept_key = callback_connect_key = NULL;
- callback_read_op = callback_write_op = NULL;
+ callback_read_op = callback_write_op = NULL;
// Poll if pending.
while (send_pending || recv_pending) {
@@ -247,9 +247,9 @@ static int compliance_test(void)
}
if (callback_read_key != skey) {
status=-65; goto on_error;
- }
- if (callback_read_op != &read_op) {
- status=-66; goto on_error;
+ }
+ if (callback_read_op != &read_op) {
+ status=-66; goto on_error;
}
if (memcmp(send_buf, recv_buf, bufsize) != 0) {
@@ -266,9 +266,9 @@ static int compliance_test(void)
}
if (callback_write_key != ckey) {
status=-75; goto on_error;
- }
- if (callback_write_op != &write_op) {
- status=-76; goto on_error;
+ }
+ if (callback_write_op != &write_op) {
+ status=-76; goto on_error;
}
send_pending = 0;
@@ -386,7 +386,7 @@ static int bench_test(int bufsize, int inactive_sock_count)
pj_sock_t ssock=-1, csock=-1;
pj_sockaddr_in addr;
pj_pool_t *pool = NULL;
- pj_sock_t *inactive_sock=NULL;
+ pj_sock_t *inactive_sock=NULL;
pj_ioqueue_op_key_t *inactive_read_op;
char *send_buf, *recv_buf;
pj_ioqueue_t *ioque = NULL;
@@ -433,13 +433,13 @@ static int bench_test(int bufsize, int inactive_sock_count)
// 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,
- inactive_sock_count*sizeof(pj_sock_t));
- inactive_read_op = (pj_ioqueue_op_key_t*)pj_pool_alloc(pool,
+ inactive_sock_count*sizeof(pj_sock_t));
+ inactive_read_op = (pj_ioqueue_op_key_t*)pj_pool_alloc(pool,
inactive_sock_count*sizeof(pj_ioqueue_op_key_t));
memset(&addr, 0, sizeof(addr));
addr.sin_family = PJ_AF_INET;
- for (i=0; i<inactive_sock_count; ++i) {
- pj_ssize_t bytes;
+ for (i=0; i<inactive_sock_count; ++i) {
+ pj_ssize_t bytes;
rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &inactive_sock[i]);
if (rc != PJ_SUCCESS || inactive_sock[i] < 0) {
@@ -460,7 +460,7 @@ static int bench_test(int bufsize, int inactive_sock_count)
app_perror("...error(1): pj_ioqueue_register_sock()", rc);
PJ_LOG(3,(THIS_FILE, "....i=%d", i));
goto on_error;
- }
+ }
bytes = bufsize;
rc = pj_ioqueue_recv(key, &inactive_read_op[i], recv_buf, &bytes, 0);
if ( rc < 0 && rc != PJ_EPENDING) {
@@ -494,13 +494,13 @@ static int bench_test(int bufsize, int inactive_sock_count)
// Test loop.
t_elapsed.u64 = 0;
for (i=0; i<LOOP; ++i) {
- pj_ssize_t bytes;
+ pj_ssize_t bytes;
pj_ioqueue_op_key_t read_op, write_op;
// Randomize send buffer.
pj_create_random_string(send_buf, bufsize);
- // Start reading on the server side.
+ // Start reading on the server side.
bytes = bufsize;
rc = pj_ioqueue_recv(skey, &read_op, recv_buf, &bytes, 0);
if (rc < 0 && rc != PJ_EPENDING) {
@@ -508,7 +508,7 @@ static int bench_test(int bufsize, int inactive_sock_count)
break;
}
- // Starts send on the client side.
+ // Starts send on the client side.
bytes = bufsize;
rc = pj_ioqueue_sendto(ckey, &write_op, send_buf, &bytes, 0,
&addr, sizeof(addr));
@@ -587,7 +587,7 @@ on_error:
pj_sock_close(csock);
for (i=0; i<inactive_sock_count && inactive_sock &&
inactive_sock[i]!=PJ_INVALID_SOCKET; ++i)
- {
+ {
pj_sock_close(inactive_sock[i]);
}
if (ioque != NULL)
@@ -601,7 +601,7 @@ int udp_ioqueue_test()
int status;
int bufsize, sock_count;
- PJ_LOG(3, (THIS_FILE, "...compliance test"));
+ PJ_LOG(3, (THIS_FILE, "...compliance test (%s)", pj_ioqueue_name()));
if ((status=compliance_test()) != 0) {
return status;
}
@@ -615,7 +615,7 @@ int udp_ioqueue_test()
PJ_LOG(4, (THIS_FILE, "... note: buf=bytes sent, fds=# of fds, "
"elapsed=in timer ticks"));
- PJ_LOG(3, (THIS_FILE, "...Benchmarking poll times:"));
+ PJ_LOG(3, (THIS_FILE, "...Benchmarking poll times for %s:", pj_ioqueue_name()));
PJ_LOG(3, (THIS_FILE, "...====================================="));
PJ_LOG(3, (THIS_FILE, "...Buf.size #inactive-socks Time/poll"));
PJ_LOG(3, (THIS_FILE, "... (bytes) (nanosec)"));
diff --git a/pjlib/src/pjlib-test/test.c b/pjlib/src/pjlib-test/test.c
index 52ed0617..c9349a21 100644
--- a/pjlib/src/pjlib-test/test.c
+++ b/pjlib/src/pjlib-test/test.c
@@ -132,10 +132,6 @@ int test_inner(void)
DO_TEST( file_test() );
#endif
-#if INCLUDE_XML_TEST
- DO_TEST( xml_test() );
-#endif
-
#if INCLUDE_ECHO_SERVER
//echo_server();
//echo_srv_sync();
diff --git a/pjlib/src/pjlib-test/test.h b/pjlib/src/pjlib-test/test.h
index cf78f4f4..17592908 100644
--- a/pjlib/src/pjlib-test/test.h
+++ b/pjlib/src/pjlib-test/test.h
@@ -10,7 +10,6 @@
#define GROUP_DATA_STRUCTURE 1
#define GROUP_NETWORK 1
#define GROUP_FILE 1
-#define GROUP_EXTRA 0
#define INCLUDE_ERRNO_TEST GROUP_LIBC
#define INCLUDE_TIMESTAMP_TEST GROUP_OS
@@ -34,7 +33,6 @@
#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_CLIENT 0
@@ -71,7 +69,6 @@ extern int udp_ioqueue_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);