dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Emil Velikov <emil.l.velikov@gmail.com>,
	Hyungwon Hwang <human.hwang@samsung.com>
Subject: [PATCH libdrm 07/10] tests: Add helper to open a device/module
Date: Wed,  9 Dec 2015 18:37:45 +0100	[thread overview]
Message-ID: <1449682668-22487-7-git-send-email-thierry.reding@gmail.com> (raw)
In-Reply-To: <1449682668-22487-1-git-send-email-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia.com>

The new function util_open() encapsulates the standard method employed
by tests to open a device or module. There is a verbatim copy of this in
almost all test programs, with slight variations in the list of modules.
Moving this code into a common helper allows code reuse and makes tests
more consistent.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/util/kms.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/util/kms.h |  2 ++
 2 files changed, 57 insertions(+)

diff --git a/tests/util/kms.c b/tests/util/kms.c
index 687b3c3c1cf3..57b0191b2655 100644
--- a/tests/util/kms.c
+++ b/tests/util/kms.c
@@ -41,9 +41,13 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
+#include "xf86drm.h"
 #include "xf86drmMode.h"
 
 #include "common.h"
@@ -120,3 +124,54 @@ const char *util_lookup_connector_type_name(unsigned int type)
 	return util_lookup_type_name(type, connector_type_names,
 				     ARRAY_SIZE(connector_type_names));
 }
+
+static const char * const modules[] = {
+	"i915",
+	"radeon",
+	"nouveau",
+	"vmwgfx",
+	"omapdrm",
+	"exynos",
+	"tilcdc",
+	"msm",
+	"sti",
+	"tegra",
+	"imx-drm",
+	"rockchip",
+	"atmel-hlcdc",
+};
+
+int util_open(const char *device, const char *module)
+{
+	int fd;
+
+	if (module) {
+		fd = drmOpen(module, device);
+		if (fd < 0) {
+			fprintf(stderr, "failed to open device '%s': %s\n",
+				module, strerror(errno));
+			return -errno;
+		}
+	} else {
+		unsigned int i;
+
+		for (i = 0; i < ARRAY_SIZE(modules); i++) {
+			printf("trying to open device '%s'...", modules[i]);
+
+			fd = drmOpen(modules[i], device);
+			if (fd < 0) {
+				printf("failed\n");
+			} else {
+				printf("done\n");
+				break;
+			}
+		}
+
+		if (fd < 0) {
+			fprintf(stderr, "no device found\n");
+			return -ENODEV;
+		}
+	}
+
+	return fd;
+}
diff --git a/tests/util/kms.h b/tests/util/kms.h
index fa9ab69983ac..dde2ed2c5636 100644
--- a/tests/util/kms.h
+++ b/tests/util/kms.h
@@ -30,4 +30,6 @@ const char *util_lookup_encoder_type_name(unsigned int type);
 const char *util_lookup_connector_status_name(unsigned int type);
 const char *util_lookup_connector_type_name(unsigned int type);
 
+int util_open(const char *device, const char *module);
+
 #endif /* UTIL_KMS_H */
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2015-12-09 17:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-09 17:37 [PATCH libdrm 01/10] tests: Split helpers into library Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 02/10] tests: Move name tables to libutil Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 03/10] proptest: Add Android support Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 04/10] tests: Add libkms-test library Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 05/10] tests: kms: Implement CRTC stealing test Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 06/10] tests: kms: Implement universal planes test Thierry Reding
2015-12-09 17:37 ` Thierry Reding [this message]
2015-12-09 17:37 ` [PATCH libdrm 08/10] modetest: Use util_open() Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 09/10] proptest: " Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 10/10] vbltest: " Thierry Reding
2015-12-12 15:26 ` [PATCH libdrm 01/10] tests: Split helpers into library Emil Velikov
2015-12-14  8:12   ` Thierry Reding
2015-12-14 13:10     ` Emil Velikov

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=1449682668-22487-7-git-send-email-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emil.l.velikov@gmail.com \
    --cc=human.hwang@samsung.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