From a1075070a4a2b9cfafdd9186ecf4bb476267ef7d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 22 May 2015 14:55:24 +1000 Subject: [PATCH 01/11] test: add missing filter for function names Was added to other places, missing from here so some tests passed the filter despite not being selected by it. Signed-off-by: Peter Hutterer --- test/litest.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/litest.c b/test/litest.c index e1db754a..1ff535d2 100644 --- a/test/litest.c +++ b/test/litest.c @@ -640,6 +640,10 @@ _litest_add_ranged_for_device(const char *name, assert(type < LITEST_NO_DEVICE); + if (filter_test && + fnmatch(filter_test, funcname, 0) != 0) + return; + if (filter_group && fnmatch(filter_group, name, 0) != 0) return; From 8bb67c25508585dfa33931340097ac0e5490af5f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 22 May 2015 14:56:09 +1000 Subject: [PATCH 02/11] test: fail if the filter leaves us with zero tests Signed-off-by: Peter Hutterer --- test/litest.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/litest.c b/test/litest.c index 1ff535d2..de53b67d 100644 --- a/test/litest.c +++ b/test/litest.c @@ -755,6 +755,12 @@ litest_run(int argc, char **argv) int failed; SRunner *sr = NULL; + if (list_empty(&all_tests)) { + fprintf(stderr, + "Error: filters are too strict, no tests to run.\n"); + return 1; + } + if (in_debugger == -1) { in_debugger = is_debugger_attached(); if (in_debugger) @@ -2204,6 +2210,8 @@ litest_parse_argv(int argc, char **argv) int main(int argc, char **argv) { + list_init(&all_tests); + if (litest_parse_argv(argc, argv) != 0) return EXIT_FAILURE; From 602bca6977d7e97e49ae400a431c313639e631a2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 May 2015 08:56:53 +1000 Subject: [PATCH 03/11] test: fix --list for the tests The argument worked, but the test list was empty since b2fd428f96. Signed-off-by: Peter Hutterer --- test/litest.c | 53 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/test/litest.c b/test/litest.c index de53b67d..267487a7 100644 --- a/test/litest.c +++ b/test/litest.c @@ -696,20 +696,6 @@ is_debugger_attached(void) return rc; } -static void -litest_list_tests(struct list *tests) -{ - struct suite *s; - - list_for_each(s, tests, node) { - struct test *t; - printf("%s:\n", s->name); - list_for_each(t, &s->tests, node) { - printf(" %s\n", t->name); - } - } -} - static void litest_log_handler(struct libinput *libinput, enum libinput_log_priority pri, @@ -2155,7 +2141,13 @@ litest_semi_mt_touch_up(struct litest_device *d, litest_event(d, EV_SYN, SYN_REPORT, 0); } -static inline int +enum litest_mode { + LITEST_MODE_ERROR, + LITEST_MODE_TEST, + LITEST_MODE_LIST, +}; + +static inline enum litest_mode litest_parse_argv(int argc, char **argv) { enum { @@ -2192,31 +2184,52 @@ litest_parse_argv(int argc, char **argv) filter_group = optarg; break; case OPT_LIST: - litest_list_tests(&all_tests); - exit(0); + return LITEST_MODE_LIST; case OPT_VERBOSE: verbose = 1; break; default: fprintf(stderr, "usage: %s [--list]\n", argv[0]); - return 1; + return LITEST_MODE_ERROR; } } - return 0; + return LITEST_MODE_TEST; } #ifndef LITEST_NO_MAIN +static void +litest_list_tests(struct list *tests) +{ + struct suite *s; + + list_for_each(s, tests, node) { + struct test *t; + printf("%s:\n", s->name); + list_for_each(t, &s->tests, node) { + printf(" %s\n", t->name); + } + } +} + int main(int argc, char **argv) { + enum litest_mode mode; + list_init(&all_tests); - if (litest_parse_argv(argc, argv) != 0) + mode = litest_parse_argv(argc, argv); + if (mode == LITEST_MODE_ERROR) return EXIT_FAILURE; litest_setup_tests(); + if (mode == LITEST_MODE_LIST) { + litest_list_tests(&all_tests); + return EXIT_SUCCESS; + } + return litest_run(argc, argv); } #endif From 8194655f2dc3d674e90f64147d9665ec439b67b5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 May 2015 09:02:25 +1000 Subject: [PATCH 04/11] Add .vimdir for libinput-specific settings To avoid introducing broken indentations when I'm working in different directories than the standard one add the vimdir with the local settings. Signed-off-by: Peter Hutterer --- .vimdir | 1 + 1 file changed, 1 insertion(+) create mode 100644 .vimdir diff --git a/.vimdir b/.vimdir new file mode 100644 index 00000000..e3ef2d84 --- /dev/null +++ b/.vimdir @@ -0,0 +1 @@ +set noexpandtab shiftwidth=8 cinoptions=:0,+0,(0 From adef7ccce32abbd3ec56411d0c700f6808de6472 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 May 2015 09:06:32 +1000 Subject: [PATCH 05/11] Add a few more exclusions to .gitignore Signed-off-by: Peter Hutterer --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 2253d454..8893a5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,13 @@ *.la *.lo *.swp +*~ +*.sig +*.tar.* +*.announce +*.patch +*.rej +*.trs Makefile Makefile.in aclocal.m4 From f2c44ac9cd097673715637f20c3ce83965f5f16d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 May 2015 16:38:12 +1000 Subject: [PATCH 06/11] test: move litest_log/vlog up outside of HAVE_LIBUNWIND Well, the patch looks like the HAVE_LIBUNWIND bit was moved down, which is the same thing. litest_log and litest_vlog are called from independent paths, we have a compiler error otherwise. Signed-off-by: Peter Hutterer --- test/litest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/litest.c b/test/litest.c index 267487a7..bc7e1cd9 100644 --- a/test/litest.c +++ b/test/litest.c @@ -56,11 +56,6 @@ const char *filter_test = NULL; const char *filter_device = NULL; const char *filter_group = NULL; -#ifdef HAVE_LIBUNWIND -#define UNW_LOCAL_ONLY -#include -#include - /* defined for the litest selftest */ #ifndef LITEST_DISABLE_BACKTRACE_LOGGING #define litest_log(...) fprintf(stderr, __VA_ARGS__) @@ -70,6 +65,11 @@ const char *filter_group = NULL; #define litest_vlog(...) /* __VA_ARGS__ */ #endif +#ifdef HAVE_LIBUNWIND +#define UNW_LOCAL_ONLY +#include +#include + static char cwd[PATH_MAX]; static bool From 2507828f3f70e00c25e076c2526db7811934eb9c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 May 2015 16:50:54 +1000 Subject: [PATCH 07/11] test: pclose the popened stream Found by Coverity Signed-off-by: Peter Hutterer --- test/litest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/litest.c b/test/litest.c index bc7e1cd9..037186f3 100644 --- a/test/litest.c +++ b/test/litest.c @@ -100,7 +100,7 @@ litest_backtrace_get_lineno(const char *executable, buffer[0] = '?'; fgets(buffer, sizeof(buffer), f); - fclose(f); + pclose(f); if (buffer[0] == '?') return false; From d9f702918cb55802519aa19ff6aa64a554d1dec4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 May 2015 17:04:56 +1000 Subject: [PATCH 08/11] test: fail if fgets() from addr2line returns NULL Found by Coverity Signed-off-by: Peter Hutterer --- test/litest.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/litest.c b/test/litest.c index 037186f3..7a4938da 100644 --- a/test/litest.c +++ b/test/litest.c @@ -99,7 +99,10 @@ litest_backtrace_get_lineno(const char *executable, } buffer[0] = '?'; - fgets(buffer, sizeof(buffer), f); + if (fgets(buffer, sizeof(buffer), f) == NULL) { + pclose(f); + return false; + } pclose(f); if (buffer[0] == '?') From c4be027b90040d04488d1e41bf311ec88e44c555 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 May 2015 17:27:14 +1000 Subject: [PATCH 09/11] test: fix coverity complaint about unbounded loop buffer tainted (from fgets()) so tighten the loop conditions a bit. Signed-off-by: Peter Hutterer --- test/litest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/litest.c b/test/litest.c index 7a4938da..040bfb4a 100644 --- a/test/litest.c +++ b/test/litest.c @@ -82,7 +82,7 @@ litest_backtrace_get_lineno(const char *executable, FILE* f; char buffer[PATH_MAX]; char *s; - int i; + unsigned int i; if (!cwd[0]) getcwd(cwd, sizeof(cwd)); @@ -119,7 +119,7 @@ litest_backtrace_get_lineno(const char *executable, /* now strip cwd from buffer */ s = buffer; i = 0; - while(cwd[i] == *s) { + while(i < strlen(cwd) && *s != '\0' && cwd[i] == *s) { *s = '\0'; s++; i++; From 0ca29c6ddc6e18d8d7babfac64e6d0c1c1ecfeca Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 26 May 2015 08:46:05 +1000 Subject: [PATCH 10/11] Add streq() helper to use instead of strcmp() == 0 Signed-off-by: Peter Hutterer --- src/evdev.c | 2 +- src/libinput-util.h | 2 ++ src/path.c | 4 ++-- src/udev-seat.c | 12 ++++++------ test/litest.c | 6 +++--- test/udev.c | 3 ++- tools/libinput-list-devices.c | 5 +++-- tools/ptraccel-debug.c | 8 ++++---- tools/shared.c | 15 ++++++++------- 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index 1a71e4c0..8e25e45d 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1970,7 +1970,7 @@ evdev_device_compare_syspath(struct udev_device *udev_device, int fd) if (!udev_device_new) goto out; - rc = strcmp(udev_device_get_syspath(udev_device_new), + rc = !streq(udev_device_get_syspath(udev_device_new), udev_device_get_syspath(udev_device)); out: if (udev_device_new) diff --git a/src/libinput-util.h b/src/libinput-util.h index 74226b96..1673551e 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -83,6 +83,8 @@ int list_empty(const struct list *list); #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) +#define streq(s1, s2) (strcmp((s1), (s2)) == 0) +#define strneq(s1, s2, n) (strncmp((s1), (s2), (n)) == 0) #define LIBINPUT_EXPORT __attribute__ ((visibility("default"))) diff --git a/src/path.c b/src/path.c index f9b1a6c2..ab5587bf 100644 --- a/src/path.c +++ b/src/path.c @@ -101,8 +101,8 @@ path_seat_get_named(struct path_input *input, struct path_seat *seat; list_for_each(seat, &input->base.seat_list, base.link) { - if (strcmp(seat->base.physical_name, seat_name_physical) == 0 && - strcmp(seat->base.logical_name, seat_name_logical) == 0) + if (streq(seat->base.physical_name, seat_name_physical) && + streq(seat->base.logical_name, seat_name_logical)) return seat; } diff --git a/src/udev-seat.c b/src/udev-seat.c index 6615f208..8dc0c236 100644 --- a/src/udev-seat.c +++ b/src/udev-seat.c @@ -57,7 +57,7 @@ device_added(struct udev_device *udev_device, if (!device_seat) device_seat = default_seat; - if (strcmp(device_seat, input->seat_id)) + if (!streq(device_seat, input->seat_id)) return 0; devnode = udev_device_get_devnode(udev_device); @@ -131,8 +131,8 @@ device_removed(struct udev_device *udev_device, struct udev_input *input) list_for_each(seat, &input->base.seat_list, base.link) { list_for_each_safe(device, next, &seat->base.devices_list, base.link) { - if (!strcmp(syspath, - udev_device_get_syspath(device->udev_device))) { + if (streq(syspath, + udev_device_get_syspath(device->udev_device))) { log_info(&input->base, "input device %s, %s removed\n", device->devname, @@ -198,9 +198,9 @@ evdev_udev_handler(void *data) if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0) goto out; - if (!strcmp(action, "add")) + if (streq(action, "add")) device_added(udev_device, input, NULL); - else if (!strcmp(action, "remove")) + else if (streq(action, "remove")) device_removed(udev_device, input); out: @@ -328,7 +328,7 @@ udev_seat_get_named(struct udev_input *input, const char *seat_name) struct udev_seat *seat; list_for_each(seat, &input->base.seat_list, base.link) { - if (strcmp(seat->base.logical_name, seat_name) == 0) + if (streq(seat->base.logical_name, seat_name)) return seat; } diff --git a/test/litest.c b/test/litest.c index 040bfb4a..8221a7a2 100644 --- a/test/litest.c +++ b/test/litest.c @@ -432,7 +432,7 @@ litest_add_tcase_for_device(struct suite *suite, const char *test_name = dev->shortname; list_for_each(t, &suite->tests, node) { - if (strcmp(t->name, test_name) != 0) + if (!streq(t->name, test_name)) continue; if (range) @@ -476,7 +476,7 @@ litest_add_tcase_no_device(struct suite *suite, return; list_for_each(t, &suite->tests, node) { - if (strcmp(t->name, test_name) != 0) + if (!streq(t->name, test_name)) continue; if (range) @@ -504,7 +504,7 @@ get_suite(const char *name) list_init(&all_tests); list_for_each(s, &all_tests, node) { - if (strcmp(s->name, name) == 0) + if (streq(s->name, name)) return s; } diff --git a/test/udev.c b/test/udev.c index 4ec956bc..f01acc7e 100644 --- a/test/udev.c +++ b/test/udev.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -184,7 +185,7 @@ START_TEST(udev_added_seat_default) ck_assert(seat != NULL); seat_name = libinput_seat_get_logical_name(seat); - default_seat_found = !strcmp(seat_name, "default"); + default_seat_found = streq(seat_name, "default"); libinput_event_destroy(event); } diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index 825969d5..66251731 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -30,6 +30,7 @@ #include #include +#include #include #include "shared.h" @@ -279,10 +280,10 @@ main(int argc, char **argv) struct libinput_event *ev; if (argc > 1) { - if (strcmp(argv[1], "--help") == 0) { + if (streq(argv[1], "--help")) { usage(); return 0; - } else if (strcmp(argv[1], "--version") == 0) { + } else if (streq(argv[1], "--version")) { printf("%s\n", LIBINPUT_VERSION); return 0; } else { diff --git a/tools/ptraccel-debug.c b/tools/ptraccel-debug.c index fdd8490e..7d722257 100644 --- a/tools/ptraccel-debug.c +++ b/tools/ptraccel-debug.c @@ -220,13 +220,13 @@ main(int argc, char **argv) switch (c) { case OPT_MODE: - if (strcmp(optarg, "accel") == 0) + if (streq(optarg, "accel")) print_accel = true; - else if (strcmp(optarg, "motion") == 0) + else if (streq(optarg, "motion")) print_motion = true; - else if (strcmp(optarg, "delta") == 0) + else if (streq(optarg, "delta")) print_delta = true; - else if (strcmp(optarg, "sequence") == 0) + else if (streq(optarg, "sequence")) print_sequence = true; else { usage(); diff --git a/tools/shared.c b/tools/shared.c index 9ccd5dda..c5f7f20e 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -31,6 +31,7 @@ #include #include +#include #include "shared.h" @@ -189,13 +190,13 @@ tools_parse_args(int argc, char **argv, struct tools_options *options) tools_usage(); return 1; } - if (strcmp(optarg, "none") == 0) { + if (streq(optarg, "none")) { options->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; - } else if (strcmp(optarg, "clickfinger") == 0) { + } else if (streq(optarg, "clickfinger")) { options->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; - } else if (strcmp(optarg, "buttonareas") == 0) { + } else if (streq(optarg, "buttonareas")) { options->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; } else { @@ -208,16 +209,16 @@ tools_parse_args(int argc, char **argv, struct tools_options *options) tools_usage(); return 1; } - if (strcmp(optarg, "none") == 0) { + if (streq(optarg, "none")) { options->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; - } else if (strcmp(optarg, "twofinger") == 0) { + } else if (streq(optarg, "twofinger")) { options->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; - } else if (strcmp(optarg, "edge") == 0) { + } else if (streq(optarg, "edge")) { options->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; - } else if (strcmp(optarg, "button") == 0) { + } else if (streq(optarg, "button")) { options->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } else { From 0c8d76181d35f30014b78385256b3a99471ac93f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 26 May 2015 08:49:04 +1000 Subject: [PATCH 11/11] evdev: rename evdev_compare_syspath for clarity Signed-off-by: Peter Hutterer --- src/evdev.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index 8e25e45d..c6c8102b 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1955,13 +1955,13 @@ evdev_notify_added_device(struct evdev_device *device) notify_added_device(&device->base); } -static int -evdev_device_compare_syspath(struct udev_device *udev_device, int fd) +static bool +evdev_device_have_same_syspath(struct udev_device *udev_device, int fd) { struct udev *udev = udev_device_get_udev(udev_device); struct udev_device *udev_device_new = NULL; struct stat st; - int rc = 1; + bool rc = false; if (fstat(fd, &st) < 0) goto out; @@ -1970,8 +1970,8 @@ evdev_device_compare_syspath(struct udev_device *udev_device, int fd) if (!udev_device_new) goto out; - rc = !streq(udev_device_get_syspath(udev_device_new), - udev_device_get_syspath(udev_device)); + rc = streq(udev_device_get_syspath(udev_device_new), + udev_device_get_syspath(udev_device)); out: if (udev_device_new) udev_device_unref(udev_device_new); @@ -2037,7 +2037,7 @@ evdev_device_create(struct libinput_seat *seat, return NULL; } - if (evdev_device_compare_syspath(udev_device, fd) != 0) + if (!evdev_device_have_same_syspath(udev_device, fd)) goto err; device = zalloc(sizeof *device); @@ -2477,7 +2477,7 @@ evdev_device_resume(struct evdev_device *device) if (fd < 0) return -errno; - if (evdev_device_compare_syspath(device->udev_device, fd)) { + if (!evdev_device_have_same_syspath(device->udev_device, fd)) { close_restricted(libinput, fd); return -ENODEV; }