mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
abort unit tests if a segfault ocurred and print a backtrace in that case
This commit is contained in:
1
tests/.gdb
Normal file
1
tests/.gdb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
bt
|
||||||
@@ -29,6 +29,9 @@ use Data::Dumper;
|
|||||||
|
|
||||||
sub run;
|
sub run;
|
||||||
sub execute;
|
sub execute;
|
||||||
|
sub final;
|
||||||
|
|
||||||
|
my $output;
|
||||||
|
|
||||||
my ($config, $check) = @ARGV;
|
my ($config, $check) = @ARGV;
|
||||||
if (! $config) {
|
if (! $config) {
|
||||||
@@ -103,18 +106,17 @@ sub runtest {
|
|||||||
$cfg->{input},
|
$cfg->{input},
|
||||||
\$out, \$error, 5, 0, undef);
|
\$out, \$error, 5, 0, undef);
|
||||||
|
|
||||||
my $output = $out . $error;
|
$output = $out . $error;
|
||||||
|
|
||||||
|
|
||||||
$output =~ s/^\s*//;
|
$output =~ s/^\s*//;
|
||||||
$output =~ s/\s*$//;
|
$output =~ s/\s*$//;
|
||||||
|
|
||||||
if (exists $cfg->{expect}) {
|
if (exists $cfg->{expect}) {
|
||||||
if ($cfg->{expect} =~ /^\//) {
|
if ($cfg->{expect} =~ /^\//) {
|
||||||
like($output, $cfg->{expect}, "$name") or return 0;
|
like($output, $cfg->{expect}, "$name") or return final 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
is($output, $cfg->{expect}, "$name") or return 0;
|
is($output, $cfg->{expect}, "$name") or return final 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +125,7 @@ sub runtest {
|
|||||||
if (-s $cfg->{"expect-file"}) {
|
if (-s $cfg->{"expect-file"}) {
|
||||||
$e = 1;
|
$e = 1;
|
||||||
}
|
}
|
||||||
is($e, 1, "$name") or return 0;
|
is($e, 1, "$name") or return final 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif (exists $cfg->{"expect-file-contains"}) {
|
elsif (exists $cfg->{"expect-file-contains"}) {
|
||||||
@@ -132,33 +134,52 @@ sub runtest {
|
|||||||
if (-s $file) {
|
if (-s $file) {
|
||||||
$e = 1;
|
$e = 1;
|
||||||
}
|
}
|
||||||
is($e, 1, "$name") or return 0;
|
is($e, 1, "$name") or return final 0;
|
||||||
if (open F, "<$file") {
|
if (open F, "<$file") {
|
||||||
my $content = join '', <F>;
|
my $content = join '', <F>;
|
||||||
close F;
|
close F;
|
||||||
like($content, qr/$expect/s, "$name") or return 0;
|
like($content, qr/$expect/s, "$name") or return final 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fail($test);
|
fail($test);
|
||||||
return 0;
|
return final 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif (exists $cfg->{exit}) {
|
elsif (exists $cfg->{exit}) {
|
||||||
is($ret, $cfg->{exit}, "$name") or return 0;
|
is($ret, $cfg->{exit}, "$name") or return final 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
diag("invalid test spec for $test");
|
diag("invalid test spec for $test");
|
||||||
fail($test);
|
fail($test);
|
||||||
return 0;
|
return final 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
|
return final 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
||||||
|
|
||||||
|
sub final {
|
||||||
|
my $ret = shift;
|
||||||
|
if ($output =~ /(segmentation fault|bus error)/i || -s "pcp1.core") {
|
||||||
|
# override $ret
|
||||||
|
$ret = 0;
|
||||||
|
diag("Abnormal program termination");
|
||||||
|
# if there is a coredump, extract a backtrace
|
||||||
|
if (-s "pcp1.core") {
|
||||||
|
# print a backtrace
|
||||||
|
system("gdb -x .gdb -batch $cfg{pcp} pcp1.core");
|
||||||
|
unlink "pcp1.core";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
# open3 wrapper. catch stderr, stdout, errno; add timeout and kill
|
# open3 wrapper. catch stderr, stdout, errno; add timeout and kill
|
||||||
my($cmd, $input, $output, $error, $timeout, $debug, $monitorfile) = @_;
|
my($cmd, $input, $output, $error, $timeout, $debug, $monitorfile) = @_;
|
||||||
|
|||||||
Reference in New Issue
Block a user