summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2024-03-14 12:07:29 +1000
committerMarge Bot <emma+marge@anholt.net>2024-03-18 16:25:47 +0000
commit3644372696f7e509c13715b81bdf8554e8a25efe (patch)
tree9ab7ea3f9f95fe1d7f5f0ebbdd2e905e2d6d99a7
parent4935e526528f98c792a0ae39cfc380dd3c99575b (diff)
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>
-rw-r--r--test/litest.c9
-rw-r--r--test/litest.h15
-rw-r--r--test/test-misc.c2
-rw-r--r--test/test-quirks.c2
4 files changed, 22 insertions, 6 deletions
diff --git a/test/litest.c b/test/litest.c
index 792b0a54..be855e15 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -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);
}
diff --git a/test/litest.h b/test/litest.h
index bdb217b2..73a4ef9a 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -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_)
diff --git a/test/test-misc.c b/test/test-misc.c
index 5f98d326..e6e3c460 100644
--- a/test/test-misc.c
+++ b/test/test-misc.c
@@ -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;
diff --git a/test/test-quirks.c b/test/test-quirks.c
index dc9bcd09..85c4792f 100644
--- a/test/test-quirks.c
+++ b/test/test-quirks.c
@@ -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;
}