The testsuite relies on there being no files in the test directory
after the test finishes. A test will fail if the test dir cannot be
removed. But the test dir isn't really random, it uses the pid of the
shell script that executes the test. On some of the buildbots that
execute a lot of tests it can happen that the pid number wraps around
and a pid of a previous pid is reused. To prevent that happening
generate a real random number (8 bytes) using od /dev/urandom and
xargs (to trim away spaces left by od).

      * tests/test-subr.sh: Define test_name and random_number and use
      those to define test_dir.

Signed-off-by: Mark Wielaard <m...@klomp.org>
---
 tests/test-subr.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/test-subr.sh b/tests/test-subr.sh
index ea80cbec3bc7..2a956b47de2f 100644
--- a/tests/test-subr.sh
+++ b/tests/test-subr.sh
@@ -23,7 +23,9 @@
 set -e
 
 # Each test runs in its own directory to make sure they can run in parallel.
-test_dir="${TMPDIR-/var/tmp}/elfutils-test-$$"
+test_name=$(basename $0)
+random_number=$(od -An -N8 -tx8 /dev/urandom | xargs)
+test_dir="${TMPDIR-/var/tmp}/elfutils-test-$test_name.${random_number}"
 mkdir -p "$test_dir"
 orig_dir="${PWD}"
 cd "$test_dir"
-- 
2.49.0

Reply via email to