diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 7 | ||||
-rw-r--r-- | tests/parser.tcl | 77 | ||||
-rwxr-xr-x | tests/parsertest | 2 | ||||
-rw-r--r-- | tests/testruns/1.parse1 | 3 | ||||
-rw-r--r-- | tests/testruns/parser.conf | 11 | ||||
-rw-r--r-- | tests/testruns/rfc3164.parse1 | 4 | ||||
-rw-r--r-- | tests/testruns/rfc5424-1.parse1 | 4 | ||||
-rw-r--r-- | tests/testruns/rfc5424-2.parse1 | 4 | ||||
-rw-r--r-- | tests/testruns/rfc5424-3.parse1 | 4 | ||||
-rw-r--r-- | tests/testruns/rfc5424-4.parse1 | 4 |
10 files changed, 118 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 7a31be45..225f087f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ check_PROGRAMS = rt_init rscript -TESTS = $(check_PROGRAMS) cfg.sh +TESTS = $(check_PROGRAMS) cfg.sh parsertest TESTS_ENVIRONMENT = RSYSLOG_MODDIR='$(abs_top_builddir)'/runtime/.libs/ #TESTS = $(check_PROGRAMS) @@ -16,7 +16,10 @@ EXTRA_DIST=1.rstest 2.rstest 3.rstest err1.rstest \ cfg4.testin \ DevNull.cfgtest \ err1.rstest \ - NoExistFile.cfgtest + NoExistFile.cfgtest \ + parsertest + parser.tcl + testruns/*.parser1 rt_init_SOURCES = rt-init.c $(test_files) rt_init_CPPFLAGS = -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS) diff --git a/tests/parser.tcl b/tests/parser.tcl new file mode 100644 index 00000000..6b08717b --- /dev/null +++ b/tests/parser.tcl @@ -0,0 +1,77 @@ +# rsyslog parser tests +# This is a first version, and can be extended and improved for +# sure. But it is far better than nothing. Please note that this +# script works together with the config file AND easily extensible +# test case files (*.parse1) to run a number of checks. All test +# cases are executed, even if there is a failure early in the +# process. When finished, the numberof failed tests will be given. +# +# Note: a lot of things are not elegant, but at least they work... +# Even simple things seem to be somewhat non-simple if you are +# not sufficiently involved with tcl/expect ;) -- rgerhards +# +# Copyright (C) 2009 by Rainer Gerhards and Adiscon GmbH +# +# This file is part of rsyslog. + + + +# HELP HELP HELP HELP HELP HELP HELP HELP +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# If you happen to know how to disable rsyslog's +# stdout from appearing on the "real" stdout, please +# let me know. This is annouying, but I have no more +# time left to invest finding a solution (as the +# rest basically works well...). +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +package require Expect +package require udp 1.0 + +set rsyslogdPID [spawn "../tools/rsyslogd" "-c4" "-ftestruns/parser.conf" "-u2" "-n" "-iwork/rsyslog.pid" "-M../runtime/.libs"]; +#interact; +expect "}}"; # eat startup message +set udpSock [udp_open]; +udp_conf $udpSock 127.0.0.1 514 +set files [glob "testruns/*.parse1"] +set failed 0; +puts "\n"; + +set i 1; + +foreach testcase $files { + puts "testing $testcase ..."; + set fp [open "$testcase" r]; + fconfigure $fp -buffering line + gets $fp input + gets $fp expected + # assemble "expected" to match the template we use + close $fp; + + # send to daemon + puts $udpSock $input; + flush $udpSock; + + # get response and compare + expect -re "{{.*}}"; + puts "\n"; # at least we make the output readbale... + + set result $expect_out(buffer); + set result [string trimleft $result "\{\{"]; + set result [string trimright $result "\}\}"]; + + if { $result != $expected } { + puts "test $i failed!\n"; + puts "expected: '$expected'\n"; + puts "returned: '$result'\n"; + puts "\n"; + set failed [expr {$failed + 1}]; + }; + set i [expr {$i + 1}]; +} + +exec kill $rsyslogdPID; +close $udpSock; + +puts "Number of failed tests: $failed.\n"; +if { $failed != 0 } { exit 1 }; diff --git a/tests/parsertest b/tests/parsertest new file mode 100755 index 00000000..78c42c07 --- /dev/null +++ b/tests/parsertest @@ -0,0 +1,2 @@ +# run parser test suite +tclsh parser.tcl diff --git a/tests/testruns/1.parse1 b/tests/testruns/1.parse1 new file mode 100644 index 00000000..5ae655e6 --- /dev/null +++ b/tests/testruns/1.parse1 @@ -0,0 +1,3 @@ +<167>Mar 6 16:57:54 172.20.245.8 %PIX-7-710005: UDP request discarded from SERVER1/2741 to test_app:255.255.255.255/61601 +167,local4,debug,Mar 6 16:57:54,172.20.245.8,%PIX-7-710005,%PIX-7-710005:, UDP request discarded from SERVER1/2741 to test_app:255.255.255.255/61601 +#Only the first two lines are important, you may place anything behind them! diff --git a/tests/testruns/parser.conf b/tests/testruns/parser.conf new file mode 100644 index 00000000..3558f143 --- /dev/null +++ b/tests/testruns/parser.conf @@ -0,0 +1,11 @@ +$ModLoad ../plugins/omstdout/.libs/omstdout +$ModLoad ../plugins/imuxsock/.libs/imuxsock +$ModLoad ../plugins/imudp/.libs/imudp +$UDPServerRun 514 + +$ErrorMessagesToStderr off + +# use a special format that we can easily parse in expect +#$template expect,"{{%PRI%,%syslogtag%,%hostname%}}" +$template expect,"{{%PRI%,%syslogfacility-text%,%syslogseverity-text%,%timestamp%,%hostname%,%programname%,%syslogtag%,%msg%}}" +*.* :omstdout:;expect diff --git a/tests/testruns/rfc3164.parse1 b/tests/testruns/rfc3164.parse1 new file mode 100644 index 00000000..e7a5fa18 --- /dev/null +++ b/tests/testruns/rfc3164.parse1 @@ -0,0 +1,4 @@ +<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8 +34,auth,crit,Oct 11 22:14:15,mymachine,su,su:, 'su root' failed for lonvick on /dev/pts/8 +#Example from RFC3164, section 5.4 +#Only the first two lines are important, you may place anything behind them! diff --git a/tests/testruns/rfc5424-1.parse1 b/tests/testruns/rfc5424-1.parse1 new file mode 100644 index 00000000..90236c7f --- /dev/null +++ b/tests/testruns/rfc5424-1.parse1 @@ -0,0 +1,4 @@ +<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8 +34,auth,crit,Oct 11 22:14:15,mymachine.example.com,,su,- BOM'su root' failed for lonvick on /dev/pts/8 +#Example from RFC5424, section 6.5 / sample 1 +#Only the first two lines are important, you may place anything behind them! diff --git a/tests/testruns/rfc5424-2.parse1 b/tests/testruns/rfc5424-2.parse1 new file mode 100644 index 00000000..a86fbc35 --- /dev/null +++ b/tests/testruns/rfc5424-2.parse1 @@ -0,0 +1,4 @@ +<165>1 2003-08-24T05:14:15.000003-07:00 192.0.2.1 myproc 8710 - - %% It's time to make the do-nuts. +165,local4,notice,Aug 24 05:14:15,192.0.2.1,,myproc[8710],- %% It's time to make the do-nuts. +#Example from RFC5424, section 6.5 / sample 2 +#Only the first two lines are important, you may place anything behind them! diff --git a/tests/testruns/rfc5424-3.parse1 b/tests/testruns/rfc5424-3.parse1 new file mode 100644 index 00000000..6ad4073d --- /dev/null +++ b/tests/testruns/rfc5424-3.parse1 @@ -0,0 +1,4 @@ +<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource= "Application" eventID="1011"][examplePriority@32473 class="high"] +165,local4,notice,Oct 11 22:14:15,mymachine.example.com,,evntslog, +#Example from RFC5424, section 6.5 / sample 4 +#Only the first two lines are important, you may place anything behind them! diff --git a/tests/testruns/rfc5424-4.parse1 b/tests/testruns/rfc5424-4.parse1 new file mode 100644 index 00000000..ecf27e14 --- /dev/null +++ b/tests/testruns/rfc5424-4.parse1 @@ -0,0 +1,4 @@ +<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource= "Application" eventID="1011"] BOMAn application event log entry... +165,local4,notice,Oct 11 22:14:15,mymachine.example.com,,evntslog,BOMAn application event log entry... +#Example from RFC5424, section 6.5 / sample 3 +#Only the first two lines are important, you may place anything behind them! |