From 5625dbd1b6cddb8b84d8a3d8c60f95eaaa49be66 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 7 Oct 2009 18:40:30 +0200 Subject: bugfix and testbench improvements - bugfix: solved potential (temporary) stall of messages when the queue was almost empty and few new data added (caused testbench to sometimes hang!) - fixed some race condition in testbench - added more elaborate diagnostics to parts of the testbench - solved a potential race inside the queue engine --- tests/arrayqueue.sh | 3 +++ tests/da-mainmsg-q.sh | 2 +- tests/daqueue-persist-drvr.sh | 1 + tests/diag.sh | 1 + tests/linkedlistqueue.sh | 3 +++ tests/nettester.c | 28 ++++++++++++++++++++++++++++ 6 files changed, 37 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/arrayqueue.sh b/tests/arrayqueue.sh index 01fc133b..58fd24ae 100755 --- a/tests/arrayqueue.sh +++ b/tests/arrayqueue.sh @@ -10,5 +10,8 @@ source $srcdir/diag.sh injectmsg 0 40000 # terminate *now* (don't wait for queue to drain!) kill `cat rsyslog.pid` + +# now wait until rsyslog.pid is gone (and the process finished) +source $srcdir/diag.sh wait-shutdown source $srcdir/diag.sh seq-check 0 39999 source $srcdir/diag.sh exit diff --git a/tests/da-mainmsg-q.sh b/tests/da-mainmsg-q.sh index 6ec2f3a9..d502fca3 100755 --- a/tests/da-mainmsg-q.sh +++ b/tests/da-mainmsg-q.sh @@ -7,7 +7,7 @@ # check everything recovers from DA mode correctly. # added 2009-04-22 by Rgerhards # This file is part of the rsyslog project, released under GPLv3 -echo "testing main message queue in DA mode (going to disk)" +echo "[da-mainmsg-q.sh]: testing main message queue in DA mode (going to disk)" source $srcdir/diag.sh init source $srcdir/diag.sh startup da-mainmsg-q.conf diff --git a/tests/daqueue-persist-drvr.sh b/tests/daqueue-persist-drvr.sh index 7b6ec6dd..d95991fc 100755 --- a/tests/daqueue-persist-drvr.sh +++ b/tests/daqueue-persist-drvr.sh @@ -26,5 +26,6 @@ source $srcdir/diag.sh check-mainq-spool echo "#" > work-delay.conf source $srcdir/diag.sh startup queue-persist.conf source $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages +$srcdir/diag.sh wait-shutdown source $srcdir/diag.sh seq-check 0 4999 source $srcdir/diag.sh exit diff --git a/tests/diag.sh b/tests/diag.sh index 56810c4f..d8ba43b8 100755 --- a/tests/diag.sh +++ b/tests/diag.sh @@ -43,6 +43,7 @@ case $1 in then echo "ABORT! core file exists, starting interactive shell" bash + exit 1 fi ;; 'wait-queueempty') # wait for main message queue to be empty diff --git a/tests/linkedlistqueue.sh b/tests/linkedlistqueue.sh index 9570ed2b..72c2a403 100755 --- a/tests/linkedlistqueue.sh +++ b/tests/linkedlistqueue.sh @@ -10,5 +10,8 @@ source $srcdir/diag.sh injectmsg 0 40000 # terminate *now* (don't wait for queue to drain) kill `cat rsyslog.pid` + +# now wait until rsyslog.pid is gone (and the process finished) +source $srcdir/diag.sh wait-shutdown source $srcdir/diag.sh seq-check 0 39999 source $srcdir/diag.sh exit diff --git a/tests/nettester.c b/tests/nettester.c index 71641745..2838b919 100644 --- a/tests/nettester.c +++ b/tests/nettester.c @@ -47,6 +47,7 @@ #include #include #include +#include #define EXIT_FAILURE 1 #define INVALID_SOCKET -1 @@ -90,6 +91,7 @@ void readLine(int fd, char *ln) if(verbose) fprintf(stderr, "begin readLine\n"); lenRead = read(fd, &c, 1); + while(lenRead == 1 && c != '\n') { if(c == '\0') { *ln = c; @@ -102,6 +104,11 @@ void readLine(int fd, char *ln) } *ln = '\0'; + if(lenRead < 0) { + printf("read from rsyslogd returned with error '%s' - aborting test\n", strerror(errno)); + exit(1); + } + if(verbose) fprintf(stderr, "end readLine, val read '%s'\n", orig); } @@ -308,6 +315,10 @@ processTestFile(int fd, char *pszFileName) /* pull response from server and then check if it meets our expectation */ readLine(fd, buf); + if(strlen(buf) == 0) { + printf("something went wrong - read a zero-length string from rsyslogd"); + exit(1); + } if(strcmp(expected, buf)) { ++iFailed; printf("\nExpected Response:\n'%s'\nActual Response:\n'%s'\n", @@ -372,11 +383,24 @@ doTests(int fd, char *files) return(iFailed); } + +/* indicate that our child has died (where it is not permitted to!). + */ +void childDied(__attribute__((unused)) int sig) +{ + printf("ERROR: child died unexpectedly (maybe a segfault?)!\n"); + exit(1); +} + + /* cleanup */ void doAtExit(void) { int status; + /* disarm died-child handler */ + signal(SIGCHLD, SIG_IGN); + if(rsyslogdPid != 0) { kill(rsyslogdPid, SIGTERM); waitpid(rsyslogdPid, &status, 0); /* wait until instance terminates */ @@ -457,6 +481,9 @@ int main(int argc, char *argv[]) } fclose(fp); + /* arm died-child handler */ + signal(SIGCHLD, childDied); + /* start to be tested rsyslogd */ openPipe(testSuite, &rsyslogdPid, &fd); readLine(fd, buf); @@ -467,5 +494,6 @@ int main(int argc, char *argv[]) ret = 1; if(verbose) printf("End of nettester run (%d).\n", ret); + exit(ret); } -- cgit