summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-03-22 14:06:05 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2010-03-22 14:06:05 +0100
commit1ddb082cfa1ca6bb7b8c44ce760ccd4200e1f2f7 (patch)
tree6591abfaa1c701eff6d89b611f4e98d06726ffbe /tests
parentdccadb677c5a6b8379f631e4c1f14c8c4089d4a6 (diff)
downloadrsyslog-1ddb082cfa1ca6bb7b8c44ce760ccd4200e1f2f7.tar.gz
rsyslog-1ddb082cfa1ca6bb7b8c44ce760ccd4200e1f2f7.tar.xz
rsyslog-1ddb082cfa1ca6bb7b8c44ce760ccd4200e1f2f7.zip
added testcase showcasing problems when dynafile can not be opened
note that so far no patch is provided. This has not yet been made part of "make check"
Diffstat (limited to 'tests')
-rwxr-xr-xtests/dynfile_invalid.sh34
-rw-r--r--tests/tcpflood.c43
-rw-r--r--tests/testsuites/dynfile_invalid.conf14
3 files changed, 75 insertions, 16 deletions
diff --git a/tests/dynfile_invalid.sh b/tests/dynfile_invalid.sh
new file mode 100755
index 00000000..f61dc104
--- /dev/null
+++ b/tests/dynfile_invalid.sh
@@ -0,0 +1,34 @@
+# This test checks if omfile segfaults when a file open() in dynacache mode fails.
+# The test is mimiced after a real-life scenario (which, of course, was much more
+# complex).
+#
+# added 2010-03-09 by Rgerhards
+#
+# This file is part of the rsyslog project, released under GPLv3
+echo ===============================================================================
+echo TEST: \[dynfile_invalid.sh\]: test open fail for dynafiles
+source $srcdir/diag.sh init
+# uncomment for debugging support:
+export RSYSLOG_DEBUG="debug nostdout noprintmutexaction"
+export RSYSLOG_DEBUGLOG="log"
+source $srcdir/diag.sh startup dynfile_invalid.conf
+# we send handcrafted message. We have a dynafile cache of 4, and now send one message
+# each to fill up the cache.
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:rsyslog.out.0.log:0"
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:rsyslog.out.1.log:1"
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:rsyslog.out.2.log:2"
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:rsyslog.out.3.log:3"
+# the next one has caused a segfault in practice
+# note that /proc/rsyslog.error.file must not be creatable
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:/proc/rsyslog.error.file:boom"
+# some more writes
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:rsyslog.out.0.log:4"
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:rsyslog.out.1.log:5"
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:rsyslog.out.2.log:6"
+./tcpflood -m1 -M "<129>Mar 10 01:00:00 172.20.245.8 tag msg:rsyslog.out.3.log:7"
+# done message generation
+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
+cat rsyslog.out.*.log > rsyslog.out.log
+source $srcdir/diag.sh seq-check 0 7
+source $srcdir/diag.sh exit
diff --git a/tests/tcpflood.c b/tests/tcpflood.c
index d4955447..2bb7ba2c 100644
--- a/tests/tcpflood.c
+++ b/tests/tcpflood.c
@@ -18,10 +18,12 @@
* -f support for testing dynafiles. If given, include a dynafile ID
* in the range 0..(f-1) as the SECOND field, shifting all field values
* one field to the right. Zero (default) disables this functionality.
+ * -M the message to be sent. Disables all message format options, as
+ * only that exact same message is sent.
*
* Part of the testbench for rsyslog.
*
- * Copyright 2009 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2009, 2010 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of rsyslog.
*
@@ -72,6 +74,7 @@ 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 char *MsgToSend = NULL; /* if non-null, this is the actual message to send */
/* open a single tcp connection
@@ -212,21 +215,26 @@ int sendMessages(void)
socknum = i - (numMsgsToSend - numConnections);
else
socknum = rand() % numConnections;
- if(dynFileIDs > 0) {
- sprintf(dynFileIDBuf, "%d:", rand() % dynFileIDs);
- }
- if(extraDataLen == 0) {
- lenBuf = sprintf(buf, "<%s>Mar 1 01:00:00 172.20.245.8 tag msgnum:%s%8.8d:\n",
- msgPRI, dynFileIDBuf, msgNum);
+ if(MsgToSend == NULL) {
+ if(dynFileIDs > 0) {
+ sprintf(dynFileIDBuf, "%d:", rand() % dynFileIDs);
+ }
+ if(extraDataLen == 0) {
+ lenBuf = sprintf(buf, "<%s>Mar 1 01:00:00 172.20.245.8 tag msgnum:%s%8.8d:\n",
+ msgPRI, dynFileIDBuf, msgNum);
+ } else {
+ if(bRandomizeExtraData)
+ edLen = ((long) rand() + extraDataLen) % extraDataLen + 1;
+ else
+ edLen = extraDataLen;
+ memset(extraData, 'X', edLen);
+ extraData[edLen] = '\0';
+ lenBuf = sprintf(buf, "<%s>Mar 1 01:00:00 172.20.245.8 tag msgnum:%s%8.8d:%d:%s\n",
+ msgPRI, dynFileIDBuf, msgNum, edLen, extraData);
+ }
} else {
- if(bRandomizeExtraData)
- edLen = ((long) rand() + extraDataLen) % extraDataLen + 1;
- else
- edLen = extraDataLen;
- memset(extraData, 'X', edLen);
- extraData[edLen] = '\0';
- lenBuf = sprintf(buf, "<%s>Mar 1 01:00:00 172.20.245.8 tag msgnum:%s%8.8d:%d:%s\n",
- msgPRI, dynFileIDBuf, msgNum, edLen, extraData);
+ /* use fixed message format from command line */
+ lenBuf = sprintf(buf, "%s\n", MsgToSend);
}
lenSend = send(sockArray[socknum], buf, lenBuf, 0);
if(lenSend != lenBuf) {
@@ -327,7 +335,7 @@ int main(int argc, char *argv[])
if(!isatty(1))
bShowProgress = 0;
- while((opt = getopt(argc, argv, "f:t:p:c:m:i:P:d:n:r")) != -1) {
+ while((opt = getopt(argc, argv, "f:t:p:c:m:i:P:d:n:M:r")) != -1) {
switch (opt) {
case 't': targetIP = optarg;
break;
@@ -354,6 +362,9 @@ int main(int argc, char *argv[])
break;
case 'f': dynFileIDs = atoi(optarg);
break;
+ case 'M': MsgToSend = optarg;
+fprintf(stderr, "msg to send: '%s'\n", MsgToSend);
+ break;
default: printf("invalid option '%c' or value missing - terminating...\n", opt);
exit (1);
break;
diff --git a/tests/testsuites/dynfile_invalid.conf b/tests/testsuites/dynfile_invalid.conf
new file mode 100644
index 00000000..458f199b
--- /dev/null
+++ b/tests/testsuites/dynfile_invalid.conf
@@ -0,0 +1,14 @@
+# simple async writing test
+# rgerhards, 2010-03-09
+$IncludeConfig diag-common.conf
+
+$ModLoad ../plugins/imtcp/.libs/imtcp
+$MainMsgQueueTimeoutShutdown 10000
+$InputTCPServerRun 13514
+
+$template outfmt,"%msg:F,58:3%\n"
+$template dynfile,"%msg:F,58:2%.log" # complete name is in message
+$OMFileFlushOnTXEnd on
+$DynaFileCacheSize 4
+$omfileFlushInterval 1
+local0.* ?dynfile;outfmt