1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

testServer modularizing

This commit is contained in:
tg(x) 2011-05-14 18:21:00 +02:00
parent d950bafa84
commit 3c9d7438a8
5 changed files with 58 additions and 44 deletions

2
.gitignore vendored
View file

@ -9,7 +9,7 @@ src/match
test/testMatch
test/testParser
test/testRender
test/testServer
test/testServerPsyc
test/testText
test/isRoutingVar
test/getVarType

View file

@ -4,7 +4,8 @@ CFLAGS = -I../include -I../src -Wall -std=c99 ${OPT}
LDFLAGS = -L../lib
LOADLIBES = -lpsyc -lm
LOADLIBES_NET = ${LOADLIBES}
TARGETS = testServer testParser testMatch testRender testText isRoutingVar getVarType
TARGETS = testServerPsyc testParser testMatch testRender testText isRoutingVar getVarType
O = testServer.o
WRAPPER =
DIET = diet
PORT = 4440
@ -19,7 +20,8 @@ endif
all: ${TARGETS}
it: all
testServer: LOADLIBES := ${LOADLIBES_NET}
testServerPsyc: LOADLIBES := ${LOADLIBES_NET}
testServerPsyc: testServer.o
diet: WRAPPER = ${DIET}
diet: all
@ -29,7 +31,7 @@ debug: CFLAGS := $(subst ${OPT},-O0,${CFLAGS})
debug: all
clean:
rm -f ${TARGETS}
rm -f ${TARGETS} $O
test: ${TARGETS}
./testRender
@ -47,12 +49,12 @@ nettest: nettestfull nettestsplit
nettestrun: srvstart pkt srvkill
nettestfull:
${MAKE} nettestrun; x=$$?; pkill -x testServer; exit $$x
${MAKE} nettestrun srv_args=r; x=$$?; pkill -x testServer; exit $$x
${MAKE} nettestrun; x=$$?; pkill -x testServerPsyc; exit $$x
${MAKE} nettestrun srv_args=r; x=$$?; pkill -x testServerPsyc; exit $$x
split_max = 10
nettestsplit:
x=0; for n in `seq 1 ${split_max}`; do ${MAKE} nettestrun srv_recvbuf=$$n && ${MAKE} nettestrun srv_args=r srv_recvbuf=$$n || break; done; x=$$?; pkill -x testServer; exit $$x
x=0; for n in `seq 1 ${split_max}`; do ${MAKE} nettestrun srv_recvbuf=$$n && ${MAKE} nettestrun srv_args=r srv_recvbuf=$$n || break; done; x=$$?; pkill -x testServerPsyc; exit $$x
pkt:
x=0; for f in packets/[0-9]*; do echo ">> $$f"; cat $$f | nc localhost ${PORT} | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
@ -64,8 +66,8 @@ pkterr:
for f in packets/err-*; do echo ">> $$f"; cat $$f | nc localhost ${PORT}; done
srvstart:
pkill -x testServer; exit 0
./testServer ${PORT} -${srv_args} ${srv_recvbuf} &
pkill -x testServerPsyc; exit 0
./testServerPsyc ${PORT} -${srv_args} ${srv_recvbuf} &
srvkill:
pkill -x testServer
pkill -x testServerPsyc

View file

