Skip to content

Commit 70fb97c

Browse files
author
Geoffrey Broadwell
committed
Add diagnose_capture() to provide a unified way to diagnose failures in test runs
1 parent 997c920 commit 70fb97c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

timeall

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,47 @@ sub time_command {
486486
return \@times;
487487
}
488488

489+
sub diagnose_capture {
490+
my ($out, $err, $status, $expected) = @_;
491+
492+
my $failed = 0;
493+
my $reason = '';
494+
495+
if ($out =~ /Segmentation/i || $err =~ /Segmentation/i) {
496+
$failed = 1;
497+
$reason = 'segfaulted';
498+
}
499+
elsif ($status) {
500+
$failed = 1;
501+
if ($status < 0) {
502+
$reason = 'failed to spawn';
503+
}
504+
elsif (my $signal = $status & 127) {
505+
$reason = "received signal $signal";
506+
507+
# Handle SIGINT specially as it indicates user intervention
508+
if ($signal == 2) {
509+
$failed = -1;
510+
$reason = 'terminated by SIGINT';
511+
}
512+
}
513+
else {
514+
my $exit = $status >> 8;
515+
$reason = "exited with exit status $exit";
516+
}
517+
}
518+
elsif (length $err) {
519+
$failed = 1;
520+
$reason = 'wrote to STDERR';
521+
}
522+
elsif (defined $expected && $expected ne $out) {
523+
$failed = 1;
524+
$reason = 'did not produce expected output';
525+
}
526+
527+
return ($failed, $reason);
528+
}
529+
489530
sub min_by(&@) {
490531
my $code = shift;
491532

0 commit comments

Comments
 (0)