From 8b29aa06a65a7b772f20f0cdd201b2976ffcfd59 Mon Sep 17 00:00:00 2001 From: teastep Date: Sat, 8 Dec 2007 00:04:43 +0000 Subject: [PATCH] Implement regression testing git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@7859 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb --- Shorewall-common/shorewall | 5 ++++ Shorewall-perl/Shorewall/Compiler.pm | 15 ++++++---- Shorewall-perl/Shorewall/Config.pm | 4 +-- Shorewall-perl/compiler.pl | 6 +++- tools/testing/accepttest | 31 ++++++++++++++++++++ tools/testing/regression | 43 ++++++++++++++++++++++++++++ 6 files changed, 94 insertions(+), 10 deletions(-) create mode 100755 tools/testing/accepttest create mode 100755 tools/testing/regression diff --git a/Shorewall-common/shorewall b/Shorewall-common/shorewall index 9a2c27449..9bb016bef 100755 --- a/Shorewall-common/shorewall +++ b/Shorewall-common/shorewall @@ -383,6 +383,7 @@ compiler() { [ -n "$EXPORT" ] && options="$options --export" [ -n "$SHOREWALL_DIR" ] && options="$options --directory=$SHOREWALL_DIR" [ -n "$TIMESTAMP" ] && options="$options --timestamp" + [ -n "$TEST" ] && options="$options --test" [ "$debugging" = trace ] && options="$options --debug" [ -n "$REFRESHCHAINS" ] && options="$options --refresh=$REFRESHCHAINS" [ -x $pc ] || startup_error "SHOREWALL_COMPILER=perl requires the shorewall-perl package which is not installed" @@ -573,6 +574,10 @@ compile_command() { option= shift ;; + t*) + TEST=Yes + option=${option#t} + ;; d*) DEBUG=Yes; option=${option#d} diff --git a/Shorewall-perl/Shorewall/Compiler.pm b/Shorewall-perl/Shorewall/Compiler.pm index 0317dd91c..0d7dbd577 100644 --- a/Shorewall-perl/Shorewall/Compiler.pm +++ b/Shorewall-perl/Shorewall/Compiler.pm @@ -45,6 +45,8 @@ our $VERSION = 4.1.2; our $export; +our $test; + our $reused = 0; use constant { EXPORT => 0x01 , @@ -82,14 +84,13 @@ sub generate_script_1() { my $date = localtime; - if ( $config{COMPILER_TEST} ) { + if ( $test ) { emit "#!/bin/sh\n#\n# Compiled firewall script generated by Shorewall-perl\n#"; } else { emit "#!/bin/sh\n#\n# Compiled firewall script generated by Shorewall-perl $globals{VERSION} - $date\n#"; + copy $globals{SHAREDIRPL} . 'prog.header'; } - copy $globals{SHAREDIRPL} . 'prog.header'; - for my $exit qw/init isusable start tcclear started stop stopped clear refresh refreshed/ { emit "\nrun_${exit}_exit() {"; push_indent; @@ -144,7 +145,7 @@ sub generate_script_1() { qq([ -n "\${RESTOREFILE:=$config{RESTOREFILE}}" ]), '[ -n "$LOGFORMAT" ] || LOGFORMAT="Shorewall:%s:%s:"' ); - emit ( qq(VERSION="$globals{VERSION}") ) unless $config{COMPILER_TEST}; + emit ( qq(VERSION="$globals{VERSION}") ) unless $test; emit ( qq(PATH="$config{PATH}") , 'TERMINATOR=fatal_error' , @@ -508,7 +509,7 @@ EOF # sub generate_script_2 () { - copy $globals{SHAREDIRPL} . 'prog.functions'; + copy $globals{SHAREDIRPL} . 'prog.functions' unless $test; emit( '', '#', @@ -698,7 +699,7 @@ EOF emit "}\n"; - copy $globals{SHAREDIRPL} . 'prog.footer'; + copy $globals{SHAREDIRPL} . 'prog.footer' unless $test; } # @@ -712,6 +713,7 @@ sub compiler { ( '', '', -1, '', 0, '', '', -1 ); $export = 0; + $test = 0; sub edit_boolean( $ ) { my $val = numeric_value( shift ); @@ -732,6 +734,7 @@ sub compiler { chains => { store => \$chains }, log => { store => \$log }, log_verbosity => { store => \$log_verbosity, edit => \&edit_verbosity } , + test => { store => \$test }, ); while ( defined ( my $name = shift ) ) { diff --git a/Shorewall-perl/Shorewall/Config.pm b/Shorewall-perl/Shorewall/Config.pm index 255d1ff96..e7ec266f7 100644 --- a/Shorewall-perl/Shorewall/Config.pm +++ b/Shorewall-perl/Shorewall/Config.pm @@ -260,8 +260,7 @@ sub initialize() { # From shorewall.conf file # %config = - ( COMPILER_TEST => undef, - STARTUP_ENABLED => undef, + ( STARTUP_ENABLED => undef, VERBOSITY => undef, # # Logging @@ -1800,7 +1799,6 @@ sub get_configuration( $ ) { $config{LOG_VERBOSITY} = -1; } - default_yes_no 'COMPILER_TEST' , ''; default_yes_no 'ADD_IP_ALIASES' , 'Yes'; default_yes_no 'ADD_SNAT_ALIASES' , ''; default_yes_no 'DETECT_DNAT_IPADDRS' , ''; diff --git a/Shorewall-perl/compiler.pl b/Shorewall-perl/compiler.pl index 1e76ee577..709f346f1 100755 --- a/Shorewall-perl/compiler.pl +++ b/Shorewall-perl/compiler.pl @@ -54,6 +54,7 @@ sub usage( $ ) { [ --refresh= ] [ --log= ] [ --log-verbose={-1|0-2} ] + [ --test ] '; exit shift @_; } @@ -70,6 +71,7 @@ my $chains = ''; my $log = ''; my $log_verbose = 0; my $help = 0; +my $test = 0; Getopt::Long::Configure ('bundling'); @@ -89,6 +91,7 @@ my $result = GetOptions('h' => \$help, 'log=s' => \$log, 'l=s' => \$log, 'log_verbosity=i' => \$log_verbose, + 'test' => \$test, ); usage(1) unless $result && @ARGV < 2; @@ -102,4 +105,5 @@ compiler( object => defined $ARGV[0] ? $ARGV[0] : '', export => $export, chains => $chains, log => $log, - log_verbosity => $log_verbose ); + log_verbosity => $log_verbose, + test => $test ); diff --git a/tools/testing/accepttest b/tools/testing/accepttest new file mode 100755 index 000000000..41f86f4b1 --- /dev/null +++ b/tools/testing/accepttest @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Clear an exception on one or more regression tests -- (C) 2007, Tom Eastep (teastep@shorewall.net) +# +# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of Version 2 of the GNU General Public License +# as published by the Free Software Foundation. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# + +for directory in $*; do + if [ -d $directory ]; then + cp -f $directory/firewall $directory/firewall.last && echo "Test $directory ACCEPTED" + else + echo " WARNING: No directory named $directory" >&2 + fi +done + + + diff --git a/tools/testing/regression b/tools/testing/regression new file mode 100755 index 000000000..cf8d14f8c --- /dev/null +++ b/tools/testing/regression @@ -0,0 +1,43 @@ +#!/bin/sh +# +# Shorewall Compiler Positive Regression test driver -- (C) 2007, Tom Eastep (teastep@shorewall.net) +# +# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of Version 2 of the GNU General Public License +# as published by the Free Software Foundation. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# + +for directory in *; do + if [ -d $directory ]; then + if /sbin/shorewall -v2 compile -t $directory $directory/firewall > $directory/compileroutput 2> $directory/compilererrors; then + if [ -f $directory/firewall.last ]; then + if diff -au $directory/firewall.last $directory/firewall > $directory/compare; then + echo "Test $directory PASSED" + else + echo "Test $directory FAILED ********* Failure data is in $directory/compare" + fi + else + cp $directory/firewall $directory/firewall.last + echo "Test $directory INITIAL RUN" + fi + else + echo "Test $directory FAILED ********* Failure data is in $directory/compilererrors" + rm -f $directory/faildata + fi + fi +done + + +