@ -19,7 +19,9 @@
#include <netdb.h>
#include "testServer.h"
#include "testServerPsyc.c"
// cmd line args
extern uint8_t verbose, stats;
// get sockaddr, IPv4 or IPv6:
void *get_in_addr (struct sockaddr *sa) {
@ -29,21 +31,9 @@ void *get_in_addr (struct sockaddr *sa) {
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
int main (int argc, char **argv) {
char *port = argc > 1 ? argv[1] : "4440";
char *opts = argc > 2 ? argv[2] : NULL;
char *v, *w;
verbose = opts && (v = memchr(opts, (int)'v', strlen(opts))) ?
v - opts > 0 && (w = memchr(v+1, (int)'v', strlen(opts) - (v - opts))) ?
w - v > 0 && memchr(w+1, (int)'v', strlen(opts) - (w - opts)) ? 3 : 2 : 1 : 0;
routing_only = opts && memchr(opts, (int)'r', strlen(opts));
parse_multiple = opts && memchr(opts, (int)'m', strlen(opts));
no_render = opts && memchr(opts, (int)'n', strlen(opts));
progress = opts && memchr(opts, (int)'p', strlen(opts));
stats = opts && memchr(opts, (int)'s', strlen(opts));
size_t recv_buf_size = argc > 3 ? atoi(argv[3]) : 0;
if (recv_buf_size <= 0)
recv_buf_size = RECV_BUF_SIZE;
void test_server(const char* port, 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: ^^^^
fd_set master; // master file descriptor list
fd_set read_fds; // temp file descriptor list for select()
@ -53,6 +43,7 @@ int main (int argc, char **argv) {
int newfd; // newly accept()ed socket descriptor
struct sockaddr_storage remoteaddr; // client address
socklen_t addrlen;
size_t nbytes;
char remoteIP[INET6_ADDRSTRLEN];
@ -62,6 +53,9 @@ int main (int argc, char **argv) {
struct addrinfo hints, *ai, *p;
struct timeval start[NUM_PARSERS], end[NUM_PARSERS];
if (recv_buf_size <= 0)
recv_buf_size = RECV_BUF_SIZE;
FD_ZERO(&master); // clear the master and temp sets
FD_ZERO(&read_fds);
@ -169,10 +163,7 @@ int main (int argc, char **argv) {
if (verbose >= 3)
printf("> [%.*s]", (int)nbytes, recvbuf);
ret = test_input(i);
if (progress)
write(1, " ", 1);
ret = test_input(i, recvbuf, nbytes);
if (stats)
gettimeofday(&end[i], NULL);
@ -188,6 +179,4 @@ int main (int argc, char **argv) {
} // END got new incoming connection
} // END looping through file descriptors
} // END for(;;)--and you thought it would never end!
return 0;
}

View file

@ -6,16 +6,8 @@
# define SEND_BUF_SIZE 8 * 1024
# define NUM_PARSERS 100
char sendbuf[SEND_BUF_SIZE];
char buf[CONT_BUF_SIZE + RECV_BUF_SIZE]; // cont buf + recv buf: [ ccrrrr]
char *recvbuf = buf + CONT_BUF_SIZE; // recv buf: ^^^^
// parse buf: ^^^^^^
// cmd line args
uint8_t verbose, routing_only, parse_multiple, no_render, progress, stats;
size_t nbytes;
void test_init(int i);
int test_input(int i);
int test_input(int i, char *recvbuf, size_t nbytes);
void test_server(const char* port, size_t recv_buf_size);
#endif

View file

@ -10,17 +10,23 @@
#include <psyc/syntax.h>
#include "testServer.h"
//#include "testServer.c"
// max size for routing & entity header
#define ROUTING_LINES 16
#define ENTITY_LINES 32
// cmd line args
uint8_t verbose, stats;
psycParseState parsers[NUM_PARSERS];
psycPacket packets[NUM_PARSERS];
psycModifier routing[NUM_PARSERS][ROUTING_LINES];
psycModifier entity[NUM_PARSERS][ENTITY_LINES];
psycModifier *mod = NULL;
uint8_t routing_only, parse_multiple, no_render, progress;
int ret, retl, contbytes = 0;
char oper;
psycString name, value, elem;
@ -28,6 +34,25 @@ psycString *pname = NULL, *pvalue = NULL;
psycParseListState listState;
size_t len;
int main (int argc, char **argv) {
char *port = argc > 1 ? argv[1] : "4440";
char *opts = argc > 2 ? argv[2] : NULL;
char *v, *w;
verbose = opts && (v = memchr(opts, (int)'v', strlen(opts))) ?
v - opts > 0 && (w = memchr(v+1, (int)'v', strlen(opts) - (v - opts))) ?
w - v > 0 && memchr(w+1, (int)'v', strlen(opts) - (w - opts)) ? 3 : 2 : 1 : 0;
stats = opts && memchr(opts, (int)'s', strlen(opts));
routing_only = opts && memchr(opts, (int)'r', strlen(opts));
parse_multiple = opts && memchr(opts, (int)'m', strlen(opts));
no_render = opts && memchr(opts, (int)'n', strlen(opts));
progress = opts && memchr(opts, (int)'p', strlen(opts));
size_t recv_buf_size = argc > 3 ? atoi(argv[3]) : 0;
test_server(port, recv_buf_size);
return 0;
}
static inline
void resetString (psycString *s, uint8_t freeptr) {
if (freeptr && s->length)
@ -51,10 +76,12 @@ void test_init (int i) {
packets[i].entity.modifiers = entity[i];
}
int test_input (int i) {
int test_input (int i, char *recvbuf, size_t nbytes) {
// we got some data from a client
int j;
char *parsebuf = recvbuf - contbytes;
char sendbuf[SEND_BUF_SIZE];
psyc_setParseBuffer2(&parsers[i], parsebuf, contbytes + nbytes);
contbytes = 0;
oper = 0;
@ -164,7 +191,7 @@ int test_input (int i) {
contbytes = psyc_getParseRemainingLength(&parsers[i]);
if (contbytes > 0) { // copy end of parsebuf before start of recvbuf
assert(recvbuf - contbytes >= buf); // make sure it's still in the buffer
assert(contbytes <= CONT_BUF_SIZE); // make sure it's still in the buffer
memmove(recvbuf - contbytes, psyc_getParseRemainingBuffer(&parsers[i]), contbytes);
}
ret = 0;
@ -271,5 +298,9 @@ int test_input (int i) {
}
}
while (ret > 0);
if (progress)
write(1, " ", 1);
return ret;
}