summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am15
-rwxr-xr-xtests/fieldtest.sh13
-rwxr-xr-xtests/imtcp-multiport.sh80
-rwxr-xr-xtests/inputname.sh20
-rwxr-xr-xtests/killrsyslog.sh7
-rw-r--r--tests/nettester.c101
-rwxr-xr-xtests/omod-if-array.sh6
-rwxr-xr-xtests/parsertest.sh6
-rw-r--r--tests/tcpflood.c2
-rw-r--r--tests/testsuites/1.field13
-rw-r--r--tests/testsuites/1.inputname_imtcp_125143
-rw-r--r--tests/testsuites/1.inputname_imtcp_125153
-rw-r--r--tests/testsuites/1.inputname_imtcp_125163
-rw-r--r--tests/testsuites/field1.conf8
-rw-r--r--tests/testsuites/imtcp-multiport.conf13
-rw-r--r--tests/testsuites/inputname_imtcp.conf19
16 files changed, 265 insertions, 37 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ed415a1e..bc1849f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,8 +1,8 @@
TESTRUNS = rt_init rscript
check_PROGRAMS = $(TESTRUNS) ourtail nettester tcpflood chkseq
-TESTS = $(TESTRUNS) cfg.sh manytcp.sh diskqueue.sh
+TESTS = $(TESTRUNS) cfg.sh manytcp.sh diskqueue.sh imtcp-multiport.sh
if ENABLE_OMSTDOUT
-TESTS += omod-if-array.sh parsertest.sh
+TESTS += omod-if-array.sh parsertest.sh inputname.sh fieldtest.sh
endif
TESTS_ENVIRONMENT = RSYSLOG_MODDIR='$(abs_top_builddir)'/runtime/.libs/
DISTCLEANFILES=rsyslog.pid
@@ -29,11 +29,22 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
testsuites/rfc5424-4.parse1 \
testsuites/omod-if-array.conf \
testsuites/1.omod-if-array \
+ killrsyslog.sh \
parsertest.sh \
diskqueue.sh \
testsuites/diskqueue.conf \
+ imtcp-multiport.sh \
+ testsuites/imtcp-multiport.conf \
manytcp.sh \
testsuites/manytcp.conf \
+ fieldtest.sh \
+ testsuites/field.conf \
+ testsuites/1.field1 \
+ inputname.sh \
+ testsuites/inputname_imtcp.conf \
+ testsuites/1.inputname_imtcp_12514 \
+ testsuites/1.inputname_imtcp_12515 \
+ testsuites/1.inputname_imtcp_12516 \
omod-if-array.sh \
cfg.sh
diff --git a/tests/fieldtest.sh b/tests/fieldtest.sh
new file mode 100755
index 00000000..7a646f00
--- /dev/null
+++ b/tests/fieldtest.sh
@@ -0,0 +1,13 @@
+echo test fieldtest via udp
+./killrsyslog.sh # kill rsyslogd if it runs for some reason
+
+./nettester -tfield1 -iudp
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
+
+echo test fieldtest via tcp
+./nettester -tfield1 -itcp
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
diff --git a/tests/imtcp-multiport.sh b/tests/imtcp-multiport.sh
new file mode 100755
index 00000000..aa1f15e8
--- /dev/null
+++ b/tests/imtcp-multiport.sh
@@ -0,0 +1,80 @@
+# Test for multiple ports in imtcp
+# This test checks if multiple tcp listener ports are correctly
+# handled by imtcp
+#
+# NOTE: this test must (and can) be enhanced when we merge in the
+# upgraded tcpflood program
+#
+# added 2009-05-22 by Rgerhards
+# This file is part of the rsyslog project, released under GPLv3
+echo testing imtcp multiple listeners
+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/imtcp-multiport.conf &
+sleep 1
+echo "rsyslogd started with pid " `cat rsyslog.pid`
+./tcpflood 127.0.0.1 13514 1 10000
+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 2 # 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 9999
+if [ "$?" -ne "0" ]; then
+ # rm -f work rsyslog.out.log
+ echo "sequence error detected"
+ exit 1
+fi
+rm -f work rsyslog.out.log
+#
+#
+# ### now complete new cycle with other port ###
+#
+#
+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/imtcp-multiport.conf &
+sleep 1
+echo "rsyslogd started with pid " `cat rsyslog.pid`
+./tcpflood 127.0.0.1 13515 1 10000
+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 2 # 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 9999
+if [ "$?" -ne "0" ]; then
+ # rm -f work rsyslog.out.log
+ echo "sequence error detected"
+ exit 1
+fi
+rm -f work rsyslog.out.log
+#
+#
+# ### now complete new cycle with other port ###
+#
+#
+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/imtcp-multiport.conf &
+sleep 1
+echo "rsyslogd started with pid " `cat rsyslog.pid`
+./tcpflood 127.0.0.1 13516 1 10000
+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 2 # 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 9999
+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/inputname.sh b/tests/inputname.sh
new file mode 100755
index 00000000..7d9ea111
--- /dev/null
+++ b/tests/inputname.sh
@@ -0,0 +1,20 @@
+echo testing $InputTCPServerInputName directive
+./killrsyslog.sh # kill rsyslogd if it runs for some reason
+
+echo port 12514
+./nettester -tinputname_imtcp_12514 -cinputname_imtcp -itcp -p12514
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
+
+echo port 12515
+./nettester -tinputname_imtcp_12515 -cinputname_imtcp -itcp -p12515
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
+
+echo port 12516
+./nettester -tinputname_imtcp_12516 -cinputname_imtcp -itcp -p12516
+if [ "$?" -ne "0" ]; then
+ exit 1
+fi
diff --git a/tests/killrsyslog.sh b/tests/killrsyslog.sh
new file mode 100755
index 00000000..b1be757b
--- /dev/null
+++ b/tests/killrsyslog.sh
@@ -0,0 +1,7 @@
+#check if rsyslog instance exists and, if so, kill it
+if [ -e "rsyslog.pid" ]
+then
+ echo rsyslog.pid exists, trying to shut down rsyslogd process `cat rsyslog.pid`.
+ kill `cat rsyslog.pid`
+ sleep 1
+fi
diff --git a/tests/nettester.c b/tests/nettester.c
index 37183ac9..566f553b 100644
--- a/tests/nettester.c
+++ b/tests/nettester.c
@@ -45,16 +45,36 @@
#include <glob.h>
#include <signal.h>
#include <netinet/in.h>
+#include <getopt.h>
#define EXIT_FAILURE 1
#define INVALID_SOCKET -1
/* Name of input file, must match $IncludeConfig in test suite .conf files */
#define NETTEST_INPUT_CONF_FILE "nettest.input.conf" /* name of input file, must match $IncludeConfig in .conf files */
-static enum { inputUDP, inputTCP } inputMode; /* input for which tests are to be run */
+typedef enum { inputUDP, inputTCP } inputMode_t;
+inputMode_t inputMode = inputTCP; /* input for which tests are to be run */
static pid_t rsyslogdPid = 0; /* pid of rsyslog instance being tested */
static char *srcdir; /* global $srcdir, set so that we can run outside of "make check" */
-static char *testSuite; /* name of current test suite */
+static char *testSuite = NULL; /* name of current test suite */
+static int iPort = 12514; /* port which shall be used for sending data */
+static char* pszCustomConf = NULL; /* custom config file, use -c conf to specify */
+static int verbose = 0; /* verbose output? -v option */
+
+
+/* provide user-friednly name of input mode
+ */
+static char *inputMode2Str(inputMode_t mode)
+{
+ char *pszMode;
+
+ if(mode == inputUDP)
+ pszMode = "udp";
+ else
+ pszMode = "tcp";
+
+ return pszMode;
+}
void readLine(int fd, char *ln)
@@ -94,7 +114,7 @@ tcpSend(char *buf, int lenBuf)
memset((char *) &addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_port = htons(13514);
+ addr.sin_port = htons(iPort);
if(inet_aton("127.0.0.1", &addr.sin_addr)==0) {
fprintf(stderr, "inet_aton() failed\n");
return(1);
@@ -139,7 +159,7 @@ udpSend(char *buf, int lenBuf)
memset((char *) &si_other, 0, sizeof(si_other));
si_other.sin_family = AF_INET;
- si_other.sin_port = htons(12514);
+ si_other.sin_port = htons(iPort);
if(inet_aton("127.0.0.1", &si_other.sin_addr)==0) {
fprintf(stderr, "inet_aton() failed\n");
return(1);
@@ -169,9 +189,14 @@ int openPipe(char *configFile, pid_t *pid, int *pfd)
"-M../runtime/.libs:../.libs", NULL };
char confFile[1024];
char *newenviron[] = { NULL };
+ /* debug aide...
+ char *newenviron[] = { "RSYSLOG_DEBUG=debug nostdout",
+ "RSYSLOG_DEBUGLOG=tmp", NULL };
+ */
- sprintf(confFile, "-f%s/testsuites/%s.conf", srcdir, configFile);
+ sprintf(confFile, "-f%s/testsuites/%s.conf", srcdir,
+ (pszCustomConf == NULL) ? configFile : pszCustomConf);
newargv[1] = confFile;
if (pipe(pipefd) == -1) {
@@ -291,12 +316,12 @@ doTests(int fd, char *files)
++iTests;
/* all regular files are run through the test logic. Symlinks don't work. */
if(S_ISREG(fileInfo.st_mode)) { /* config file */
- printf("processing test case '%s' ... ", testFile);
+ if(verbose) printf("processing test case '%s' ... ", testFile);
ret = processTestFile(fd, testFile);
if(ret == 0) {
- printf("successfully completed\n");
+ if(verbose) printf("successfully completed\n");
} else {
- printf("failed!\n");
+ if(verbose) printf("failed!\n");
++iFailed;
}
}
@@ -334,36 +359,54 @@ void doAtExit(void)
int main(int argc, char *argv[])
{
int fd;
+ int opt;
int ret = 0;
FILE *fp;
char buf[4096];
char testcases[4096];
- if(argc != 3) {
- printf("Invalid call of nettester\n");
- printf("Usage: nettester testsuite-name input\n");
- printf(" input = udp|tcp\n");
- exit(1);
+ while((opt = getopt(argc, argv, "c:i:p:t:v")) != EOF) {
+ switch((char)opt) {
+ case 'c':
+ pszCustomConf = optarg;
+ break;
+ case 'i':
+ if(!strcmp(optarg, "udp"))
+ inputMode = inputUDP;
+ else if(!strcmp(optarg, "tcp"))
+ inputMode = inputTCP;
+ else {
+ printf("error: unsupported input mode '%s'\n", optarg);
+ exit(1);
+ }
+ break;
+ case 'p':
+ iPort = atoi(optarg);
+ break;
+ case 't':
+ testSuite = optarg;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ default:printf("Invalid call of nettester, invalid option '%c'.\n", opt);
+ printf("Usage: nettester -ttestsuite-name -iudp|tcp [-pport] [-ccustomConfFile] \n");
+ exit(1);
+ }
}
- atexit(doAtExit);
-
- testSuite = argv[1];
-
- if(!strcmp(argv[2], "udp"))
- inputMode = inputUDP;
- else if(!strcmp(argv[2], "tcp"))
- inputMode = inputTCP;
- else {
- printf("error: unsupported input mode '%s'\n", argv[2]);
+ if(testSuite == NULL) {
+ printf("error: no testsuite given, need to specify -t testsuite!\n");
exit(1);
}
+ atexit(doAtExit);
+
if((srcdir = getenv("srcdir")) == NULL)
srcdir = ".";
- printf("Start of nettester run ($srcdir=%s, testsuite=%s, input=%s)\n",
- srcdir, testSuite, argv[2]);
+ if(verbose) printf("Start of nettester run ($srcdir=%s, testsuite=%s, input=%s/%d)\n",
+ srcdir, testSuite, inputMode2Str(inputMode), iPort);
/* create input config file */
if((fp = fopen(NETTEST_INPUT_CONF_FILE, "w")) == NULL) {
@@ -373,15 +416,15 @@ int main(int argc, char *argv[])
}
if(inputMode == inputUDP) {
fputs("$ModLoad ../plugins/imudp/.libs/imudp\n", fp);
- fputs("$UDPServerRun 12514\n", fp);
+ fprintf(fp, "$UDPServerRun %d\n", iPort);
} else {
fputs("$ModLoad ../plugins/imtcp/.libs/imtcp\n", fp);
- fputs("$InputTCPServerRun 13514\n", fp);
+ fprintf(fp, "$InputTCPServerRun %d\n", iPort);
}
fclose(fp);
/* start to be tested rsyslogd */
- openPipe(argv[1], &rsyslogdPid, &fd);
+ openPipe(testSuite, &rsyslogdPid, &fd);
readLine(fd, buf);
/* generate filename */
@@ -389,6 +432,6 @@ int main(int argc, char *argv[])
if(doTests(fd, testcases) != 0)
ret = 1;
- printf("End of nettester run (%d).\n", ret);
+ if(verbose) printf("End of nettester run (%d).\n", ret);
exit(ret);
}
diff --git a/tests/omod-if-array.sh b/tests/omod-if-array.sh
index fd845b4d..7b4b5611 100755
--- a/tests/omod-if-array.sh
+++ b/tests/omod-if-array.sh
@@ -1,11 +1,13 @@
echo test omod-if-array via udp
-./nettester omod-if-array udp
+./killrsyslog.sh # kill rsyslogd if it runs for some reason
+
+./nettester -tomod-if-array -iudp -p4711
if [ "$?" -ne "0" ]; then
exit 1
fi
echo test omod-if-array via tcp
-./nettester omod-if-array tcp
+./nettester -tomod-if-array -itcp
if [ "$?" -ne "0" ]; then
exit 1
fi
diff --git a/tests/parsertest.sh b/tests/parsertest.sh
index a6b7d45c..152d8b60 100755
--- a/tests/parsertest.sh
+++ b/tests/parsertest.sh
@@ -1,11 +1,13 @@
echo test parsertest via udp
-./nettester parse1 udp
+./killrsyslog.sh # kill rsyslogd if it runs for some reason
+
+./nettester -tparse1 -iudp
if [ "$?" -ne "0" ]; then
exit 1
fi
echo test parsertest via tcp
-./nettester parse1 tcp
+./nettester -tparse1 -itcp
if [ "$?" -ne "0" ]; then
exit 1
fi
diff --git a/tests/tcpflood.c b/tests/tcpflood.c
index 8dbc201b..c3c9c871 100644
--- a/tests/tcpflood.c
+++ b/tests/tcpflood.c
@@ -154,8 +154,6 @@ int sendMessages(void)
int lenBuf;
int lenSend;
char buf[2048];
- char msgBuf[128];
- size_t lenMsg;
srand(time(NULL)); /* seed is good enough for our needs */
diff --git a/tests/testsuites/1.field1 b/tests/testsuites/1.field1
new file mode 100644
index 00000000..54751171
--- /dev/null
+++ b/tests/testsuites/1.field1
@@ -0,0 +1,3 @@
+<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: DROP_url_www.sina.com.cn:IN=eth1 OUT=eth0 SRC=192.168.10.78 DST=61.172.201.194 LEN=1182 TOS=0x00 PREC=0x00 TTL=63 ID=14368 DF PROTO=TCP SPT=33343 DPT=80 WINDOW=92 RES=0x00 ACK PSH URGP=0
+DROP_url_www.sina.com.cn:IN=eth1
+#Only the first two lines are important, you may place anything behind them!
diff --git a/tests/testsuites/1.inputname_imtcp_12514 b/tests/testsuites/1.inputname_imtcp_12514
new file mode 100644
index 00000000..178b1724
--- /dev/null
+++ b/tests/testsuites/1.inputname_imtcp_12514
@@ -0,0 +1,3 @@
+<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: MSG
+12514
+#Only the first two lines are important, you may place anything behind them!
diff --git a/tests/testsuites/1.inputname_imtcp_12515 b/tests/testsuites/1.inputname_imtcp_12515
new file mode 100644
index 00000000..d616098b
--- /dev/null
+++ b/tests/testsuites/1.inputname_imtcp_12515
@@ -0,0 +1,3 @@
+<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: MSG
+12515
+#Only the first two lines are important, you may place anything behind them!
diff --git a/tests/testsuites/1.inputname_imtcp_12516 b/tests/testsuites/1.inputname_imtcp_12516
new file mode 100644
index 00000000..8e6997ce
--- /dev/null
+++ b/tests/testsuites/1.inputname_imtcp_12516
@@ -0,0 +1,3 @@
+<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: MSG
+12516
+#Only the first two lines are important, you may place anything behind them!
diff --git a/tests/testsuites/field1.conf b/tests/testsuites/field1.conf
new file mode 100644
index 00000000..1ff833dd
--- /dev/null
+++ b/tests/testsuites/field1.conf
@@ -0,0 +1,8 @@
+$ModLoad ../plugins/omstdout/.libs/omstdout
+$IncludeConfig nettest.input.conf # This picks the to be tested input from the test driver!
+
+$ErrorMessagesToStderr off
+
+# use a special format that we can easily parse in expect
+$template fmt,"%msg:F,32:2%\n"
+*.* :omstdout:;fmt
diff --git a/tests/testsuites/imtcp-multiport.conf b/tests/testsuites/imtcp-multiport.conf
new file mode 100644
index 00000000..00b63cb2
--- /dev/null
+++ b/tests/testsuites/imtcp-multiport.conf
@@ -0,0 +1,13 @@
+# Test for queue disk mode (see .sh file for details)
+# rgerhards, 2009-05-22
+$ModLoad ../plugins/imtcp/.libs/imtcp
+$MainMsgQueueTimeoutShutdown 10000
+$InputTCPServerRun 13514
+$InputTCPServerRun 13515
+$InputTCPServerRun 13516
+
+$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
diff --git a/tests/testsuites/inputname_imtcp.conf b/tests/testsuites/inputname_imtcp.conf
new file mode 100644
index 00000000..a25eab37
--- /dev/null
+++ b/tests/testsuites/inputname_imtcp.conf
@@ -0,0 +1,19 @@
+# This is a special case, thus we define the inputs ourselfs
+$ModLoad ../plugins/omstdout/.libs/omstdout
+
+$ModLoad ../plugins/imtcp/.libs/imtcp
+
+$InputTCPServerInputname 12514
+$InputTCPServerRun 12514
+
+$InputTCPServerInputname 12515
+$InputTCPServerRun 12515
+
+$InputTCPServerInputname 12516
+$InputTCPServerRun 12516
+
+$ErrorMessagesToStderr off
+
+# use a special format that we can easily parse in expect
+$template fmt,"%inputname%\n"
+*.* :omstdout:;fmt