Skip to content

shared: add weston-assert

Pekka Paalanen requested to merge pq/weston:mr/wassert into main

Add yet another flavor of assertion macros.

Unlike libc assert.h assert(), these cannot be easily disabled by the build. They also print both the implied expression and the compared values.

Unlike ZUC macros, there is much less framework code and it can handle also floating-point types.

The function custom_assert_fail_ can be redefined, meaning that different compilation units can do different things on failure. Also 'priv' parameter is passed through. For example, we could have weston_compositor_assert_*() macros that take a weston_compositor as 'priv', so that failure printing goes into the right log scopes explicitly, no need for thread-local variables. Test suite failure function OTOH can just print what "failed" without aborting.

There is also limited support for custom types.

These are actually pretty similar to libinput's litest macros.

But do we want this?

This is just something I scribbled in an afternoon for my own amusement mostly.


The test prints:

../../git/weston/tests/assert-test.c:84: Assertion ((void *)0) != NULL ((nil) != (nil)) failed!
../../git/weston/tests/assert-test.c:90: Assertion &ret == NULL (0x7ffd0ca9ad50 == (nil)) failed!
../../git/weston/tests/assert-test.c:96: Assertion &ret == &ret + 1 (0x7ffd0ca9ad50 == 0x7ffd0ca9ad51) failed!
../../git/weston/tests/assert-test.c:100: Assertion fifteen == 15.000001 (15 == 15.000001) failed!
../../git/weston/tests/assert-test.c:109: Assertion nom == "baz" (bar == baz) failed!
../../git/weston/tests/assert-test.c:116: Assertion &a < &b (my_type 0x7ffd0ca9ad60 < my_type 0x7ffd0ca9ad80) failed!

Merge request reports