[Intel-gfx] [PATCH i-g-t 2/4 v5] lib/igt_gvt: Make use of libkmod helpers and fix reading gvt parameter.

Marius Vlad marius.c.vlad at intel.com
Thu Nov 3 16:28:11 UTC 2016


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 <marius.c.vlad at intel.com>
---
 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 <signal.h>
 #include <dirent.h>
 #include <unistd.h>
 #include <fcntl.h>
 
 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");
-- 
2.7.4



More information about the Intel-gfx mailing list