From 0b8b6683fb525bbeaf118014beb2371e0cf23d90 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Mon, 11 Nov 2019 20:34:27 -0600 Subject: [PATCH] tests: Fix manpage tests for objdir builds The manpage tests have a couple of problems when running for objdir builds: - We try to specify './tests-lib/perl5' as a directory to find our helper library. However, the cwd when we're running the tests is in an objdir build, where the helper library is in the srcdir. Fix this by using the SOURCE env var specified by the tests wrapper. - All of these tests specify the directory in which to find the man pages in a subdir of BUILD, but our manpages are located in the src dir (since they are built by regen.sh, not by configure/make). Fix this by specifying a SOURCE-based directory instead. To avoid needing to make the same change for each of these tests, also refactor the manpage tests so each test only needs to specify the subdirectory and command name, and get rid of some of the common boilerplate. Change-Id: I96be199b1dec8db0545ae3cf19d2595c4afe4cdd Reviewed-on: https://gerrit.openafs.org/13940 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- tests/bozo/bos-man-t | 21 ++-------------- tests/bucoord/backup-man-t | 21 ++-------------- tests/kauth/kas-man-t | 21 ++-------------- tests/ptserver/pts-man-t | 21 ++-------------- tests/tests-lib/perl5/mancheck_utils.pm | 32 +++++++++++++++++++++---- tests/venus/fs-man-t | 21 ++-------------- tests/volser/vos-man-t | 20 ++-------------- 7 files changed, 40 insertions(+), 117 deletions(-) diff --git a/tests/bozo/bos-man-t b/tests/bozo/bos-man-t index fedcf5863d..32001c169e 100755 --- a/tests/bozo/bos-man-t +++ b/tests/bozo/bos-man-t @@ -2,24 +2,7 @@ use strict; use warnings; -use File::Basename; -use lib "./tests-lib/perl5"; +use lib $ENV{SOURCE} . "/tests-lib/perl5"; use mancheck_utils; -# Set this to the bare command to test -my $command = 'bos'; -my $builddir = $ENV{BUILD}; -if (!$builddir) { - $builddir = dirname($0) . "/.."; -} -$builddir .= "/.."; -# Set this to the directory holding $command -my $srcdir = "$builddir/src/bozo"; - -#--------------------------------------------------------------------- - -my @sub_commands = lookup_sub_commands($srcdir, $command); -plan tests => scalar @sub_commands; - -test_command_man_pages($builddir, $command, @sub_commands); - +run_manpage_tests("src/bozo", "bos"); diff --git a/tests/bucoord/backup-man-t b/tests/bucoord/backup-man-t index d8df2c823b..d062a80301 100755 --- a/tests/bucoord/backup-man-t +++ b/tests/bucoord/backup-man-t @@ -2,24 +2,7 @@ use strict; use warnings; -use File::Basename; -use lib "./tests-lib/perl5"; +use lib $ENV{SOURCE} . "/tests-lib/perl5"; use mancheck_utils; -# Set this to the bare command to test -my $command = 'backup'; -my $builddir = $ENV{BUILD}; -if (!$builddir) { - $builddir = dirname($0) . "/.."; -} -$builddir .= "/.."; -# Set this to the directory holding $command -my $srcdir = "$builddir/src/bucoord"; - -#--------------------------------------------------------------------- - -my @sub_commands = lookup_sub_commands($srcdir, $command); -plan tests => scalar @sub_commands; - -test_command_man_pages($builddir, $command, @sub_commands); - +run_manpage_tests("src/bucoord", "backup"); diff --git a/tests/kauth/kas-man-t b/tests/kauth/kas-man-t index 1629588964..fb6b8cd75b 100755 --- a/tests/kauth/kas-man-t +++ b/tests/kauth/kas-man-t @@ -2,24 +2,7 @@ use strict; use warnings; -use File::Basename; -use lib "./tests-lib/perl5"; +use lib $ENV{SOURCE} . "/tests-lib/perl5"; use mancheck_utils; -# Set this to the bare command to test -my $command = 'kas'; -my $builddir = $ENV{BUILD}; -if (!$builddir) { - $builddir = dirname($0) . "/.."; -} -$builddir .= "/.."; -# Set this to the directory holding $command -my $srcdir = "$builddir/src/kauth"; - -#--------------------------------------------------------------------- - -my @sub_commands = lookup_sub_commands($srcdir, $command); -plan tests => scalar @sub_commands; - -test_command_man_pages($builddir, $command, @sub_commands); - +run_manpage_tests("src/kauth", "kas"); diff --git a/tests/ptserver/pts-man-t b/tests/ptserver/pts-man-t index 60645ea2bf..0c32dc91a8 100755 --- a/tests/ptserver/pts-man-t +++ b/tests/ptserver/pts-man-t @@ -2,24 +2,7 @@ use strict; use warnings; -use File::Basename; -use lib "./tests-lib/perl5"; +use lib $ENV{SOURCE} . "/tests-lib/perl5"; use mancheck_utils; -# Set this to the bare command to test -my $command = 'pts'; -my $builddir = $ENV{BUILD}; -if (!$builddir) { - $builddir = dirname($0) . "/.."; -} -$builddir .= "/.."; -# Set this to the directory holding $command -my $srcdir = "$builddir/src/ptserver"; - -#--------------------------------------------------------------------- - -my @sub_commands = lookup_sub_commands($srcdir, $command); -plan tests => scalar @sub_commands; - -test_command_man_pages($builddir, $command, @sub_commands); - +run_manpage_tests("src/ptserver", "pts"); diff --git a/tests/tests-lib/perl5/mancheck_utils.pm b/tests/tests-lib/perl5/mancheck_utils.pm index edfa8fc3da..90a9e0a89c 100644 --- a/tests/tests-lib/perl5/mancheck_utils.pm +++ b/tests/tests-lib/perl5/mancheck_utils.pm @@ -52,7 +52,7 @@ sub lookup_sub_commands { # # Arguments: # -# builddir : A path to the OpenAFS build directory, +# srcdir : A path to the OpenAFS source directory, # such as /tmp/1.4.14 # # command : the name of the command (e.g. vos) @@ -60,7 +60,7 @@ sub lookup_sub_commands { # subcommlist : a list of sub-commands for command # sub test_command_man_pages { - my ($builddir, $command, @subcommlist) = @_; + my ($srcdir, $command, @subcommlist) = @_; # The following is because File::Find makes no sense to me # for this purpose, and actually seems totally misnamed @@ -69,9 +69,9 @@ sub test_command_man_pages { my $frex = ""; # Since we don't know what man section it might be in, # search all existing man page files for a filename match - my @mandirglob = glob("$builddir/doc/man-pages/man[1-8]/*"); + my @mandirglob = glob("$srcdir/doc/man-pages/man[1-8]/*"); # For every subcommand, see if command_subcommand.[1-8] exists - # in our man page build dir. + # in our man page source dir. foreach (@subcommlist) { my $subcommand = $_; $found = 0; @@ -89,4 +89,28 @@ sub test_command_man_pages { ok($found eq 1, "existence of man page for $command" . "_$subcommand"); } } + +# +# Setup the test plan and run all of the tests for the given command suite. +# +# Call like so: +# run_manpage_tests("src/ptserver", "pts"); +# +sub run_manpage_tests($$) { + my ($subdir, $command) = @_; + + # When run from 'runtests', our cwd will be TOP_OBJDIR/tests. $SOURCE is + # set to TOP_SRCDIR/tests, and $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{SOURCE} . "/.."; + my $objdir = $ENV{BUILD} . "/.."; + + my @sub_commands = lookup_sub_commands("$objdir/$subdir", $command); + die("No subcommands found in $objdir/$subdir/$command?") unless(@sub_commands); + + plan tests => scalar @sub_commands; + + test_command_man_pages($srcdir, $command, @sub_commands); +} 1; diff --git a/tests/venus/fs-man-t b/tests/venus/fs-man-t index 3267b5ddd8..2f3e644a50 100755 --- a/tests/venus/fs-man-t +++ b/tests/venus/fs-man-t @@ -2,24 +2,7 @@ use strict; use warnings; -use File::Basename; -use lib "./tests-lib/perl5"; +use lib $ENV{SOURCE} . "/tests-lib/perl5"; use mancheck_utils; -# Set this to the bare command to test -my $command = 'fs'; -my $builddir = $ENV{BUILD}; -if (!$builddir) { - $builddir = dirname($0) . "/.."; -} -$builddir .= "/.."; -# Set this to the directory holding $command -my $srcdir = "$builddir/src/venus"; - -#--------------------------------------------------------------------- - -my @sub_commands = lookup_sub_commands($srcdir, $command); -plan tests => scalar @sub_commands; - -test_command_man_pages($builddir, $command, @sub_commands); - +run_manpage_tests("src/venus", "fs"); diff --git a/tests/volser/vos-man-t b/tests/volser/vos-man-t index 2e2cc3560c..90770b2570 100755 --- a/tests/volser/vos-man-t +++ b/tests/volser/vos-man-t @@ -2,24 +2,8 @@ use strict; use warnings; -use File::Basename; -use lib "./tests-lib/perl5"; +use lib $ENV{SOURCE} . "/tests-lib/perl5"; use mancheck_utils; -# Set this to the bare command to test -my $command = 'vos'; -my $builddir = $ENV{BUILD}; -if (!$builddir) { - $builddir = dirname($0) . "/.."; -} -$builddir .= "/.."; -# Set this to the directory holding $command -my $srcdir = "$builddir/src/volser"; - -#--------------------------------------------------------------------- - -my @sub_commands = lookup_sub_commands($srcdir, $command); -plan tests => scalar @sub_commands; - -test_command_man_pages($builddir, $command, @sub_commands); +run_manpage_tests("src/volser", "vos");