tests: Accommodate c-tap-harness 4.7
[openafs.git] / tests / opr / softsig-t
index 58c7a61..d750d98 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
 #
 # Copyright (c) 2010 Your File System Inc. All rights reserved.
 #
@@ -28,12 +28,29 @@ use Test::More tests => 11;
 use IO::File;
 use POSIX qw(:signal_h);
 use File::Temp;
+use FindBin qw($Bin);
 
 # Start up our test process, and send it various signals. Check that these
 # signals make it to it correctly, and are reported on the command line.
 
-my $pid=open(HELPER, "./softsig-helper |")
-    or die "Couldn't start test helper.";
+my $softsig_helper;
+
+# Our softsig helper should be in $TOP_OBJDIR/tests/opr. To calculate that
+# path, use the C_TAP_BUILD env var if the test harness has set it; otherwise,
+# our next best guess is that it's in the same dir as this script.
+if (defined($ENV{C_TAP_BUILD})) {
+    $softsig_helper = $ENV{C_TAP_BUILD} . "/opr/softsig-helper";
+} else {
+    $softsig_helper = $Bin . "/softsig-helper";
+}
+
+# This -dummy argument prevents Perl from putting an intermediate sh
+# -c between us and softsig-helper in the case where the build
+# directory happens to contain shell metacharacters, like the ~ in
+# /build/openafs-vb8tid/openafs-1.8.0~pre1 used by the Debian
+# builders.
+my $pid = open(HELPER, "-|", $softsig_helper, "-dummy")
+  or die "Couldn't start test helper.";
 
 # Wait for softsig to start up.
 is(<HELPER>, "Ready\n");
@@ -70,17 +87,24 @@ is($?, SIGKILL, "Helper exited on KILL signal.");
 
 # Check that an internal segmentation fault kills the process.
 
-$pid = open(HELPER, "./softsig-helper -crash |")
+$pid = open(HELPER, "-|", $softsig_helper, "-crash")
     or die "Couldn't start test helper.";
 close(HELPER);
 is($? & 0x7f, SIGSEGV, "Helper exited on SEGV signal.");
 
 # Check that an internal bus error kills the process.
-
-my ($fh, $path) = mkstemp("/tmp/softsig-t_XXXXXX");
-$pid = open(HELPER, "./softsig-helper -buserror $path |")
-    or die "Couldn't start test helper.";
-close(HELPER);
-is($? & 0x7f, SIGBUS, "Helper exited on BUS signal.");
-$fh->close;
-unlink $path;
+# Skip this test when running on ancient versions of Perl
+# which do not have SIGBUS defined.
+SKIP: {
+    my $sigbus = eval "SIGBUS";
+    skip("Skipping buserror test; SIGBUS constant is not defined.", 1) unless $sigbus;
+    skip("Skipping buserror test; test unreliable on FreeBSD.", 1) if ($^O eq 'freebsd');
+
+    my ($fh, $path) = mkstemp("/tmp/softsig-t_XXXXXX");
+    $pid = open(HELPER, "-|", $softsig_helper, "-buserror", $path)
+        or die "Couldn't start test helper.";
+    close(HELPER);
+    is($? & 0x7f, $sigbus, "Helper exited on BUS signal.");
+    $fh->close;
+    unlink $path;
+}