mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-13 04:50:41 +01:00
begun building a testbench
This commit is contained in:
parent
fa3451aaa4
commit
4f32b62990
@ -50,7 +50,7 @@ EXTRA_DIST = \
|
||||
contrib/gnutls/cert.pem \
|
||||
contrib/gnutls/key.pem
|
||||
|
||||
SUBDIRS = doc runtime .
|
||||
SUBDIRS = doc tests runtime .
|
||||
|
||||
SUBDIRS += plugins/immark plugins/imuxsock plugins/imtcp plugins/imudp plugins/omtesting
|
||||
|
||||
|
||||
@ -623,6 +623,7 @@ AM_CONDITIONAL(ENABLE_IMTEMPLATE, test x$enable_imtemplate = xyes)
|
||||
AC_CONFIG_FILES([Makefile \
|
||||
runtime/Makefile \
|
||||
tools/Makefile \
|
||||
tests/Makefile \
|
||||
doc/Makefile \
|
||||
plugins/imudp/Makefile \
|
||||
plugins/imtcp/Makefile \
|
||||
|
||||
@ -14,6 +14,8 @@ librsyslog_la_SOURCES = \
|
||||
nsd.h \
|
||||
glbl.h \
|
||||
glbl.c \
|
||||
conf.c \
|
||||
conf.h \
|
||||
msg.c \
|
||||
msg.h \
|
||||
linkedlist.c \
|
||||
@ -63,7 +65,23 @@ librsyslog_la_SOURCES = \
|
||||
queue.c \
|
||||
queue.h \
|
||||
cfsysline.c \
|
||||
cfsysline.h
|
||||
cfsysline.h \
|
||||
\
|
||||
\
|
||||
../action.h \
|
||||
../action.c \
|
||||
../threads.c \
|
||||
../threads.h \
|
||||
\
|
||||
../parse.c \
|
||||
../parse.h \
|
||||
\
|
||||
../outchannel.c \
|
||||
../outchannel.h \
|
||||
../template.c \
|
||||
../template.h
|
||||
# the files with ../ we need to work on - so that they either become part of the
|
||||
# runtime or will no longer be needed. -- rgerhards, 2008-06-13
|
||||
|
||||
librsyslog_la_CPPFLAGS = -D_PATH_MODDIR=\"$(pkglibdir)/\" -I$(top_srcdir) $(pthreads_cflags)
|
||||
#librsyslog_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
@ -7,6 +7,11 @@
|
||||
* kept in memory only as long as the config file is actually being
|
||||
* processed. Thereafter, it shall be unloaded. -- rgerhards
|
||||
*
|
||||
* TODO: the license MUST be changed to LGPL. However, we can not
|
||||
* currently do that, because we use some sysklogd code to crunch
|
||||
* the selector lines (e.g. *.info). That code is scheduled for removal
|
||||
* as part of RainerScript. After this is done, we can change licenses.
|
||||
*
|
||||
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
|
||||
*
|
||||
* This file is part of rsyslog.
|
||||
@ -45,7 +50,7 @@
|
||||
#endif
|
||||
|
||||
#include "rsyslog.h"
|
||||
#include "syslogd.h" /* this actually *is* part of the syslogd! */
|
||||
#include "../tools/syslogd.h" /* TODO: this must be removed! */
|
||||
#include "dirty.h"
|
||||
#include "parse.h"
|
||||
#include "action.h"
|
||||
@ -130,7 +130,7 @@ ctokSkipWhitespaceFromStream(ctok_t *pThis)
|
||||
/* we must unget the one non-whitespace we found */
|
||||
CHKiRet(ctokUngetCharFromStream(pThis, c));
|
||||
|
||||
dbgprintf("skipped whitepsace, stream now '%s'\n", pThis->pp);
|
||||
dbgprintf("skipped whitespace, stream now '%s'\n", pThis->pp);
|
||||
finalize_it:
|
||||
RETiRet;
|
||||
}
|
||||
@ -390,6 +390,7 @@ ctokGetToken(ctok_t *pThis, ctok_token_t **ppToken)
|
||||
uchar szWord[128];
|
||||
int bRetry = 0; /* retry parse? Only needed for inline comments... */
|
||||
|
||||
dbgprintf("ctokGetToken\n");
|
||||
ISOBJ_TYPE_assert(pThis, ctok);
|
||||
ASSERT(ppToken != NULL);
|
||||
|
||||
@ -408,6 +409,7 @@ ctokGetToken(ctok_t *pThis, ctok_token_t **ppToken)
|
||||
|
||||
/* find the next token. We may loop when we have inline comments */
|
||||
do {
|
||||
dbgprintf("we search for a new token\n");
|
||||
bRetry = 0;
|
||||
CHKiRet(ctokSkipWhitespaceFromStream(pThis));
|
||||
CHKiRet(ctokGetCharFromStream(pThis, &c)); /* read a charater */
|
||||
@ -514,6 +516,7 @@ ctokGetToken(ctok_t *pThis, ctok_token_t **ppToken)
|
||||
pToken->tok = ctok_FUNCTION;
|
||||
// TODO: fill function name
|
||||
} else { /* give up... */
|
||||
dbgprintf("parser has an invalid word (token) '%s'\n", szWord);
|
||||
pToken->tok = ctok_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,9 @@
|
||||
* a module provides multiple types, several separate modules must be created which
|
||||
* then should share a single library containing the majority of code. This macro
|
||||
* must be present in each module. -- rgerhards, 2007-12-14
|
||||
* Note that MODULE_TYPE_TESTBENCH is reserved for testbenches, but
|
||||
* declared in their own header files (because the rest does not need these
|
||||
* defines). -- rgerhards, 2008-06-13
|
||||
*/
|
||||
#define MODULE_TYPE(x)\
|
||||
static rsRetVal modGetType(eModType_t *modType) \
|
||||
@ -65,6 +68,7 @@ static rsRetVal modGetType(eModType_t *modType) \
|
||||
DEF_LMOD_STATIC_DATA \
|
||||
MODULE_TYPE(eMOD_LIB)
|
||||
|
||||
|
||||
/* macro to define a unique module id. This must be able to fit in a void*. The
|
||||
* module id must be unique inside a running rsyslogd application. It is used to
|
||||
* track ownership of several objects. Most importantly, when the module is
|
||||
|
||||
14
tests/Makefile.am
Normal file
14
tests/Makefile.am
Normal file
@ -0,0 +1,14 @@
|
||||
check_PROGRAMS = rt_init rscript_parse
|
||||
TESTS = $(check_PROGRAMS)
|
||||
|
||||
test_files = testbench.h runtime-dummy.c
|
||||
|
||||
rt_init_SOURCES = rt-init.c $(test_files)
|
||||
rt_init_CPPFLAGS = -I$(top_srcdir) $(pthreads_cflags) $(rsrt_cflags)
|
||||
rt_init_LDADD = $(rsrt_libs) $(zlib_libs) $(pthreads_libs)
|
||||
rt_init_LDFLAGS = -export-dynamic
|
||||
|
||||
rscript_parse_SOURCES = rscript-parse.c $(test_files)
|
||||
rscript_parse_CPPFLAGS = -I$(top_srcdir) $(pthreads_cflags) $(rsrt_cflags)
|
||||
rscript_parse_LDADD = $(rsrt_libs) $(zlib_libs) $(pthreads_libs)
|
||||
rscript_parse_LDFLAGS = -export-dynamic
|
||||
9
tests/README
Normal file
9
tests/README
Normal file
@ -0,0 +1,9 @@
|
||||
This directory contains the rsyslog testbench. It is slowly
|
||||
evolving. New tests are always welcome. So far, most tests check
|
||||
out the functionality of a single module. More complex tests are
|
||||
welcome.
|
||||
|
||||
For a simple sample, see rtinit.c, which does a simple
|
||||
init/deinit check of the runtime system.
|
||||
|
||||
rgerhards, 2008-06-13
|
||||
90
tests/rscript-parse.c
Normal file
90
tests/rscript-parse.c
Normal file
@ -0,0 +1,90 @@
|
||||
/* This test checks runtime initialization and exit. Other than that, it
|
||||
* also serves as the most simplistic sample of how a test can be coded.
|
||||
*
|
||||
* Part of the testbench for rsyslog.
|
||||
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
|
||||
*
|
||||
* This file is part of rsyslog.
|
||||
*
|
||||
* Rsyslog is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Rsyslog is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* A copy of the GPL can be found in the file "COPYING" in this distribution.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "rsyslog.h"
|
||||
#include "testbench.h"
|
||||
#include "ctok.h"
|
||||
#include "expr.h"
|
||||
|
||||
MODULE_TYPE_TESTBENCH
|
||||
/* define addtional objects we need for our tests */
|
||||
DEFobjCurrIf(expr)
|
||||
DEFobjCurrIf(ctok)
|
||||
DEFobjCurrIf(ctok_token)
|
||||
|
||||
BEGINInit
|
||||
CODESTARTInit
|
||||
pErrObj = "expr"; CHKiRet(objUse(expr, CORE_COMPONENT));
|
||||
pErrObj = "ctok"; CHKiRet(objUse(ctok, CORE_COMPONENT));
|
||||
pErrObj = "ctok_token"; CHKiRet(objUse(ctok_token, CORE_COMPONENT));
|
||||
ENDInit
|
||||
|
||||
BEGINExit
|
||||
CODESTARTExit
|
||||
ENDExit
|
||||
|
||||
BEGINTest
|
||||
ctok_t *tok;
|
||||
ctok_token_t *pToken;
|
||||
expr_t *pExpr;
|
||||
/* the string below is an expression as defined up to 3.19.x - note that the
|
||||
* then and the space after it MUST be present!
|
||||
*/
|
||||
uchar szExpr[] = "$msg contains 'test' then ";
|
||||
/*uchar szSynErr[] = "$msg == 1 and syntaxerror ";*/
|
||||
CODESTARTTest
|
||||
/* we first need a tokenizer... */
|
||||
CHKiRet(ctok.Construct(&tok));
|
||||
CHKiRet(ctok.Setpp(tok, szExpr));
|
||||
CHKiRet(ctok.ConstructFinalize(tok));
|
||||
|
||||
/* now construct our expression */
|
||||
CHKiRet(expr.Construct(&pExpr));
|
||||
CHKiRet(expr.ConstructFinalize(pExpr));
|
||||
|
||||
/* ready to go... */
|
||||
CHKiRet(expr.Parse(pExpr, tok));
|
||||
|
||||
/* we now need to parse off the "then" - and note an error if it is
|
||||
* missing...
|
||||
*/
|
||||
CHKiRet(ctok.GetToken(tok, &pToken));
|
||||
if(pToken->tok != ctok_THEN) {
|
||||
ctok_token.Destruct(&pToken);
|
||||
ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
|
||||
}
|
||||
|
||||
ctok_token.Destruct(&pToken); /* no longer needed */
|
||||
|
||||
/* we are done, so we now need to restore things */
|
||||
CHKiRet(ctok.Destruct(&tok));
|
||||
finalize_it:
|
||||
/* here we may do custom error reporting */
|
||||
if(iRet != RS_RET_OK) {
|
||||
uchar *pp;
|
||||
ctok.Getpp(tok, &pp);
|
||||
printf("error on or before '%s'\n", pp);
|
||||
}
|
||||
ENDTest
|
||||
44
tests/rt-init.c
Normal file
44
tests/rt-init.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* This test checks runtime initialization and exit. Other than that, it
|
||||
* also serves as the most simplistic sample of how a test can be coded.
|
||||
*
|
||||
* Part of the testbench for rsyslog.
|
||||
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
|
||||
*
|
||||
* This file is part of rsyslog.
|
||||
*
|
||||
* Rsyslog is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Rsyslog is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* A copy of the GPL can be found in the file "COPYING" in this distribution.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "rsyslog.h"
|
||||
#include "testbench.h"
|
||||
|
||||
MODULE_TYPE_TESTBENCH
|
||||
|
||||
|
||||
BEGINInit
|
||||
CODESTARTInit
|
||||
ENDInit
|
||||
|
||||
BEGINExit
|
||||
CODESTARTExit
|
||||
ENDExit
|
||||
|
||||
BEGINTest
|
||||
CODESTARTTest
|
||||
finalize_it:
|
||||
/* room for custom error reporter, leave blank if not needed */
|
||||
ENDTest
|
||||
41
tests/runtime-dummy.c
Normal file
41
tests/runtime-dummy.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* Testbench for rsyslog
|
||||
*
|
||||
* This are dummy calls for "runtime" routines which are not yet properly
|
||||
* abstracted and part of the actual runtime libraries. This module tries
|
||||
* to make the linker happy. Please note that it does NOT provide anything
|
||||
* more but the symbols. If a test requires these functions (or functions
|
||||
* that depend on them), this dummy can not be used.
|
||||
*
|
||||
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
|
||||
*
|
||||
* This file is part of rsyslog.
|
||||
*
|
||||
* Rsyslog is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Rsyslog is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* A copy of the GPL can be found in the file "COPYING" in this distribution.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
int bReduceRepeatMsgs = 0;
|
||||
int repeatinterval = 30;
|
||||
int bActExecWhenPrevSusp = 0;
|
||||
int iActExecOnceInterval = 1;
|
||||
int MarkInterval = 30;
|
||||
|
||||
void cflineClassic(void) {};
|
||||
void selectorAddList(void) {};
|
||||
void selectorConstruct(void) {};
|
||||
void selectorDestruct(void) {};
|
||||
|
||||
/* these are required by some dynamically loaded modules */
|
||||
102
tests/testbench.h
Normal file
102
tests/testbench.h
Normal file
@ -0,0 +1,102 @@
|
||||
/* Defines for a rsyslog standard testbench application.
|
||||
*
|
||||
* Work begun 2008-06-13 by Rainer Gerhards (written from scratch)
|
||||
*
|
||||
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
|
||||
*
|
||||
* This file is part of rsyslog.
|
||||
*
|
||||
* Rsyslog is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Rsyslog is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* A copy of the GPL can be found in the file "COPYING" in this distribution.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
|
||||
/* everything we need to begin a testbench */
|
||||
#define MODULE_TYPE_TESTBENCH \
|
||||
/* definitions for objects we access */ \
|
||||
DEFobjCurrIf(obj) \
|
||||
\
|
||||
static rsRetVal doInit(void); \
|
||||
static rsRetVal doTest(void); \
|
||||
static rsRetVal doExit(void); \
|
||||
\
|
||||
/* Below is the driver, which is always the same */ \
|
||||
int main(int __attribute__((unused)) argc, char __attribute__((unused)) *argv[]) \
|
||||
{ \
|
||||
DEFiRet; \
|
||||
CHKiRet(doInit()); \
|
||||
CHKiRet(doTest()); \
|
||||
CHKiRet(doExit()); \
|
||||
finalize_it: \
|
||||
printf("test returns iRet %d\n", iRet); \
|
||||
RETiRet; \
|
||||
}
|
||||
|
||||
|
||||
/* Initialize everything (most importantly the runtime objects) for the test. The framework
|
||||
* initializes the global runtime, user must add those objects that it needs additionally.
|
||||
*/
|
||||
#define BEGINInit \
|
||||
static rsRetVal doInit(void) \
|
||||
{ \
|
||||
DEFiRet; \
|
||||
char *pErrObj; /* tells us which object failed if that happens */ \
|
||||
putenv("RSYSLOG_MODDIR=../runtime/.libs/"); /* this is a bit hackish... */ \
|
||||
\
|
||||
dbgClassInit(); \
|
||||
/* Intialize the runtime system */ \
|
||||
pErrObj = "rsyslog runtime"; /* set in case the runtime errors before setting an object */ \
|
||||
CHKiRet(rsrtInit(&pErrObj, &obj)); \
|
||||
|
||||
#define CODESTARTInit
|
||||
|
||||
#define ENDInit \
|
||||
finalize_it: \
|
||||
if(iRet != RS_RET_OK) { \
|
||||
printf("failure occured during init of object '%s'\n", pErrObj); \
|
||||
} \
|
||||
\
|
||||
RETiRet; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Carry out the actual test...
|
||||
*/
|
||||
#define BEGINTest \
|
||||
rsRetVal doTest(void) \
|
||||
{ \
|
||||
DEFiRet;
|
||||
|
||||
#define CODESTARTTest
|
||||
|
||||
#define ENDTest \
|
||||
RETiRet; \
|
||||
}
|
||||
|
||||
|
||||
/* De-init everything (most importantly the runtime objects) for the test. */
|
||||
#define BEGINExit \
|
||||
rsRetVal doExit(void) \
|
||||
{ \
|
||||
DEFiRet; \
|
||||
CHKiRet(rsrtExit());
|
||||
|
||||
#define CODESTARTExit
|
||||
|
||||
#define ENDExit \
|
||||
finalize_it: \
|
||||
RETiRet; \
|
||||
}
|
||||
@ -20,22 +20,7 @@ rsyslogd_SOURCES = \
|
||||
pidfile.c \
|
||||
pidfile.h \
|
||||
\
|
||||
../dirty.h \
|
||||
\
|
||||
../action.h \
|
||||
../action.c \
|
||||
../threads.c \
|
||||
../threads.h \
|
||||
\
|
||||
../parse.c \
|
||||
../parse.h \
|
||||
\
|
||||
../outchannel.c \
|
||||
../outchannel.h \
|
||||
../template.c \
|
||||
../template.h \
|
||||
../conf.c \
|
||||
../conf.h
|
||||
../dirty.h
|
||||
|
||||
rsyslogd_CPPFLAGS = $(pthreads_cflags) $(rsrt_cflags)
|
||||
rsyslogd_LDADD = $(zlib_libs) $(pthreads_libs) $(rsrt_libs)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user