[RFC PATCH i-g-t 1/3] tests/chamelium: Move some functions and structures to a common place

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We are going to use a few functions already defined in kms_chamelium in
other tests. Let's move them out in a separate file / header.

Signed-off-by: Maxime Ripard <maxime.ripard@xxxxxxxxxxx>
---
 tests/Makefile.sources    |   5 ++
 tests/helpers_chamelium.c | 165 ++++++++++++++++++++++++++++++++++++++++++++
 tests/helpers_chamelium.h |  65 ++++++++++++++++++
 tests/kms_chamelium.c     | 170 +---------------------------------------------
 4 files changed, 236 insertions(+), 169 deletions(-)
 create mode 100644 tests/helpers_chamelium.c
 create mode 100644 tests/helpers_chamelium.h

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 23f859beecef..c27226fc96c9 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -275,6 +275,11 @@ scripts = \
 
 IMAGES = pass.png 1080p-left.png 1080p-right.png
 
+kms_chamelium_SOURCES = \
+	kms_chamelium.c \
+	helpers_chamelium.h \
+	helpers_chamelium.c
+
 testdisplay_SOURCES = \
 	testdisplay.c \
 	testdisplay.h \
diff --git a/tests/helpers_chamelium.c b/tests/helpers_chamelium.c
new file mode 100644
index 000000000000..2d60a8c5f944
--- /dev/null
+++ b/tests/helpers_chamelium.c
@@ -0,0 +1,165 @@
+/*
+ * Copyright © 2016 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Lyude Paul <lyude@xxxxxxxxxx>
+ */
+#include "helpers_chamelium.h"
+
+void require_connector_present(data_t *data, unsigned int type)
+{
+	int i;
+	bool found = false;
+
+	for (i = 0; i < data->port_count && !found; i++) {
+		if (chamelium_port_get_type(data->ports[i]) == type)
+			found = true;
+	}
+
+	igt_require_f(found, "No port of type %s was found\n",
+		      kmstest_connector_type_str(type));
+}
+
+drmModeConnection reprobe_connector(data_t *data, struct chamelium_port *port)
+{
+	drmModeConnector *connector;
+	drmModeConnection status;
+
+	igt_debug("Reprobing %s...\n", chamelium_port_get_name(port));
+	connector = chamelium_port_get_connector(data->chamelium, port, true);
+	igt_assert(connector);
+	status = connector->connection;
+
+	drmModeFreeConnector(connector);
+	return status;
+}
+
+void wait_for_connector(data_t *data, struct chamelium_port *port,
+			drmModeConnection status)
+{
+	bool finished = false;
+
+	igt_debug("Waiting for %s to %sconnect...\n",
+		  chamelium_port_get_name(port),
+		  status == DRM_MODE_DISCONNECTED ? "dis" : "");
+
+	/*
+	 * Rely on simple reprobing so we don't fail tests that don't require
+	 * that hpd events work in the event that hpd doesn't work on the system
+	 */
+	igt_until_timeout(HOTPLUG_TIMEOUT) {
+		if (reprobe_connector(data, port) == status) {
+			finished = true;
+			return;
+		}
+
+		usleep(50000);
+	}
+
+	igt_assert(finished);
+}
+
+void reset_state(data_t *data, struct chamelium_port *port)
+{
+	int p;
+
+	chamelium_reset(data->chamelium);
+
+	if (port) {
+		wait_for_connector(data, port, DRM_MODE_DISCONNECTED);
+	} else {
+		for (p = 0; p < data->port_count; p++) {
+			port = data->ports[p];
+			wait_for_connector(data, port, DRM_MODE_DISCONNECTED);
+		}
+	}
+}
+
+igt_output_t *prepare_output(data_t *data, struct chamelium_port *port)
+{
+	igt_display_t *display = &data->display;
+	igt_output_t *output;
+	drmModeRes *res;
+	drmModeConnector *connector =
+		chamelium_port_get_connector(data->chamelium, port, false);
+	enum pipe pipe;
+	bool found = false;
+
+	igt_assert(res = drmModeGetResources(data->drm_fd));
+
+	/* The chamelium's default EDID has a lot of resolutions, way more then
+	 * we need to test
+	 */
+	chamelium_port_set_edid(data->chamelium, port, data->edid_id);
+
+	chamelium_plug(data->chamelium, port);
+	wait_for_connector(data, port, DRM_MODE_CONNECTED);
+
+	igt_display_reset(display);
+
+	output = igt_output_from_connector(display, connector);
+
+	for_each_pipe(display, pipe) {
+		if (!igt_pipe_connector_valid(pipe, output))
+			continue;
+
+		found = true;
+		break;
+	}
+
+	igt_assert_f(found, "No pipe found for output %s\n", igt_output_name(output));
+
+	igt_output_set_pipe(output, pipe);
+
+	drmModeFreeConnector(connector);
+	drmModeFreeResources(res);
+
+	return output;
+}
+
+void enable_output(data_t *data, struct chamelium_port *port,
+		   igt_output_t *output, drmModeModeInfo *mode,
+		   struct igt_fb *fb)
+{
+	igt_display_t *display = output->display;
+	igt_plane_t *primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
+	drmModeConnector *connector = chamelium_port_get_connector(
+	    data->chamelium, port, false);
+
+	igt_assert(primary);
+
+	igt_plane_set_size(primary, mode->hdisplay, mode->vdisplay);
+	igt_plane_set_fb(primary, fb);
+	igt_output_override_mode(output, mode);
+
+	/* Clear any color correction values that might be enabled */
+	igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_DEGAMMA_LUT, NULL, 0);
+	igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_GAMMA_LUT, NULL, 0);
+	igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_CTM, NULL, 0);
+
+	igt_display_commit2(display, COMMIT_ATOMIC);
+
+	if (chamelium_port_get_type(port) == DRM_MODE_CONNECTOR_VGA)
+		usleep(250000);
+
+	drmModeFreeConnector(connector);
+}
diff --git a/tests/helpers_chamelium.h b/tests/helpers_chamelium.h
new file mode 100644
index 000000000000..5ae67bc4410d
--- /dev/null
+++ b/tests/helpers_chamelium.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2016 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Lyude Paul <lyude@xxxxxxxxxx>
+ */
+#include "igt.h"
+
+#define HOTPLUG_TIMEOUT 20 /* seconds */
+
+#define HPD_STORM_PULSE_INTERVAL_DP 100 /* ms */
+#define HPD_STORM_PULSE_INTERVAL_HDMI 200 /* ms */
+
+#define HPD_TOGGLE_COUNT_VGA 5
+#define HPD_TOGGLE_COUNT_DP_HDMI 15
+#define HPD_TOGGLE_COUNT_FAST 3
+
+struct chamelium_frame_dump {
+	unsigned char *bgr;
+	size_t size;
+	int width;
+	int height;
+	struct chamelium_port *port;
+};
+
+typedef struct {
+	struct chamelium *chamelium;
+	struct chamelium_port **ports;
+	igt_display_t display;
+	int port_count;
+
+	int drm_fd;
+
+	int edid_id;
+	int alt_edid_id;
+} data_t;
+
+void require_connector_present(data_t *data, unsigned int type);
+drmModeConnection reprobe_connector(data_t *data, struct chamelium_port *port);
+void wait_for_connector(data_t *data, struct chamelium_port *port,
+			drmModeConnection status);
+void reset_state(data_t *data, struct chamelium_port *port);
+igt_output_t *prepare_output(data_t *data, struct chamelium_port *port);
+void enable_output(data_t *data, struct chamelium_port *port,
+		   igt_output_t *output, drmModeModeInfo *mode,
+		   struct igt_fb *fb);
diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
index 8855a8300049..6419b72fcc9f 100644
--- a/tests/kms_chamelium.c
+++ b/tests/kms_chamelium.c
@@ -25,32 +25,12 @@
  */
 
 #include "config.h"
+#include "helpers_chamelium.h"
 #include "igt.h"
 
 #include <fcntl.h>
 #include <string.h>
 
-typedef struct {
-	struct chamelium *chamelium;
-	struct chamelium_port **ports;
-	igt_display_t display;
-	int port_count;
-
-	int drm_fd;
-
-	int edid_id;
-	int alt_edid_id;
-} data_t;
-
-#define HOTPLUG_TIMEOUT 20 /* seconds */
-
-#define HPD_STORM_PULSE_INTERVAL_DP 100 /* ms */
-#define HPD_STORM_PULSE_INTERVAL_HDMI 200 /* ms */
-
-#define HPD_TOGGLE_COUNT_VGA 5
-#define HPD_TOGGLE_COUNT_DP_HDMI 15
-#define HPD_TOGGLE_COUNT_FAST 3
-
 static void
 get_connectors_link_status_failed(data_t *data, bool *link_status_failed)
 {
@@ -76,62 +56,6 @@ get_connectors_link_status_failed(data_t *data, bool *link_status_failed)
 	}
 }
 
-static void
-require_connector_present(data_t *data, unsigned int type)
-{
-	int i;
-	bool found = false;
-
-	for (i = 0; i < data->port_count && !found; i++) {
-		if (chamelium_port_get_type(data->ports[i]) == type)
-			found = true;
-	}
-
-	igt_require_f(found, "No port of type %s was found\n",
-		      kmstest_connector_type_str(type));
-}
-
-static drmModeConnection
-reprobe_connector(data_t *data, struct chamelium_port *port)
-{
-	drmModeConnector *connector;
-	drmModeConnection status;
-
-	igt_debug("Reprobing %s...\n", chamelium_port_get_name(port));
-	connector = chamelium_port_get_connector(data->chamelium, port, true);
-	igt_assert(connector);
-	status = connector->connection;
-
-	drmModeFreeConnector(connector);
-	return status;
-}
-
-static void
-wait_for_connector(data_t *data, struct chamelium_port *port,
-		   drmModeConnection status)
-{
-	bool finished = false;
-
-	igt_debug("Waiting for %s to %sconnect...\n",
-		  chamelium_port_get_name(port),
-		  status == DRM_MODE_DISCONNECTED ? "dis" : "");
-
-	/*
-	 * Rely on simple reprobing so we don't fail tests that don't require
-	 * that hpd events work in the event that hpd doesn't work on the system
-	 */
-	igt_until_timeout(HOTPLUG_TIMEOUT) {
-		if (reprobe_connector(data, port) == status) {
-			finished = true;
-			return;
-		}
-
-		usleep(50000);
-	}
-
-	igt_assert(finished);
-}
-
 static int chamelium_vga_modes[][2] = {
 	{ 1600, 1200 },
 	{ 1920, 1200 },
@@ -202,23 +126,6 @@ check_analog_bridge(data_t *data, struct chamelium_port *port)
 	return false;
 }
 
