diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c index 49ee0707a..a55fe5bb8 100644 --- a/libweston/backend-drm/drm.c +++ b/libweston/backend-drm/drm.c @@ -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, diff --git a/libweston/color-lcms/color-profile.c b/libweston/color-lcms/color-profile.c index a2af63bef..d49bfd420 100644 --- a/libweston/color-lcms/color-profile.c +++ b/libweston/color-lcms/color-profile.c @@ -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); diff --git a/libweston/color-lcms/color-transform.c b/libweston/color-lcms/color-transform.c index 688fe3473..1bf98cca4 100644 --- a/libweston/color-lcms/color-transform.c +++ b/libweston/color-lcms/color-transform.c @@ -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 diff --git a/libweston/color-management.c b/libweston/color-management.c index 3369dd6cc..2fea1f55d 100644 --- a/libweston/color-management.c +++ b/libweston/color-management.c @@ -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, diff --git a/libweston/color-noop.c b/libweston/color-noop.c index 7c3dfff76..56ec01fd3 100644 --- a/libweston/color-noop.c +++ b/libweston/color-noop.c @@ -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); diff --git a/libweston/color-profile-param-builder.c b/libweston/color-profile-param-builder.c index bb903e66e..628397316 100644 --- a/libweston/color-profile-param-builder.c +++ b/libweston/color-profile-param-builder.c @@ -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; diff --git a/libweston/color.c b/libweston/color.c index 9a7fc52d4..cc330e739 100644 --- a/libweston/color.c +++ b/libweston/color.c @@ -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); diff --git a/libweston/id-number-allocator.c b/libweston/id-number-allocator.c index 0917601e0..72fa30342 100644 --- a/libweston/id-number-allocator.c +++ b/libweston/id-number-allocator.c @@ -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]; diff --git a/libweston/renderer-gl/gl-shaders.c b/libweston/renderer-gl/gl-shaders.c index 50834135a..9477e97b6 100644 --- a/libweston/renderer-gl/gl-shaders.c +++ b/libweston/renderer-gl/gl-shaders.c @@ -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); } diff --git a/shared/weston-assert.h b/shared/weston-assert.h index a7c36f23c..3f8ed46a4 100644 --- a/shared/weston-assert.h +++ b/shared/weston-assert.h @@ -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); \ diff --git a/tests/assert-test.c b/tests/assert-test.c index 0e6910b64..9c8ed4a5d 100644 --- a/tests/assert-test.c +++ b/tests/assert-test.c @@ -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; diff --git a/tests/weston-test-assert.h b/tests/weston-test-assert.h index 008b431aa..4337b2d3c 100644 --- a/tests/weston-test-assert.h +++ b/tests/weston-test-assert.h @@ -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)