shared: add weston_assert_bit_is_set()

Will be used in the next patch.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2024-02-16 14:55:39 +02:00
parent d9a7b3795a
commit bdea44919b
2 changed files with 19 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include <stdarg.h>
#include <string.h>
#include <stdbool.h>
#include <inttypes.h>
struct weston_compositor;
@ -110,3 +111,15 @@ do { \
#define weston_assert_str_eq(compositor, a, b) \
weston_assert_fn_(compositor, strcmp, a, b, const char *, "%s", ==)
#define weston_assert_bit_is_set(compositor, value, bit) \
({ \
struct weston_compositor *ec = compositor; \
uint64_t v = (value); \
uint8_t b = (bit); \
bool cond = (v >> b) & 1; \
if (!cond) \
custom_assert_fail_(ec, "%s:%u: Assertion failed! Bit %s (%u) of %s (0x%" PRIx64 ") is not set.\n", \
__FILE__, __LINE__, #bit, b, #value, v); \
cond; \
})

View File

@ -126,4 +126,10 @@ TEST(asserts)
abort_if_not(ret);
ret = weston_assert_my_type_lt(compositor, &a, &b);
abort_if_not(ret == false);
uint32_t bitfield = 0xffff;
ret = weston_assert_bit_is_set(compositor, bitfield, 2);
abort_if_not(ret);
ret = weston_assert_bit_is_set(compositor, bitfield, 57);
abort_if_not(ret == false);
}