mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 06:50:12 +00:00
tests: Introduce afstest.pm
Create a perl module for some generic common code for our tests written in perl: afstest.pm. With this commit, the module just contains a couple of functions to calculate paths in our src and obj trees (src_path(), obj_path()), analogous to afstest_src_path and afstest_obj_path in our C helper library, libafstest_common.la. Convert all existing perl test code that uses C_TAP_SOURCE/C_TAP_BUILD to use these new functions. Change-Id: I5e4d45e3d2d59449bbfc426476cb29b710c73bc1 Reviewed-on: https://gerrit.openafs.org/14800 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
parent
83d947c150
commit
e07768aaf7
@ -2,9 +2,11 @@
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5";
|
||||
|
||||
use afstest qw(src_path obj_path);
|
||||
use Test::More;
|
||||
use File::Temp qw/tempdir/;
|
||||
use FindBin qw($Bin);
|
||||
use Cwd qw/abs_path/;
|
||||
use File::Compare;
|
||||
use Sys::Hostname;
|
||||
@ -19,20 +21,10 @@ if (!defined(gethostbyname(hostname()))) {
|
||||
}
|
||||
plan tests => 1;
|
||||
|
||||
my $cmd;
|
||||
if (defined($ENV{C_TAP_BUILD})) {
|
||||
$cmd = $ENV{C_TAP_BUILD} . "/auth/writekeyfile";
|
||||
} else {
|
||||
$cmd = $Bin . "/writekeyfile";
|
||||
}
|
||||
my $cmd = obj_path("tests/auth/writekeyfile");
|
||||
$cmd = abs_path($cmd);
|
||||
|
||||
my $keyfile;
|
||||
if (defined($ENV{C_TAP_SOURCE})) {
|
||||
$keyfile = $ENV{C_TAP_SOURCE} . "/auth/KeyFile.short";
|
||||
} else {
|
||||
$keyfile = $Bin . "/KeyFile.short";
|
||||
}
|
||||
my $keyfile = src_path("tests/auth/KeyFile.short");
|
||||
$keyfile = abs_path($keyfile);
|
||||
|
||||
my $dir = tempdir('afs_XXXXXX', CLEANUP => 1);
|
||||
|
@ -24,6 +24,9 @@
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5";
|
||||
|
||||
use afstest qw(obj_path);
|
||||
use Test::More tests => 11;
|
||||
use IO::File;
|
||||
use POSIX qw(:signal_h);
|
||||
@ -33,16 +36,7 @@ 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;
|
||||
|
||||
# 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";
|
||||
}
|
||||
my $softsig_helper = obj_path("tests/opr/softsig-helper");
|
||||
|
||||
# This -dummy argument prevents Perl from putting an intermediate sh
|
||||
# -c between us and softsig-helper in the case where the build
|
||||
|
@ -2,17 +2,14 @@
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5";
|
||||
|
||||
use afstest qw(obj_path);
|
||||
use File::Basename;
|
||||
use File::Temp qw(tempfile);
|
||||
use Test::More tests=>2;
|
||||
|
||||
my $builddir = $ENV{C_TAP_BUILD};
|
||||
if (!$builddir) {
|
||||
$builddir = dirname($0)."/..";
|
||||
}
|
||||
|
||||
$builddir.="/..";
|
||||
my $pt_util = obj_path("src/ptserver/pt_util");
|
||||
|
||||
(undef, my $prdbfile) = tempfile("prdbtest.XXXXXX", TMPDIR => 1, UNLINK => 1);
|
||||
|
||||
@ -35,13 +32,13 @@ EOF
|
||||
|
||||
my $fh;
|
||||
|
||||
open $fh, '|-', "$builddir/src/ptserver/pt_util", '-w', '-p', $prdbfile
|
||||
open $fh, '|-', "$pt_util", '-w', '-p', $prdbfile
|
||||
or die "Failed to start pt_util for DB creation\n";
|
||||
print $fh $instructions;
|
||||
close($fh)
|
||||
or die "pt util failed while creating DB\n";
|
||||
|
||||
open $fh, '-|', "$builddir/src/ptserver/pt_util", '-p', $prdbfile,
|
||||
open $fh, '-|', "$pt_util", '-p', $prdbfile,
|
||||
'-user', '-group', '-members'
|
||||
or die "Failed to start pt_util for DB reading\n";
|
||||
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5";
|
||||
|
||||
use afstest qw(obj_path);
|
||||
use Test::More tests=>4;
|
||||
use POSIX qw(:sys_wait_h :signal_h);
|
||||
|
||||
my $port = 4000;
|
||||
my $build = $ENV{C_TAP_BUILD};
|
||||
$build = ".." if (!defined($build));
|
||||
my $rxperf = $build."/../src/tools/rxperf/rxperf";
|
||||
my $rxperf = obj_path("src/tools/rxperf/rxperf");
|
||||
|
||||
# Start up an rxperf server
|
||||
|
||||
|
61
tests/tests-lib/perl5/afstest.pm
Normal file
61
tests/tests-lib/perl5/afstest.pm
Normal file
@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2020 Sine Nomine Associates. 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.
|
||||
|
||||
package afstest;
|
||||
require Exporter;
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT_OK = qw(src_path obj_path);
|
||||
|
||||
sub
|
||||
x_path($;$)
|
||||
{
|
||||
my ($env_var, $path) = @_;
|
||||
my $tdir = $ENV{$env_var};
|
||||
if (!defined($tdir)) {
|
||||
# If C_TAP_SOURCE/C_TAP_BUILD isn't set, we assume we're running from
|
||||
# the same cwd as one of the test programs (e.g. 'tests/foo/'). So to
|
||||
# get to 'tests/', just go up one level.
|
||||
$tdir = "..";
|
||||
}
|
||||
|
||||
# $tdir now represents the 'tests/' dir. Go one level up to get to the
|
||||
# top-level dir.
|
||||
if (defined($path)) {
|
||||
return "$tdir/../$path";
|
||||
} else {
|
||||
return "$tdir/..";
|
||||
}
|
||||
}
|
||||
|
||||
sub
|
||||
src_path(;$)
|
||||
{
|
||||
my $path = $_[0];
|
||||
return x_path("C_TAP_SOURCE", $path);
|
||||
}
|
||||
|
||||
sub
|
||||
obj_path(;$)
|
||||
{
|
||||
my $path = $_[0];
|
||||
return x_path("C_TAP_BUILD", $path);
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
#
|
||||
use File::Basename;
|
||||
use Test::More;
|
||||
use afstest qw(src_path obj_path);
|
||||
|
||||
sub check_command_binary {
|
||||
my $c = shift(@_);
|
||||
@ -99,12 +100,8 @@ sub test_command_man_pages {
|
||||
sub run_manpage_tests($$) {
|
||||
my ($subdir, $command) = @_;
|
||||
|
||||
# When run from 'runtests', our cwd will be TOP_OBJDIR/tests. $C_TAP_SOURCE
|
||||
# is set to TOP_SRCDIR/tests, and $C_TAP_BUILD is set to TOP_OBJDIR/tests.
|
||||
# We want the top-level src and obj dirs, in order to find the relevant
|
||||
# binaries and manpages.
|
||||
my $srcdir = $ENV{C_TAP_SOURCE} . "/..";
|
||||
my $objdir = $ENV{C_TAP_BUILD} . "/..";
|
||||
my $srcdir = src_path();
|
||||
my $objdir = obj_path();
|
||||
|
||||
my @sub_commands = lookup_sub_commands("$objdir/$subdir", $command);
|
||||
die("No subcommands found in $objdir/$subdir/$command?") unless(@sub_commands);
|
||||
|
Loading…
Reference in New Issue
Block a user