summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am5
-rwxr-xr-xtests/manytcp.sh18
-rwxr-xr-xtests/tcpfloodbin17972 -> 0 bytes
-rw-r--r--tests/tcpflood.c68
-rw-r--r--tests/testsuites/manytcp.conf13
5 files changed, 86 insertions, 18 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 53a81a93..87dca985 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,13 +28,16 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
testsuites/1.omod-if-array \
parsertest.sh \
manytcp.sh \
+ testsuites/manytcp.conf \
omod-if-array.sh \
cfg.sh
ourtail_SOURCES = ourtail.c
-tcpflood_SOURCES = tcpflood.c
chkseq_SOURCES = chkseq.c
+tcpflood_SOURCES = tcpflood.c
+tcpflood_LDADD = $(SOL_LIBS)
+
nettester_SOURCES = nettester.c getline.c
nettester_LDADD = $(SOL_LIBS)
diff --git a/tests/manytcp.sh b/tests/manytcp.sh
index 3accfb8a..d9b2e9a0 100755
--- a/tests/manytcp.sh
+++ b/tests/manytcp.sh
@@ -1,13 +1,21 @@
-rm -f rsyslog.out.log # work file
-../tools/rsyslogd -c4 -u2 -n -irsyslog.pid -M../runtime/.libs:../.libs -ftestsuites/manytcp.conf &
-echo "rsyslogd started with pid " `cat rsyslog.pid`
-./tcpflood 127.0.0.1 13514 1000 20000
+rm -f work rsyslog.out.log rsyslog.out.log.save # work files
+../tools/rsyslogd -c4 -u2 -n -irsyslog.pid -M../runtime/.libs:../.libs -f$srcdir/testsuites/manytcp.conf &
sleep 1
+echo "rsyslogd started with pid " `cat rsyslog.pid`
+# the config file specifies exactly 1100 connections
+./tcpflood 127.0.0.1 13514 1000 40000
+if [ "$?" -ne "0" ]; then
+ echo "error during tcpflood! see rsyslog.out.log.save for what was written"
+ cp rsyslog.out.log rsyslog.out.log.save
+fi
+sleep 5 # we need this so that rsyslogd can receive all outstanding messages
kill `cat rsyslog.pid`
rm -f work
sort < rsyslog.out.log > work
-./chkseq work 0 19999
+./chkseq work 0 39999
if [ "$?" -ne "0" ]; then
+ rm -f work rsyslog.out.log
echo "sequence error detected"
exit 1
fi
+rm -f work rsyslog.out.log
diff --git a/tests/tcpflood b/tests/tcpflood
deleted file mode 100755
index ae00fcd5..00000000
--- a/tests/tcpflood
+++ /dev/null
Binary files differ
diff --git a/tests/tcpflood.c b/tests/tcpflood.c
index 83f0d1ee..9c17fd5b 100644
--- a/tests/tcpflood.c
+++ b/tests/tcpflood.c
@@ -95,21 +95,49 @@ int openConnections(void)
sockArray = calloc(numConnections, sizeof(int));
for(i = 0 ; i < numConnections ; ++i) {
if(i % 10 == 0) {
- lenMsg = sprintf(msgBuf, "\retb\b\b\b\b%5.5d", i);
- write(1, msgBuf, lenMsg);
+ 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);
return 1;
}
}
- lenMsg = sprintf(msgBuf, "\retb\b\b\b\b%5.5d open connections\n", i);
+ lenMsg = sprintf(msgBuf, "\r%5.5d open connections\n", i);
write(1, msgBuf, lenMsg);
return 0;
}
+/* we also close all connections because otherwise we may get very bad
+ * timing for the syslogd - it may not be able to process all incoming
+ * messages fast enough if we immediately shut down.
+ * TODO: it may be an interesting excercise to handle that situation
+ * at the syslogd level, too
+ * rgerhards, 2009-04-14
+ */
+void closeConnections(void)
+{
+ int i;
+ char msgBuf[128];
+ size_t lenMsg;
+
+ write(1, " close connections", sizeof(" close connections")-1);
+ for(i = 0 ; i < numConnections ; ++i) {
+ if(i % 10 == 0) {
+ lenMsg = sprintf(msgBuf, "\r%5.5d", i);
+ write(1, msgBuf, lenMsg);
+ }
+ close(sockArray[i]);
+ }
+ lenMsg = sprintf(msgBuf, "\r%5.5d close connections\n", i);
+ write(1, msgBuf, lenMsg);
+
+}
+
+
/* send messages to the tcp connections we keep open. We use
* a very basic format that helps identify the message
* (via msgnum:<number>: e.g. msgnum:00000001:). This format is suitable
@@ -123,14 +151,15 @@ int sendMessages(void)
int i;
int socknum;
int lenBuf;
+ int lenSend;
char buf[2048];
char msgBuf[128];
size_t lenMsg;
srand(time(NULL)); /* seed is good enough for our needs */
- lenMsg = sprintf(msgBuf, "\retb\b\b\b\b%5.5d messages sent", 0);
- write(1, msgBuf, lenMsg);
+ printf("Sending %d messages.\n", numMsgsToSend);
+ printf("\r%5.5d messages sent", 0);
for(i = 0 ; i < numMsgsToSend ; ++i) {
if(i < numConnections)
socknum = i;
@@ -139,18 +168,20 @@ int sendMessages(void)
else
socknum = rand() % numConnections;
lenBuf = sprintf(buf, "<167>Mar 1 01:00:00 172.20.245.8 tag msgnum:%8.8d:\n", i);
- if(send(sockArray[socknum], buf, lenBuf, 0) != lenBuf) {
+ lenSend = send(sockArray[socknum], buf, lenBuf, 0);
+ if(lenSend != lenBuf) {
+ printf("\r%5.5d\n", i);
+ fflush(stdout);
perror("send test data");
- fprintf(stderr, "send() failed\n");
+ printf("send() failed at socket %d, index %d\n", socknum, i);
+ fflush(stderr);
return(1);
}
if(i % 100 == 0) {
- lenMsg = sprintf(msgBuf, "\retb\b\b\b\b%5.5d", i);
- write(1, msgBuf, lenMsg);
+ printf("\r%5.5d", i);
}
}
- lenMsg = sprintf(msgBuf, "\retb\b\b\b\b%5.5d messages sent\n", i);
- write(1, msgBuf, lenMsg);
+ printf("\r%5.5d messages sent\n", i);
return 0;
}
@@ -217,9 +248,18 @@ tcpSend(char *buf, int lenBuf)
int main(int argc, char *argv[])
{
int ret = 0;
+ struct sigaction sigAct;
static char buf[1024];
- setvbuf(stdout, _IONBF, buf, 48);
+ /* on Solaris, we do not HAVE MSG_NOSIGNAL, so for this reason
+ * we block SIGPIPE (not an issue for this program)
+ */
+ memset(&sigAct, 0, sizeof(sigAct));
+ sigemptyset(&sigAct.sa_mask);
+ sigAct.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE, &sigAct, NULL);
+
+ setvbuf(stdout, buf, _IONBF, 48);
if(argc != 5) {
printf("Invalid call of tcpflood\n");
@@ -241,5 +281,9 @@ int main(int argc, char *argv[])
printf("error sending messages\n");
exit(1);
}
+
+ //closeConnections();
+ printf("End of tcpflood Run\n");
+
exit(ret);
}
diff --git a/tests/testsuites/manytcp.conf b/tests/testsuites/manytcp.conf
new file mode 100644
index 00000000..8175732e
--- /dev/null
+++ b/tests/testsuites/manytcp.conf
@@ -0,0 +1,13 @@
+# Test for tcp "flood" testing
+# rgerhards, 2009-04-08
+$ModLoad ../plugins/imtcp/.libs/imtcp
+$MainMsgQueueTimeoutShutdown 10000
+$MaxOpenFiles 2000
+$InputTCPMaxSessions 1100
+$InputTCPServerRun 13514
+
+$ErrorMessagesToStderr off
+
+$template outfmt,"%msg:F,58:2%\n"
+$template dynfile,"rsyslog.out.log" # trick to use relative path names!
+:msg, contains, "msgnum:" ?dynfile;outfmt