From: Eric Bollengier Date: Mon, 28 Sep 2009 14:44:46 +0000 (+0200) Subject: regress: Replace some awk by perl for Solaris X-Git-Tag: Release-7.0.0~2616^2~7 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b329ff9857b84dbfcce6c69fdb7b3e722ab04f4f;p=bacula%2Fbacula regress: Replace some awk by perl for Solaris --- diff --git a/regress/scripts/functions.pm b/regress/scripts/functions.pm index 57fb3629b5..f14817fcf2 100644 --- a/regress/scripts/functions.pm +++ b/regress/scripts/functions.pm @@ -33,10 +33,14 @@ use strict; =cut package scripts::functions; + +# Export all functions needed to be used by a simple +# perl -Mscripts::functions -e '' script use Exporter; our @ISA = qw(Exporter); -our @EXPORT = qw(update_some_files create_many_files); +our @EXPORT = qw(update_some_files create_many_files detect_multiple_copies); +# open a directory and update all files sub update_some_files { my ($dest)=@_; @@ -58,6 +62,11 @@ sub update_some_files print "$nb files updated\n"; } +# create big number of files in a given directory +# Inputs: dest destination directory +# nb number of file to create +# Example: +# perl -Mscripts::functions -e 'create_many_files("$cwd/files", 100000)' sub create_many_files { my ($dest, $nb) = @_; @@ -65,7 +74,7 @@ sub create_many_files my $dir=$dest; $nb = $nb || 750000; mkdir $dest; - $base = chr($nb % 26 + 65); + $base = chr($nb % 26 + 65); # We use a base directory A-Z # already done if (-f "$dest/$base/a${base}a750000aaa$base") { @@ -99,4 +108,56 @@ sub create_many_files print "\n"; } +# This test ensure that 'list copies' displays only each copy one time +# +# Input: read stream from stdin or with file list argument +# check the number of copies with the ARGV[1] +# Output: exit(1) if something goes wrong and print error +sub check_multiple_copies +{ + my ($nb_to_found) = @_; + + my $in_list_copies=0; # are we or not in a list copies block + my $nb_found=0; # count the number of copies found + my $ret = 0; + my %seen; + + while (my $l = <>) # read all files to check + { + if ($l =~ /list copies/) { + $in_list_copies=1; + %seen = (); + next; + } + + # not in a list copies anymore + if ($in_list_copies && $l =~ /^ /) { + $in_list_copies=0; + next; + } + + # list copies ouput: + # | 3 | Backup.2009-09-28 | 9 | DiskChangerMedia | + if ($in_list_copies && $l =~ /^\|\s+\d+/) { + my (undef, $jobid, undef, $copyid, undef) = split(/\s*\|\s*/, $l); + if (exists $seen{$jobid}) { + print "ERROR: $jobid/$copyid already known as $seen{$jobid}\n"; + $ret = 1; + } else { + $seen{$jobid}=$copyid; + $nb_found++; + } + } + } + + # test the number of copies against the given arg + if ($nb_to_found && ($nb_to_found != $nb_found)) { + print "ERROR: Found wrong number of copies ", + "($nb_to_found != $nb_found)\n"; + exit 1; + } + + exit $ret; +} + 1; diff --git a/regress/tests/copy-uncopied-test b/regress/tests/copy-uncopied-test index 07e535c37b..ce92667cc0 100755 --- a/regress/tests/copy-uncopied-test +++ b/regress/tests/copy-uncopied-test @@ -103,54 +103,17 @@ rstat=0 dstat=0 zstat=0 -for i in tmp/log1[0-9].out; do - awk -F '|' ' - /list copies/ { ok=1; delete already } - /^[|][ ]+[0-9]+/ { - if (ok) { - jobid=$2 - copyid=$4 +perl -Mscripts::functions -e 'check_multiple_copies(3)' tmp/log11.out +bstat=`expr $bstat + $?` - if (already[jobid]) { - print "ERROR: " jobid " " copyid " " already[jobid] - } else { - print "OK: " jobid " " copyid - } +perl -Mscripts::functions -e 'check_multiple_copies(3)' tmp/log12.out +bstat=`expr $bstat + $?` - already[jobid]=copyid - } -}' $i > $i.result -done +perl -Mscripts::functions -e 'check_multiple_copies(2)' tmp/log13.out +bstat=`expr $bstat + $?` -grep ERROR tmp/log*result -if [ $? -eq 0 ]; then - print_debug "Found multiple copies" - bstat=2 -fi - -n=`wc -l tmp/log11.out.result | awk '{ print $1 }'` -if [ $n -ne 3 ]; then - print_debug "log11: Bad copies number" - bstat=3 -fi - -n=`wc -l tmp/log12.out.result| awk '{ print $1 }'` -if [ $n -ne 3 ]; then - print_debug "log12: Bad copies number" - bstat=3 -fi - -n=`wc -l tmp/log13.out.result| awk '{ print $1 }'` -if [ $n -ne 2 ]; then - print_debug "log13: Bad copies number" - bstat=3 -fi - -n=`wc -l tmp/log14.out.result| awk '{ print $1 }'` -if [ $n -ne 2 ]; then - print_debug "log14: Bad copies number" - bstat=3 -fi +perl -Mscripts::functions -e 'check_multiple_copies(2)' tmp/log14.out +bstat=`expr $bstat + $?` check_two_logs end_test