summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-03-26 15:30:46 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2009-03-26 15:30:46 +0100
commit5103c912eeb8c0d410f641a971d3687a02c8c02b (patch)
treed2a2012ebbdf274ca2337fff893511c9a0e8663e
parentc11b7ec7d6e6216481f28447b94e59e524dd824c (diff)
downloadrsyslog-5103c912eeb8c0d410f641a971d3687a02c8c02b.tar.gz
rsyslog-5103c912eeb8c0d410f641a971d3687a02c8c02b.tar.xz
rsyslog-5103c912eeb8c0d410f641a971d3687a02c8c02b.zip
parser test script created
more or less complete now, with some minor nits left for later but is usable.
-rw-r--r--tests/parser.tcl76
-rw-r--r--tests/test.tcl41
-rw-r--r--tests/testruns/parser.conf3
3 files changed, 78 insertions, 42 deletions
diff --git a/tests/parser.tcl b/tests/parser.tcl
new file mode 100644
index 00000000..274c08a3
--- /dev/null
+++ b/tests/parser.tcl
@@ -0,0 +1,76 @@
+# 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 test: $failed.\n";
diff --git a/tests/test.tcl b/tests/test.tcl
deleted file mode 100644
index 7f1b7a6b..00000000
--- a/tests/test.tcl
+++ /dev/null
@@ -1,41 +0,0 @@
-# rsyslog parser tests
-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;
-#puts "pid: $rsyslogdPID";
-#sleep 1;
-#expect "\n";
-expect "}}"; # eat startup message
-set udpSock [udp_open];
-udp_conf $udpSock 127.0.0.1 514
-set files [glob *.parse1]
-puts "done init\n";
-
-
-foreach testcase $files {
- puts "File $testcase";
- set fp [open "$testcase" r];
- fconfigure $fp -buffering line
- #set data [read $fp];
- #set data [split $data "\n"];
- gets $fp input
- puts "Line 1: $input\n";
-
- puts $udpSock $input;
- flush $udpSock;
-
-
- set i 1
- expect -re "{{.*}}";
- set result $expect_out(buffer);
-
- #puts "MSG $i: '$expect_out(buffer)'";
- puts "MSG $i: '$result'\n";
- set i [expr {$i + 1}];
-
-}
-
-exec kill $rsyslogdPID;
-close $udpSock;
diff --git a/tests/testruns/parser.conf b/tests/testruns/parser.conf
index a515ff6c..3558f143 100644
--- a/tests/testruns/parser.conf
+++ b/tests/testruns/parser.conf
@@ -6,5 +6,6 @@ $UDPServerRun 514
$ErrorMessagesToStderr off
# use a special format that we can easily parse in expect
-$template expect,"{{%PRI%,%syslogtag%,%hostname%}}"
+#$template expect,"{{%PRI%,%syslogtag%,%hostname%}}"
+$template expect,"{{%PRI%,%syslogfacility-text%,%syslogseverity-text%,%timestamp%,%hostname%,%programname%,%syslogtag%,%msg%}}"
*.* :omstdout:;expect