From patchwork Thu Nov 3 16:28:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marius Vlad X-Patchwork-Id: 9411193 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 396D660722 for ; Thu, 3 Nov 2016 16:22:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24EC22ACBB for ; Thu, 3 Nov 2016 16:22:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19FA12AD0D; Thu, 3 Nov 2016 16:22:09 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM 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 CD0102AD0A for ; Thu, 3 Nov 2016 16:22:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 24CF26E768; Thu, 3 Nov 2016 16:22:08 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id C83B76E768 for ; Thu, 3 Nov 2016 16:22:07 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP; 03 Nov 2016 09:22:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,587,1473145200"; d="scan'208";a="27406991" Received: from mcvlad-wk.rb.intel.com ([10.237.105.57]) by orsmga004.jf.intel.com with ESMTP; 03 Nov 2016 09:22:06 -0700 From: Marius Vlad To: intel-gfx@lists.freedesktop.org Date: Thu, 3 Nov 2016 18:28:11 +0200 Message-Id: <20161103162813.22622-3-marius.c.vlad@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161103162813.22622-1-marius.c.vlad@intel.com> References: <20161103162813.22622-1-marius.c.vlad@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 2/4 v5] lib/igt_gvt: Make use of libkmod helpers and fix reading gvt parameter. 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 v2: - use igt_sysfs_get_boolean() to get gvt status (Chris Wilson) - do not hard-fail when i915 module could not be loaded/unloaded (Chris Wilson) Signed-off-by: Marius Vlad Acked-by: Zhenyu Wang --- lib/igt_gvt.c | 37 ++++++++++++++++++------------------- tests/gvt_basic.c | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/igt_gvt.c b/lib/igt_gvt.c index 8bbf9bd..4ab7433 100644 --- a/lib/igt_gvt.c +++ b/lib/igt_gvt.c @@ -24,35 +24,30 @@ #include "igt.h" #include "igt_gvt.h" #include "igt_sysfs.h" +#include "igt_kmod.h" +#include #include #include #include static bool is_gvt_enabled(void) { - FILE *file; - int value; bool enabled = false; + int dir, fd; - file = fopen("/sys/module/i915/parameters/enable_gvt", "r"); - if (!file) + fd = __drm_open_driver(DRIVER_INTEL); + dir = igt_sysfs_open_parameters(fd); + if (dir < 0) return false; - if (fscanf(file, "%d", &value) == 1) - enabled = value; - fclose(file); + enabled = igt_sysfs_get_boolean(dir, "enable_gvt"); - errno = 0; - return enabled; -} + close(dir); + close(fd); -static void unload_i915(void) -{ - kick_fbcon(false); - /* pkill alsact */ + return enabled; - igt_ignore_warn(system("/sbin/modprobe -s -r i915")); } bool igt_gvt_load_module(void) @@ -60,8 +55,11 @@ bool igt_gvt_load_module(void) if (is_gvt_enabled()) return true; - unload_i915(); - igt_ignore_warn(system("/sbin/modprobe -s i915 enable_gvt=1")); + if (igt_i915_driver_unload()) + return false; + + if (igt_i915_driver_load("enable_gvt=1")) + return false; return is_gvt_enabled(); } @@ -71,8 +69,9 @@ void igt_gvt_unload_module(void) if (!is_gvt_enabled()) return; - unload_i915(); - igt_ignore_warn(system("/sbin/modprobe -s i915 enable_gvt=0")); + igt_i915_driver_unload(); + + igt_i915_driver_load(NULL); igt_assert(!is_gvt_enabled()); } diff --git a/tests/gvt_basic.c b/tests/gvt_basic.c index 48b853a..4e909a5 100644 --- a/tests/gvt_basic.c +++ b/tests/gvt_basic.c @@ -32,7 +32,7 @@ igt_main igt_fixture { igt_require(igt_gvt_load_module()); - fd = drm_open_driver(DRIVER_INTEL); + fd = __drm_open_driver(DRIVER_INTEL); } igt_subtest_f("invalid-placeholder-test");