shared: rename a few weston assert

Currently weston-test-assert.h has a better naming style than
weston-assert.h: more concise and standardized.

So let's copy the same style to weston-assert.h

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2025-07-28 15:50:59 -03:00
parent b268b3827c
commit a4cefa69a2
12 changed files with 66 additions and 54 deletions

View file

@ -2164,8 +2164,8 @@ lut_3x1d_from_blend_to_output(struct weston_compositor *compositor,
* No need to craft LUT 3x1D from identity. But there shouldn't be a
* blend-to-output xform like this in first place.
*/
weston_assert_uint32_neq(compositor, xform->pre_curve.type,
WESTON_COLOR_CURVE_TYPE_IDENTITY);
weston_assert_u32_ne(compositor, xform->pre_curve.type,
WESTON_COLOR_CURVE_TYPE_IDENTITY);
return weston_color_curve_to_3x1D_LUT(compositor, xform,
WESTON_COLOR_CURVE_STEP_PRE,

View file

@ -748,7 +748,7 @@ cmlcms_send_image_desc_info(struct cm_image_desc_info *cm_image_desc_info,
}
len = os_ro_anonymous_file_size(cprof->icc.prof_rofile);
weston_assert_uint32_gt(compositor, len, 0);
weston_assert_u32_gt(compositor, len, 0);
weston_cm_send_icc_file(cm_image_desc_info, fd, len);

View file

@ -424,8 +424,8 @@ lcms_curve_matches_any_tf(struct weston_compositor *compositor,
return NULL;
}
weston_assert_uint32_lt_or_eq(compositor,
n_lcms_curve_params, MAX_PARAMS_LCMS_PARAM_CURVE);
weston_assert_u32_le(compositor,
n_lcms_curve_params, MAX_PARAMS_LCMS_PARAM_CURVE);
for (i = 0; i < 3; i++)
for (j = 0; j < n_lcms_curve_params; j++)
@ -880,7 +880,7 @@ translate_curve_element_LUT(struct cmlcms_color_transform *xform,
curve->type = WESTON_COLOR_CURVE_TYPE_LUT_3x1D;
curve->u.lut_3x1d.optimal_len = cmlcms_reasonable_1D_points();
weston_assert_uint32_eq(compositor, trc_data->nCurves, 3);
weston_assert_u32_eq(compositor, trc_data->nCurves, 3);
for (i = 0; i < 3; i++) {
stash[i] = cmsDupToneCurve(trc_data->TheCurves[i]);
abort_oom_if_null(stash[i]);
@ -896,8 +896,8 @@ translate_curve_element(struct cmlcms_color_transform *xform,
struct weston_compositor *compositor = xform->base.cm->compositor;
_cmsStageToneCurvesData *trc_data;
weston_assert_uint64_eq(compositor, cmsStageType(elem),
cmsSigCurveSetElemType);
weston_assert_u64_eq(compositor, cmsStageType(elem),
cmsSigCurveSetElemType);
trc_data = cmsStageData(elem);
if (trc_data->nCurves != 3)
@ -1314,10 +1314,10 @@ init_icc_to_icc_chain(struct cmlcms_color_transform *xform)
struct lcmsProfilePtr chain[5];
unsigned chain_len = 0;
weston_assert_uint32_eq(cm->base.compositor, out_prof->type, CMLCMS_PROFILE_TYPE_ICC);
weston_assert_u32_eq(cm->base.compositor, out_prof->type, CMLCMS_PROFILE_TYPE_ICC);
if (in_prof) {
weston_assert_uint32_eq(cm->base.compositor, in_prof->type,
CMLCMS_PROFILE_TYPE_ICC);
weston_assert_u32_eq(cm->base.compositor, in_prof->type,
CMLCMS_PROFILE_TYPE_ICC);
}
render_intent = xform->search_key.render_intent;
@ -1393,9 +1393,9 @@ init_blend_to_parametric(struct cmlcms_color_transform *xform)
{
struct weston_color_profile_params *out = xform->search_key.output_profile->params;
weston_assert_uint32_eq(xform->base.cm->compositor,
xform->search_key.output_profile->type,
CMLCMS_PROFILE_TYPE_PARAMS);
weston_assert_u32_eq(xform->base.cm->compositor,
xform->search_key.output_profile->type,
CMLCMS_PROFILE_TYPE_PARAMS);
/*
* For blend-to-output with a parametric output profile, all we need
@ -1560,12 +1560,10 @@ init_parametric_to_parametric(struct cmlcms_color_transform *xform)
struct weston_mat4f mat;
char *errmsg = NULL;
weston_assert_uint32_eq(cm->base.compositor,
recipe->input_profile->type,
CMLCMS_PROFILE_TYPE_PARAMS);
weston_assert_uint32_eq(cm->base.compositor,
recipe->output_profile->type,
CMLCMS_PROFILE_TYPE_PARAMS);
weston_assert_u32_eq(cm->base.compositor, recipe->input_profile->type,
CMLCMS_PROFILE_TYPE_PARAMS);
weston_assert_u32_eq(cm->base.compositor, recipe->output_profile->type,
CMLCMS_PROFILE_TYPE_PARAMS);
/*
* Decode input TF

View file

@ -1741,9 +1741,9 @@ weston_compositor_enable_color_management_protocol(struct weston_compositor *com
{
uint32_t version = 1;
weston_assert_bit_is_set(compositor,
compositor->color_manager->supported_rendering_intents,
1ull << WESTON_RENDER_INTENT_PERCEPTUAL);
weston_assert_bit_set(compositor,
compositor->color_manager->supported_rendering_intents,
1ull << WESTON_RENDER_INTENT_PERCEPTUAL);
if (!wl_global_create(compositor->wl_display,
&wp_color_manager_v1_interface,

View file

@ -245,8 +245,8 @@ cmnoop_destroy(struct weston_color_manager *cm_base)
* Currently we have a bug in which we leak surfaces when shutting down
* Weston with client surfaces alive, and these surfaces may have a
* reference to the stock sRGB profile. */
weston_assert_uint32_gt_or_eq(cm_base->compositor,
cmnoop->stock_cprof->base.ref_count, 1);
weston_assert_u32_ge(cm_base->compositor,
cmnoop->stock_cprof->base.ref_count, 1);
unref_cprof(cmnoop->stock_cprof);
free(cmnoop);

View file

@ -311,8 +311,8 @@ weston_color_profile_param_builder_set_tf_named(struct weston_color_profile_para
return false;
builder->params.tf_info = weston_color_tf_info_from(compositor, tf);
weston_assert_uint32_eq(builder->compositor,
builder->params.tf_info->count_parameters, 0);
weston_assert_u32_eq(builder->compositor,
builder->params.tf_info->count_parameters, 0);
builder->group_mask |= WESTON_COLOR_PROFILE_PARAMS_TF;

View file

@ -260,7 +260,7 @@ weston_color_curve_enum_get_parametric(struct weston_compositor *compositor,
}
/* No other TF's have params. */
weston_assert_uint32_eq(compositor, curve->tf->count_parameters, 0);
weston_assert_u32_eq(compositor, curve->tf->count_parameters, 0);
if (!curve->tf->curve_params_valid)
return false;
@ -456,7 +456,7 @@ find_neighbors(struct weston_compositor *compositor, uint32_t len, float *array,
int32_t mid;
/* We need at least 2 elements in the array. */
weston_assert_uint32_gt(compositor, len, 1);
weston_assert_u32_gt(compositor, len, 1);
while (right - left > 1) {
mid = left + ((right - left) / 2);

View file

@ -103,7 +103,7 @@ update_lowest_free_bucket(struct weston_idalloc *idalloc)
/* We didn't find any free bucket, so we need to add more buckets. */
next_num = idalloc->num_buckets * 2;
weston_assert_uint32_gt(idalloc->compositor, next_num, idalloc->num_buckets);
weston_assert_u32_gt(idalloc->compositor, next_num, idalloc->num_buckets);
idalloc->buckets = xrealloc(idalloc->buckets, next_num * sizeof(*idalloc->buckets));
memset(&idalloc->buckets[idalloc->num_buckets], 0,
@ -129,7 +129,7 @@ weston_idalloc_get_id(struct weston_idalloc *idalloc)
uint32_t id;
/* Sanity check: lowest free bucket should not be full. */
weston_assert_uint32_neq(idalloc->compositor, *bucket, 0xffffffff);
weston_assert_u32_ne(idalloc->compositor, *bucket, 0xffffffff);
for (i = 0; i < 32; i++) {
/* Id already used, skip it. */
@ -170,11 +170,11 @@ weston_idalloc_put_id(struct weston_idalloc *idalloc, uint32_t id)
uint32_t *bucket;
/* Shouldn't try to release index 0, we never advertise this id to anyone. */
weston_assert_uint32_neq(idalloc->compositor, id, 0);
weston_assert_u32_ne(idalloc->compositor, id, 0);
/* Bucket index should be lower than num_buckets. */
weston_assert_uint32_lt(idalloc->compositor,
bucket_index, idalloc->num_buckets);
weston_assert_u32_lt(idalloc->compositor,
bucket_index, idalloc->num_buckets);
bucket = &idalloc->buckets[bucket_index];

View file

@ -290,7 +290,7 @@ get_uniform_location(struct gl_renderer *gr,
int ret;
ret = snprintf(str, sizeof str, "%s_%s", prefix, field);
weston_assert_uint32_lt(gr->compositor, ret, sizeof str);
weston_assert_u32_lt(gr->compositor, ret, sizeof str);
return glGetUniformLocation(program, str);
}

View file

@ -75,6 +75,8 @@ weston_assert_fail_(const struct weston_compositor *compositor, const char *fmt,
cond; \
})
/* Misc asserts. */
#define weston_assert_not_reached(compositor, reason) \
do { \
struct weston_compositor *ec = compositor; \
@ -82,12 +84,16 @@ do { \
__FILE__, __LINE__, reason); \
} while (0)
/* Boolean asserts. */
#define weston_assert_true(compositor, a) \
weston_assert_(compositor, a, true, bool, "%d", ==)
#define weston_assert_false(compositor, a) \
weston_assert_(compositor, a, false, bool, "%d", ==)
/* Pointer asserts. */
#define weston_assert_ptr_not_null(compositor, a) \
weston_assert_(compositor, a, NULL, const void *, "%p", !=)
@ -97,34 +103,42 @@ do { \
#define weston_assert_ptr_eq(compositor, a, b) \
weston_assert_(compositor, a, b, const void *, "%p", ==)
#define weston_assert_double_eq(compositor, a, b) \
/* Floating-point asserts. */
#define weston_assert_f64_eq(compositor, a, b) \
weston_assert_(compositor, a, b, double, "%.10g", ==)
#define weston_assert_uint32_eq(compositor, a, b) \
/* Unsigned int asserts. */
#define weston_assert_u32_eq(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", ==)
#define weston_assert_uint32_neq(compositor, a, b) \
#define weston_assert_u32_ne(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", !=)
#define weston_assert_uint32_gt(compositor, a, b) \
#define weston_assert_u32_gt(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", >)
#define weston_assert_uint32_gt_or_eq(compositor, a, b) \
#define weston_assert_u32_ge(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", >=)
#define weston_assert_uint32_lt(compositor, a, b) \
#define weston_assert_u32_lt(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", <)
#define weston_assert_uint32_lt_or_eq(compositor, a, b) \
#define weston_assert_u32_le(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", <=)
#define weston_assert_uint64_eq(compositor, a, b) \
#define weston_assert_u64_eq(compositor, a, b) \
weston_assert_(compositor, a, b, uint64_t, "%" PRIx64, ==)
/* String asserts. */
#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) \
/* Bitmask asserts. */
#define weston_assert_bit_set(compositor, value, bit) \
({ \
struct weston_compositor *ec = compositor; \
uint64_t v = (value); \
@ -137,7 +151,7 @@ do { \
cond; \
})
#define weston_assert_bit_is_not_set(compositor, value, bit) \
#define weston_assert_bit_not_set(compositor, value, bit) \
({ \
struct weston_compositor *ec = compositor; \
uint64_t v = (value); \

View file

@ -100,15 +100,15 @@ TEST(asserts)
abort_if_not(ret == false);
double fifteen = 15.0;
ret = weston_assert_double_eq(compositor, fifteen, 15.000001);
ret = weston_assert_f64_eq(compositor, fifteen, 15.000001);
abort_if_not(ret == false);
ret = weston_assert_double_eq(compositor, fifteen, 15);
ret = weston_assert_f64_eq(compositor, fifteen, 15);
abort_if_not(ret);
ret = weston_assert_uint32_lt_or_eq(compositor, 0, 0);
ret = weston_assert_u32_le(compositor, 0, 0);
abort_if_not(ret);
ret = weston_assert_uint32_lt_or_eq(compositor, 1, 0);
ret = weston_assert_u32_le(compositor, 1, 0);
abort_if_not(ret == false);
const char *nom = "bar";
@ -125,13 +125,13 @@ TEST(asserts)
abort_if_not(ret == false);
uint32_t bitfield = 0xffff;
ret = weston_assert_bit_is_set(compositor, bitfield, 1ull << 2);
ret = weston_assert_bit_set(compositor, bitfield, 1ull << 2);
abort_if_not(ret);
ret = weston_assert_bit_is_set(compositor, bitfield, 1ull << 57);
ret = weston_assert_bit_set(compositor, bitfield, 1ull << 57);
abort_if_not(ret == false);
uint64_t max_uint64 = UINT64_MAX;
ret = weston_assert_uint64_eq(compositor, max_uint64, 0);
ret = weston_assert_u64_eq(compositor, max_uint64, 0);
abort_if_not(ret == false);
uint64_t val = 0x200010001000ffff;

View file

@ -166,8 +166,8 @@ test_assert_fail(void *compositor, const char *fmt, ...)
/* Various helpers. */
#define test_assert_bit_set(a, bit) weston_assert_bit_is_set(NULL, a, bit)
#define test_assert_bit_not_set(a, bit) weston_assert_bit_is_not_set(NULL, a, bit)
#define test_assert_bit_set(a, bit) weston_assert_bit_set(NULL, a, bit)
#define test_assert_bit_not_set(a, bit) weston_assert_bit_not_set(NULL, a, bit)
#define test_assert_errno(a) test_assert_int_eq(a, errno)
#define test_assert_enum(a, b) test_assert_u64_eq(a, b)