From patchwork Thu Oct 12 13:29:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 10002011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89D2E6028A for ; Thu, 12 Oct 2017 13:30:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B22325F3E for ; Thu, 12 Oct 2017 13:30:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 703F128DD9; Thu, 12 Oct 2017 13:30:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C58A25F3E for ; Thu, 12 Oct 2017 13:30:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E79946E862; Thu, 12 Oct 2017 13:30:03 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qt0-x244.google.com (mail-qt0-x244.google.com [IPv6:2607:f8b0:400d:c0d::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 68BCD6E861; Thu, 12 Oct 2017 13:30:02 +0000 (UTC) Received: by mail-qt0-x244.google.com with SMTP id z50so13576434qtj.4; Thu, 12 Oct 2017 06:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kK8woCfEAgZvrmbvKbnKEQvElUtn9kMguTEWXKAB7uE=; b=fuvdy9Sn7Enx8LOVLEoYTFlguOjjZfbiAZAR3B5FcxxzJg18Bg1TGl3q4/G9FdWzov D70/Dkko6PcMgBUsNHDa8eQuqdR+a+HffMcTTFQMZLiLHy7ZcBTNPVduUjMTQrzYQNWj CXtwh4h/QA6ekKQ5fUIQVocv+02pNTJBOm2Tr2UGhTcvL10/YLDHaFunB/UPTlgIFrao 5q8wolSy1lYU5yPZznquofbOM25iZnABjDBz0GI97/vaw5LQKBI3E3vnxLwV2U+L0/+s DDdrrDH++easHAkt5VxdKnhp4vXpESnGqX5TW9ytwn4uy2ZBto1ESH6PVSk+v+5M3A4p AdZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kK8woCfEAgZvrmbvKbnKEQvElUtn9kMguTEWXKAB7uE=; b=Hx4N3M3ihvgRWSQ4S2uZdRoV9jFxu/emclToeCAUwaQEGQYVYhIv4a4PAvD4t+QI8Y UAecRqVFMnMwszQSc0IAd+rz2cqmI1Z0XrrzRo0L1GDs/MmmwJeTzHsJvDhq6aJWfhKg ig3pku6kit0TEyzluodPHsqaERwKo1TcYH/ciEAoYI0KC3FOZCaoocNk1Xi3+DwzCKPF xkSsHUQR/IbpOMzYPNW/jPXlwh9ZpGNrsEaizkU4Rdt/E4iASVsafYn5b+n8vpPQpMv5 CLzhPe2UQ5lBIagHq0quyHBg8YhmEZcNeApRzczvYsZG4fixPwWUrERJ7pTK7mTKmCBd vwNg== X-Gm-Message-State: AMCzsaWuD9/gwSdfRrbD712ApHzii4dVs8S++HBaoCIgqBVc/qAMQ7Z8 qgvp3E5x7gP9CxdSvgR6csozag== X-Google-Smtp-Source: AOwi7QAS25JmF6UAbNbTOJt+ohxRL/+7H48SOTGJe8eaE4TtLcG6lIWI2PIlynhCwS4S6VQbf93Qsw== X-Received: by 10.200.25.46 with SMTP id t43mr3592812qtj.204.1507815001347; Thu, 12 Oct 2017 06:30:01 -0700 (PDT) Received: from localhost (p200300E41BE4FD00CEAD5B94E1CFD280.dip0.t-ipconnect.de. [2003:e4:1be4:fd00:cead:5b94:e1cf:d280]) by smtp.gmail.com with ESMTPSA id w8sm9336969qka.88.2017.10.12.06.30.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Oct 2017 06:30:00 -0700 (PDT) From: Thierry Reding To: intel-gfx@lists.freedesktop.org Date: Thu, 12 Oct 2017 15:29:43 +0200 Message-Id: <20171012132943.28316-7-thierry.reding@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171012132943.28316-1-thierry.reding@gmail.com> References: <20171012132943.28316-1-thierry.reding@gmail.com> Cc: dri-devel@lists.freedesktop.org Subject: [Intel-gfx] [PATCH i-g-t 7/7] lib/drmtest: Allow the test device to be overridden X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding 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 --- 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;