Skip to content

Commit

Permalink
test: init the quirks once per test suite run
Browse files Browse the repository at this point in the history
So we have them available per litest device and can check in tests for certain
quirks to be present.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Jun 8, 2018
1 parent 5e4dee2 commit a50e13d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/litest.c
Expand Up @@ -55,6 +55,7 @@
#include "litest.h"
#include "litest-int.h"
#include "libinput-util.h"
#include "quirks.h"

#include <linux/kd.h>

Expand All @@ -76,6 +77,7 @@ static int verbose = 0;
const char *filter_test = NULL;
const char *filter_device = NULL;
const char *filter_group = NULL;
static struct quirks_context *quirks_context;

struct created_file {
struct list link;
Expand Down Expand Up @@ -790,6 +792,19 @@ litest_free_test_list(struct list *tests)
}
}

LIBINPUT_ATTRIBUTE_PRINTF(3, 0)
static inline void
quirk_log_handler(struct libinput *unused,
enum libinput_log_priority priority,
const char *format,
va_list args)
{
if (priority < LIBINPUT_LOG_PRIORITY_ERROR)
return;

vfprintf(stderr, format, args);
}

static int
litest_run_suite(struct list *tests, int which, int max, int error_fd)
{
Expand All @@ -805,6 +820,12 @@ litest_run_suite(struct list *tests, int which, int max, int error_fd)
struct name *n, *tmp;
struct list testnames;

quirks_context = quirks_init_subsystem(getenv("LIBINPUT_DATA_DIR"),
NULL,
quirk_log_handler,
NULL,
QLOG_LIBINPUT_LOGGING);

/* Check just takes the suite/test name pointers but doesn't strdup
* them - we have to keep them around */
list_init(&testnames);
Expand Down Expand Up @@ -889,6 +910,8 @@ litest_run_suite(struct list *tests, int which, int max, int error_fd)
free(n);
}

quirks_context_unref(quirks_context);

return failed;
}

Expand Down Expand Up @@ -1494,6 +1517,9 @@ litest_add_device_with_overrides(struct libinput *libinput,

d->libinput = libinput;
d->libinput_device = libinput_path_add_device(d->libinput, path);
d->quirks = quirks_fetch_for_device(quirks_context,
libinput_device_get_udev_device(d->libinput_device));

litest_assert(d->libinput_device != NULL);
libinput_device_ref(d->libinput_device);

Expand Down Expand Up @@ -1617,6 +1643,8 @@ litest_delete_device(struct litest_device *d)

litest_assert_int_eq(d->skip_ev_syn, 0);

quirks_unref(d->quirks);

if (d->libinput_device) {
libinput_path_remove_device(d->libinput_device);
libinput_device_unref(d->libinput_device);
Expand Down
2 changes: 2 additions & 0 deletions test/litest.h
Expand Up @@ -35,6 +35,7 @@
#include <math.h>

#include "libinput-util.h"
#include "quirks.h"

struct test_device {
const char *name;
Expand Down Expand Up @@ -345,6 +346,7 @@ struct litest_device {
struct libevdev *evdev;
struct libevdev_uinput *uinput;
struct libinput *libinput;
struct quirks *quirks;
bool owns_context;
struct libinput_device *libinput_device;
struct litest_device_interface *interface;
Expand Down

0 comments on commit a50e13d

Please sign in to comment.