Commit 86946342 authored by Peter Hutterer's avatar Peter Hutterer

test: store the list of open file descriptors in the litest context

Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 52d63987
......@@ -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);
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment