tests: Fix manpage tests for objdir builds 40/13940/2
authorAndrew Deason <adeason@sinenomine.net>
Tue, 12 Nov 2019 02:34:27 +0000 (20:34 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 20 Dec 2019 16:29:45 +0000 (11:29 -0500)
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 <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

tests/bozo/bos-man-t
tests/bucoord/backup-man-t
tests/kauth/kas-man-t
tests/ptserver/pts-man-t
tests/tests-lib/perl5/mancheck_utils.pm
tests/venus/fs-man-t
tests/volser/vos-man-t

index fedcf58..32001c1 100755 (executable)
@@ -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");
index d8df2c8..d062a80 100755 (executable)
@@ -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");
index 1629588..fb6b8cd 100755 (executable)
@@ -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");
index 60645ea..0c32dc9 100755 (executable)
@@ -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");
index edfa8fc..90a9e0a 100644 (file)
@@ -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;
index 3267b5d..2f3e644 100755 (executable)
@@ -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");
index 2e2cc35..90770b2 100755 (executable)
@@ -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");