summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-08-11 11:49:32 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2010-08-11 11:49:32 +0200
commit32e715929f5d946d7244db3bc0595842dd293dd9 (patch)
tree2a154cd6984690e91569feebcd6924efa0eb91b7 /tests
parent89f7dddf36d57c9261464560e3b2c0fb8ea88fd2 (diff)
parentc664adfa1683763ae503f2da9e8d4d528d6634d1 (diff)
downloadrsyslog-32e715929f5d946d7244db3bc0595842dd293dd9.tar.gz
rsyslog-32e715929f5d946d7244db3bc0595842dd293dd9.tar.xz
rsyslog-32e715929f5d946d7244db3bc0595842dd293dd9.zip
Merge branch 'v4-stable-imptcp' into tmp
Conflicts: Makefile.am configure.ac runtime/rsyslog.h tests/Makefile.am
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am12
-rwxr-xr-xtests/complex1.sh2
-rwxr-xr-xtests/imptcp_conndrop.sh16
-rwxr-xr-xtests/imptcp_large.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/imptcp_large.conf16
-rw-r--r--tests/testsuites/imtcp_conndrop.conf16
9 files changed, 146 insertions, 59 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 201fbed6..ac0844e9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,6 +8,10 @@ TESTS = $(TESTRUNS) cfg.sh \
diskqueue-fsync.sh \
manytcp.sh \
rsf_getenv.sh \
+ manyptcp.sh \
+ imptcp_large.sh \
+ imptcp_conndrop.sh \
+ imtcp_conndrop.sh \
sndrcv.sh \
sndrcv_gzip.sh \
asynwr_simple.sh \
@@ -138,6 +142,14 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
testsuites/imtcp-multiport.conf \
manytcp.sh \
testsuites/manytcp.conf \
+ manyptcp.sh \
+ 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/complex1.sh b/tests/complex1.sh
index b3e31b30..e138bff5 100755
--- a/tests/complex1.sh
+++ b/tests/complex1.sh
@@ -12,7 +12,7 @@ source $srcdir/diag.sh init
source $srcdir/diag.sh startup complex1.conf
# send 40,000 messages of 400 bytes plus header max, via three dest ports
source $srcdir/diag.sh tcpflood -m40000 -rd400 -P129 -f5 -n3 -c15 -i1
-sleep 2 # due to large messages, we need this time for the tcp receiver to settle...
+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
ls rsyslog.out.*.log
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/imptcp_large.sh b/tests/imptcp_large.sh
new file mode 100755
index 00000000..b4d130bb
--- /dev/null
+++ b/tests/imptcp_large.sh
@@ -0,0 +1,16 @@
+# Test imptcp with large messages
+# added 2010-08-10 by Rgerhards
+#
+# This file is part of the rsyslog project, released under GPLv3
+echo ====================================================================================
+echo TEST: \[imptcp_large.sh\]: test imptcp with large-size messages
+cat rsyslog.action.1.include
+source $srcdir/diag.sh init
+source $srcdir/diag.sh startup imptcp_large.conf
+# send 4000 messages of 10.000bytes plus header max, randomized
+source $srcdir/diag.sh tcpflood -c5 -m20000 -r -d10000 -P129
+sleep 2 # 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 19999 -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 e92d1308..2d8be10f 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.
*
@@ -83,11 +85,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
@@ -154,8 +158,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);
@@ -180,6 +182,7 @@ void closeConnections(void)
{
int i;
size_t lenMsg;
+ struct linger ling;
char msgBuf[128];
if(bShowProgress)
@@ -191,7 +194,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);
@@ -288,12 +299,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);
@@ -308,6 +325,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;
}
@@ -317,59 +344,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
*/
@@ -395,7 +369,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;
@@ -420,6 +394,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);
@@ -471,7 +447,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/imptcp_large.conf b/tests/testsuites/imptcp_large.conf
new file mode 100644
index 00000000..677e33f6
--- /dev/null
+++ b/tests/testsuites/imptcp_large.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