[PATCH 16/16] tests: Source test_lib.sh via dirname so tests run from any directory

Arnaldo Carvalho de Melo <[email protected]> Mon, 22 Jun 2026 17:24:39 -0300
Newsgroups org.kernel.vger.dwarves
Message-ID <[email protected]>
From: Arnaldo Carvalho de Melo <[email protected]>

The test scripts sourced test_lib.sh using a bare filename (source
test_lib.sh or . ./test_lib.sh), which only works when the current
working directory is tests/.  Running a test from the repository root
(e.g. tests/inter_cu_refs.sh) would fail with "test_lib.sh: No such
file or directory".

Use $(dirname "$0")/test_lib.sh so each script locates the library
relative to its own path, regardless of the caller's working directory.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
 tests/btf_functions.sh        | 2 +-
 tests/btf_type_tag_order.sh   | 2 +-
 tests/default_vmlinux_btf.sh  | 2 +-
 tests/flexible_arrays.sh      | 2 +-
 tests/gcc_true_signatures.sh  | 2 +-
 tests/inter_cu_refs.sh        | 2 +-
 tests/pfunct-btf-decl-tags.sh | 2 +-
 tests/prettify_perf.data.sh   | 2 +-
 tests/reproducible_build.sh   | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/tests/btf_functions.sh b/tests/btf_functions.sh
index 127640e158b70805..351412a4c6a8ccb9 100755
--- a/tests/btf_functions.sh
+++ b/tests/btf_functions.sh
@@ -8,7 +8,7 @@
 # also should have been.
 #
 
-source test_lib.sh
+source "$(dirname "$0")/test_lib.sh"
 
 vmlinux=$(get_vmlinux $1)
 if [ $? -ne 0 ] ; then
diff --git a/tests/btf_type_tag_order.sh b/tests/btf_type_tag_order.sh
index 09d1ac346000bb6b..0e671ae538603d2b 100755
--- a/tests/btf_type_tag_order.sh
+++ b/tests/btf_type_tag_order.sh
@@ -3,7 +3,7 @@
 
 # Check that pahole preserves btf_type_tag order when emitting BTF from DWARF.
 
-source test_lib.sh
+source "$(dirname "$0")/test_lib.sh"
 
 outdir=$(make_tmpdir)
 
diff --git a/tests/default_vmlinux_btf.sh b/tests/default_vmlinux_btf.sh
index 496e840bfbec8f3a..b3d6e9cff8719e5f 100755
--- a/tests/default_vmlinux_btf.sh
+++ b/tests/default_vmlinux_btf.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-source test_lib.sh
+source "$(dirname "$0")/test_lib.sh"
 
 title_log "Default BTF on a system without BTF."
 
diff --git a/tests/flexible_arrays.sh b/tests/flexible_arrays.sh
index 4e9e995271ce816f..6443449b50e6c9c2 100755
--- a/tests/flexible_arrays.sh
+++ b/tests/flexible_arrays.sh
@@ -5,7 +5,7 @@
 #
 # Arnaldo Carvalho de Melo <[email protected]> (C) 2024-
 
-source test_lib.sh
+source "$(dirname "$0")/test_lib.sh"
 
 vmlinux=$(get_vmlinux $1)
 if [ $? -ne 0 ] ; then
diff --git a/tests/gcc_true_signatures.sh b/tests/gcc_true_signatures.sh
index 9ebe1fa6c32f7bf7..96b282be5dba721a 100755
--- a/tests/gcc_true_signatures.sh
+++ b/tests/gcc_true_signatures.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0-only
 
-source test_lib.sh
+source "$(dirname "$0")/test_lib.sh"
 
 outdir=$(make_tmpdir)
 
diff --git a/tests/inter_cu_refs.sh b/tests/inter_cu_refs.sh
index 6827bf83931eb3ed..0df0ce13cd948f1f 100755
--- a/tests/inter_cu_refs.sh
+++ b/tests/inter_cu_refs.sh
@@ -10,7 +10,7 @@
 # that the automatic detection produces the same output as explicitly
 # forcing CU merging.
 
-. ./test_lib.sh
+. "$(dirname "$0")/test_lib.sh"
 
 outdir=$(make_tmpdir)
 trap cleanup EXIT
diff --git a/tests/pfunct-btf-decl-tags.sh b/tests/pfunct-btf-decl-tags.sh
index 520148b2ccef15b2..25d9cd6d4ad8551f 100755
--- a/tests/pfunct-btf-decl-tags.sh
+++ b/tests/pfunct-btf-decl-tags.sh
@@ -3,7 +3,7 @@
 
 # Check that pfunct can print btf_decl_tags read from BTF
 
-source test_lib.sh
+source "$(dirname "$0")/test_lib.sh"
 
 outdir=$(make_tmpdir)
 
diff --git a/tests/prettify_perf.data.sh b/tests/prettify_perf.data.sh
index 384c250ff4e01a4c..ae0a7d995da6cad2 100755
--- a/tests/prettify_perf.data.sh
+++ b/tests/prettify_perf.data.sh
@@ -7,7 +7,7 @@
 # Check if the perf binary is available, if it is from a distro, normally it
 # will get the needed DWARF info using libddebuginfod, we'll check if the
 # needed types are available, skipping the test and informing the reason.
-. ./test_lib.sh
+. "$(dirname "$0")/test_lib.sh"
 
 outdir=$(make_tmpdir)
 
diff --git a/tests/reproducible_build.sh b/tests/reproducible_build.sh
index d8c6507526bdfbbc..7b7a5afd1fe4e50d 100755
--- a/tests/reproducible_build.sh
+++ b/tests/reproducible_build.sh
@@ -4,7 +4,7 @@
 # Test if BTF generated serially matches reproducible parallel DWARF loading + serial BTF encoding
 # Arnaldo Carvalho de Melo <[email protected]> (C) 2024-
 
-source test_lib.sh
+source "$(dirname "$0")/test_lib.sh"
 
 vmlinux=$(get_vmlinux $1)
 if [ $? -ne 0 ]; then
-- 
2.54.0