summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-04-08 12:19:54 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-04-08 12:19:54 +0200
commit8f8e2cd66bd7f1e35f7bf0678e25bbdb99d67093 (patch)
tree0998e3290329337e7093d1856f8e87112d449270 /tests
parenta6c743e5ec5d213d3aa6404553fe65d59f065799 (diff)
downloadrsyslog-8f8e2cd66bd7f1e35f7bf0678e25bbdb99d67093.tar.gz
rsyslog-8f8e2cd66bd7f1e35f7bf0678e25bbdb99d67093.tar.xz
rsyslog-8f8e2cd66bd7f1e35f7bf0678e25bbdb99d67093.zip
improved testbench, added tests for tcp-based reception
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/nettester.c (renamed from tests/udptester.c)129
-rwxr-xr-xtests/omod-if-array.sh6
-rwxr-xr-xtests/parsertest.sh6
-rw-r--r--tests/testsuites/omod-if-array.conf3
-rw-r--r--tests/testsuites/parse1.conf3
6 files changed, 129 insertions, 24 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ab1c5a62..fa662a3e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,5 @@
TESTRUNS = rt_init rscript
-check_PROGRAMS = $(TESTRUNS) ourtail udptester
+check_PROGRAMS = $(TESTRUNS) ourtail nettester
TESTS = $(TESTRUNS) cfg.sh parsertest.sh omod-if-array.sh
TESTS_ENVIRONMENT = RSYSLOG_MODDIR='$(abs_top_builddir)'/runtime/.libs/
DISTCLEANFILES=rsyslog.pid
@@ -32,8 +32,8 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
ourtail_SOURCES = ourtail.c
-udptester_SOURCES = udptester.c getline.c
-udptester_LDADD = $(SOL_LIBS)
+nettester_SOURCES = nettester.c getline.c
+nettester_LDADD = $(SOL_LIBS)
rt_init_SOURCES = rt-init.c $(test_files)
rt_init_CPPFLAGS = -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS)
diff --git a/tests/udptester.c b/tests/nettester.c
index a3c6658d..89a784f3 100644
--- a/tests/udptester.c
+++ b/tests/nettester.c
@@ -46,7 +46,12 @@
#include <netinet/in.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 */
+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 */
@@ -64,6 +69,59 @@ void readLine(int fd, char *ln)
}
+/* 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;
+}
+
+
/* send a message via UDP
* returns 0 if ok, something else otherwise.
*/
@@ -107,7 +165,7 @@ int openPipe(char *configFile, pid_t *pid, int *pfd)
int pipefd[2];
pid_t cpid;
char *newargv[] = {"../tools/rsyslogd", "dummy", "-c4", "-u2", "-n", "-irsyslog.pid",
- "-M../runtime//.libs", NULL };
+ "-M../runtime/.libs:../.libs", NULL };
char confFile[1024];
char *newenviron[] = { NULL };
@@ -173,9 +231,14 @@ processTestFile(int fd, char *pszFileName)
testdata[strlen(testdata)-1] = '\0'; /* remove \n */
- /* now we have the test data to send */
- if(udpSend(testdata, strlen(testdata)) != 0)
- return(2);
+ /* now we have the test data to send (we could use function pointers here...) */
+ if(inputMode == inputUDP) {
+ if(udpSend(testdata, strlen(testdata)) != 0)
+ return(2);
+ } else {
+ if(tcpSend(testdata, strlen(testdata)) != 0)
+ return(2);
+ }
/* next line is expected output
* we do not care about EOF here, this will lead to a failure and thus
@@ -249,6 +312,18 @@ doTests(int fd, char *files)
return(iFailed);
}
+/* cleanup */
+void doAtExit(void)
+{
+ int status;
+
+ if(rsyslogdPid != 0) {
+ kill(rsyslogdPid, SIGTERM);
+ waitpid(rsyslogdPid, &status, 0); /* wait until instance terminates */
+ }
+
+ unlink(NETTEST_INPUT_CONF_FILE);
+}
/* Run the test suite. This must be called with exactly one parameter, the
* name of the test suite. For details, see file header comment at the top
@@ -258,26 +333,53 @@ doTests(int fd, char *files)
int main(int argc, char *argv[])
{
int fd;
- pid_t pid;
- int status;
int ret = 0;
+ FILE *fp;
char buf[4096];
char testcases[4096];
- if(argc != 2) {
- printf("Invalid call of udptester\n");
- printf("Usage: udptester testsuite-name\n");
+ if(argc != 3) {
+ printf("Invalid call of nettester\n");
+ printf("Usage: nettester testsuite-name input\n");
+ printf(" input = udp|tcp\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]);
+ exit(1);
+ }
+
if((srcdir = getenv("srcdir")) == NULL)
srcdir = ".";
- printf("Start of udptester run ($srcdir=%s, testsuite=%s)\n", srcdir, testSuite);
+ printf("Start of nettester run ($srcdir=%s, testsuite=%s)\n", srcdir, testSuite);
+
+ /* create input config file */
+ if((fp = fopen(NETTEST_INPUT_CONF_FILE, "w")) == NULL) {
+ perror(NETTEST_INPUT_CONF_FILE);
+ printf("error opening input configuration file\n");
+ exit(1);
+ }
+ if(inputMode == inputUDP) {
+ fputs("$ModLoad ../plugins/imudp/.libs/imudp\n", fp);
+ fputs("$UDPServerRun 12514\n", fp);
+ } else {
+ fputs("$ModLoad ../plugins/imtcp/.libs/imtcp\n", fp);
+ fputs("$InputTCPServerRun 13514\n", fp);
+ }
+ fclose(fp);
- openPipe(argv[1], &pid, &fd);
+ /* start to be tested rsyslogd */
+ openPipe(argv[1], &rsyslogdPid, &fd);
readLine(fd, buf);
/* generate filename */
@@ -285,9 +387,6 @@ int main(int argc, char *argv[])
if(doTests(fd, testcases) != 0)
ret = 1;
- /* cleanup */
- kill(pid, SIGTERM);
- waitpid(pid, &status, 0); /* wait until instance terminates */
- printf("End of udptester run.\n");
+ 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 cac08928..8a8d67f3 100755
--- a/tests/omod-if-array.sh
+++ b/tests/omod-if-array.sh
@@ -1 +1,5 @@
-./udptester omod-if-array
+#!/bin/bash -e
+echo test omod-if-array via udp
+./nettester omod-if-array udp
+echo test omod-if-array via tcp
+./nettester omod-if-array tcp
diff --git a/tests/parsertest.sh b/tests/parsertest.sh
index e7985bb0..fabe7e8d 100755
--- a/tests/parsertest.sh
+++ b/tests/parsertest.sh
@@ -1 +1,5 @@
-./udptester parse1
+#!/bin/bash -e
+echo test parsertest via udp
+./nettester parse1 udp
+echo test parsertest via tcp
+./nettester parse1 tcp
diff --git a/tests/testsuites/omod-if-array.conf b/tests/testsuites/omod-if-array.conf
index e6c05a52..d88db166 100644
--- a/tests/testsuites/omod-if-array.conf
+++ b/tests/testsuites/omod-if-array.conf
@@ -3,8 +3,7 @@
# the testbench, so we do not need to focus on that)
# rgerhards, 2009-04-03
$ModLoad ../plugins/omstdout/.libs/omstdout
-$ModLoad ../plugins/imudp/.libs/imudp
-$UDPServerRun 12514
+$IncludeConfig nettest.input.conf # This picks the to be tested input from the test driver!
$ActionOMStdoutArrayInterface on
$ErrorMessagesToStderr off
diff --git a/tests/testsuites/parse1.conf b/tests/testsuites/parse1.conf
index 0fb7d16d..947a05a8 100644
--- a/tests/testsuites/parse1.conf
+++ b/tests/testsuites/parse1.conf
@@ -1,6 +1,5 @@
$ModLoad ../plugins/omstdout/.libs/omstdout
-$ModLoad ../plugins/imudp/.libs/imudp
-$UDPServerRun 12514
+$IncludeConfig nettest.input.conf # This picks the to be tested input from the test driver!
$ErrorMessagesToStderr off