File 0012-test-make-running-parallel-out-of-tree-safe.patch of Package acl

From 2d13383b7fbcc04fc16681caa4f43d9d9083cca1 Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Fri, 10 Jan 2014 10:07:40 -0500
Subject: [PATCH 12/34] test: make running parallel/out-of-tree safe

Change the run program to update PATH to find the tools locally
automatically.  This lets us avoid having to always build in the
tree and allows for direct running.

Also update the program to create a tempdir for each test to run
inside of.  This way we can run all the tests in parallel without
randomly clobbering each other.
---
 test/getfacl-recursive.test | 12 ++++++------
 test/malformed-restore.test |  2 +-
 test/run                    | 29 ++++++++++++++++++++++++++++-
 3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/test/getfacl-recursive.test b/test/getfacl-recursive.test
index a72192e..8f5dd4e 100644
--- a/test/getfacl-recursive.test
+++ b/test/getfacl-recursive.test
@@ -5,7 +5,7 @@ Tests for proper path recursion
 	$ mkdir 1/link
 	$ touch 1/link/file
 	$ ln -s `pwd`/1/link 1/2/link
-	$ getfacl -P -R 1/2 | ./sort-getfacl-output
+	$ getfacl -P -R 1/2 | sort-getfacl-output
 	> # file: 1/2
 	> # owner: %TUSER
 	> # group: %TGROUP
@@ -21,7 +21,7 @@ Tests for proper path recursion
 	> other::r-x
 	>
 
-	$ getfacl -R 1/2 | ./sort-getfacl-output
+	$ getfacl -R 1/2 | sort-getfacl-output
 	> # file: 1/2
 	> # owner: %TUSER
 	> # group: %TGROUP
@@ -37,7 +37,7 @@ Tests for proper path recursion
 	> other::r-x
 	>
 
-	$ getfacl -R -L 1/2 | ./sort-getfacl-output
+	$ getfacl -R -L 1/2 | sort-getfacl-output
 	> # file: 1/2
 	> # owner: %TUSER
 	> # group: %TGROUP
@@ -67,7 +67,7 @@ Tests for proper path recursion
 	> other::r--
 	>
 
-	$ getfacl -P -R 1 | ./sort-getfacl-output
+	$ getfacl -P -R 1 | sort-getfacl-output
 	> # file: 1
 	> # owner: %TUSER
 	> # group: %TGROUP
@@ -104,7 +104,7 @@ Tests for proper path recursion
 	> other::r--
 	>
 
-	$ getfacl -R 1 | ./sort-getfacl-output
+	$ getfacl -R 1 | sort-getfacl-output
 	> # file: 1
 	> # owner: %TUSER
 	> # group: %TGROUP
@@ -141,7 +141,7 @@ Tests for proper path recursion
 	> other::r--
 	>
 
-	$ getfacl -R -L 1 | ./sort-getfacl-output
+	$ getfacl -R -L 1 | sort-getfacl-output
 	> # file: 1
 	> # owner: %TUSER
 	> # group: %TGROUP
diff --git a/test/malformed-restore.test b/test/malformed-restore.test
index e92b75b..5e5391c 100644
--- a/test/malformed-restore.test
+++ b/test/malformed-restore.test
@@ -1,7 +1,7 @@
 Test for malformed input to --restore
  https://savannah.nongnu.org/bugs/index.php?28185
 
-	$ cp malformed-restore-double-owner.acl tmp.acl
+	$ cp "%TESTDIR/malformed-restore-double-owner.acl" tmp.acl
 	$ sed -i "s/USER/%TUSER/g" tmp.acl
 	$ sed -i "s/GROUP/%TGROUP/g" tmp.acl
 	$ touch tmp
diff --git a/test/run b/test/run
index 2cf52e8..0a12be6 100755
--- a/test/run
+++ b/test/run
@@ -37,7 +37,10 @@
 #
 
 use strict;
+use Cwd qw(abs_path);
 use FileHandle;
+use File::Basename qw(basename dirname);
+use File::Path qw(rmtree);
 use Getopt::Std;
 use POSIX qw(isatty setuid getcwd);
 use vars qw($opt_l $opt_v);
@@ -53,9 +56,28 @@ if (isatty(fileno(STDOUT))) {
 	$FAILED = "\033[31m\033[1m" . $FAILED . "\033[m";
 }
 
+# Export this dir to tests so they can access data files if needed.
+$ENV{"TESTDIR"} = abs_path(dirname($0));
+# Add the current dir to PATH so we can find sort-getfattr-output and such.
+$ENV{"PATH"} = $ENV{"TESTDIR"} . ":$ENV{PATH}";
+# Add the parent dir to PATH so we can find the compiled tools.
+$ENV{"PATH"} = dirname(abs_path(dirname($0))) . ":$ENV{PATH}";
 $ENV{"TUSER"} = getpwuid($>);
 $ENV{"TGROUP"} = getgrgid($));
 
+open(TEST_FILE, $ARGV[0]);
+
+# Create a tempdir to run in for parallel test execution.
+my $tmpdir = $ARGV[0] . ".dir";
+rmtree($tmpdir);
+if (!mkdir($tmpdir)) {
+	$tmpdir = getcwd() . "/" . basename($ARGV[0]) . ".dir";
+	rmtree($tmpdir);
+	mkdir($tmpdir) or die "could not create $tmpdir";
+}
+my $pretmpdir = getcwd();
+chdir($tmpdir) or die "could not enter $tmpdir";
+
 sub exec_test($$);
 sub process_test($$$$);
 
@@ -66,7 +88,7 @@ my $lineno;
 my $width = ($ENV{COLUMNS} || 80) >> 1;
 
 for (;;) {
-  my $line = <>; $lineno++;
+  my $line = <TEST_FILE>; $lineno++;
   if (defined $line) {
     # Substitute %VAR and %{VAR} with environment variables.
     $line =~ s[%(\w+)][$ENV{$1}]eg;
@@ -106,6 +128,11 @@ if (isatty(fileno(STDOUT))) {
 	}
 }
 print $status, "\n";
+
+# Now clean up the testdir.
+chdir($pretmpdir);
+rmtree($tmpdir);
+
 exit $failed ? 1 : 0;
 
 
-- 
2.5.2
openSUSE Build Service is sponsored by