igt/gem_eio: Install an exithandler to unwedge the device after failure

Under normal conditions, we try to repair the damage we inflict to the
GPU, but if we fail we don't. Make sure that if the test does die, we do
try to restore normal operation by using an atexit handler.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102616
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
diff --git a/tests/gem_eio.c b/tests/gem_eio.c
index 1512084..207a9ef 100644
--- a/tests/gem_eio.c
+++ b/tests/gem_eio.c
@@ -220,14 +220,27 @@
 	trigger_reset(fd);
 }
 
+static int fd = -1;
+
+static void
+exit_handler(int sig)
+{
+	i915_reset_control(true);
+	igt_force_gpu_reset(fd);
+}
+
 igt_main
 {
-	int fd = -1;
 
 	igt_skip_on_simulation();
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
+
+		igt_require(i915_reset_control(true));
+		igt_force_gpu_reset(fd);
+		igt_install_exit_handler(exit_handler);
+
 		igt_require_gem(fd);
 		igt_require_hang_ring(fd, I915_EXEC_DEFAULT);
 	}
@@ -243,7 +256,4 @@
 
 	igt_subtest("in-flight")
 		test_inflight(fd);
-
-	igt_fixture
-		close(fd);
 }