shared: add wl_list asserts

We were missing that, so let's include them.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2026-03-16 17:38:20 -03:00
parent 711ae922a8
commit b75f8ce2ae
4 changed files with 57 additions and 2 deletions

View file

@ -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);

View file

@ -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);

View file

@ -32,6 +32,8 @@
#include <stdbool.h>
#include <inttypes.h>
#include <wayland-util.h>
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) \

View file

@ -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. */