mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-20 08:00:09 +01:00
test: abort on unexpected log messages
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>
This commit is contained in:
parent
77bf0fe228
commit
0c01886985
5 changed files with 46 additions and 0 deletions
|
|
@ -24,9 +24,28 @@
|
|||
#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,
|
||||
...)
|
||||
|
|
|
|||
|
|
@ -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_ */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue