From a6806304b998baab07f7da95251032fee6783b70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Fri, 2 Dec 2011 22:40:39 +0000 Subject: [PATCH] Launch server-bones test. --- org.glite.lbjp-common.server-bones/Makefile | 10 +++--- .../examples/cnt_example.c | 6 +++- .../examples/run_test.sh | 37 ++++++++++++++++++++++ .../examples/srv_example.c | 3 +- 4 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 org.glite.lbjp-common.server-bones/examples/run_test.sh diff --git a/org.glite.lbjp-common.server-bones/Makefile b/org.glite.lbjp-common.server-bones/Makefile index 4709fa2..4746115 100644 --- a/org.glite.lbjp-common.server-bones/Makefile +++ b/org.glite.lbjp-common.server-bones/Makefile @@ -70,15 +70,15 @@ ${LTLIB}: ${LOBJS} stage: compile $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes -check: - -echo "No unit tests so far." +check: example + LOG4C_RCPATH=${PREFIX}${sysconfdir}/glite-lb ${top_srcdir}/examples/run_test.sh example: srv_example cnt_example -srv_example: srv_example.o +srv_example: srv_example.o ${LTLIB} ${LINK} -o $@ ${LTLIB} srv_example.o -cnt_example: cnt_example.o +cnt_example: cnt_example.o ${LTLIB} ${LINK} -o $@ cnt_example.o doc: @@ -94,5 +94,5 @@ clean: rm -rvf *.o *.lo .libs lib* srv_example cnt_example rm -rvf log.xml rpmbuild/ RPMS/ tgz/ debian/ -%.o: %.c +%.o %.lo: %.c ${COMPILE} -c $< diff --git a/org.glite.lbjp-common.server-bones/examples/cnt_example.c b/org.glite.lbjp-common.server-bones/examples/cnt_example.c index ae32eb0..c6a4830 100644 --- a/org.glite.lbjp-common.server-bones/examples/cnt_example.c +++ b/org.glite.lbjp-common.server-bones/examples/cnt_example.c @@ -92,6 +92,7 @@ int main(int argc, char **argv) *me; int opt, sock = -1, + fd, n; int repeat = 1; @@ -123,6 +124,7 @@ int main(int argc, char **argv) } n = strlen(msg? msg: DEF_MSG); + fd = fileno(stdout); for (;repeat; repeat--) { if ( writen(sock, msg? msg: DEF_MSG, n) != n ) { @@ -134,12 +136,14 @@ int main(int argc, char **argv) if ( n < 0 ) { perror("read() reply error"); + free(msg); return 1; } - writen(0, buff, n); + writen(fd, buff, n); } close(sock); + free(msg); return 0; } diff --git a/org.glite.lbjp-common.server-bones/examples/run_test.sh b/org.glite.lbjp-common.server-bones/examples/run_test.sh new file mode 100644 index 0000000..d21b8a2 --- /dev/null +++ b/org.glite.lbjp-common.server-bones/examples/run_test.sh @@ -0,0 +1,37 @@ +#! /bin/bash + +./srv_example > /tmp/log.$$ & +SRV_PID=$! +disown $SRV_PID + +sleep 1 + +a=`./cnt_example -p 9999 -m "Applejack +"` +ret1=$? + +b=`./cnt_example -p 9998 -m "Applejack +"` +ret2=$? + +kill -SIGTERM $SRV_PID + +n=`grep 'disconnect handler' /tmp/log.$$ | wc -l` +rm -f /tmp/log.$$ + +if [ $ret1 -ne 0 -o $ret2 -ne 0 ]; then + echo "$0: error launching cnt_example" + exit 1 +fi + +if [ "$a" != "reply: Applejack" -o "$b" != "reply: APPLEJACK" ]; then + echo "$0: error in reply" + exit 2 +fi + +if [ "$n" != "2" ]; then + echo "$0: error running server" + exit 3 +fi + +exit 0 diff --git a/org.glite.lbjp-common.server-bones/examples/srv_example.c b/org.glite.lbjp-common.server-bones/examples/srv_example.c index c54eb85..cd46278 100644 --- a/org.glite.lbjp-common.server-bones/examples/srv_example.c +++ b/org.glite.lbjp-common.server-bones/examples/srv_example.c @@ -73,6 +73,8 @@ int main(void) exit(1); } + setpgid(0, getpid()); + glite_srvbones_set_param(GLITE_SBPARAM_SLAVES_COUNT, 1); glite_srvbones_run(NULL, service_table, sizofa(service_table), 1); @@ -176,7 +178,6 @@ int readln(int fd, char *out, int nbytes) static char *buffer_end = buffer; int n; - dprintf(("reading line\n")); while ( 1 ) { if ( buffer_end - buffer ) { -- 1.8.2.3