X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8cbf22c982842e3e988125fef8f898dec699097b..39206ce7634bcbb07c6b8ec500e8a01e601d70eb:/buildtools/Cmake/Scripts/tesh.pl diff --git a/buildtools/Cmake/Scripts/tesh.pl b/buildtools/Cmake/Scripts/tesh.pl index a5b53c437a..174245cf48 100755 --- a/buildtools/Cmake/Scripts/tesh.pl +++ b/buildtools/Cmake/Scripts/tesh.pl @@ -13,9 +13,11 @@ tesh -- testing shell B [I] I =cut -my($bindir); -my($srcdir); +my($bindir)="."; +my($srcdir)="."; +my($timeout)=0; my $path = $0; +my $OS; $path =~ s|[^/]*$||; push @INC,$path; @@ -24,14 +26,22 @@ use strict; use Term::ANSIColor; use IPC::Open3; -my($OS)=`echo %OS%`; -if($OS eq "%OS%"){ +if($^O eq "linux"){ $OS = "UNIX"; } else{ $OS = "WIN"; } + +sub trim($) +{ + my $string = shift; + $string =~ s/^\s+//; + $string =~ s/\s+$//; + return $string; +} + print "OS: ".$OS."\n"; # make sure we received a tesh file @@ -58,9 +68,19 @@ sub cd_cmd { } } +sub timeout_cmd{ + $timeout=$_[1]; +} + sub setenv_cmd { - if ($_[1] =~ /^(.*)=(.*)$/) { - my($var,$ctn)=($1,$2); + my($var,$ctn); + if ($_[0] =~ /^(.*)=(.*)$/) { + ($var,$ctn)=($1,$2); + }elsif ($_[1] =~ /^(.*)=(.*)$/) { + ($var,$ctn)=($1,$2); + } else { + die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$_[1]'\n"; + } if($var =~ /bindir/){ print "[Tesh/INFO] setenv $var=$ctn\n"; @@ -76,9 +96,6 @@ sub setenv_cmd { print "[Tesh/INFO] setenv $var=$ctn\n"; } } - } else { - die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$_[1]'\n"; - } } # Main option parsing sub @@ -108,6 +125,7 @@ sub get_options { 'debug|d' => \$opt{"debug"}, 'cd=s' => \&cd_cmd, + 'timeout=s' => \&timeout_cmd, 'setenv=s' => \&setenv_cmd, 'cfg=s' => \@cfg, 'log=s' => \$log, @@ -127,7 +145,6 @@ my %opts = get_options(@ARGV); ## my($sort)=0; my($nb_arg)=0; -my($timeout)=0; my($old_buffer); my($linebis); my($SIGABRT)=0; @@ -220,12 +237,25 @@ sub exec_cmd { my @got; while(defined(my $got=)) { $got =~ s/\r//g; - #$got =~ s/^( )*//g; + $got =~ s/^( )*//g; chomp $got; - push @got, "$got"; + $got=trim($got); + if( $got ne ""){ + push @got, "$got"; + } } close OUT; - + + if ($sort){ + sub mysort{ + $a cmp $b + } + use sort qw(defaults _quicksort); # force quicksort + @got = sort mysort @got; + #also resort the other one, as perl sort is not the same as the C one used to generate teshes + @{$cmd{'out'}}=sort mysort @{$cmd{'out'}}; + } + # Cleanup the executing child, and kill the timeouter brother on need $cmd{'return'} = 0 unless defined($cmd{'return'}); my $wantret = "returned code ".(defined($cmd{'return'})? $cmd{'return'} : 0); @@ -304,7 +334,10 @@ LINE: while (defined(my $line=)) { if ($cmd =~ /^#/) { #comment } elsif ($cmd eq '> '){ #expected result line print "[TESH/debug] push expected result\n" if $opts{'debug'}; - push @{$cmd{'out'}}, $arg; + $arg=trim($arg); + if($arg ne ""){ + push @{$cmd{'out'}}, $arg; + } } elsif ($cmd eq '< ') { # provided input print "[TESH/debug] push provided input\n" if $opts{'debug'}; @@ -346,6 +379,7 @@ LINE: while (defined(my $line=)) { $cmd{'cmd'} = $arg; } elsif($line =~ /^! output sort/){ #output sort + $sort=1; $cmd{'sort'} = 1; } elsif($line =~ /^! output ignore/){ #output ignore