[PATCH libinput 05/13] test: make sure we remove all udev rules when we SIGINT the test

Peter Hutterer peter.hutterer at who-t.net
Tue Aug 2 02:40:50 UTC 2016


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/litest.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/test/litest.c b/test/litest.c
index 7c18568..492aa3a 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -34,6 +34,7 @@
 #include <fnmatch.h>
 #include <getopt.h>
 #include <poll.h>
+#include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -73,6 +74,9 @@ struct created_file {
 	char *path;
 };
 
+struct list created_files_list; /* list of all files to remove at the end of
+				   the test run */
+
 static void litest_init_udev_rules(struct list *created_files_list);
 static void litest_remove_udev_rules(struct list *created_files_list);
 
@@ -837,13 +841,40 @@ struct libinput_interface interface = {
 	.close_restricted = close_restricted,
 };
 
+static void
+litest_signal(int sig)
+{
+	struct created_file *f, *tmp;
+
+	list_for_each_safe(f, tmp, &created_files_list, link) {
+		list_remove(&f->link);
+		unlink(f->path);
+		/* in the sighandler, we can't free */
+	}
+
+	exit(1);
+}
+
+static inline void
+litest_setup_sighandler(int sig)
+{
+	struct sigaction act, oact;
+	int rc;
+
+	sigemptyset(&act.sa_mask);
+	sigaddset(&act.sa_mask, sig);
+	act.sa_flags = 0;
+	act.sa_handler = litest_signal;
+	rc = sigaction(sig, &act, &oact);
+	litest_assert_int_ne(rc, -1);
+}
+
 static inline int
 litest_run(int argc, char **argv)
 {
 	struct suite *s, *snext;
 	int failed;
 	SRunner *sr = NULL;
-	struct list created_files_list;
 
 	list_init(&created_files_list);
 
@@ -871,6 +902,8 @@ litest_run(int argc, char **argv)
 
 	litest_init_udev_rules(&created_files_list);
 
+	litest_setup_sighandler(SIGINT);
+
 	srunner_run_all(sr, CK_ENV);
 	failed = srunner_ntests_failed(sr);
 	srunner_free(sr);
-- 
2.7.4



More information about the wayland-devel mailing list