Skip to contentSkip to conversation

tests/kms_force_connector: free the display struct when no longer needed

PATCH New Thomas Wood 1 participant 5 messages Nov 2, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 tests/kms_force_connector: free the display struct when no longer needed

---
 tests/kms_force_connector.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/kms_force_connector.c +3 -1
index 7485ca8..f48b187 100644
@@ -36,7 +36,6 @@ igt_main
 	int drm_fd = 0;
 	drmModeRes *res;
 	drmModeConnector *vga_connector = NULL, *temp;
-	igt_display_t display;
 	int start_n_modes;
 
 	igt_fixture {
@@ -60,6 +59,8 @@ igt_main
 	}
 
 	igt_subtest("force-connector-state") {
+		igt_display_t display;
+
 		/* force the connector on and check the reported values */
 		kmstest_force_connector(drm_fd, vga_connector, FORCE_CONNECTOR_ON);
 		temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
@@ -71,6 +72,7 @@ igt_main
 		kmstest_set_vt_graphics_mode();
 		igt_display_init(&display, drm_fd);
 		igt_display_commit(&display);
+		igt_display_fini(&display);
 
 
 		/* force the connector off */
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 2/5 lib: add documentation for igt_display_init/fini

---
 lib/igt_kms.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
lib/igt_kms.c +16 -0
index 51d735d..878e1fb 100644
@@ -962,6 +962,15 @@ static int get_drm_plane_type(int drm_fd, uint32_t plane_id)
 	return DRM_PLANE_TYPE_OVERLAY;
 }
 
+/**
+ * igt_display_init:
+ * @display: a pointer to an #igt_display_t structure
+ * @drm_fd: a drm file descriptor
+ *
+ * Initialize @display and allocate the various resources required. Use
+ * #igt_display_fini to release the resources when they are no longer required.
+ *
+ */
 void igt_display_init(igt_display_t *display, int drm_fd)
 {
 	drmModeRes *resources;
@@ -1160,6 +1169,13 @@ static void igt_output_fini(igt_output_t *output)
 	free(output->name);
 }
 
+/**
+ * igt_display_fini:
+ * @display: a pointer to an #igt_display_t structure
+ *
+ * Release any resources associated with @display. This does not free @display
+ * itself.
+ */
 void igt_display_fini(igt_display_t *display)
 {
 	int i;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 3/5 tests/kms_force_connector: skip if the required connector is connected

In reply to Thomas Wood
---
 tests/kms_force_connector.c | 1 +
 1 file changed, 1 insertion(+)
tests/kms_force_connector.c +1 -0
index f48b187..1e5ec6f 100644
@@ -56,6 +56,7 @@ igt_main
 		}
 
 		igt_require(vga_connector);
+		igt_skip_on(vga_connector->connection == DRM_MODE_CONNECTED);
 	}
 
 	igt_subtest("force-connector-state") {
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH 4/5 tests/kms_force_connector: add an option to reset connector force states

In reply to Thomas Wood
---
 tests/kms_force_connector.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
tests/kms_force_connector.c +43 -1
index 1e5ec6f..2cb149a 100644
@@ -30,13 +30,55 @@ IGT_TEST_DESCRIPTION("Check the debugfs force connector/edid features work"
 #define CHECK_MODE(m, h, w, r) igt_assert(m.hdisplay == h && m.vdisplay == w \
 					  && m.vrefresh == r)
 
-igt_main
+static void __attribute__((noreturn)) reset_connectors()
+{
+	int drm_fd = 0;
+	drmModeRes *res;
+	drmModeConnector *connector = NULL;
+
+	drm_fd = drm_open_driver_master(DRIVER_INTEL);
+	res = drmModeGetResources(drm_fd);
+
+	for (int i = 0; i < res->count_connectors; i++) {
+
+		connector = drmModeGetConnector(drm_fd, res->connectors[i]);
+
+		kmstest_force_connector(drm_fd, connector,
+					FORCE_CONNECTOR_UNSPECIFIED);
+
+		drmModeFreeConnector(connector);
+	}
+
+	exit(0);
+}
+
+static int opt_handler(int opt, int opt_index, void *data)
+{
+	switch (opt) {
+	case 'r':
+		reset_connectors();
+		break;
+	}
+
+	return 0;
+}
+
+int main(int argc, char **argv)
 {
 	/* force the VGA output and test that it worked */
 	int drm_fd = 0;
 	drmModeRes *res;
 	drmModeConnector *vga_connector = NULL, *temp;
 	int start_n_modes;
+	struct option long_opts[] = {
+		{"reset", 0, 0, 'r'},
+		{0, 0, 0, 0}
+	};
+	const char *help_str =
+	       "  --reset\t\tReset all connector force states.\n";
+
+	igt_subtest_init_parse_opts(&argc, argv, "", long_opts, help_str,
+				    opt_handler, NULL);
 
 	igt_fixture {
 		drm_fd = drm_open_driver_master(DRIVER_INTEL);
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH 5/5 tests/kms_force_connector: use comparison macros

In reply to Thomas Wood

Use the comparison macros to make debug output clearer.

v2: fix incorrect comparison

---
 tests/kms_force_connector.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
tests/kms_force_connector.c +9 -8
index 2cb149a..f34f21a 100644
@@ -27,8 +27,9 @@
 IGT_TEST_DESCRIPTION("Check the debugfs force connector/edid features work"
 		     " correctly.");
 
-#define CHECK_MODE(m, h, w, r) igt_assert(m.hdisplay == h && m.vdisplay == w \
-					  && m.vrefresh == r)
+#define CHECK_MODE(m, h, w, r) \
+	igt_assert_eq(m.hdisplay, h); igt_assert_eq(m.vdisplay, w); \
+	igt_assert_eq(m.vrefresh, r);
 
 static void __attribute__((noreturn)) reset_connectors()
 {
@@ -107,8 +108,8 @@ int main(int argc, char **argv)
 		/* force the connector on and check the reported values */
 		kmstest_force_connector(drm_fd, vga_connector, FORCE_CONNECTOR_ON);
 		temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
-		igt_assert(temp->connection == DRM_MODE_CONNECTED);
-		igt_assert(temp->count_modes > 0);
+		igt_assert_eq(temp->connection, DRM_MODE_CONNECTED);
+		igt_assert_lt(0, temp->count_modes);
 		drmModeFreeConnector(temp);
 
 		/* attempt to use the display */
@@ -122,15 +123,15 @@ int main(int argc, char **argv)
 		kmstest_force_connector(drm_fd, vga_connector,
 					FORCE_CONNECTOR_OFF);
 		temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
-		igt_assert(temp->connection == DRM_MODE_DISCONNECTED);
-		igt_assert(temp->count_modes == 0);
+		igt_assert_eq(temp->connection, DRM_MODE_DISCONNECTED);
+		igt_assert_eq(0, temp->count_modes);
 		drmModeFreeConnector(temp);
 
 		/* check that the previous state is restored */
 		kmstest_force_connector(drm_fd, vga_connector,
 					FORCE_CONNECTOR_UNSPECIFIED);
 		temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
-		igt_assert(temp->connection == vga_connector->connection);
+		igt_assert_eq(temp->connection, vga_connector->connection);
 		drmModeFreeConnector(temp);
 	}
 
@@ -160,7 +161,7 @@ int main(int argc, char **argv)
 		temp = drmModeGetConnector(drm_fd, vga_connector->connector_id);
 		/* the connector should now have the same number of modes that
 		 * it started with */
-		igt_assert(temp->count_modes == start_n_modes);
+		igt_assert_eq(temp->count_modes, start_n_modes);
 		drmModeFreeConnector(temp);
 
 		kmstest_force_connector(drm_fd, vga_connector,
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx