[PATCH i-g-t v7 02/48] lib/igt_kms: Add helper to wait for a specific status on a connector

Louis Chauvet
2026-02-23T12:08:48Z

During testing with chamelium, it is frequent to wait for a specific
connector status. This new helper is polling the DRM API to wait for this
status. This allows detecting it without notifier systems which can fail
if hot plug detection is not working properly on the device under test.

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/igt_kms.c | 40 ++++++++++++++++++++++++++++++++++++++++
lib/igt_kms.h | 3 +++
2 files changed, 43 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 65e657cffda7..6435ea25db0b 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -7953,3 +7953,43 @@ bool igt_has_lobf_debugfs(int drmfd, igt_output_t *output)
buf, sizeof(buf));
return res == 0;
}
+
+/**
+ * igt_wait_for_connector_status:
+ * @drm_fd: drm file descriptor
+ * @connector_id: connector to monitor
+ * @timeout: maximum duration to wait, in second. Use -1.0 to set the timeout
+ * to igt_default_detect_timeout().
+ * @drm_mode: mode to wait for, see enum drmModeConnection
+ *
+ * Wait for at most @timeout that the connector @connector_id status
+ * become @drm_mode
+ * Returns: true when the status is reached, false if there is a timeout
+ */
+bool igt_wait_for_connector_status(int drm_fd, unsigned int connector_id, double timeout,
+ int drm_mode)
+{
+ drmModeConnector *connector;
+ struct timespec start, end;
+
+ if (timeout == -1.0)
+ timeout = igt_default_display_detect_timeout();
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ end = start;
+
+ while (igt_time_elapsed(&start, &end) <= timeout) {
+ connector = drmModeGetConnector(drm_fd, connector_id);
+ if (connector && connector->connection == drm_mode) {
+ drmModeFreeConnector(connector);
+ return true;
+ }
+ drmModeFreeConnector(connector);
+ usleep(10000);
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ }
+
+ igt_debug("Timeout waiting for connection status %d on connector %d\n", drm_mode,
+ connector_id);
+ return false;
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index dedc3f88055b..27357854e442 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -1319,4 +1319,7 @@ void igt_get_and_wait_out_fence(igt_output_t *output);

igt_colorop_t *igt_find_colorop(igt_display_t *display, uint32_t id);

+bool igt_wait_for_connector_status(int drm_fd, unsigned int connector_id, double timeout,
+ int drm_mode);
+
#endif /* __IGT_KMS_H__ */

--
2.52.0