run_vmtests.sh relies on being invoked from its own directory and uses relative paths to run tests.
Change to the script directory at startup so it can be run from any working directory without failing.
Signed-off-by: Sun Jian sun.jian.kdev@gmail.com --- tools/testing/selftests/mm/run_vmtests.sh | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index d9173f2312b7..74c33fd07764 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -5,6 +5,10 @@ # Kselftest framework requirement - SKIP code is 4. ksft_skip=4
+# Ensure relative paths work regardless of caller's cwd. +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +cd "$SCRIPT_DIR" || exit 1 + count_total=0 count_pass=0 count_fail=0
On Thu, 8 Jan 2026 11:16:04 +0800 Sun Jian sun.jian.kdev@gmail.com wrote:
run_vmtests.sh relies on being invoked from its own directory and uses relative paths to run tests.
Change to the script directory at startup so it can be run from any working directory without failing.
...
hm, why? Is that a thing people actually do?
Is anyone going to actually test this feature?
--- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -5,6 +5,10 @@ # Kselftest framework requirement - SKIP code is 4. ksft_skip=4 +# Ensure relative paths work regardless of caller's cwd. +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +cd "$SCRIPT_DIR" || exit 1
Alternatively we could check that we're in the correct directory and error out if not.
hm, why? Is that a thing people actually do?
Is anyone going to actually test this feature?
Yes — invoking selftests directly from the kernel root can easily happen in practice, for example::
sudo tools/testing/selftests/mm/run_vmtests.sh
This currently results in false failures because relative paths being resolved against the caller's cwd instead of the script directory.
Alternatively we could check that we're in the correct directory and error out if not.
That would also be reasonable, but I slightly prefer auto-cd because it avoids an easy invocation pitfall and makes the runner more robust for wrappers/CI where the cwd is not stable. That said, I'm happy to switch to a fail-fast cwd check if you prefer the behavior.
Regards, Sun
linux-kselftest-mirror@lists.linaro.org