mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-04 01:10:25 +01:00
test: add helpers for checking (negative) errnos
This way we get to see the actual error when it happens. Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/984>
This commit is contained in:
parent
4935e52652
commit
3644372696
4 changed files with 22 additions and 6 deletions
|
|
@ -792,10 +792,10 @@ litest_init_all_device_udev_rules(struct list *created_files)
|
|||
rc = xasprintf(&path,
|
||||
"%s/99-litest-XXXXXX.rules",
|
||||
UDEV_RULES_D);
|
||||
litest_assert_int_gt(rc, 0);
|
||||
litest_assert_errno_success(rc);
|
||||
|
||||
fd = mkstemps(path, 6);
|
||||
litest_assert_int_ne(fd, -1);
|
||||
litest_assert_errno_success(fd);
|
||||
f = fdopen(fd, "w");
|
||||
litest_assert_notnull(f);
|
||||
|
||||
|
|
@ -1687,7 +1687,7 @@ litest_create(enum litest_device_type which,
|
|||
litest_assert_int_ne(fd, -1);
|
||||
|
||||
rc = libevdev_new_from_fd(fd, &d->evdev);
|
||||
litest_assert_int_eq(rc, 0);
|
||||
litest_assert_neg_errno_success(rc);
|
||||
|
||||
return d;
|
||||
|
||||
|
|
@ -1963,7 +1963,7 @@ litest_event(struct litest_device *d, unsigned int type,
|
|||
return;
|
||||
|
||||
ret = libevdev_uinput_write_event(d->uinput, type, code, value);
|
||||
litest_assert_int_eq(ret, 0);
|
||||
litest_assert_neg_errno_success(ret);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -3049,6 +3049,7 @@ litest_wait_for_event_of_type(struct libinput *li, ...)
|
|||
|
||||
while ((type = libinput_next_event_type(li)) == LIBINPUT_EVENT_NONE) {
|
||||
int rc = poll(&fds, 1, 2000);
|
||||
litest_assert_errno_success(rc);
|
||||
litest_assert_int_gt(rc, 0);
|
||||
libinput_dispatch(li);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,6 +161,21 @@ litest_fail_comparison_ptr(const char *file,
|
|||
#a_, #b_); \
|
||||
} while(0)
|
||||
|
||||
#define litest_assert_neg_errno_success(a_) \
|
||||
do { \
|
||||
__typeof__(a_) _a = a_; \
|
||||
if (_a < 0) \
|
||||
litest_abort_msg("Unexpected negative errno: %d (%s)", _a, strerror(-_a)); \
|
||||
} while(0);
|
||||
|
||||
#define litest_assert_errno_success(a_) \
|
||||
do { \
|
||||
__typeof__(a_) _a = a_; \
|
||||
__typeof__(a_) _e = errno; \
|
||||
if (_a < 0) \
|
||||
litest_abort_msg("Unexpected errno: %d (%s)", _e, strerror(_e)); \
|
||||
} while(0);
|
||||
|
||||
#define litest_assert_int_eq(a_, b_) \
|
||||
litest_assert_comparison_int_(a_, ==, b_)
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ create_simple_test_device(const char *name, ...)
|
|||
rc = libevdev_uinput_create_from_device(evdev,
|
||||
LIBEVDEV_UINPUT_OPEN_MANAGED,
|
||||
&uinput);
|
||||
litest_assert_int_eq(rc, 0);
|
||||
litest_assert_neg_errno_success(rc);
|
||||
libevdev_free(evdev);
|
||||
|
||||
return uinput;
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ make_data_dir(const char *file_content)
|
|||
fp = fopen(filename, "w+");
|
||||
litest_assert_notnull(fp);
|
||||
rc = fputs(file_content, fp);
|
||||
litest_assert_errno_success(rc);
|
||||
fclose(fp);
|
||||
litest_assert_int_ge(rc, 0);
|
||||
dir.filename = filename;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue