diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2020-07-03 12:29:16 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2020-07-07 18:51:33 +1000 |
commit | 86946342fb164cdbceb30955fd8f001218871a36 (patch) | |
tree | e337fe54b156be9c666a92929935837a8e044f97 | |
parent | 52d639875366d7337a35c14759adc52112c011c0 (diff) |
test: store the list of open file descriptors in the litest context
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | test/litest-int.h | 10 | ||||
-rw-r--r-- | test/litest.c | 52 | ||||
-rw-r--r-- | test/test-misc.c | 8 | ||||
-rw-r--r-- | test/test-tablet.c | 4 |
4 files changed, 70 insertions, 4 deletions
diff --git a/test/litest-int.h b/test/litest-int.h index 36be7a5b..c5b05e68 100644 --- a/test/litest-int.h +++ b/test/litest-int.h @@ -131,6 +131,16 @@ struct litest_device_interface { int max[2]; /* x/y axis maximum */ }; +struct path { + struct list link; + char *path; + int fd; +}; + +struct litest_context { + struct list paths; +}; + void litest_set_current_device(struct litest_device *device); int litest_scale(const struct litest_device *d, unsigned int axis, double val); void litest_generic_device_teardown(void); diff --git a/test/litest.c b/test/litest.c index 9965b72f..da634e03 100644 --- a/test/litest.c +++ b/test/litest.c @@ -769,13 +769,41 @@ litest_init_all_device_udev_rules(struct list *created_files) static int open_restricted(const char *path, int flags, void *userdata) { - int fd = open(path, flags); - return fd < 0 ? -errno : fd; + const char prefix[] = "/dev/input/event"; + struct litest_context *ctx = userdata; + struct path *p; + int fd; + + litest_assert_ptr_notnull(ctx); + + fd = open(path, flags); + if (fd < 0) + return -errno; + + if (strneq(path, prefix, strlen(prefix))) { + p = zalloc(sizeof *p); + p->path = safe_strdup(path); + p->fd = fd; + list_append(&ctx->paths, &p->link); + } + + return fd; } static void close_restricted(int fd, void *userdata) { + struct litest_context *ctx = userdata; + struct path *p, *tmp; + + list_for_each_safe(p, tmp, &ctx->paths, link) { + if (p->fd != fd) + continue; + list_remove(&p->link); + free(p->path); + free(p); + } + close(fd); } @@ -1620,8 +1648,13 @@ litest_create(enum litest_device_type which, struct libinput * litest_create_context(void) { - struct libinput *libinput = - libinput_path_create_context(&interface, NULL); + struct libinput *libinput; + struct litest_context *ctx; + + ctx = zalloc(sizeof *ctx); + list_init(&ctx->paths); + + libinput = libinput_path_create_context(&interface, ctx); litest_assert_notnull(libinput); libinput_log_set_handler(libinput, litest_log_handler); @@ -1634,7 +1667,18 @@ litest_create_context(void) void litest_destroy_context(struct libinput *li) { + struct path *p, *tmp; + struct litest_context *ctx; + + + ctx = libinput_get_user_data(li); + litest_assert_ptr_notnull(ctx); libinput_unref(li); + + list_for_each_safe(p, tmp, &ctx->paths, link) { + litest_abort_msg("Device paths should be removed by now"); + } + free(ctx); } void diff --git a/test/test-misc.c b/test/test-misc.c index 8030e198..b72a77ec 100644 --- a/test/test-misc.c +++ b/test/test-misc.c @@ -669,6 +669,7 @@ START_TEST(timer_offset_bug_warning) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int warning_triggered = 0; + void *old_user_data; litest_enable_tap(dev->libinput_device); litest_drain_events(li); @@ -678,6 +679,7 @@ START_TEST(timer_offset_bug_warning) litest_timeout_tap(); + old_user_data = libinput_get_user_data(li); libinput_set_user_data(li, &warning_triggered); libinput_log_set_handler(li, timer_offset_warning); libinput_dispatch(li); @@ -685,6 +687,8 @@ START_TEST(timer_offset_bug_warning) /* triggered for touch down and touch up */ ck_assert_int_eq(warning_triggered, 2); litest_restore_log_handler(li); + + libinput_set_user_data(li, old_user_data); } END_TEST @@ -706,7 +710,9 @@ START_TEST(timer_delay_bug_warning) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; int warning_triggered = 0; + void *old_user_data; + old_user_data = libinput_get_user_data(li); litest_drain_events(li); for (int i = 0; i < 10; i++) { @@ -720,8 +726,10 @@ START_TEST(timer_delay_bug_warning) libinput_dispatch(li); } + ck_assert_int_ge(warning_triggered, 1); litest_restore_log_handler(li); + libinput_set_user_data(li, old_user_data); } END_TEST diff --git a/test/test-tablet.c b/test/test-tablet.c index a722deed..a3060f1c 100644 --- a/test/test-tablet.c +++ b/test/test-tablet.c @@ -4073,9 +4073,11 @@ START_TEST(tablet_pressure_offset_exceed_threshold) }; double pressure; int warning_triggered = 0; + void *old_user_data; litest_drain_events(li); + old_user_data = libinput_get_user_data(li); libinput_set_user_data(li, &warning_triggered); libinput_log_set_handler(li, pressure_threshold_warning); @@ -4090,6 +4092,8 @@ START_TEST(tablet_pressure_offset_exceed_threshold) ck_assert_int_eq(warning_triggered, 1); litest_restore_log_handler(li); + + libinput_set_user_data(li, old_user_data); } END_TEST |