mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
test: getopt
This commit is contained in:
parent
a4b1dca3be
commit
4b9fba98d4
2 changed files with 34 additions and 24 deletions
|
@ -39,8 +39,8 @@ test: ${TARGETS}
|
||||||
./testText
|
./testText
|
||||||
./isRoutingVar
|
./isRoutingVar
|
||||||
./getVarType
|
./getVarType
|
||||||
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 -f $$f | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
|
||||||
x=0; for f in packets/[0-9]*; do echo ">> $$f"; ./testPsyc $$f -fr | ${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
|
||||||
|
|
||||||
.NOTPARALLEL: nettestrun
|
.NOTPARALLEL: nettestrun
|
||||||
|
|
||||||
|
@ -50,11 +50,11 @@ nettestrun: srvstart pkt srvkill
|
||||||
|
|
||||||
nettestfull:
|
nettestfull:
|
||||||
${MAKE} nettestrun; x=$$?; pkill -x testPsyc; exit $$x
|
${MAKE} nettestrun; x=$$?; pkill -x testPsyc; exit $$x
|
||||||
${MAKE} nettestrun srv_args=r; x=$$?; pkill -x testPsyc; exit $$x
|
${MAKE} nettestrun srv_args=-r; x=$$?; pkill -x testPsyc; exit $$x
|
||||||
|
|
||||||
split_max = 10
|
split_max = 10
|
||||||
nettestsplit:
|
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 testPsyc; exit $$x
|
x=0; for n in `seq 1 ${split_max}`; do ${MAKE} nettestrun srv_args="-b $$n" && ${MAKE} nettestrun srv_args="-r -b $$n" || break; done; x=$$?; pkill -x testPsyc; exit $$x
|
||||||
|
|
||||||
pkt:
|
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
|
x=0; for f in packets/[0-9]*; do echo ">> $$f"; cat $$f | nc localhost ${PORT} | ${DIFF} -u $$f -; x=$$((x+$$?)); done; exit $$x
|
||||||
|
@ -67,7 +67,7 @@ pkterr:
|
||||||
|
|
||||||
srvstart:
|
srvstart:
|
||||||
pkill -x testPsyc; exit 0
|
pkill -x testPsyc; exit 0
|
||||||
./testPsyc ${PORT} -${srv_args} ${srv_recvbuf} &
|
./testPsyc -p ${PORT} ${srv_args} &
|
||||||
|
|
||||||
srvkill:
|
srvkill:
|
||||||
pkill -x testPsyc
|
pkill -x testPsyc
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include <psyc.h>
|
#include <psyc.h>
|
||||||
|
@ -16,8 +18,10 @@
|
||||||
#define ENTITY_LINES 32
|
#define ENTITY_LINES 32
|
||||||
|
|
||||||
// cmd line args
|
// cmd line args
|
||||||
uint8_t verbose, stats, file;
|
uint8_t verbose, stats;
|
||||||
uint8_t routing_only, parse_multiple, no_render, progress;
|
uint8_t routing_only, parse_multiple, no_render, progress;
|
||||||
|
char *filename, *port = "4440";
|
||||||
|
size_t recv_buf_size = RECV_BUF_SIZE;
|
||||||
|
|
||||||
psycParseState parsers[NUM_PARSERS];
|
psycParseState parsers[NUM_PARSERS];
|
||||||
psycPacket packets[NUM_PARSERS];
|
psycPacket packets[NUM_PARSERS];
|
||||||
|
@ -27,23 +31,29 @@ psycModifier entity[NUM_PARSERS][ENTITY_LINES];
|
||||||
int contbytes = 0, last_ret = 0;
|
int contbytes = 0, last_ret = 0;
|
||||||
|
|
||||||
int main (int argc, char **argv) {
|
int main (int argc, char **argv) {
|
||||||
char *port = argc > 1 ? argv[1] : "4440";
|
int c;
|
||||||
char *opts = argc > 2 ? argv[2] : NULL;
|
while ((c = getopt (argc, argv, "f:p:b:mnrsvP")) != -1) {
|
||||||
char *v, *w;
|
switch (c) {
|
||||||
verbose = opts && (v = memchr(opts, (int)'v', strlen(opts))) ?
|
case 'f': filename = optarg; break;
|
||||||
v - opts > 0 && (w = memchr(v+1, (int)'v', strlen(opts) - (v - opts))) ?
|
case 'p': port = optarg;
|
||||||
w - v > 0 && memchr(w+1, (int)'v', strlen(opts) - (w - opts)) ? 3 : 2 : 1 : 0;
|
if (atoi(optarg) <= 0) { printf("-p: error, should be > 0\n"); exit(-1); }
|
||||||
stats = opts && memchr(opts, (int)'s', strlen(opts));
|
break;
|
||||||
|
case 'b': recv_buf_size = atoi(optarg);
|
||||||
|
if (atoi(optarg) <= 0) { printf("-b: error, should be > 0\n"); exit(-1); }
|
||||||
|
break;
|
||||||
|
case 'm': parse_multiple = 1; break;
|
||||||
|
case 'n': no_render = 1; break;
|
||||||
|
case 'r': routing_only = 1; break;
|
||||||
|
case 's': stats = 1; break;
|
||||||
|
case 'v': verbose++; break;
|
||||||
|
case 'P': progress = 1; break;
|
||||||
|
case '?': exit(-1);
|
||||||
|
default: abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
routing_only = opts && memchr(opts, (int)'r', strlen(opts));
|
if (filename)
|
||||||
parse_multiple = opts && memchr(opts, (int)'m', strlen(opts));
|
test_file(filename, recv_buf_size);
|
||||||
no_render = opts && memchr(opts, (int)'n', strlen(opts));
|
|
||||||
progress = opts && memchr(opts, (int)'p', strlen(opts));
|
|
||||||
file = opts && memchr(opts, (int)'f', strlen(opts));
|
|
||||||
size_t recv_buf_size = argc > 3 ? atoi(argv[3]) : RECV_BUF_SIZE;
|
|
||||||
|
|
||||||
if (file)
|
|
||||||
test_file(argv[1], recv_buf_size);
|
|
||||||
else
|
else
|
||||||
test_server(port, recv_buf_size);
|
test_server(port, recv_buf_size);
|
||||||
|
|
||||||
|
@ -150,10 +160,10 @@ int test_input (int i, char *recvbuf, size_t nbytes) {
|
||||||
psyc_setPacketLength(&packets[i]);
|
psyc_setPacketLength(&packets[i]);
|
||||||
|
|
||||||
if (psyc_render(&packets[i], sendbuf, SEND_BUF_SIZE) == PSYC_RENDER_SUCCESS) {
|
if (psyc_render(&packets[i], sendbuf, SEND_BUF_SIZE) == PSYC_RENDER_SUCCESS) {
|
||||||
if (file && write(1, sendbuf, packets[i].length) == -1) {
|
if (filename && write(1, sendbuf, packets[i].length) == -1) {
|
||||||
perror("write");
|
perror("write");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
} else if (!file && send(i, sendbuf, packets[i].length, 0) == -1) {
|
} else if (!filename && send(i, sendbuf, packets[i].length, 0) == -1) {
|
||||||
perror("send");
|
perror("send");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue