[igt-dev] [PATCH i-g-t 1/3] tests/gem_exec_alignment.c: Timeout alarm wrappers

Dominik Grzegorzek dominik.grzegorzek at intel.com
Thu Mar 19 07:38:17 UTC 2020


Implementation of timeout functions in gem_exec_alignment.c.

Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
---
 tests/i915/gem_exec_alignment.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tests/i915/gem_exec_alignment.c b/tests/i915/gem_exec_alignment.c
index a10571c9..b7c11947 100644
--- a/tests/i915/gem_exec_alignment.c
+++ b/tests/i915/gem_exec_alignment.c
@@ -36,6 +36,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <signal.h>
 #include "drm.h"
 
 IGT_TEST_DESCRIPTION("Exercises the basic execbuffer using object alignments");
@@ -65,6 +66,37 @@ static uint32_t file_max(void)
 	return max;
 }
 
+static bool timed_out;
+static void alignment_alarm_handler(int signal)
+{
+	igt_debug("alignment test timed out!\n");
+	timed_out = true;
+}
+
+static void alignment_set_timeout(unsigned int sec, unsigned int usec)
+{
+	struct sigaction sa = {};
+	struct itimerval itv = {};
+
+	sa.sa_handler = alignment_alarm_handler;
+	sigemptyset(&sa.sa_mask);
+	sa.sa_flags = 0;
+	sigaction(SIGALRM, &sa, NULL);
+
+	timed_out = false;
+	itv.it_value.tv_sec = sec;
+	itv.it_value.tv_usec = usec;
+	setitimer(ITIMER_REAL, &itv, NULL);
+}
+
+static inline void alignment_reset_timeout(void)
+{
+	struct itimerval itv = {};
+
+	sigaction(SIGALRM, NULL, NULL);
+	setitimer(ITIMER_REAL, &itv, NULL);
+}
+
 static void many(int fd)
 {
 	uint32_t bbe = MI_BATCH_BUFFER_END;
-- 
2.20.1



More information about the igt-dev mailing list