All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Daniel Vetter <daniel@ffwll.ch>
Subject: [igt-dev] [PATCH i-g-t v2 2/2] tests/kms_chamelium: add a hotplug test with active connector
Date: Wed, 28 Aug 2019 15:00:46 +0300	[thread overview]
Message-ID: <20190828120046.24259-3-simon.ser@intel.com> (raw)
In-Reply-To: <20190828120046.24259-1-simon.ser@intel.com>

This test enables a connector, unplugs it, re-plugs it, and makes sure the
Chamelium board still receives a video signal.

Legacy userspace doesn't necessarily handle hotplug uevents. This test makes
sure we don't break it.

The test skips DP-MST connectors (because the kernel doesn't support legacy
userspace for those) and Intel ICL Type-C connectors (hardware bug).

See [1] and [2] for more context.

[1]: https://lists.freedesktop.org/archives/igt-dev/2019-July/015071.html
[2]: https://bugs.freedesktop.org/show_bug.cgi?id=111045

Signed-off-by: Simon Ser <simon.ser@intel.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Imre Deak <imre.deak@intel.com>
---
 tests/kms_chamelium.c | 179 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 179 insertions(+)

diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
index d6aec8b97eb2..819525c6c5b7 100644
--- a/tests/kms_chamelium.c
+++ b/tests/kms_chamelium.c
@@ -1186,6 +1186,175 @@ static void test_display_aspect_ratio(data_t *data, struct chamelium_port *port)
 	drmModeFreeConnector(connector);
 }
 
+static bool is_dp_mst(data_t *data, drmModeConnector *connector)
+{
+	igt_output_t *output;
+	uint64_t path_id;
+	drmModePropertyBlobRes *path_blob;
+	bool mst;
+	const char mst_prefix[] = "mst:";
+
+	if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
+		return false;
+
+	output = igt_output_from_connector(&data->display, connector);
+	if (!igt_output_has_prop(output, IGT_CONNECTOR_PATH))
+		return false;
+
+	path_id = igt_output_get_prop(output, IGT_CONNECTOR_PATH);
+	if (path_id == 0)
+		return false;
+
+	path_blob = drmModeGetPropertyBlob(data->drm_fd, path_id);
+	igt_assert(path_blob);
+	mst = strncmp(path_blob->data, mst_prefix, strlen(mst_prefix)) == 0;
+	drmModeFreePropertyBlob(path_blob);
+	return mst;
+}
+
+static bool i915_is_type_c(data_t *data, drmModeConnector *connector)
+{
+	int fd;
+	FILE *f;
+	char *line = NULL;
+	size_t line_cap = 0;
+	ssize_t line_len;
+	bool found_connector, found_port, type_c;
+	char conn_prefix[128];
+	const char port_prefix[] = "port:";
+
+	if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
+		return false;
+
+	snprintf(conn_prefix, sizeof(conn_prefix), "connector %u:",
+		 connector->connector_id);
+
+	fd = igt_debugfs_open(data->drm_fd, "i915_display_info", O_RDONLY);
+	f = fdopen(fd, "r");
+	igt_assert(f);
+
+	found_connector = false;
+	found_port = false;
+	type_c = false;
+	while (1) {
+		line_len = getline(&line, &line_cap, f);
+		if (line_len < 0)
+			break;
+
+		if (!found_connector) {
+			found_connector = strncmp(line, conn_prefix,
+						  strlen(conn_prefix)) == 0;
+		} else {
+			if (line[0] != '\t') {
+				break;
+			}
+
+			if (strncmp(&line[1], port_prefix,
+				    strlen(port_prefix)) == 0) {
+				igt_debug("Found i915_debug_info port entry: %s",
+					  &line[1]);
+				found_port = true;
+				type_c = strstr(line, "/TC") != NULL;
+				break;
+			}
+		}
+	}
+	free(line);
+
+	fclose(f);
+
+	igt_assert(found_connector);
+	if (!found_port)
+		igt_debug("Cannot detect whether port is Type-C: "
+			  "port entry not found in i915_debug_info\n");
+
+	return type_c;
+}
+
+#define WAIT_VIDEO_INPUT_STABLE_TIMEOUT 5 /* seconds */
+
+/** test_hotplug_while_active:
+ *
+ * Plug a connector, enable it, unplug it, re-plug it and check we still have a
+ * stable input signal.
+ *
+ * Legacy userspace that doesn't consume hotplug events rely on this behaviour.
+ */
+static void
+test_hotplug_while_active(data_t *data, struct chamelium_port *port)
+{
+	struct udev_monitor *mon = igt_watch_hotplug();
+	igt_output_t *output;
+	drmModeConnector *connector;
+	igt_plane_t *primary;
+	struct igt_fb fb;
+	drmModeModeInfo mode;
+	unsigned int fb_id;
+	bool ok;
+
+	connector = chamelium_port_get_connector(data->chamelium, port, false);
+	/* The kernel doesn't support legacy userspace for DP-MST */
+	igt_skip_on(is_dp_mst(data, connector));
+	/* i915 has a hardware bug for Type-C connectors on ICL. See:
+	 * https://bugs.freedesktop.org/show_bug.cgi?id=111045 */
+	if (intel_get_device_info(intel_get_drm_devid(data->drm_fd))->is_icelake)
+		igt_skip_on(i915_is_type_c(data, connector));
+	drmModeFreeConnector(connector);
+
+	reset_state(data, port);
+
+	igt_flush_hotplugs(mon);
+
+	chamelium_plug(data->chamelium, port);
+	igt_assert(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT));
+	igt_assert_eq(reprobe_connector(data, port), DRM_MODE_CONNECTED);
+
+	output = prepare_output(data, port, TEST_EDID_BASE);
+	connector = chamelium_port_get_connector(data->chamelium, port, false);
+	primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
+	igt_assert(primary);
+
+	igt_assert(connector->count_modes > 0);
+	mode = connector->modes[0];
+	drmModeFreeConnector(connector);
+
+	fb_id = igt_create_color_pattern_fb(data->drm_fd,
+					    mode.hdisplay, mode.vdisplay,
+					    DRM_FORMAT_XRGB8888,
+					    LOCAL_DRM_FORMAT_MOD_NONE,
+					    0, 0, 0, &fb);
+	igt_assert(fb_id > 0);
+
+	enable_output(data, port, output, &mode, &fb);
+
+	ok = chamelium_port_wait_video_input_stable(data->chamelium, port,
+						    WAIT_VIDEO_INPUT_STABLE_TIMEOUT);
+	igt_assert_f(ok, "Failed to wait for video input to become stable "
+		     "after hotplug\n");
+
+	igt_flush_hotplugs(mon);
+
+	/* Unplug and re-plug the connector without disabling the output. */
+	chamelium_unplug(data->chamelium, port);
+	igt_assert_f(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT),
+		     "Expected hotplug event after unplug\n");
+	igt_assert_eq(reprobe_connector(data, port), DRM_MODE_DISCONNECTED);
+
+	igt_flush_hotplugs(mon);
+
+	chamelium_plug(data->chamelium, port);
+	igt_assert_f(igt_hotplug_detected(mon, HOTPLUG_TIMEOUT),
+		     "Expected hotplug event after unplug-replug sequence\n");
+	igt_assert_eq(reprobe_connector(data, port), DRM_MODE_CONNECTED);
+
+	ok = chamelium_port_wait_video_input_stable(data->chamelium, port,
+						    WAIT_VIDEO_INPUT_STABLE_TIMEOUT);
+	igt_assert_f(ok, "Failed to wait for video input to become stable "
+		     "after unplug and re-plug\n");
+
+	igt_cleanup_hotplug(mon);
+}
+
 
 /* Playback parameters control the audio signal we synthesize and send */
 #define PLAYBACK_CHANNELS 2
