public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Petri Latvala <petri.latvala@intel.com>
Subject: [igt-dev] [PATCH i-g-t 2/2] lib/igt_kms: Make igt_display_require() + chamelium more robust
Date: Wed, 6 May 2020 18:58:03 +0300	[thread overview]
Message-ID: <20200506155803.358220-2-arkadiusz.hiler@intel.com> (raw)
In-Reply-To: <20200506155803.358220-1-arkadiusz.hiler@intel.com>

1. We don't reset Chamelium, as this generates extra unplug events if
   any of the ports is already connected which is often the case

2. We try to plug all the chamelium ports, it's a noop if they are
   already plugged

2. We wait for all the ports being connected:
   - if the port mapping is provided: wait for the ports to be connected
   - if there is no mapping: sleep(10) and hope for the best

Cc: Petri Latvala <petri.latvala@intel.com>
Cc: Imre Deak <imre.deak@intel.com>
Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
---
 lib/igt_chamelium.c | 87 +++++++++++++++++++++++++++++++++++++++------
 lib/igt_chamelium.h |  2 ++
 lib/igt_kms.c       |  2 ++
 3 files changed, 80 insertions(+), 11 deletions(-)

diff --git a/lib/igt_chamelium.c b/lib/igt_chamelium.c
index 28be5248..69ad8378 100644
--- a/lib/igt_chamelium.c
+++ b/lib/igt_chamelium.c
@@ -2532,17 +2532,6 @@ bool chamelium_plug_all(struct chamelium *chamelium)
 	size_t port_count;
 	int port_ids[CHAMELIUM_MAX_PORTS];
 	xmlrpc_value *v;
-	v = __chamelium_rpc(chamelium, NULL, "Reset", "()");
-
-	if (v != NULL)
-		xmlrpc_DECREF(v);
-
-	if (chamelium->env.fault_occurred) {
-		igt_debug("Chamelium RPC call failed: %s\n",
-		     chamelium->env.fault_string);
-
-		return false;
-	}
 
 	port_count = chamelium_get_video_ports(chamelium, port_ids);
 	if (port_count <= 0)
@@ -2565,6 +2554,82 @@ bool chamelium_plug_all(struct chamelium *chamelium)
 	return true;
 }
 
+bool chamelium_wait_all_configured_ports_connected(struct chamelium *chamelium, int drm_fd)
+{
+	drmModeRes *res;
+	drmModeConnector *connector;
+	char **group_list;
+	char *group;
+	bool ret = true;
+
+	int connectors[CHAMELIUM_MAX_PORTS];
+	int connectors_count = 0;
+
+	res = drmModeGetResources(drm_fd);
+
+	group_list = g_key_file_get_groups(igt_key_file, NULL);
+
+	for (int i = 0; group_list[i] != NULL; i++) {
+		char *map_name;
+		group = group_list[i];
+
+		if (!strstr(group, "Chamelium:"))
+			continue;
+
+		igt_assert(chamelium->port_count <= CHAMELIUM_MAX_PORTS);
+
+		map_name = group + (sizeof("Chamelium:") - 1);
+
+		for (int j = 0;
+		     j < res->count_connectors;
+		     j++) {
+			char name[50];
+
+			connector = drmModeGetConnectorCurrent(
+			    drm_fd, res->connectors[j]);
+
+			/* We have to generate the connector name on our own */
+			snprintf(name, 50, "%s-%u",
+				 kmstest_connector_type_str(connector->connector_type),
+				 connector->connector_type_id);
+
+
+			if (strcmp(name, map_name) == 0) {
+				igt_assert(connectors_count < CHAMELIUM_MAX_PORTS);
+				connectors[connectors_count++] = connector->connector_id;
+				break;
+			}
+
+			drmModeFreeConnector(connector);
+		}
+	}
+
+	drmModeFreeResources(res);
+
+	if (connectors_count == 0) {
+		igt_info("No chamelium port mappping, sleeping for %d seconds "
+			 "for the hotplug to take effect",
+			 CHAMELIUM_HOTPLUG_DETECTION_DELAY);
+		sleep(CHAMELIUM_HOTPLUG_DETECTION_DELAY);
+		return true;
+	}
+
+	igt_until_timeout(CHAMELIUM_HOTPLUG_DETECTION_DELAY) {
+		ret = true;
+		for (int i = 0; i < connectors_count; ++i) {
+			connector = drmModeGetConnector(drm_fd, connectors[i]);
+			if (connector->connection != DRM_MODE_CONNECTED)
+				ret = false;
+			drmModeFreeConnector(connector);
+		}
+
+		if (ret)
+			break;
+	}
+
+	return ret;
+}
+
 igt_constructor {
 	/* Frame dumps can be large, so we need to be able to handle very large
 	 * responses
diff --git a/lib/igt_chamelium.h b/lib/igt_chamelium.h
index c29741b4..359f4ab3 100644
--- a/lib/igt_chamelium.h
+++ b/lib/igt_chamelium.h
@@ -215,5 +215,7 @@ void chamelium_destroy_frame_dump(struct chamelium_frame_dump *dump);
 void chamelium_destroy_audio_file(struct chamelium_audio_file *audio_file);
 void chamelium_infoframe_destroy(struct chamelium_infoframe *infoframe);
 bool chamelium_plug_all(struct chamelium *chamelium);
+bool chamelium_wait_all_configured_ports_connected(struct chamelium *chamelium,
+						   int drm_fd);
 
 #endif /* IGT_CHAMELIUM_H */
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index e9621e7e..d4cbc1c5 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -1899,6 +1899,8 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 				       "cannot reach the configured chamelium!\n");
 			igt_abort_on_f(!chamelium_plug_all(chamelium),
 				       "failed to plug all the chamelium ports!\n");
+			igt_abort_on_f(!chamelium_wait_all_configured_ports_connected(chamelium, drm_fd),
+				       "not all configured chamelium ports are connected!\n");
 			chamelium_deinit_rpc_only(chamelium);
 		}
 	}
-- 
2.25.2

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

  reply	other threads:[~2020-05-06 15:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-06 15:58 [igt-dev] [PATCH i-g-t 1/2] lib/igt_chamelium: Sleep when doing autodiscovery Arkadiusz Hiler
2020-05-06 15:58 ` Arkadiusz Hiler [this message]
2020-05-07 19:53   ` [igt-dev] [PATCH i-g-t 2/2] lib/igt_kms: Make igt_display_require() + chamelium more robust Imre Deak
2020-05-07 20:16     ` Imre Deak
2020-05-08 10:25       ` Arkadiusz Hiler
2020-05-06 16:37 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] lib/igt_chamelium: Sleep when doing autodiscovery Patchwork
2020-05-06 18:59 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2020-05-07 19:05 ` [igt-dev] [PATCH i-g-t 1/2] " Imre Deak

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=20200506155803.358220-2-arkadiusz.hiler@intel.com \
    --to=arkadiusz.hiler@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=petri.latvala@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox