linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: run_vmtests.sh: fix relative path handling
@ 2026-01-08  3:16 Sun Jian
  2026-01-08 21:28 ` Andrew Morton
  2026-01-09 17:28 ` [PATCH v2] selftests/mm: run_vmtests.sh: fail if invoked from the wrong directory Sun Jian
  0 siblings, 2 replies; 6+ messages in thread
From: Sun Jian @ 2026-01-08  3:16 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Andrew Morton, David Hildenbrand, linux-kselftest, linux-mm,
	linux-kernel, Sun Jian

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
-- 
2.43.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] selftests/mm: run_vmtests.sh: fix relative path handling
  2026-01-08  3:16 [PATCH] selftests/mm: run_vmtests.sh: fix relative path handling Sun Jian
@ 2026-01-08 21:28 ` Andrew Morton
  2026-01-09  2:08   ` sun jian
  2026-01-09 17:28 ` [PATCH v2] selftests/mm: run_vmtests.sh: fail if invoked from the wrong directory Sun Jian
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2026-01-08 21:28 UTC (permalink / raw)
  To: Sun Jian
  Cc: Shuah Khan, David Hildenbrand, linux-kselftest, linux-mm, linux-kernel

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.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] selftests/mm: run_vmtests.sh: fix relative path handling
  2026-01-08 21:28 ` Andrew Morton
@ 2026-01-09  2:08   ` sun jian
  2026-01-09 13:41     ` David Hildenbrand (Red Hat)
  0 siblings, 1 reply; 6+ messages in thread
From: sun jian @ 2026-01-09  2:08 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Shuah Khan, David Hildenbrand, linux-kselftest, linux-mm, linux-kernel

> 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] selftests/mm: run_vmtests.sh: fix relative path handling
  2026-01-09  2:08   ` sun jian
@ 2026-01-09 13:41     ` David Hildenbrand (Red Hat)
  0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand (Red Hat) @ 2026-01-09 13:41 UTC (permalink / raw)
  To: sun jian, Andrew Morton
  Cc: Shuah Khan, linux-kselftest, linux-mm, linux-kernel

On 1/9/26 03:08, sun jian wrote:
>> 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.

I'd prefer to just fail for the case that we never supported instead of 
adding support for it.

-- 
Cheers

David


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] selftests/mm: run_vmtests.sh: fail if invoked from the wrong directory
  2026-01-08  3:16 [PATCH] selftests/mm: run_vmtests.sh: fix relative path handling Sun Jian
  2026-01-08 21:28 ` Andrew Morton
@ 2026-01-09 17:28 ` Sun Jian
  2026-01-10  1:00   ` SeongJae Park
  1 sibling, 1 reply; 6+ messages in thread
From: Sun Jian @ 2026-01-09 17:28 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Andrew Morton, Shuah Khan, linux-mm, linux-kselftest,
	linux-kernel, Sun Jian

run_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.

Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
 tools/testing/selftests/mm/run_vmtests.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh
index d9173f2312b7..b7025afb56fd 100755
--- a/tools/testing/selftests/mm/run_vmtests.sh
+++ b/tools/testing/selftests/mm/run_vmtests.sh
@@ -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
-- 
2.43.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] selftests/mm: run_vmtests.sh: fail if invoked from the wrong directory
  2026-01-09 17:28 ` [PATCH v2] selftests/mm: run_vmtests.sh: fail if invoked from the wrong directory Sun Jian
@ 2026-01-10  1:00   ` SeongJae Park
  0 siblings, 0 replies; 6+ messages in thread
From: SeongJae Park @ 2026-01-10  1:00 UTC (permalink / raw)
  To: Sun Jian
  Cc: SeongJae Park, David Hildenbrand, Andrew Morton, Shuah Khan,
	linux-mm, linux-kselftest, linux-kernel

On Sat, 10 Jan 2026 01:28:33 +0800 Sun Jian <sun.jian.kdev@gmail.com> wrote:

> run_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.
> 
> Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-01-10  1:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-08  3:16 [PATCH] selftests/mm: run_vmtests.sh: fix relative path handling Sun Jian
2026-01-08 21:28 ` Andrew Morton
2026-01-09  2:08   ` sun jian
2026-01-09 13:41     ` David Hildenbrand (Red Hat)
2026-01-09 17:28 ` [PATCH v2] selftests/mm: run_vmtests.sh: fail if invoked from the wrong directory Sun Jian
2026-01-10  1:00   ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox