diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c index 6e52a0cda..613ebf770 100644 --- a/libweston/backend-drm/drm.c +++ b/libweston/backend-drm/drm.c @@ -4215,7 +4215,7 @@ drm_device_destroy(struct drm_device *device) &device->writeback_connector_list, link) drm_writeback_destroy(writeback); - weston_assert_true(ec, wl_list_empty(&device->drm_colorop_3x1d_lut_list)); + weston_assert_list_empty(ec, &device->drm_colorop_3x1d_lut_list); if (device->drm_event_source) wl_event_source_remove(device->drm_event_source); diff --git a/libweston/linux-dmabuf.c b/libweston/linux-dmabuf.c index c460ff58e..75b2944d0 100644 --- a/libweston/linux-dmabuf.c +++ b/libweston/linux-dmabuf.c @@ -800,7 +800,7 @@ weston_dmabuf_feedback_send_all(struct weston_compositor *compositor, { struct wl_resource *res; - weston_assert_true(compositor, !wl_list_empty(&dmabuf_feedback->resource_list)); + weston_assert_list_not_empty(compositor, &dmabuf_feedback->resource_list); wl_resource_for_each(res, &dmabuf_feedback->resource_list) weston_dmabuf_feedback_send(dmabuf_feedback, format_table, res, false); diff --git a/shared/weston-assert.h b/shared/weston-assert.h index 905f2c5de..75cb6d66b 100644 --- a/shared/weston-assert.h +++ b/shared/weston-assert.h @@ -32,6 +32,8 @@ #include #include +#include + struct weston_compositor; __attribute__((noreturn, format(printf, 2, 3))) @@ -224,6 +226,30 @@ weston_assert_fail_(const struct weston_compositor *compositor, const char *fmt, cond; \ }) +/* wl_list asserts */ + +#define weston_assert_list_empty(compositor, list) \ +({ \ + struct weston_compositor *wc_ = compositor; \ + struct wl_list *l_ = list; \ + bool cond = wl_list_empty(l_); \ + if (!cond) \ + custom_assert_fail_(wc_, "%s:%u: Assertion failed! wl_list '%s' is not empty.\n", \ + __FILE__, __LINE__, #list); \ + cond; \ +}) + +#define weston_assert_list_not_empty(compositor, list) \ +({ \ + struct weston_compositor *wc_ = compositor; \ + struct wl_list *l_ = list; \ + bool cond = !wl_list_empty(l_); \ + if (!cond) \ + custom_assert_fail_(wc_, "%s:%u: Assertion failed! wl_list '%s' is empty.\n", \ + __FILE__, __LINE__, #list); \ + cond; \ +}) + /* Misc asserts. */ #define weston_assert_not_reached(compositor, reason) \ diff --git a/tests/assert-test.c b/tests/assert-test.c index c357c6529..2a8719c88 100644 --- a/tests/assert-test.c +++ b/tests/assert-test.c @@ -110,6 +110,35 @@ TEST(asserts_boolean) return RESULT_OK; } +TEST(asserts_list) +{ + /* Unused by the macros for now, so let's just use NULL. */ + struct weston_compositor *compositor = NULL; + struct wl_list list; + struct wl_list link; + bool ret; + + wl_list_init(&list); + + ret = weston_assert_list_empty(compositor, &list); + abort_if_not(ret); + ret = weston_assert_list_not_empty(compositor, &list); + abort_if_not(ret == false); + + wl_list_insert(&list, &link); + + ret = weston_assert_list_empty(compositor, &list); + abort_if_not(ret == false); + ret = weston_assert_list_not_empty(compositor, &list); + abort_if_not(ret); + + /* If we reach that point, it's a success so reset the assert counter + * that's been incremented to check that assertions work. */ + weston_assert_counter_reset(); + + return RESULT_OK; +} + TEST(asserts_pointer) { /* Unused by the macros for now, so let's just use NULL. */