* [PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
@ 2026-09-08 21:42 Eva Kurchatova
2026-09-09 0:20 ` SJ Park
0 siblings, 1 reply; 2+ 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 [flat|nested] 2+ 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-09 0:20 ` SJ Park
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2026-09-09 0:20 UTC | newest]
Thread overview: 2+ 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-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
all inboxes | Powered by JetHome®