[PATCH] selftests: damon: add script dir to sys.path for PYTHONSAFEPATH compatibility
From: Eva Kurchatova
Date: Tue Sep 08 2026 - 18:35:08 EST
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@xxxxxxxxxxxxx>
---
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