[PATCH i-g-t] lib/i915: Reset all engine properties to defaults prior to the start of a test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We need each test in an isolated context, so that bad results from one
test do not interfere with the next. In particular, we want to clean up
the device and reset it to the defaults so that they are known for the
next test, and the test can focus on behaviour it wants to control.

Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Cc: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxx>
Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>
---
 lib/i915/gem.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/lib/i915/gem.c b/lib/i915/gem.c
index b2717ba6a..6fa8abf21 100644
--- a/lib/i915/gem.c
+++ b/lib/i915/gem.c
@@ -22,6 +22,7 @@
  *
  */
 
+#include <dirent.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 
@@ -30,6 +31,87 @@
 #include "igt_debugfs.h"
 #include "igt_sysfs.h"
 
+static void __restore_defaults(int engine)
+{
+	struct dirent *de;
+	int defaults;
+	DIR *dir;
+
+	defaults = openat(engine, ".defaults", O_RDONLY);
+	if (defaults < 0)
+		return;
+
+	dir = fdopendir(defaults);
+	if (!dir) {
+		close(defaults);
+		return;
+	}
+
+	while ((de = readdir(dir))) {
+		char buf[256];
+		int fd, len;
+
+		if (*de->d_name == '.')
+			continue;
+
+		fd = openat(defaults, de->d_name, O_RDONLY);
+		if (fd < 0)
+			continue;
+
+		len = read(fd, buf, sizeof(buf));
+		close(fd);
+
+		fd = openat(engine, de->d_name, O_WRONLY);
+		if (fd < 0)
+			continue;
+
+		write(fd, buf, len);
+		close(fd);
+	}
+
+	closedir(dir);
+}
+
+static void restore_defaults(int i915)
+{
+	struct dirent *de;
+	int engines;
+	DIR *dir;
+	int sys;
+
+	sys = igt_sysfs_open(i915);
+	if (sys < 0)
+		return;
+
+	engines = openat(sys, "engine", O_RDONLY);
+	if (engines < 0)
+		goto close_sys;
+
+	dir = fdopendir(engines);
+	if (!dir) {
+		close(engines);
+		goto close_sys;
+	}
+
+	while ((de = readdir(dir))) {
+		int engine;
+
+		if (*de->d_name == '.')
+			continue;
+
+		engine = openat(engines, de->d_name, O_RDONLY);
+		if (engine < 0)
+			continue;
+
+		__restore_defaults(engine);
+		close(engine);
+	}
+
+	closedir(dir);
+close_sys:
+	close(sys);
+}
+
 static void reset_device(int i915)
 {
 	int dir;
@@ -66,6 +148,7 @@ void igt_require_gem(int i915)
 	 * sequences of batches.
 	 */
 	reset_device(i915);
+	restore_defaults(i915);
 
 	err = 0;
 	if (ioctl(i915, DRM_IOCTL_I915_GEM_THROTTLE)) {
-- 
2.26.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx



[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux