summaryrefslogtreecommitdiffstats
path: root/tests/parser.tcl
blob: 6b08717bade7b89d62df8b0dcc4aa7abc901064f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 };