[igt-dev] [PATCH i-g-t v2 2/2] tests/kms_chamelium: add a hotplug test with active connector

Simon Ser simon.ser at intel.com
Wed Aug 28 12:00:46 UTC 2019


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 at intel.com>
Cc: Daniel Vetter <daniel at ffwll.ch>
Cc: Imre Deak <imre.deak at 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



More information about the igt-dev mailing list