@@ -2593,6 +2762,9 @@ igt_main
 			test_basic_hotplug(&data, port,
 					   HPD_TOGGLE_COUNT_FAST);
 
+		connector_subtest("dp-hpd-active", DisplayPort)
+			test_hotplug_while_active(&data, port);
+
 		connector_subtest("dp-edid-read", DisplayPort) {
 			test_edid_read(&data, port, TEST_EDID_BASE);
 			test_edid_read(&data, port, TEST_EDID_ALT);
@@ -2674,6 +2846,9 @@ igt_main
 			test_basic_hotplug(&data, port,
 					   HPD_TOGGLE_COUNT_FAST);
 
+		connector_subtest("hdmi-hpd-active", HDMIA)
+			test_hotplug_while_active(&data, port);
+
 		connector_subtest("hdmi-edid-read", HDMIA) {
 			test_edid_read(&data, port, TEST_EDID_BASE);
 			test_edid_read(&data, port, TEST_EDID_ALT);
@@ -2833,6 +3008,10 @@ igt_main
 		connector_subtest("vga-hpd-fast", VGA)
 			test_basic_hotplug(&data, port, HPD_TOGGLE_COUNT_FAST);
 
+		connector_subtest("vga-hpd-active", VGA)
+			test_hotplug_while_active(&data, port);
+
+
 		connector_subtest("vga-edid-read", VGA) {
 			test_edid_read(&data, port, TEST_EDID_BASE);
 			test_edid_read(&data, port, TEST_EDID_ALT);
-- 
2.23.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-08-28 11:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-28 12:00 [igt-dev] [PATCH i-g-t v2 0/2] Add a hotplug test with an active connector Simon Ser
2019-08-28 12:00 ` [igt-dev] [PATCH i-g-t v2 1/2] lib/igt_kms: add the PATH property Simon Ser
2019-08-28 12:00 ` Simon Ser [this message]
2019-08-28 12:01   ` [igt-dev] [PATCH i-g-t v2 2/2] tests/kms_chamelium: add a hotplug test with active connector Ser, Simon
2019-08-29  8:22 ` [igt-dev] ✓ Fi.CI.BAT: success for Add a hotplug test with an " Patchwork
2019-08-29 12:16 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190828120046.24259-3-simon.ser@intel.com \
    --to=simon.ser@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.