-static void
-reset_state(data_t *data, struct chamelium_port *port)
-{
-	int p;
-
-	chamelium_reset(data->chamelium);
-
-	if (port) {
-		wait_for_connector(data, port, DRM_MODE_DISCONNECTED);
-	} else {
-		for (p = 0; p < data->port_count; p++) {
-			port = data->ports[p];
-			wait_for_connector(data, port, DRM_MODE_DISCONNECTED);
-		}
-	}
-}
-
 static void
 test_basic_hotplug(data_t *data, struct chamelium_port *port, int toggle_count)
 {
@@ -408,81 +315,6 @@ test_suspend_resume_edid_change(data_t *data, struct chamelium_port *port,
 		igt_skip_on(!link_status_failed[0][p] && link_status_failed[1][p]);
 }
 
-static igt_output_t *
-prepare_output(data_t *data,
-	       struct chamelium_port *port)
-{
-	igt_display_t *display = &data->display;
-	igt_output_t *output;
-	drmModeRes *res;
-	drmModeConnector *connector =
-		chamelium_port_get_connector(data->chamelium, port, false);
-	enum pipe pipe;
-	bool found = false;
-
-	igt_assert(res = drmModeGetResources(data->drm_fd));
-
-	/* The chamelium's default EDID has a lot of resolutions, way more then
-	 * we need to test
-	 */
-	chamelium_port_set_edid(data->chamelium, port, data->edid_id);
-
-	chamelium_plug(data->chamelium, port);
-	wait_for_connector(data, port, DRM_MODE_CONNECTED);
-
-	igt_display_reset(display);
-
-	output = igt_output_from_connector(display, connector);
-
-	for_each_pipe(display, pipe) {
-		if (!igt_pipe_connector_valid(pipe, output))
-			continue;
-
-		found = true;
-		break;
-	}
-
-	igt_assert_f(found, "No pipe found for output %s\n", igt_output_name(output));
-
-	igt_output_set_pipe(output, pipe);
-
-	drmModeFreeConnector(connector);
-	drmModeFreeResources(res);
-
-	return output;
-}
-
-static void
-enable_output(data_t *data,
-	      struct chamelium_port *port,
-	      igt_output_t *output,
-	      drmModeModeInfo *mode,
-	      struct igt_fb *fb)
-{
-	igt_display_t *display = output->display;
-	igt_plane_t *primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
-	drmModeConnector *connector = chamelium_port_get_connector(
-	    data->chamelium, port, false);
-
-	igt_assert(primary);
-
-	igt_plane_set_size(primary, mode->hdisplay, mode->vdisplay);
-	igt_plane_set_fb(primary, fb);
-	igt_output_override_mode(output, mode);
-
-	/* Clear any color correction values that might be enabled */
-	igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_DEGAMMA_LUT, NULL, 0);
-	igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_GAMMA_LUT, NULL, 0);
-	igt_pipe_obj_replace_prop_blob(primary->pipe, IGT_CRTC_CTM, NULL, 0);
-
-	igt_display_commit2(display, COMMIT_ATOMIC);
-
-	if (chamelium_port_get_type(port) == DRM_MODE_CONNECTOR_VGA)
-		usleep(250000);
-
-	drmModeFreeConnector(connector);
-}
-
 static void
 test_display_crc(data_t *data, struct chamelium_port *port, int count,
 		 bool fast)
-- 
2.14.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux