DAMON development mailing list
 help / color / mirror / Atom feed
* [PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
@ 2026-09-08 21:42 Eva Kurchatova
  2026-09-08 21:48 ` sashiko-bot
  2026-09-09  0:20 ` SJ Park
  0 siblings, 2 replies; 4+ messages in thread
From: Eva Kurchatova @ 2026-09-08 21:42 UTC (permalink / raw)
  To: SJ Park, Shuah Khan
  Cc: linux-kernel, Eva Kurchatova, damon, linux-mm, linux-kselftest

Running these tests under Python's safe path mode, either with -P on the
interpreter command line or with PYTHONSAFEPATH set in the environment,
stops the script's own directory being prepended to sys.path. Some
distributions (RHEL, for example) build the tests with -P in the shebang.

This breaks all 7 DAMON Python selftests that import the _damon_sysfs
helper module located in the same directory:

  ModuleNotFoundError: No module named '_damon_sysfs'

Fix this by explicitly adding the script's directory to sys.path before
importing _damon_sysfs, following the same pattern used in commit
c3b3eb565bd7 ("tools: ynl: add script dir to sys.path") which fixed the
identical issue for the YNL tools.

Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
 tools/testing/selftests/damon/damon_nr_regions.py              | 3 +++
 tools/testing/selftests/damon/damos_apply_interval.py          | 3 +++
 tools/testing/selftests/damon/damos_quota.py                   | 3 +++
 tools/testing/selftests/damon/damos_quota_goal.py              | 3 +++
 tools/testing/selftests/damon/damos_tried_regions.py           | 3 +++
 .../selftests/damon/sysfs_update_schemes_tried_regions_hang.py | 3 +++
 .../damon/sysfs_update_schemes_tried_regions_wss_estimation.py | 3 +++
 7 files changed, 21 insertions(+)

diff --git a/tools/testing/selftests/damon/damon_nr_regions.py b/tools/testing/selftests/damon/damon_nr_regions.py
index 58f3291fed12..e55239813c65 100755
--- a/tools/testing/selftests/damon/damon_nr_regions.py
+++ b/tools/testing/selftests/damon/damon_nr_regions.py
@@ -1,9 +1,12 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
+import os
 import subprocess
+import sys
 import time
 
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 import _damon_sysfs
 
 def test_nr_regions(real_nr_regions, min_nr_regions, max_nr_regions):
diff --git a/tools/testing/selftests/damon/damos_apply_interval.py b/tools/testing/selftests/damon/damos_apply_interval.py
index 0f2f36584e48..0bf7768b2006 100755
--- a/tools/testing/selftests/damon/damos_apply_interval.py
+++ b/tools/testing/selftests/damon/damos_apply_interval.py
@@ -1,9 +1,12 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
+import os
 import subprocess
+import sys
 import time
 
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 import _damon_sysfs
 
 def main():
diff --git a/tools/testing/selftests/damon/damos_quota.py b/tools/testing/selftests/damon/damos_quota.py
index 57c4937aaed2..879115a499bf 100755
--- a/tools/testing/selftests/damon/damos_quota.py
+++ b/tools/testing/selftests/damon/damos_quota.py
@@ -1,9 +1,12 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
+import os
 import subprocess
+import sys
 import time
 
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 import _damon_sysfs
 
 def main():
diff --git a/tools/testing/selftests/damon/damos_quota_goal.py b/tools/testing/selftests/damon/damos_quota_goal.py
index 661e4ba4765a..fed033a0afdf 100755
--- a/tools/testing/selftests/damon/damos_quota_goal.py
+++ b/tools/testing/selftests/damon/damos_quota_goal.py
@@ -1,9 +1,12 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
+import os
 import subprocess
+import sys
 import time
 
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 import _damon_sysfs
 
 def main():
diff --git a/tools/testing/selftests/damon/damos_tried_regions.py b/tools/testing/selftests/damon/damos_tried_regions.py
index d6472e6a6e08..6941f87c10b1 100755
--- a/tools/testing/selftests/damon/damos_tried_regions.py
+++ b/tools/testing/selftests/damon/damos_tried_regions.py
@@ -1,9 +1,12 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
+import os
 import subprocess
+import sys
 import time
 
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 import _damon_sysfs
 
 def main():
diff --git a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py
index 28c887a0108f..625761c243b5 100755
--- a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py
+++ b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py
@@ -1,9 +1,12 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
+import os
 import subprocess
+import sys
 import time
 
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 import _damon_sysfs
 
 def main():
diff --git a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py
index 16fdc6e7fc56..36e7ae5f826d 100755
--- a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py
+++ b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py
@@ -1,9 +1,12 @@
 #!/usr/bin/env python3
 # SPDX-License-Identifier: GPL-2.0
 
+import os
 import subprocess
+import sys
 import time
 
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 import _damon_sysfs
 
 def pass_wss_estimation(sz_region):
-- 
2.55.0


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

* Re: [PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
  2026-09-08 21:42 [PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility Eva Kurchatova
@ 2026-09-08 21:48 ` sashiko-bot
  2026-09-09  0:24   ` SJ Park
  2026-09-09  0:20 ` SJ Park
  1 sibling, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-09-08 21:48 UTC (permalink / raw)
  To: Eva Kurchatova; +Cc: damon

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch claims to fix PYTHONSAFEPATH compatibility for all DAMON Python selftests, but misses 3 test scripts, leading to an incomplete fix and a commit message mismatch.
--

commit 3a3c43c4b8c811027e52bf0fa5b68c48216e86c4
Author: Eva Kurchatova <eva.kurchatova@virtuozzo.com>

selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility

This commit adds the script's directory to sys.path for several DAMON Python
selftests to fix ModuleNotFoundError issues when running under Python's safe
path mode. It claims to fix all 7 tests that import the _damon_sysfs helper
module.

>     This breaks all 7 DAMON Python selftests that import the _damon_sysfs
>     helper module located in the same directory:

[Severity: Medium]
Are there more than 7 tests affected by this? It looks like sysfs.py,
sysfs_refresh.py, and sysfs_no_op_commit_break.py in
tools/testing/selftests/damon/ also import _damon_sysfs but lack the
sys.path.append() workaround introduced in this commit.

If these tests are run with PYTHONSAFEPATH set in the environment or with -P
on the interpreter command line, will they continue to fail with a
ModuleNotFoundError?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908214238.2680324-1-eva.kurchatova@virtuozzo.com?part=1

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

* Re: [PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
  2026-09-08 21:42 [PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility Eva Kurchatova
  2026-09-08 21:48 ` sashiko-bot
@ 2026-09-09  0:20 ` SJ Park
  1 sibling, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-09-09  0:20 UTC (permalink / raw)
  To: Eva Kurchatova
  Cc: SJ Park, Shuah Khan, linux-kernel, damon, linux-mm,
	linux-kselftest

On Wed,  9 Sep 2026 00:42:35 +0300 Eva Kurchatova <eva.kurchatova@virtuozzo.com> wrote:

> Running these tests under Python's safe path mode, either with -P on the
> interpreter command line or with PYTHONSAFEPATH set in the environment,
> stops the script's own directory being prepended to sys.path. Some
> distributions (RHEL, for example) build the tests with -P in the shebang.
> 
> This breaks all 7 DAMON Python selftests that import the _damon_sysfs
> helper module located in the same directory:
> 
>   ModuleNotFoundError: No module named '_damon_sysfs'
> 
> Fix this by explicitly adding the script's directory to sys.path before
> importing _damon_sysfs, following the same pattern used in commit
> c3b3eb565bd7 ("tools: ynl: add script dir to sys.path") which fixed the
> identical issue for the YNL tools.

Thank you for finding and fixing this, Eva!

> 
> Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>

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

This patch is applied to damon/next [1] tree.  If this patch is not added to
mm.git in short term (~1 week?), I will ask mm.git maintainer (Andrew Morton)
to pick this.  So, no action from your side is needed for now.  If it seems I
also forgot doing that or you cannot wait for my action, please feel free to
directly ask that to Andrew.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees


Thanks,
SJ

[...]

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

* Re: [PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
  2026-09-08 21:48 ` sashiko-bot
@ 2026-09-09  0:24   ` SJ Park
  0 siblings, 0 replies; 4+ messages in thread
From: SJ Park @ 2026-09-09  0:24 UTC (permalink / raw)
  To: Eva Kurchatova; +Cc: SJ Park, sashiko-bot, damon

Hi Eva,

On Tue, 08 Sep 2026 21:48:17 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The patch claims to fix PYTHONSAFEPATH compatibility for all DAMON Python selftests, but misses 3 test scripts, leading to an incomplete fix and a commit message mismatch.
> --
> 
> commit 3a3c43c4b8c811027e52bf0fa5b68c48216e86c4
> Author: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
> 
> selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
> 
> This commit adds the script's directory to sys.path for several DAMON Python
> selftests to fix ModuleNotFoundError issues when running under Python's safe
> path mode. It claims to fix all 7 tests that import the _damon_sysfs helper
> module.
> 
> >     This breaks all 7 DAMON Python selftests that import the _damon_sysfs
> >     helper module located in the same directory:
> 
> [Severity: Medium]
> Are there more than 7 tests affected by this? It looks like sysfs.py,
> sysfs_refresh.py, and sysfs_no_op_commit_break.py in
> tools/testing/selftests/damon/ also import _damon_sysfs but lack the
> sys.path.append() workaround introduced in this commit.
> 
> If these tests are run with PYTHONSAFEPATH set in the environment or with -P
> on the interpreter command line, will they continue to fail with a
> ModuleNotFoundError?

I think this is not a blocker of your patch, but could you please confirm if
Sashiko's finding is correct, and if you have a plan to fix those in future?

> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260908214238.2680324-1-eva.kurchatova@virtuozzo.com?part=1
> 


Thanks,
SJ

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

end of thread, other threads:[~2026-09-09  0:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-08 21:42 [PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility Eva Kurchatova
2026-09-08 21:48 ` sashiko-bot
2026-09-09  0:24   ` SJ Park
2026-09-09  0:20 ` SJ Park

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