[PATCH i-g-t v5 5/5] lib/igt_sysfs: Move igt_exit_handler into test

Pranay Samala pranay.samala at intel.com
Mon Jul 7 03:32:46 UTC 2025


In case of nested updated the exit handler will be called multiple
times. Hence calling it before the updates rather than calling after
update.

v3:
- Refactored for readability and address logical comment.

Fixes: 56b91193b825 ("lib/igt_sysfs: Implement dynamic adjustment of debug log level")
Fixes: a2ab0ec12ef4 ("tests/kms_atomic_transition: Reducing debug loglevel dynamically")
Fixes: 4baeb7397d71 ("tests/intel/kms_dp_linktrain_fallback: Reduce debug loglevel dynamically")
Fixes: 7a8a3744466f ("tests/kms_cursor_legacy: Reduce debug loglevel dynamically")
Signed-off-by: Pranay Samala <pranay.samala at intel.com>
Reviewed-by: Jan Sokolowski <jan.sokolowski at intel.com>
Reviewed-by: Naladala Ramanaidu <ramanaidu.naladala at intel.com>
---
 lib/igt_sysfs.c                         | 8 +-------
 lib/igt_sysfs.h                         | 1 +
 tests/intel/kms_dp_linktrain_fallback.c | 1 +
 tests/kms_atomic_transition.c           | 1 +
 tests/kms_cursor_legacy.c               | 1 +
 5 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 3331d46d0..aec157b5b 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -493,7 +493,7 @@ void igt_drm_debug_mask_reset(void)
 	close(dir);
 }
 
-static void igt_drm_debug_mask_reset_exit_handler(int sig)
+void igt_drm_debug_mask_reset_exit_handler(int sig)
 {
 	igt_drm_debug_mask_reset();
 }
@@ -530,12 +530,6 @@ void igt_drm_debug_mask_update(unsigned int mask_to_set)
 	igt_assert(igt_sysfs_set(dir, "debug", buf));
 
 	close(dir);
-
-	/*
-	 * TODO: Check whether multiple exit handlers will get installed,
-	 * if we call this api multiple times
-	 */
-	igt_install_exit_handler(igt_drm_debug_mask_reset_exit_handler);
 }
 
 void update_debug_mask_if_ci(unsigned int debug_mask_if_ci)
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index b86ceb63d..9cbd216e6 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -148,6 +148,7 @@ void igt_drm_debug_mask_reset(void);
 int igt_drm_debug_mask_get(int dir);
 int igt_sysfs_drm_module_params_open(void);
 void update_debug_mask_if_ci(unsigned int debug_mask_if_ci);
+void igt_drm_debug_mask_reset_exit_handler(int sig);
 
 enum drm_debug_category {
 	DRM_UT_CORE      = 1 << 0,
diff --git a/tests/intel/kms_dp_linktrain_fallback.c b/tests/intel/kms_dp_linktrain_fallback.c
index e67c29f86..fa58999e8 100644
--- a/tests/intel/kms_dp_linktrain_fallback.c
+++ b/tests/intel/kms_dp_linktrain_fallback.c
@@ -605,6 +605,7 @@ igt_main
 		igt_display_require_output(&data.display);
 		for_each_pipe(&data.display, data.pipe)
 			data.n_pipes++;
+		igt_install_exit_handler(igt_drm_debug_mask_reset_exit_handler);
 		update_debug_mask_if_ci(debug_mask_if_ci);
 
 		/*
diff --git a/tests/kms_atomic_transition.c b/tests/kms_atomic_transition.c
index 0829133a1..8c6094987 100644
--- a/tests/kms_atomic_transition.c
+++ b/tests/kms_atomic_transition.c
@@ -1187,6 +1187,7 @@ igt_main_args("", long_opts, help_str, opt_handler, &data)
 		for_each_connected_output(&data.display, output)
 			count++;
 
+		igt_install_exit_handler(igt_drm_debug_mask_reset_exit_handler);
 		update_debug_mask_if_ci(debug_mask_if_ci);
 	}
 
diff --git a/tests/kms_cursor_legacy.c b/tests/kms_cursor_legacy.c
index 5973dcaed..9f6e644e1 100644
--- a/tests/kms_cursor_legacy.c
+++ b/tests/kms_cursor_legacy.c
@@ -1851,6 +1851,7 @@ igt_main
 		 */
 		intel_psr2_restore = i915_psr2_sel_fetch_to_psr1(display.drm_fd, NULL);
 
+		igt_install_exit_handler(igt_drm_debug_mask_reset_exit_handler);
 		update_debug_mask_if_ci(debug_mask_if_ci);
 	}
 
-- 
2.34.1



More information about the igt-dev mailing list