summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-08-10 19:34:42 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2010-08-10 19:34:42 +0200
commitc664adfa1683763ae503f2da9e8d4d528d6634d1 (patch)
treefcbf9bf7eea51374dbc405b6d7e0839df9ee495a
parentb5b4bd138949f09b3703e6f7f5caf46d361fa41c (diff)
downloadrsyslog-c664adfa1683763ae503f2da9e8d4d528d6634d1.tar.gz
rsyslog-c664adfa1683763ae503f2da9e8d4d528d6634d1.tar.xz
rsyslog-c664adfa1683763ae503f2da9e8d4d528d6634d1.zip
more testbench improvements and new tests
-rw-r--r--tests/Makefile.am6
-rwxr-xr-xtests/imptcp_conndrop.sh16
-rwxr-xr-xtests/imtcp_conndrop.sh16
-rw-r--r--tests/tcpflood.c95
-rw-r--r--tests/testsuites/imptcp_conndrop.conf16
-rw-r--r--tests/testsuites/imtcp_conndrop.conf16
6 files changed, 107 insertions, 58 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b9b1ede7..b500bc85 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,6 +9,8 @@ TESTS = $(TESTRUNS) cfg.sh \
manytcp.sh \
manyptcp.sh \
imptcp_large.sh \
+ imptcp_conndrop.sh \
+ imtcp_conndrop.sh \
sndrcv.sh \
sndrcv_gzip.sh \
asynwr_simple.sh \
@@ -142,6 +144,10 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
testsuites/manyptcp.conf \
imptcp_large.sh \
testsuites/imptcp_large.conf \
+ imptcp_conndrop.sh \
+ testsuites/imptcp_conndrop.conf \
+ imtcp_conndrop.sh \
+ testsuites/imtcp_conndrop.conf \
inputname.sh \
testsuites/inputname_imtcp.conf \
testsuites/1.inputname_imtcp_12514 \
diff --git a/tests/imptcp_conndrop.sh b/tests/imptcp_conndrop.sh
new file mode 100755
index 00000000..684de6b5
--- /dev/null
+++ b/tests/imptcp_conndrop.sh
@@ -0,0 +1,16 @@
+# Test imptcp with many dropping connections
+# added 2010-08-10 by Rgerhards
+#
+# This file is part of the rsyslog project, released under GPLv3
+echo ====================================================================================
+echo TEST: \[imptcp_conndrop.sh\]: test imptcp with random connection drops
+cat rsyslog.action.1.include
+source $srcdir/diag.sh init
+source $srcdir/diag.sh startup imptcp_large.conf
+# 100 byte messages to gain more practical data use
+source $srcdir/diag.sh tcpflood -c20 -m50000 -r -d100 -P129 -D
+sleep 4 # due to large messages, we need this time for the tcp receiver to settle...
+source $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages
+source $srcdir/diag.sh wait-shutdown # and wait for it to terminate
+source $srcdir/diag.sh seq-check 0 49999 -E
+source $srcdir/diag.sh exit
diff --git a/tests/imtcp_conndrop.sh b/tests/imtcp_conndrop.sh
new file mode 100755
index 00000000..2caa0ce2
--- /dev/null
+++ b/tests/imtcp_conndrop.sh
@@ -0,0 +1,16 @@
+# Test imtcp with many dropping connections
+# added 2010-08-10 by Rgerhards
+#
+# This file is part of the rsyslog project, released under GPLv3
+echo ====================================================================================
+echo TEST: \[imtcp_conndrop.sh\]: test imtcp with random connection drops
+cat rsyslog.action.1.include
+source $srcdir/diag.sh init
+source $srcdir/diag.sh startup imptcp_large.conf
+# 100 byte messages to gain more practical data use
+source $srcdir/diag.sh tcpflood -c20 -m50000 -r -d100 -P129 -D
+sleep 4 # due to large messages, we need this time for the tcp receiver to settle...
+source $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages
+source $srcdir/diag.sh wait-shutdown # and wait for it to terminate
+source $srcdir/diag.sh seq-check 0 49999 -E
+source $srcdir/diag.sh exit
diff --git a/tests/tcpflood.c b/tests/tcpflood.c
index d8c3f038..ee43449e 100644
--- a/tests/tcpflood.c
+++ b/tests/tcpflood.c
@@ -28,6 +28,8 @@
* delemiters into account.
* -C when input from a file is read, this file is transmitted -C times
* (C like cycle, running out of meaningful option switches ;))
+ * -D randomly drop and re-establish connections. Useful for stress-testing
+ * the TCP receiver.
*
* Part of the testbench for rsyslog.
*
@@ -82,11 +84,13 @@ static int numConnections = 1; /* number of connections to create */
static int *sockArray; /* array of sockets to use */
static int msgNum = 0; /* initial message number to start with */
static int bShowProgress = 1; /* show progress messages */
+static int bRandConnDrop = 0; /* randomly drop connections? */
static char *MsgToSend = NULL; /* if non-null, this is the actual message to send */
static int bBinaryFile = 0; /* is -I file binary */
static char *dataFile = NULL; /* name of data file, if NULL, generate own data */
static int numFileIterations = 1;/* how often is file data to be sent? */
FILE *dataFP = NULL; /* file pointer for data file, if used */
+static long nConnDrops = 0; /* counter: number of time connection was dropped (-D option) */
/* open a single tcp connection
@@ -153,8 +157,6 @@ int openConnections(void)
if(i % 10 == 0) {
if(bShowProgress)
printf("\r%5.5d", i);
- //lenMsg = sprintf(msgBuf, "\r%5.5d", i);
- //write(1, msgBuf, lenMsg);
}
if(openConn(&(sockArray[i])) != 0) {
printf("error in trying to open connection i=%d\n", i);
@@ -179,6 +181,7 @@ void closeConnections(void)
{
int i;
size_t lenMsg;
+ struct linger ling;
char msgBuf[128];
if(bShowProgress)
@@ -190,7 +193,15 @@ void closeConnections(void)
write(1, msgBuf, lenMsg);
}
}
- close(sockArray[i]);
+ if(sockArray[i] != -1) {
+ /* we try to not overrun the receiver by trying to flush buffers
+ * *during* close(). -- rgerhards, 2010-08-10
+ */
+ ling.l_onoff = 1;
+ ling.l_linger = 1;
+ setsockopt(sockArray[i], SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
+ close(sockArray[i]);
+ }
}
lenMsg = sprintf(msgBuf, "\r%5.5d close connections\n", i);
write(1, msgBuf, lenMsg);
@@ -287,12 +298,18 @@ int sendMessages(void)
socknum = i - (numMsgsToSend - numConnections);
else {
int rnd = rand();
- //socknum = rand() % numConnections;
socknum = rnd % numConnections;
}
genMsg(buf, sizeof(buf), &lenBuf); /* generate the message to send according to params */
if(lenBuf == 0)
break; /* end of processing! */
+ if(sockArray[socknum] == -1) {
+ /* connection was dropped, need to re-establish */
+ if(openConn(&(sockArray[socknum])) != 0) {
+ printf("error in trying to re-open connection %d\n", socknum);
+ exit(1);
+ }
+ }
lenSend = send(sockArray[socknum], buf, lenBuf, 0);
if(lenSend != lenBuf) {
printf("\r%5.5d\n", i);
@@ -307,6 +324,16 @@ int sendMessages(void)
if(bShowProgress)
printf("\r%8.8d", i);
}
+ if(bRandConnDrop) {
+ /* if we need to randomly drop connections, see if we
+ * are a victim
+ */
+ if(rand() > (int) (RAND_MAX * 0.95)) {
+ ++nConnDrops;
+ close(sockArray[socknum]);
+ sockArray[socknum] = -1;
+ }
+ }
++msgNum;
++i;
}
@@ -316,59 +343,6 @@ int sendMessages(void)
}
-/* send a message via TCP
- * We open the connection on the initial send, and never close it
- * (let the OS do that). If a conneciton breaks, we do NOT try to
- * recover, so all test after that one will fail (and the test
- * driver probably hang. returns 0 if ok, something else otherwise.
- * We use traditional framing '\n' at EOR for this tester. It may be
- * worth considering additional framing modes.
- * rgerhards, 2009-04-08
- */
-int
-tcpSend(char *buf, int lenBuf)
-{
- static int sock = INVALID_SOCKET;
- struct sockaddr_in addr;
-
- if(sock == INVALID_SOCKET) {
- /* first time, need to connect to target */
- if((sock=socket(AF_INET, SOCK_STREAM, 0))==-1) {
- perror("socket()");
- return(1);
- }
-
- memset((char *) &addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(13514);
- if(inet_aton("127.0.0.1", &addr.sin_addr)==0) {
- fprintf(stderr, "inet_aton() failed\n");
- return(1);
- }
- if(connect(sock, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
- fprintf(stderr, "connect() failed\n");
- return(1);
- }
- }
-
- /* send test data */
- if(send(sock, buf, lenBuf, 0) != lenBuf) {
- perror("send test data");
- fprintf(stderr, "send() failed\n");
- return(1);
- }
-
- /* send record terminator */
- if(send(sock, "\n", 1, 0) != 1) {
- perror("send record terminator");
- fprintf(stderr, "send() failed\n");
- return(1);
- }
-
- return 0;
-}
-
-
/* Run the test.
* rgerhards, 2009-04-03
*/
@@ -394,7 +368,7 @@ int main(int argc, char *argv[])
if(!isatty(1))
bShowProgress = 0;
- while((opt = getopt(argc, argv, "f:t:p:c:C:m:i:I:P:d:n:M:rB")) != -1) {
+ while((opt = getopt(argc, argv, "f:t:p:c:C:m:i:I:P:d:Dn:M:rB")) != -1) {
switch (opt) {
case 't': targetIP = optarg;
break;
@@ -419,6 +393,8 @@ int main(int argc, char *argv[])
exit(1);
}
break;
+ case 'D': bRandConnDrop = 1;
+ break;
case 'r': bRandomizeExtraData = 1;
break;
case 'f': dynFileIDs = atoi(optarg);
@@ -456,7 +432,10 @@ int main(int argc, char *argv[])
exit(1);
}
+ if(nConnDrops > 0)
+ printf("-D option initiated %ld connection closures\n", nConnDrops);
printf("End of tcpflood Run\n");
+ closeConnections(); /* this is important so that we do not finish too early! */
exit(ret);
}
diff --git a/tests/testsuites/imptcp_conndrop.conf b/tests/testsuites/imptcp_conndrop.conf
new file mode 100644
index 00000000..677e33f6
--- /dev/null
+++ b/tests/testsuites/imptcp_conndrop.conf
@@ -0,0 +1,16 @@
+# simple async writing test
+# rgerhards, 2010-03-09
+$MaxMessageSize 10k
+$IncludeConfig diag-common.conf
+
+$ModLoad ../plugins/imptcp/.libs/imptcp
+$MainMsgQueueTimeoutShutdown 10000
+$InputPTCPServerRun 13514
+
+$template outfmt,"%msg:F,58:2%,%msg:F,58:3%,%msg:F,58:4%\n"
+$template dynfile,"rsyslog.out.log" # trick to use relative path names!
+$OMFileFlushOnTXEnd off
+$OMFileFlushInterval 2
+$OMFileIOBufferSize 256k
+$IncludeConfig rsyslog.action.1.include
+local0.* ?dynfile;outfmt
diff --git a/tests/testsuites/imtcp_conndrop.conf b/tests/testsuites/imtcp_conndrop.conf
new file mode 100644
index 00000000..b64f132b
--- /dev/null
+++ b/tests/testsuites/imtcp_conndrop.conf
@@ -0,0 +1,16 @@
+# simple async writing test
+# rgerhards, 2010-03-09
+$MaxMessageSize 10k
+$IncludeConfig diag-common.conf
+
+$ModLoad ../plugins/imtcp/.libs/imtcp
+$MainMsgQueueTimeoutShutdown 10000
+$InputTCPServerRun 13514
+
+$template outfmt,"%msg:F,58:2%,%msg:F,58:3%,%msg:F,58:4%\n"
+$template dynfile,"rsyslog.out.log" # trick to use relative path names!
+$OMFileFlushOnTXEnd off
+$OMFileFlushInterval 2
+$OMFileIOBufferSize 256k
+$IncludeConfig rsyslog.action.1.include
+local0.* ?dynfile;outfmt