2020-04-12 20:16:55 -05:00
|
|
|
#!/usr/bin/env perl
|
2012-03-23 21:26:14 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Your File System Inc. All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2020-12-28 13:12:59 -06:00
|
|
|
use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5";
|
|
|
|
|
|
|
|
use afstest qw(obj_path);
|
2012-03-23 21:26:14 +00:00
|
|
|
use Test::More tests => 11;
|
|
|
|
use IO::File;
|
|
|
|
use POSIX qw(:signal_h);
|
|
|
|
use File::Temp;
|
2015-08-06 11:53:23 -03:00
|
|
|
use FindBin qw($Bin);
|
2012-03-23 21:26:14 +00:00
|
|
|
|
|
|
|
# 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.
|
tests: Fix most tests for objdir builds
Fix a few miscellaneous issues with building and running our tests in
objdir builds:
- Our C tests use -I$(srcdir)/../.. in the CFLAGS, so we can #include
<tests/tap/basic.h>. However, basic.h actually gets copied from
src/external/c-tap-harness/tests/tap/ to tests/tap/ during the
build, and so basic.h is available in the objdir, not srcdir. For
objdir builds, this causes building the tests to fail with failing
to find basic.h. Fix this to use TOP_OBJDIR as the include path
instead.
- Our 'make check' in tests/ tries to run ./libwrap; but our cwd will
be in the objdir for objdir builds, and libwrap is a script in our
srcdir. Fix this to run libwrap from the srcdir path.
- In tests/opr/softsig-t, it tries to find the 'softsig-helper' binary
in the same dir as 'softsig-t'. However, softsig-t is just a script
in the srcdir, but softsig-helper is a binary built in the objdir.
Fix this to use the BUILD env var provided by the tests wrapper, by
default.
Change-Id: Iff642613bfc88d0d7e348660dc62f59e6fa8af75
Reviewed-on: https://gerrit.openafs.org/13939
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2019-11-11 20:34:07 -06:00
|
|
|
|
2020-12-28 13:12:59 -06:00
|
|
|
my $softsig_helper = obj_path("tests/opr/softsig-helper");
|
2016-12-14 15:47:21 -05:00
|
|
|
|
|
|
|
# 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.";
|
2012-03-23 21:26:14 +00:00
|
|
|
|
|
|
|
# Wait for softsig to start up.
|
|
|
|
is(<HELPER>, "Ready\n");
|
|
|
|
|
|
|
|
# Check that a load of common signals are correctly trapped.
|
|
|
|
|
|
|
|
kill 'INT', $pid;
|
|
|
|
is(<HELPER>, "Received INT\n");
|
|
|
|
|
|
|
|
kill 'HUP', $pid;
|
|
|
|
is(<HELPER>, "Received HUP\n");
|
|
|
|
|
|
|
|
kill 'QUIT', $pid;
|
|
|
|
is(<HELPER>, "Received QUIT\n");
|
|
|
|
|
|
|
|
kill 'ALRM', $pid;
|
|
|
|
is(<HELPER>, "Received ALRM\n");
|
|
|
|
|
|
|
|
kill 'TERM', $pid;
|
|
|
|
is(<HELPER>, "Received TERM\n");
|
|
|
|
|
|
|
|
kill 'USR1', $pid;
|
|
|
|
is(<HELPER>, "Received USR1\n");
|
|
|
|
|
|
|
|
kill 'USR2', $pid;
|
|
|
|
is(<HELPER>, "Received USR2\n");
|
|
|
|
|
|
|
|
|
|
|
|
# Check that we can actually stop the process with a kill.
|
|
|
|
|
|
|
|
kill 'KILL', $pid;
|
|
|
|
close(HELPER);
|
|
|
|
is($?, SIGKILL, "Helper exited on KILL signal.");
|
|
|
|
|
|
|
|
# Check that an internal segmentation fault kills the process.
|
|
|
|
|
2016-12-14 15:47:21 -05:00
|
|
|
$pid = open(HELPER, "-|", $softsig_helper, "-crash")
|
2012-03-23 21:26:14 +00:00
|
|
|
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.
|
2016-02-08 10:10:32 -05:00
|
|
|
# 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;
|
2020-04-12 22:28:29 -05:00
|
|
|
skip("Skipping buserror test; test unreliable on FreeBSD.", 1) if ($^O eq 'freebsd');
|
2016-02-08 10:10:32 -05:00
|
|
|
|
|
|
|
my ($fh, $path) = mkstemp("/tmp/softsig-t_XXXXXX");
|
2016-12-14 15:47:21 -05:00
|
|
|
$pid = open(HELPER, "-|", $softsig_helper, "-buserror", $path)
|
2016-02-08 10:10:32 -05:00
|
|
|
or die "Couldn't start test helper.";
|
|
|
|
close(HELPER);
|
|
|
|
is($? & 0x7f, $sigbus, "Helper exited on BUS signal.");
|
|
|
|
$fh->close;
|
|
|
|
unlink $path;
|
|
|
|
}
|