From patchwork Wed Nov 23 12:35:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marius Vlad X-Patchwork-Id: 9443089 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 8E5816075F for ; Wed, 23 Nov 2016 12:29:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 874BE20499 for ; Wed, 23 Nov 2016 12:29:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C0CF25D99; Wed, 23 Nov 2016 12:29:29 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 15C9920499 for ; Wed, 23 Nov 2016 12:29:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DB4C06E868; Wed, 23 Nov 2016 12:29:27 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3B5256E864 for ; Wed, 23 Nov 2016 12:29:17 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 23 Nov 2016 04:29:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,538,1473145200"; d="scan'208";a="194863472" Received: from mcvlad-wk.rb.intel.com ([10.237.105.57]) by fmsmga004.fm.intel.com with ESMTP; 23 Nov 2016 04:29:15 -0800 From: Marius Vlad To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Nov 2016 14:35:10 +0200 Message-Id: <20161123123512.11421-3-marius.c.vlad@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161123123512.11421-1-marius.c.vlad@intel.com> References: <20161123123512.11421-1-marius.c.vlad@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 2/4 v6] 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 --- 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");