mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-15 12:50:41 +01:00
improved testbench, added tests for tcp-based reception
This commit is contained in:
parent
a6c743e5ec
commit
8f8e2cd66b
@ -5,6 +5,7 @@ Version 4.1.7 [DEVEL] (rgerhards), 2009-03-??
|
|||||||
performance. This is also necessary towards the long-term goal
|
performance. This is also necessary towards the long-term goal
|
||||||
of loadable library modules.
|
of loadable library modules.
|
||||||
- added new RainerScript function "tolower"
|
- added new RainerScript function "tolower"
|
||||||
|
- improved testbench, added tests for tcp-based reception
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
Version 4.1.6 [DEVEL] (rgerhards), 2009-04-07
|
Version 4.1.6 [DEVEL] (rgerhards), 2009-04-07
|
||||||
- added new "csv" property replacer options to enable simple creation
|
- added new "csv" property replacer options to enable simple creation
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
TESTRUNS = rt_init rscript
|
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 = $(TESTRUNS) cfg.sh parsertest.sh omod-if-array.sh
|
||||||
TESTS_ENVIRONMENT = RSYSLOG_MODDIR='$(abs_top_builddir)'/runtime/.libs/
|
TESTS_ENVIRONMENT = RSYSLOG_MODDIR='$(abs_top_builddir)'/runtime/.libs/
|
||||||
DISTCLEANFILES=rsyslog.pid
|
DISTCLEANFILES=rsyslog.pid
|
||||||
@ -32,8 +32,8 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
|
|||||||
|
|
||||||
ourtail_SOURCES = ourtail.c
|
ourtail_SOURCES = ourtail.c
|
||||||
|
|
||||||
udptester_SOURCES = udptester.c getline.c
|
nettester_SOURCES = nettester.c getline.c
|
||||||
udptester_LDADD = $(SOL_LIBS)
|
nettester_LDADD = $(SOL_LIBS)
|
||||||
|
|
||||||
rt_init_SOURCES = rt-init.c $(test_files)
|
rt_init_SOURCES = rt-init.c $(test_files)
|
||||||
rt_init_CPPFLAGS = -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS)
|
rt_init_CPPFLAGS = -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS)
|
||||||
|
|||||||
@ -46,7 +46,12 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
#define EXIT_FAILURE 1
|
#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 *srcdir; /* global $srcdir, set so that we can run outside of "make check" */
|
||||||
static char *testSuite; /* name of current test suite */
|
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
|
/* send a message via UDP
|
||||||
* returns 0 if ok, something else otherwise.
|
* returns 0 if ok, something else otherwise.
|
||||||
*/
|
*/
|
||||||
@ -107,7 +165,7 @@ int openPipe(char *configFile, pid_t *pid, int *pfd)
|
|||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
pid_t cpid;
|
pid_t cpid;
|
||||||
char *newargv[] = {"../tools/rsyslogd", "dummy", "-c4", "-u2", "-n", "-irsyslog.pid",
|
char *newargv[] = {"../tools/rsyslogd", "dummy", "-c4", "-u2", "-n", "-irsyslog.pid",
|
||||||
"-M../runtime//.libs", NULL };
|
"-M../runtime/.libs:../.libs", NULL };
|
||||||
char confFile[1024];
|
char confFile[1024];
|
||||||
char *newenviron[] = { NULL };
|
char *newenviron[] = { NULL };
|
||||||
|
|
||||||
@ -173,9 +231,14 @@ processTestFile(int fd, char *pszFileName)
|
|||||||
|
|
||||||
|
|
||||||
testdata[strlen(testdata)-1] = '\0'; /* remove \n */
|
testdata[strlen(testdata)-1] = '\0'; /* remove \n */
|
||||||
/* now we have the test data to send */
|
/* now we have the test data to send (we could use function pointers here...) */
|
||||||
|
if(inputMode == inputUDP) {
|
||||||
if(udpSend(testdata, strlen(testdata)) != 0)
|
if(udpSend(testdata, strlen(testdata)) != 0)
|
||||||
return(2);
|
return(2);
|
||||||
|
} else {
|
||||||
|
if(tcpSend(testdata, strlen(testdata)) != 0)
|
||||||
|
return(2);
|
||||||
|
}
|
||||||
|
|
||||||
/* next line is expected output
|
/* next line is expected output
|
||||||
* we do not care about EOF here, this will lead to a failure and thus
|
* 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);
|
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
|
/* 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
|
* 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 main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
pid_t pid;
|
|
||||||
int status;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
FILE *fp;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
char testcases[4096];
|
char testcases[4096];
|
||||||
|
|
||||||
if(argc != 2) {
|
if(argc != 3) {
|
||||||
printf("Invalid call of udptester\n");
|
printf("Invalid call of nettester\n");
|
||||||
printf("Usage: udptester testsuite-name\n");
|
printf("Usage: nettester testsuite-name input\n");
|
||||||
|
printf(" input = udp|tcp\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atexit(doAtExit);
|
||||||
|
|
||||||
testSuite = argv[1];
|
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)
|
if((srcdir = getenv("srcdir")) == NULL)
|
||||||
srcdir = ".";
|
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);
|
||||||
|
|
||||||
openPipe(argv[1], &pid, &fd);
|
/* 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);
|
||||||
|
|
||||||
|
/* start to be tested rsyslogd */
|
||||||
|
openPipe(argv[1], &rsyslogdPid, &fd);
|
||||||
readLine(fd, buf);
|
readLine(fd, buf);
|
||||||
|
|
||||||
/* generate filename */
|
/* generate filename */
|
||||||
@ -285,9 +387,6 @@ int main(int argc, char *argv[])
|
|||||||
if(doTests(fd, testcases) != 0)
|
if(doTests(fd, testcases) != 0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
/* cleanup */
|
printf("End of nettester run (%d).\n", ret);
|
||||||
kill(pid, SIGTERM);
|
|
||||||
waitpid(pid, &status, 0); /* wait until instance terminates */
|
|
||||||
printf("End of udptester run.\n");
|
|
||||||
exit(ret);
|
exit(ret);
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
|
|||||||
@ -1 +1,5 @@
|
|||||||
./udptester parse1
|
#!/bin/bash -e
|
||||||
|
echo test parsertest via udp
|
||||||
|
./nettester parse1 udp
|
||||||
|
echo test parsertest via tcp
|
||||||
|
./nettester parse1 tcp
|
||||||
|
|||||||
@ -3,8 +3,7 @@
|
|||||||
# the testbench, so we do not need to focus on that)
|
# the testbench, so we do not need to focus on that)
|
||||||
# rgerhards, 2009-04-03
|
# rgerhards, 2009-04-03
|
||||||
$ModLoad ../plugins/omstdout/.libs/omstdout
|
$ModLoad ../plugins/omstdout/.libs/omstdout
|
||||||
$ModLoad ../plugins/imudp/.libs/imudp
|
$IncludeConfig nettest.input.conf # This picks the to be tested input from the test driver!
|
||||||
$UDPServerRun 12514
|
|
||||||
|
|
||||||
$ActionOMStdoutArrayInterface on
|
$ActionOMStdoutArrayInterface on
|
||||||
$ErrorMessagesToStderr off
|
$ErrorMessagesToStderr off
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
$ModLoad ../plugins/omstdout/.libs/omstdout
|
$ModLoad ../plugins/omstdout/.libs/omstdout
|
||||||
$ModLoad ../plugins/imudp/.libs/imudp
|
$IncludeConfig nettest.input.conf # This picks the to be tested input from the test driver!
|
||||||
$UDPServerRun 12514
|
|
||||||
|
|
||||||
$ErrorMessagesToStderr off
|
$ErrorMessagesToStderr off
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user