- if($timeout){kill(9, $forked);$timeout=0;}
- $timeout = 0;
-
- ###
- # Check the result of execution
- ###
- my $diff = build_diff(\@{$cmd{'out'}}, \@got);
- if (length $diff) {
- print color("red")."[TESH/CRITICAL$$] Output mismatch\n";
- map { print "[TESH/CRITICAL] $_\n" } split(/\n/,$diff);
- print color("reset");
- die "Tesh failed\n";
+ }
+
+
+ # pop all output from executing child
+ my @got;
+ while(defined(my $got=<OUT>)) {
+ $got =~ s/\r//g;
+ $got =~ s/^( )*//g;
+ chomp $got;
+ $got=trim($got);
+ if( $got ne ""){
+ if (!($enable_coverage and $got=~ /^profiling:/)){
+ push @got, "$got";
+ }
+ }
+ }
+ close OUT;
+
+ if ($cmd{'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
+ if(defined($cmd{'out'})){
+ @{$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;
+ if(defined($cmd{'expect'}) and ($cmd{'expect'} ne "")){
+ $wantret = "got signal $cmd{'expect'}";
+ }else{
+ $wantret = "returned code ".(defined($cmd{'return'})? $cmd{'return'} : 0);
+ $exitcode= 41;
+ }
+ my $gotret;
+ waitpid ($pid, 0);
+ $gotret = exit_status($?);
+ #Did we timeout ? If yes, handle it. If not, kill the forked process.
+
+ if($timeout==-1 and $gotret eq "got signal SIGKILL"){
+ $gotret="return code 0";
+ $timeout=1;
+ $gotret= "timeout after $time_to_wait sec";
+ $error=1;
+ $exitcode=3;
+ print STDERR "<$cmd{'file'}:$cmd{'line'}> timeouted. Kill the process.\n";
+ }else{
+ $timeout=0;
+ }
+ if($gotret ne $wantret) {
+ $error=1;
+ my $msg = "Test suite `$cmd{'file'}': NOK (<$cmd{'file'}:$cmd{'line'}> $gotret)\n";
+ if ($timeout!=1) {
+ $msg=$msg."Output of <$cmd{'file'}:$cmd{'line'}> so far:\n";