public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH i-g-t 7/7] lib/drmtest: Allow the test device to be overridden
Date: Thu, 12 Oct 2017 15:29:43 +0200	[thread overview]
Message-ID: <20171012132943.28316-7-thierry.reding@gmail.com> (raw)
In-Reply-To: <20171012132943.28316-1-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia.com>

On setups where the device to be tested is not the first one, allow
users to override it using the IGT_DEVICE environment variable.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 lib/drmtest.c | 91 ++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 56 insertions(+), 35 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index e05f88d4a887..1d814734162c 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -245,6 +245,47 @@ static int modprobe(const char *driver)
 	return igt_kmod_load(driver, "");
 }
 
+static int __drm_open_device(const char *device, int chipset)
+{
+	int fd;
+
+	fd = open(device, O_RDWR);
+	if (fd == -1)
+		return fd;
+
+	if (chipset & DRIVER_INTEL && is_i915_device(fd) &&
+	    has_known_intel_chipset(fd))
+		return fd;
+
+	if (chipset & DRIVER_VC4 &&
+	    is_vc4_device(fd))
+		return fd;
+
+	if (chipset & DRIVER_VGEM &&
+	    is_vgem_device(fd))
+		return fd;
+
+	if (chipset & DRIVER_VIRTIO &&
+	    is_virtio_device(fd))
+		return fd;
+
+	if (chipset & DRIVER_AMDGPU && is_amd_device(fd))
+		return fd;
+
+	if (chipset & DRIVER_NOUVEAU && is_nouveau_device(fd))
+		return fd;
+
+	if (chipset & DRIVER_TEGRA && is_tegra_device(fd))
+		return fd;
+
+	/* Only VGEM-specific tests should be run on VGEM */
+	if (chipset == DRIVER_ANY && !is_vgem_device(fd))
+		return fd;
+
+	close(fd);
+	return -1;
+}
+
 /**
  * __drm_open_driver:
  * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
@@ -256,48 +297,25 @@ static int modprobe(const char *driver)
  */
 int __drm_open_driver(int chipset)
 {
+	char *name = getenv("IGT_DEVICE");
+
+	if (name)
+		return __drm_open_device(name, chipset);
+
 	if (chipset & DRIVER_VGEM)
 		modprobe("vgem");
 
 	for (int i = 0; i < 16; i++) {
-		char name[80];
-		int fd;
+		int fd, ret;
 
-		sprintf(name, "/dev/dri/card%u", i);
-		fd = open(name, O_RDWR);
-		if (fd == -1)
-			continue;
-
-		if (chipset & DRIVER_INTEL && is_i915_device(fd) &&
-		    has_known_intel_chipset(fd))
-			return fd;
-
-		if (chipset & DRIVER_VC4 &&
-		    is_vc4_device(fd))
-			return fd;
-
-		if (chipset & DRIVER_VGEM &&
-		    is_vgem_device(fd))
-			return fd;
-
-		if (chipset & DRIVER_VIRTIO &&
-		    is_virtio_device(fd))
-			return fd;
-
-		if (chipset & DRIVER_AMDGPU && is_amd_device(fd))
-			return fd;
-
-		if (chipset & DRIVER_NOUVEAU && is_nouveau_device(fd))
-			return fd;
+		ret = asprintf(&name, "/dev/dri/card%u", i);
+		igt_assert(ret != -1);
 
-		if (chipset & DRIVER_TEGRA && is_tegra_device(fd))
-			return fd;
+		fd = __drm_open_device(name, chipset);
+		free(name);
 
-		/* Only VGEM-specific tests should be run on VGEM */
-		if (chipset == DRIVER_ANY && !is_vgem_device(fd))
+		if (fd >= 0)
 			return fd;
-
-		close(fd);
 	}
 
 	return -1;
@@ -305,9 +323,12 @@ int __drm_open_driver(int chipset)
 
 static int __drm_open_driver_render(int chipset)
 {
-	char *name;
+	char *name = getenv("IGT_DEVICE");
 	int i, fd;
 
+	if (name)
+		return __drm_open_device(name, chipset);
+
 	for (i = 128; i < (128 + 16); i++) {
 		int ret;
 
-- 
2.14.1

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

  parent reply	other threads:[~2017-10-12 13:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-12 13:29 [PATCH i-g-t 1/7] tests/perf: Fix a bunch of warnings on 32-bit systems Thierry Reding
2017-10-12 13:29 ` [PATCH i-g-t 2/7] tools/aubdump: Avoid ISO C90 warning Thierry Reding
2017-10-12 13:29 ` [PATCH i-g-t 3/7] lib: Fix compilation on non-x86 Thierry Reding
2017-10-12 13:44   ` Ville Syrjälä
2017-10-12 13:56     ` [Intel-gfx] " Thierry Reding
2017-10-17 22:05   ` Chris Wilson
2017-10-12 13:29 ` [PATCH i-g-t 4/7] lib/drmtest: Fix typo Thierry Reding
2017-10-12 13:29 ` [PATCH i-g-t 5/7] lib/drmtest: Support nouveau Thierry Reding
2017-10-12 13:29 ` [PATCH i-g-t 6/7] lib/drmtest: Support Tegra Thierry Reding
2017-10-12 13:29 ` Thierry Reding [this message]
2017-10-12 13:38 ` [PATCH i-g-t 1/7] tests/perf: Fix a bunch of warnings on 32-bit systems Lionel Landwerlin
2017-10-12 13:42 ` Ville Syrjälä
2017-10-12 14:08 ` ✓ Fi.CI.BAT: success for series starting with [1/7] " Patchwork
2017-10-12 19:55 ` ✗ Fi.CI.IGT: failure " 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=20171012132943.28316-7-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox