summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-07-20 08:43:05 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2016-08-02 10:19:38 +1000
commitf9f4bb026603738dda0367a3eb4cfb7289cf0211 (patch)
treee4ced441962f886d43f087317262943c92102912 /test
parenta7f04c9a8498c6b0f1a3fd910dcd8f2d0d59733a (diff)
test: make sure we remove all udev rules when we SIGINT the test
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rw-r--r--test/litest.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/test/litest.c b/test/litest.c
index 7c185682..492aa3ac 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);