Skip to contentSkip to conversation

lib: don't abort if forcing the connector state fails

PATCH In review Thomas Wood 3 participants 3 messages Jul 28, 2014 – Jul 29, 2014 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: don't abort if forcing the connector state fails

Ensure tests using igt_enable_connectors can still run even if the relevant debugfs files are not available.

---
 lib/igt_kms.c | 19 ++++++++++++++-----
 lib/igt_kms.h |  2 +-
 2 files changed, 15 insertions(+), 6 deletions(-)
lib/igt_kms.c +14 -5
index 20370a9..740b5dd 100644
@@ -429,9 +429,11 @@ static char* get_debugfs_connector_path(int drm_fd, drmModeConnector *connector,
  * @state: state to force on @connector
  *
  * Force the specified state on the specified connector.
+ *
+ * Returns: true on success
  */
-void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum
-			     kmstest_force_connector_state state)
+bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
+			     enum kmstest_force_connector_state state)
 {
 	char *path;
 	const char *value;
@@ -458,12 +460,15 @@ void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum
 	debugfs_fd = open(path, O_WRONLY | O_TRUNC);
 	free(path);
 
-	igt_assert(debugfs_fd != -1);
+	if (debugfs_fd == -1) {
+		return false;
+	}
 
 	ret = write(debugfs_fd, value, strlen(value));
 	close(debugfs_fd);
 
 	igt_assert(ret != -1);
+	return (ret == -1) ? false : true;
 }
 
 /**
@@ -1509,8 +1514,12 @@ void igt_enable_connectors(void)
 			continue;
 
 		/* just enable VGA for now */
-		if (c->connector_type == DRM_MODE_CONNECTOR_VGA)
-			kmstest_force_connector(drm_fd, c, FORCE_CONNECTOR_ON);
+		if (c->connector_type == DRM_MODE_CONNECTOR_VGA) {
+			if (!kmstest_force_connector(drm_fd, c, FORCE_CONNECTOR_ON))
+				igt_info("Unable to force state on %s-%d\n",
+					 kmstest_connector_type_str(c->connector_type),
+					 c->connector_type_id);
+		}
 
 		drmModeFreeConnector(c);
 	}
lib/igt_kms.h +1 -1
index fb0e66a..08b46ab 100644
@@ -130,7 +130,7 @@ int kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
 int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
 				 unsigned long crtc_idx_mask,
 				 struct kmstest_connector_config *config);
-void kmstest_force_connector(int fd, drmModeConnector *connector,
+bool kmstest_force_connector(int fd, drmModeConnector *connector,
 			     enum kmstest_force_connector_state state);
 void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
 			const unsigned char *edid, size_t length);
Signature · 1 line
1.9.3
#1 lore raw
Quoted 28 lines · Thomas Wood

Ensure tests using igt_enable_connectors can still run even if the relevant debugfs files are not available.

---
 lib/igt_kms.c | 19 ++++++++++++++-----
 lib/igt_kms.h |  2 +-
 2 files changed, 15 insertions(+), 6 deletions(-)
lib/igt_kms.c +4 -2
index 20370a9..740b5dd 100644
@@ -429,9 +429,11 @@ static char* get_debugfs_connector_path(int drm_fd, drmModeConnector *connector,
  * @state: state to force on @connector
  *
  * Force the specified state on the specified connector.
+ *
+ * Returns: true on success
  */
-void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum
-			     kmstest_force_connector_state state)
+bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
+			     enum kmstest_force_connector_state state)
 {
 	char *path;
 	const char *value;

lib/igt_kms.c void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum · line 465

Quoted 7 lines
lib/igt_kms.c +3 -1
@@ -458,12 +460,15 @@ void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum
 	debugfs_fd = open(path, O_WRONLY | O_TRUNC);
 	free(path);
 
-	igt_assert(debugfs_fd != -1);
+	if (debugfs_fd == -1) {
+		return false;
+	}

Aside: We have some neat debugfs helpers in igt_debugfs.c. Might convert over to them while at it.
-Daniel

Quoted 44 lines
lib/igt_kms.c +7 -2
 	ret = write(debugfs_fd, value, strlen(value));
 	close(debugfs_fd);
 
 	igt_assert(ret != -1);
+	return (ret == -1) ? false : true;
 }
 
 /**
@@ -1509,8 +1514,12 @@ void igt_enable_connectors(void)
 			continue;
 
 		/* just enable VGA for now */
-		if (c->connector_type == DRM_MODE_CONNECTOR_VGA)
-			kmstest_force_connector(drm_fd, c, FORCE_CONNECTOR_ON);
+		if (c->connector_type == DRM_MODE_CONNECTOR_VGA) {
+			if (!kmstest_force_connector(drm_fd, c, FORCE_CONNECTOR_ON))
+				igt_info("Unable to force state on %s-%d\n",
+					 kmstest_connector_type_str(c->connector_type),
+					 c->connector_type_id);
+		}
 
 		drmModeFreeConnector(c);
 	}
lib/igt_kms.h +1 -1
index fb0e66a..08b46ab 100644
@@ -130,7 +130,7 @@ int kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
 int kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
 				 unsigned long crtc_idx_mask,
 				 struct kmstest_connector_config *config);
-void kmstest_force_connector(int fd, drmModeConnector *connector,
+bool kmstest_force_connector(int fd, drmModeConnector *connector,
 			     enum kmstest_force_connector_state state);
 void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
 			const unsigned char *edid, size_t length);
Signature · 6 lines
1.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#2 lore raw
Quoted 32 lines · Daniel Vetter
Quoted 31 lines · Thomas Wood

Ensure tests using igt_enable_connectors can still run even if the relevant debugfs files are not available.

---
 lib/igt_kms.c | 19 ++++++++++++++-----
 lib/igt_kms.h |  2 +-
 2 files changed, 15 insertions(+), 6 deletions(-)
lib/igt_kms.c +4 -2
index 20370a9..740b5dd 100644
@@ -429,9 +429,11 @@ static char* get_debugfs_connector_path(int drm_fd, drmModeConnector *connector,
  * @state: state to force on @connector
  *
  * Force the specified state on the specified connector.
+ *
+ * Returns: true on success
  */
-void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum
-			     kmstest_force_connector_state state)
+bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
+			     enum kmstest_force_connector_state state)
 {
 	char *path;
 	const char *value;
@@ -458,12 +460,15 @@ void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum
 	debugfs_fd = open(path, O_WRONLY | O_TRUNC);
 	free(path);
 
Quoted 7 lines

lib/igt_kms.c void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum · line 465

Quoted 4 lines
lib/igt_kms.c +3 -1
-	igt_assert(debugfs_fd != -1);
+	if (debugfs_fd == -1) {
+		return false;
+	}

Aside: We have some neat debugfs helpers in igt_debugfs.c. Might convert over to them while at it.

Aside: they are not that neat... :p I felt restricted that I couldn't open the right debugfs for an fd I had - the assumption of the singleton is too prescriptive.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre