tests: Fix most tests for objdir builds
[openafs.git] / tests / opr / softsig-t
index a2e6fc9..09f4e50 100755 (executable)
@@ -32,9 +32,25 @@ 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 $softsig_helper = $Bin . "/softsig-helper";
-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 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{BUILD})) {
+    $softsig_helper = $ENV{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");
@@ -71,17 +87,23 @@ 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;
+
+    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;
+}