selftests/mm: run_vmtests.sh: fix relative path handling
Subsystems (3)
PATCH 1/1 selftests/mm: run_vmtests.sh: fix relative path handling
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.
--- tools/testing/selftests/mm/run_vmtests.sh | 4 ++++ 1 file changed, 4 insertions(+)
tools/testing/selftests/mm/run_vmtests.sh +4 -0
@@ -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
Signature · 1 line
2.43.0
Andrew Morton
maintainerQuoted 8 lines · On Thu, 8 Jan 2026 11:16:04 +0800 Sun Jian <[email protected]> wrote:
run_vmtests.shrelies 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?
tools/testing/selftests/mm/run_vmtests.sh line 11
Quoted 10 lines
tools/testing/selftests/mm/run_vmtests.sh +4
-0@@ -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.
Quoted 3 lines
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.
Quoted 3 lines
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
David Hildenbrand (Red Hat)
maintainerQuoted 12 lines · sun jian
Quoted 3 lines
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.shThis currently results in false failures because relative paths being resolved against the caller's cwd instead of the script directory.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
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.
I'd prefer to just fail for the case that we never supported instead of adding support for it.
Signature · 3 lines
Cheers David
PATCH v2 1/1 selftests/mm: run_vmtests.sh: fail if invoked from the wrong directory
In reply to Sun Jianrun_vmtests.sh assumes it is invoked from tools/testing/selftests/mm. When run from another working directory, relative paths can lead to confusing failures. Detect this case and abort with a clear message.
--- tools/testing/selftests/mm/run_vmtests.sh | 7 +++++++ 1 file changed, 7 insertions(+)
tools/testing/selftests/mm/run_vmtests.sh +7 -0
@@ -5,6 +5,13 @@ # Kselftest framework requirement - SKIP code is 4. ksft_skip=4 +# Verify invocation from the script directory. +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +if [ "$(pwd -P)" != "$SCRIPT_DIR" ]; then + echo "Please run this test from $SCRIPT_DIR" >&2 + exit 1 +fi + count_total=0 count_pass=0 count_fail=0
Signature · 1 line
2.43.0
Re: [PATCH v2] selftests/mm: run_vmtests.sh: fail if invoked from the wrong directory
Quoted 5 lines · On Sat, 10 Jan 2026 01:28:33 +0800 Sun Jian <[email protected]> wrote:
run_vmtests.shassumes it is invoked fromtools/testing/selftests/mm. When run from another working directory, relative paths can lead to confusing failures. Detect this case and abort with a clear message.Signed-off-by Sun Jian <[email protected]>
Thanks,
SJ
[...]