]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: Create random test_dir name
authorMark Wielaard <mark@klomp.org>
Tue, 6 May 2025 09:50:12 +0000 (11:50 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 13 May 2025 19:21:34 +0000 (21:21 +0200)
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 <mark@klomp.org>
tests/test-subr.sh

index ea80cbec3bc75fa7448f6610458a56508ed94b93..2a956b47de2f8fafea2cc1445275d6f37eea19c2 100644 (file)
@@ -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"