test: abort on unexpected log messages
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 17 Jan 2014 00:21:48 +0000 (10:21 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 21 Jan 2014 23:14:40 +0000 (09:14 +1000)
Add two log functions, one that aborts on a received message. We know when we
expect to receive an error, so anytime this happens unexpectedly should
terminate the test.

And for those tests do issue a log message, let them ignore it and don't
print anything.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/test-common.c
test/test-common.h
test/test-libevdev-init.c
test/test-main.c
test/test-uinput.c

index b33a2cd..6449d46 100644 (file)
 #include <check.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdio.h>
 
 #include "test-common.h"
 
+void test_logfunc_abort_on_error(enum libevdev_log_priority priority,
+                                void *data,
+                                const char *file, int line,
+                                const char *func,
+                                const char *format, va_list args)
+{
+       vprintf(format, args);
+       ck_abort();
+}
+
+void test_logfunc_ignore_error(enum libevdev_log_priority priority,
+                              void *data,
+                              const char *file, int line,
+                              const char *func,
+                              const char *format, va_list args)
+{
+}
+
 int test_create_device(struct uinput_device **uidev_return,
                       struct libevdev **dev_return,
                       ...)
index 16b5800..d7a33d0 100644 (file)
@@ -42,4 +42,14 @@ int test_create_abs_device(struct uinput_device **uidev,
                           const struct input_absinfo *abs,
                           ...);
 
+void test_logfunc_abort_on_error(enum libevdev_log_priority priority,
+                                void *data,
+                                const char *file, int line,
+                                const char *func,
+                                const char *format, va_list args);
+void test_logfunc_ignore_error(enum libevdev_log_priority priority,
+                              void *data,
+                              const char *file, int line,
+                              const char *func,
+                              const char *format, va_list args);
 #endif /* _TEST_COMMON_H_ */
index bf0b874..6be3d74 100644 (file)
@@ -73,7 +73,10 @@ START_TEST(test_init_and_change_fd)
        dev = libevdev_new();
        ck_assert(dev != NULL);
        ck_assert_int_eq(libevdev_set_fd(dev, -1), -EBADF);
+
+       libevdev_set_log_function(test_logfunc_ignore_error, NULL);
        ck_assert_int_eq(libevdev_change_fd(dev, -1), -1);
+       libevdev_set_log_function(test_logfunc_abort_on_error, NULL);
 
        rc = uinput_device_new_with_events(&uidev,
                                           TEST_DEVICE_NAME, DEFAULT_IDS,
@@ -87,7 +90,10 @@ START_TEST(test_init_and_change_fd)
                                           -1);
        ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
        ck_assert_int_eq(libevdev_set_fd(dev, uinput_device_get_fd(uidev)), 0);
+
+       libevdev_set_log_function(test_logfunc_ignore_error, NULL);
        ck_assert_int_eq(libevdev_set_fd(dev, 0), -EBADF);
+       libevdev_set_log_function(test_logfunc_abort_on_error, NULL);
 
        ck_assert_int_eq(libevdev_get_fd(dev), uinput_device_get_fd(uidev));
 
@@ -136,6 +142,8 @@ START_TEST(test_log_init)
        ck_assert_int_eq(log_fn_called, 2);
 
        libevdev_free(dev);
+
+       libevdev_set_log_function(test_logfunc_abort_on_error, NULL);
 }
 END_TEST
 
@@ -247,10 +255,12 @@ START_TEST(test_device_grab)
                                -1);
        ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
 
+       libevdev_set_log_function(test_logfunc_ignore_error, NULL);
        rc = libevdev_grab(dev, 0);
        ck_assert_int_eq(rc, -EINVAL);
        rc = libevdev_grab(dev, 1);
        ck_assert_int_eq(rc, -EINVAL);
+       libevdev_set_log_function(test_logfunc_abort_on_error, NULL);
 
        rc = libevdev_grab(dev, LIBEVDEV_UNGRAB);
        ck_assert_int_eq(rc, 0);
index 91128c3..6d17f7c 100644 (file)
@@ -26,6 +26,9 @@
 #include <unistd.h>
 #include <sys/ptrace.h>
 #include <sys/wait.h>
+#include <libevdev/libevdev.h>
+
+#include "test-common.h"
 
 extern Suite *event_name_suite(void);
 extern Suite *event_code_suite(void);
@@ -71,6 +74,8 @@ int main(int argc, char **argv)
        if (is_debugger_attached())
                setenv("CK_FORK", "no", 0);
 
+       libevdev_set_log_function(test_logfunc_abort_on_error, NULL);
+
        Suite *s = libevdev_has_event_test();
        SRunner *sr = srunner_create(s);
        srunner_add_suite(sr, libevdev_events());
index 2e9d3cd..99738e3 100644 (file)
@@ -101,9 +101,11 @@ START_TEST(test_uinput_create_device_invalid)
        libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
        libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
 
+       libevdev_set_log_function(test_logfunc_ignore_error, NULL);
        rc = libevdev_uinput_create_from_device(dev, -1, &uidev);
        ck_assert_int_eq(rc, -EBADF);
        ck_assert(uidev == NULL);
+       libevdev_set_log_function(test_logfunc_abort_on_error, NULL);
 
        libevdev_free(dev);
 }