mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
test: support for large files; make bench
This commit is contained in:
parent
909a908107
commit
e04c15efc0
10 changed files with 118 additions and 72 deletions
3
Makefile
3
Makefile
|
@ -30,6 +30,9 @@ testdebug: debug
|
|||
test: all
|
||||
${MAKE} -C test test nettest
|
||||
|
||||
bench: all
|
||||
${MAKE} -C test bench
|
||||
|
||||
doc:
|
||||
doxygen
|
||||
|
||||
|
|
1
bench/.gitignore
vendored
1
bench/.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
*.html
|
||||
*.pdf
|
||||
results/
|
||||
|
|
|
@ -2,6 +2,7 @@ OPT = -O2
|
|||
DEBUG = 2
|
||||
CFLAGS_COMMON = -Wall -std=c99 ${OPT}
|
||||
CFLAGS = -I../include -I../src ${CFLAGS_COMMON}
|
||||
CFLAGS_TEST = -Wall ${OPT}
|
||||
LDFLAGS = -L../lib
|
||||
LOADLIBES = -lpsyc -lm
|
||||
TARGETS = testPsyc testPsycSpeed testParser testMatch testRender testText isRoutingVar getVarType
|
||||
|
@ -11,6 +12,7 @@ DIET = diet
|
|||
PORT = 4440
|
||||
NC = nc
|
||||
DIFF = diff
|
||||
TEE = tee
|
||||
|
||||
ifeq ($(shell uname),SunOS)
|
||||
LOADLIBES_NET := -lsocket -lnsl
|
||||
|
@ -20,7 +22,9 @@ endif
|
|||
all: ${TARGETS}
|
||||
it: all
|
||||
|
||||
testPsyc: CFLAGS := ${CFLAGS_TEST}
|
||||
testPsyc: LOADLIBES := ${LOADLIBES} ${LOADLIBES_NET}
|
||||
testPsycSpeed: CFLAGS := ${CFLAGS_TEST}
|
||||
testPsycSpeed: LOADLIBES := ${LOADLIBES} ${LOADLIBES_NET}
|
||||
#testPsycSpeed: LOADLIBES := ${LOADLIBES_NET}
|
||||
|
||||
|
@ -50,6 +54,23 @@ test: ${TARGETS}
|
|||
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testPsyc -f $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
|
||||
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testPsyc -rf $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
|
||||
|
||||
bench: bench-psyc bench-json bench-xml
|
||||
|
||||
bench-dir:
|
||||
@mkdir -p ../bench/results
|
||||
|
||||
bench-psyc: bench-dir testStrlen testPsycSpeed
|
||||
for f in ../bench/packets/*.psyc; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done
|
||||
for f in ../bench/packets/*.psyc; do bf=`basename $$f`; echo libpsyc: $$f; ./testPsycSpeed -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf; done
|
||||
|
||||
bench-json: bench-dir testStrlen testJson testJsonGlib
|
||||
for f in ../bench/packets/*.json; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done
|
||||
for f in ../bench/packets/*.json; do bf=`basename $$f`; echo json-c: $$bf; ./testJson -snc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf; done
|
||||
for f in ../bench/packets/*.json; do bf=`basename $$f`; echo json-glib: $$bf; ./testJsonGlib -snc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf-glib; done
|
||||
|
||||
bench-xml: bench-dir testStrlen
|
||||
for f in ../bench/packets/*.xml; do bf=`basename $$f`; echo strlen: $$bf; ./testStrlen -sc 1000000 -f $$f | ${TEE} -a ../bench/results/$$bf.strlen; done
|
||||
|
||||
.NOTPARALLEL: nettestrun
|
||||
|
||||
nettest: nettestfull nettestsplit
|
||||
|
|
33
test/test.c
33
test/test.c
|
@ -18,6 +18,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
@ -50,10 +51,10 @@ void *get_in_addr (struct sockaddr *sa) {
|
|||
}
|
||||
|
||||
void test_file(const char* filename, size_t count, 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: ^^^^
|
||||
char *buf, *recvbuf; // cont buf + recv buf: [ ccrrrr]
|
||||
size_t i, nbytes;
|
||||
struct timeval start, end;
|
||||
struct stat st;
|
||||
|
||||
int fd = open(filename, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
|
@ -61,18 +62,38 @@ void test_file(const char* filename, size_t count, size_t recv_buf_size) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
fstat(fd, &st);
|
||||
|
||||
buf = malloc(CONT_BUF_SIZE + st.st_size);
|
||||
if (!buf) {
|
||||
perror("malloc");
|
||||
exit(1);
|
||||
}
|
||||
recvbuf = buf + CONT_BUF_SIZE;
|
||||
|
||||
test_init(0);
|
||||
|
||||
if (stats)
|
||||
gettimeofday(&start, NULL);
|
||||
if (recv_buf_size) {
|
||||
if (stats)
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
while ((nbytes = read(fd, (void*)recvbuf, recv_buf_size)))
|
||||
test_input(0, recvbuf, nbytes);
|
||||
|
||||
} else {
|
||||
nbytes = read(fd, (void*)recvbuf, RECV_BUF_SIZE);
|
||||
|
||||
if (stats)
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
while ((nbytes = read(fd, (void*)recvbuf, recv_buf_size)))
|
||||
for (i = 0; i < count; i++)
|
||||
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);
|
||||
printf("%ld\n", (end.tv_sec * 1000000 + end.tv_usec - start.tv_sec * 1000000 - start.tv_usec) / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#define CASE_f case 'f': filename = optarg; break;
|
||||
#define CASE_p case 'p': port = optarg; check_range(c, optarg, 1, 0); break;
|
||||
#define CASE_b case 'b': recv_buf_size = atoi(optarg); check_range(c, optarg, 1, RECV_BUF_SIZE); break;
|
||||
#define CASE_b case 'b': recv_buf_size = atoi(optarg); check_range(c, optarg, 1, 0); break;
|
||||
#define CASE_c case 'c': count = atoi(optarg); check_range(c, optarg, 1, 0); break;
|
||||
#define CASE_n case 'n': no_render = 1; break;
|
||||
#define CASE_m case 'm': multiple = 1; break;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
char *filename, *port = "4441";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t multiple, single, no_render, quiet, progress;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
size_t count = 1, recv_buf_size;
|
||||
|
||||
int exit_code;
|
||||
|
||||
|
@ -26,36 +26,6 @@ json_object *obj;
|
|||
json_tokener *tok;
|
||||
enum json_tokener_error error;
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:mnqsvPSh")) != -1) {
|
||||
switch (c) {
|
||||
CASE_f CASE_p CASE_b CASE_c
|
||||
CASE_m CASE_n CASE_q CASE_s
|
||||
CASE_v CASE_S CASE_P
|
||||
case 'h':
|
||||
printf(
|
||||
HELP_FILE("testJson", "mnqSsvP")
|
||||
HELP_PORT("testJson", "nqsvP")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_m HELP_n HELP_q HELP_S
|
||||
HELP_s HELP_v HELP_P HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
void test_init (int i) {
|
||||
tok = json_tokener_new();
|
||||
}
|
||||
|
@ -111,3 +81,33 @@ int test_input (int i, char *recvbuf, size_t nbytes) {
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:mnqsvPSh")) != -1) {
|
||||
switch (c) {
|
||||
CASE_f CASE_p CASE_b CASE_c
|
||||
CASE_m CASE_n CASE_q CASE_s
|
||||
CASE_v CASE_S CASE_P
|
||||
case 'h':
|
||||
printf(
|
||||
HELP_FILE("testJson", "mnqSsvP")
|
||||
HELP_PORT("testJson", "nqsvP")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_m HELP_n HELP_q HELP_S
|
||||
HELP_s HELP_v HELP_P HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
|
|
@ -17,43 +17,13 @@
|
|||
char *filename, *port = "4442";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t no_render, quiet, progress;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
size_t count = 1, recv_buf_size;
|
||||
|
||||
int exit_code;
|
||||
|
||||
JsonParser *parser;
|
||||
JsonGenerator *generator;
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:nqsvPh")) != -1) {
|
||||
switch (c) {
|
||||
CASE_f CASE_p CASE_b
|
||||
CASE_c CASE_n CASE_q
|
||||
CASE_s CASE_v CASE_P
|
||||
case 'h':
|
||||
printf(
|
||||
HELP_FILE("testJsonGlib", "mnqSsvP")
|
||||
HELP_PORT("testJsonGlib", "nqsvP")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_m HELP_n HELP_q HELP_S
|
||||
HELP_s HELP_v HELP_P HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
void test_init (int i) {
|
||||
g_type_init();
|
||||
parser = json_parser_new();
|
||||
|
@ -98,3 +68,33 @@ int test_input (int i, char *recvbuf, size_t nbytes) {
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
while ((c = getopt (argc, argv, "f:p:b:c:nqsvPh")) != -1) {
|
||||
switch (c) {
|
||||
CASE_f CASE_p CASE_b
|
||||
CASE_c CASE_n CASE_q
|
||||
CASE_s CASE_v CASE_P
|
||||
case 'h':
|
||||
printf(
|
||||
HELP_FILE("testJsonGlib", "mnqSsvP")
|
||||
HELP_PORT("testJsonGlib", "nqsvP")
|
||||
HELP_f HELP_p HELP_b HELP_c
|
||||
HELP_m HELP_n HELP_q HELP_S
|
||||
HELP_s HELP_v HELP_P HELP_h,
|
||||
port, RECV_BUF_SIZE);
|
||||
exit(0);
|
||||
case '?': exit(-1);
|
||||
default: abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (filename)
|
||||
test_file(filename, count, recv_buf_size);
|
||||
else
|
||||
test_server(port, count, recv_buf_size);
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
char *filename, *port = "4440";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t multiple, single, routing_only, no_render, quiet, progress;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
size_t count = 1, recv_buf_size;
|
||||
|
||||
psycParseState parsers[NUM_PARSERS];
|
||||
psycPacket packets[NUM_PARSERS];
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
char *filename, *port = "4440";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t routing_only;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
size_t count = 1, recv_buf_size;
|
||||
|
||||
psycParseState parser;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
char *filename, *port = "4443";
|
||||
uint8_t verbose, stats;
|
||||
uint8_t no_render, quiet, progress;
|
||||
size_t count = 1, recv_buf_size = RECV_BUF_SIZE;
|
||||
size_t count = 1, recv_buf_size;
|
||||
|
||||
int exit_code;
|
||||
|
||||
|
|
Loading…
Reference in a new issue