From 1ba95671005521f5d9bf2939612ee3f1e3d2b1c9 Mon Sep 17 00:00:00 2001 From: Gabor Adam Toth Date: Sun, 15 May 2011 11:51:30 +0200 Subject: [PATCH] test: stats option for files too --- test/test.c | 10 ++++++++++ test/testPsyc.c | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/test/test.c b/test/test.c index b2dbadf..1dabfdc 100644 --- a/test/test.c +++ b/test/test.c @@ -38,6 +38,7 @@ void test_file(const char* filename, size_t recv_buf_size) { char buf[CONT_BUF_SIZE + RECV_BUF_SIZE]; // cont buf + recv buf: [ ccrrrr] char *recvbuf = buf + CONT_BUF_SIZE; // recv buf: ^^^^ size_t nbytes; + struct timeval start, end; int fd = open(filename, O_RDONLY); if (fd < 0) { @@ -45,10 +46,19 @@ void test_file(const char* filename, size_t recv_buf_size) { exit(1); } + test_init(0); + if (stats) + gettimeofday(&start, NULL); + while ((nbytes = read(fd, (void*)recvbuf, recv_buf_size))) test_input(0, recvbuf, nbytes); + + if (stats) { + gettimeofday(&end, NULL); + printf("%ld ms\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec) / 1000); + } } void test_server(const char* port, size_t recv_buf_size) { diff --git a/test/testPsyc.c b/test/testPsyc.c index 9a3c868..c3905ba 100644 --- a/test/testPsyc.c +++ b/test/testPsyc.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,7 @@ // cmd line args uint8_t verbose, stats; -uint8_t routing_only, parse_multiple, no_render, progress; +uint8_t routing_only, parse_multiple, no_render, quiet, progress; char *filename, *port = "4440"; size_t recv_buf_size = RECV_BUF_SIZE; @@ -32,7 +33,7 @@ int contbytes, last_ret; int main (int argc, char **argv) { int c; - while ((c = getopt (argc, argv, "f:p:b:mnrsvP")) != -1) { + while ((c = getopt (argc, argv, "f:p:b:mnqrsvP")) != -1) { switch (c) { case 'f': filename = optarg; break; case 'p': port = optarg; @@ -43,6 +44,7 @@ int main (int argc, char **argv) { break; case 'm': parse_multiple = 1; break; case 'n': no_render = 1; break; + case 'q': quiet = 1; break; case 'r': routing_only = 1; break; case 's': stats = 1; break; case 'v': verbose++; break; @@ -160,12 +162,14 @@ int test_input (int i, char *recvbuf, size_t nbytes) { psyc_setPacketLength(&packets[i]); if (psyc_render(&packets[i], sendbuf, SEND_BUF_SIZE) == PSYC_RENDER_SUCCESS) { - if (filename && write(1, sendbuf, packets[i].length) == -1) { - perror("write"); - ret = -1; - } else if (!filename && send(i, sendbuf, packets[i].length, 0) == -1) { - perror("send"); - ret = -1; + if (!quiet) { + if (filename && write(1, sendbuf, packets[i].length) == -1) { + perror("write"); + ret = -1; + } else if (!filename && send(i, sendbuf, packets[i].length, 0) == -1) { + perror("send"); + ret = -1; + } } } else { printf("# Render error");