tests: use mp_require to allow tests to be run with NDEBUG
This commit is contained in:
1 parent
1c49cfdb97
commit
450535ba1e
6 files changed
+44
-48
No files matched your search
+10
-10
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
|
||||
fprintf(f, " {");
|
||||
for (int n = 0; n < MP_MAX_PLANES; n++) {
|
||||
if (n >= d.num_planes) {
|
||||
mp_assert(d.bpp[n] == 0 && d.xs[n] == 0 && d.ys[n] == 0);
|
||||
mp_require(d.bpp[n] == 0 && d.xs[n] == 0 && d.ys[n] == 0);
|
||||
continue;
|
||||
}
|
||||
fprintf(f, "%d/[%d:%d] ", d.bpp[n], d.xs[n], d.ys[n]);
|
||||
@@ -91,24 +91,24 @@ int main(int argc, char *argv[])
|
||||
if (cm.pad)
|
||||
fprintf(f, "/%d", cm.pad);
|
||||
} else {
|
||||
mp_assert(cm.offset == 0);
|
||||
mp_assert(cm.pad == 0);
|
||||
mp_require(cm.offset == 0);
|
||||
mp_require(cm.pad == 0);
|
||||
}
|
||||
}
|
||||
fprintf(f, "}");
|
||||
if (!(d.flags & (MP_IMGFLAG_PACKED_SS_YUV | MP_IMGFLAG_HAS_COMPS)))
|
||||
{
|
||||
mp_assert(cm.size == 0);
|
||||
mp_assert(cm.offset == 0);
|
||||
mp_assert(cm.pad == 0);
|
||||
mp_require(cm.size == 0);
|
||||
mp_require(cm.offset == 0);
|
||||
mp_require(cm.pad == 0);
|
||||
}
|
||||
}
|
||||
fprintf(f, "\n");
|
||||
if (d.flags & MP_IMGFLAG_PACKED_SS_YUV) {
|
||||
mp_assert(!(d.flags & MP_IMGFLAG_HAS_COMPS));
|
||||
mp_require(!(d.flags & MP_IMGFLAG_HAS_COMPS));
|
||||
uint8_t offsets[10];
|
||||
bool r = mp_imgfmt_get_packed_yuv_locations(mpfmt, offsets);
|
||||
mp_assert(r);
|
||||
mp_require(r);
|
||||
fprintf(f, " luma_offsets=[");
|
||||
for (int x = 0; x < d.align_x; x++)
|
||||
fprintf(f, " %d", offsets[x]);
|
||||
@@ -122,7 +122,7 @@ int main(int argc, char *argv[])
|
||||
fr->width = 128;
|
||||
fr->height = 128;
|
||||
int err = av_frame_get_buffer(fr, MP_IMAGE_BYTE_ALIGN);
|
||||
mp_assert(err >= 0);
|
||||
mp_require(err >= 0);
|
||||
struct mp_image *mpi = mp_image_alloc(mpfmt, fr->width, fr->height);
|
||||
if (mpi) {
|
||||
// A rather fuzzy test, which might fail even if there's no bug.
|
||||
@@ -190,7 +190,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
for (int n = avd->nb_components; n < 4; n++) {
|
||||
const AVComponentDescriptor *cd = &avd->comp[n];
|
||||
mp_assert(!cd->plane && !cd->step && !cd->offset && !cd->shift &&
|
||||
mp_require(!cd->plane && !cd->step && !cd->offset && !cd->shift &&
|
||||
!cd->depth);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ void init_imgfmts_list(void)
|
||||
enum AVPixelFormat fmt = av_pix_fmt_desc_get_id(avd);
|
||||
int mpfmt = pixfmt2imgfmt(fmt);
|
||||
if (!mpfmt) {
|
||||
mp_assert(num_pixfmt_unsup < MP_ARRAY_SIZE(pixfmt_unsup));
|
||||
mp_require(num_pixfmt_unsup < MP_ARRAY_SIZE(pixfmt_unsup));
|
||||
pixfmt_unsup[num_pixfmt_unsup++] = fmt;
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ void init_imgfmts_list(void)
|
||||
struct mp_imgfmt_desc d = mp_imgfmt_get_desc(fmt);
|
||||
enum AVPixelFormat pixfmt = imgfmt2pixfmt(fmt);
|
||||
if (d.id || pixfmt != AV_PIX_FMT_NONE) {
|
||||
mp_assert(num_imgfmts < MP_ARRAY_SIZE(imgfmts)); // enlarge that array
|
||||
mp_require(num_imgfmts < MP_ARRAY_SIZE(imgfmts)); // enlarge that array
|
||||
imgfmts[num_imgfmts++] = fmt;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -195,10 +195,10 @@ static int try_repack(FILE *f, int imgfmt, int flags, int not_if_fmt)
|
||||
|
||||
// If both exists, they must be always symmetric.
|
||||
if (un && pa) {
|
||||
mp_assert(mp_repack_get_format_src(pa) == mp_repack_get_format_dst(un));
|
||||
mp_assert(mp_repack_get_format_src(un) == mp_repack_get_format_dst(pa));
|
||||
mp_assert(mp_repack_get_align_x(pa) == mp_repack_get_align_x(un));
|
||||
mp_assert(mp_repack_get_align_y(pa) == mp_repack_get_align_y(un));
|
||||
mp_require(mp_repack_get_format_src(pa) == mp_repack_get_format_dst(un));
|
||||
mp_require(mp_repack_get_format_src(un) == mp_repack_get_format_dst(pa));
|
||||
mp_require(mp_repack_get_align_x(pa) == mp_repack_get_align_x(un));
|
||||
mp_require(mp_repack_get_align_y(pa) == mp_repack_get_align_y(un));
|
||||
}
|
||||
|
||||
int a = 0;
|
||||
@@ -214,10 +214,10 @@ static int try_repack(FILE *f, int imgfmt, int flags, int not_if_fmt)
|
||||
// Skip the identity ones because they're uninteresting, and add too much
|
||||
// noise. But still make sure they behave as expected.
|
||||
if (a == imgfmt && b == imgfmt) {
|
||||
mp_assert(is_true_planar(imgfmt));
|
||||
mp_require(is_true_planar(imgfmt));
|
||||
// (note that we require alpha-enabled zimg)
|
||||
mp_assert(mp_zimg_supports_in_format(imgfmt));
|
||||
mp_assert(un && pa);
|
||||
mp_require(mp_zimg_supports_in_format(imgfmt));
|
||||
mp_require(un && pa);
|
||||
talloc_free(pa);
|
||||
talloc_free(un);
|
||||
return b;
|
||||
@@ -230,7 +230,7 @@ static int try_repack(FILE *f, int imgfmt, int flags, int not_if_fmt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
mp_assert(a == imgfmt);
|
||||
mp_require(a == imgfmt);
|
||||
if (b && b == not_if_fmt) {
|
||||
talloc_free(pa);
|
||||
talloc_free(un);
|
||||
@@ -270,7 +270,7 @@ static int try_repack(FILE *f, int imgfmt, int flags, int not_if_fmt)
|
||||
struct mp_image *ib = mp_image_alloc(fmt_b, e->w * 7 * ax, e->h * 6 * ay);
|
||||
int sx = 4 * ax, sy = 3 * ay, dx = 3 * ax, dy = 2 * ay;
|
||||
|
||||
mp_assert(ia && ib);
|
||||
mp_require(ia && ib);
|
||||
|
||||
mp_image_params_guess_csp(&ia->params);
|
||||
mp_image_params_guess_csp(&ib->params);
|
||||
@@ -289,7 +289,7 @@ static int try_repack(FILE *f, int imgfmt, int flags, int not_if_fmt)
|
||||
struct mp_image *srci = pack ? ib : ia;
|
||||
|
||||
bool r = repack_config_buffers(repacker, 0, dsti, 0, srci, NULL);
|
||||
mp_assert(r);
|
||||
mp_require(r);
|
||||
|
||||
for (int p = 0; p < srci->num_planes; p++) {
|
||||
uint8_t *ptr = mp_image_pixel_ptr(srci, p, sx, sy);
|
||||
@@ -335,7 +335,7 @@ static void check_float_repack(int imgfmt, enum pl_color_system csp,
|
||||
int bpp = desc.component_size;
|
||||
int comp_bits = desc.component_size * 8 + MPMIN(desc.component_pad, 0);
|
||||
|
||||
mp_assert(bpp == 1 || bpp == 2);
|
||||
mp_require(bpp == 1 || bpp == 2);
|
||||
|
||||
int w = 1 << (bpp * 8);
|
||||
|
||||
@@ -346,14 +346,14 @@ static void check_float_repack(int imgfmt, enum pl_color_system csp,
|
||||
}
|
||||
|
||||
struct mp_image *src = mp_image_alloc(imgfmt, w, 1);
|
||||
mp_assert(src);
|
||||
mp_require(src);
|
||||
|
||||
src->params.repr.sys = csp;
|
||||
src->params.repr.levels = levels;
|
||||
mp_image_params_guess_csp(&src->params);
|
||||
// mpv may not allow all combinations
|
||||
mp_assert(src->params.repr.sys == csp);
|
||||
mp_assert(src->params.repr.levels == levels);
|
||||
mp_require(src->params.repr.sys == csp);
|
||||
mp_require(src->params.repr.levels == levels);
|
||||
|
||||
for (int p = 0; p < src->num_planes; p++) {
|
||||
int val = 0;
|
||||
@@ -373,13 +373,13 @@ static void check_float_repack(int imgfmt, enum pl_color_system csp,
|
||||
mp_repack_create_planar(src->imgfmt, false, REPACK_CREATE_PLANAR_F32);
|
||||
struct mp_repack *from_f =
|
||||
mp_repack_create_planar(src->imgfmt, true, REPACK_CREATE_PLANAR_F32);
|
||||
mp_assert(to_f && from_f);
|
||||
mp_require(to_f && from_f);
|
||||
|
||||
struct mp_image *z_f = mp_image_alloc(mp_repack_get_format_dst(to_f), w, 1);
|
||||
struct mp_image *r_f = mp_image_alloc(z_f->imgfmt, w, 1);
|
||||
struct mp_image *z_i = mp_image_alloc(src->imgfmt, w, 1);
|
||||
struct mp_image *r_i = mp_image_alloc(src->imgfmt, w, 1);
|
||||
mp_assert(z_f && r_f && z_i && r_i);
|
||||
mp_require(z_f && r_f && z_i && r_i);
|
||||
|
||||
z_f->params.color = r_f->params.color = z_i->params.color =
|
||||
r_i->params.color = src->params.color;
|
||||
|
||||
+13
-13
@@ -20,9 +20,9 @@ static struct mp_image *gen_repack_test_img(int w, int h, int bytes, bool rgb,
|
||||
},
|
||||
};
|
||||
int mpfmt = mp_find_regular_imgfmt(&planar_desc);
|
||||
mp_assert(mpfmt);
|
||||
mp_require(mpfmt);
|
||||
struct mp_image *mpi = mp_image_alloc(mpfmt, w, h);
|
||||
mp_assert(mpi);
|
||||
mp_require(mpi);
|
||||
|
||||
// Well, I have no idea what makes a good test image. So here's some crap.
|
||||
// This contains bars/tiles of solid colors. For each of R/G/B, it toggles
|
||||
@@ -73,12 +73,12 @@ static void dump_image(struct scale_test *stest, const char *name,
|
||||
static void assert_imgs_equal(struct scale_test *stest, FILE *f,
|
||||
struct mp_image *ref, struct mp_image *new)
|
||||
{
|
||||
mp_assert(ref->imgfmt == new->imgfmt);
|
||||
mp_assert(ref->w == new->w);
|
||||
mp_assert(ref->h == new->h);
|
||||
mp_require(ref->imgfmt == new->imgfmt);
|
||||
mp_require(ref->w == new->w);
|
||||
mp_require(ref->h == new->h);
|
||||
|
||||
mp_assert(ref->fmt.flags & MP_IMGFLAG_BYTE_ALIGNED);
|
||||
mp_assert(ref->fmt.bpp[0]);
|
||||
mp_require(ref->fmt.flags & MP_IMGFLAG_BYTE_ALIGNED);
|
||||
mp_require(ref->fmt.bpp[0]);
|
||||
|
||||
for (int p = 0; p < ref->num_planes; p++) {
|
||||
for (int y = 0; y < ref->h; y++) {
|
||||
@@ -155,29 +155,29 @@ void repack_test_run(struct scale_test *stest)
|
||||
mp_imgfmt_to_name(test_img->imgfmt));
|
||||
|
||||
struct mp_image *dst = mp_image_alloc(mpfmt, test_img->w, test_img->h);
|
||||
mp_assert(dst);
|
||||
mp_require(dst);
|
||||
|
||||
// This tests packing.
|
||||
bool ok = stest->fns->scale(stest->fns_priv, dst, test_img);
|
||||
mp_assert(ok);
|
||||
mp_require(ok);
|
||||
|
||||
// Cross-check with swscale in the other direction.
|
||||
// (Mostly so we don't have to worry about padding.)
|
||||
struct mp_image *src2 =
|
||||
mp_image_alloc(test_img->imgfmt, test_img->w, test_img->h);
|
||||
mp_assert(src2);
|
||||
mp_require(src2);
|
||||
ok = mp_sws_scale(stest->sws, src2, dst) >= 0;
|
||||
assert_imgs_equal(stest, f, test_img, src2);
|
||||
|
||||
// Assume the other conversion direction also works.
|
||||
mp_assert(stest->fns->supports_fmts(stest->fns_priv, test_img->imgfmt, mpfmt));
|
||||
mp_require(stest->fns->supports_fmts(stest->fns_priv, test_img->imgfmt, mpfmt));
|
||||
|
||||
struct mp_image *back = mp_image_alloc(test_img->imgfmt, dst->w, dst->h);
|
||||
mp_assert(back);
|
||||
mp_require(back);
|
||||
|
||||
// This tests unpacking.
|
||||
ok = stest->fns->scale(stest->fns_priv, back, dst);
|
||||
mp_assert(ok);
|
||||
mp_require(ok);
|
||||
|
||||
assert_imgs_equal(stest, f, test_img, back);
|
||||
|
||||
|
||||
+1
-5
@@ -7,10 +7,6 @@
|
||||
#include "osdep/terminal.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
#ifdef NDEBUG
|
||||
static_assert(false, "don't define NDEBUG for tests");
|
||||
#endif
|
||||
|
||||
void assert_int_equal_impl(const char *file, int line, int64_t a, int64_t b)
|
||||
{
|
||||
if (a != b) {
|
||||
@@ -43,7 +39,7 @@ void assert_float_equal_impl(const char *file, int line,
|
||||
FILE *test_open_out(const char *outdir, const char *name)
|
||||
{
|
||||
mp_mkdirp(outdir);
|
||||
mp_assert(mp_path_isdir(outdir));
|
||||
mp_require(mp_path_isdir(outdir));
|
||||
char *path = mp_tprintf(4096, "%s/%s", outdir, name);
|
||||
FILE *f = fopen(path, "wb");
|
||||
if (!f) {
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@
|
||||
|
||||
#include "common/common.h"
|
||||
|
||||
#define assert_true(x) mp_assert(x)
|
||||
#define assert_false(x) mp_assert(!(x))
|
||||
#define assert_true(x) mp_require(x)
|
||||
#define assert_false(x) mp_require(!(x))
|
||||
#define assert_int_equal(a, b) \
|
||||
assert_int_equal_impl(__FILE__, __LINE__, (a), (b))
|
||||
#define assert_string_equal(a, b) \
|
||||
|
||||
Reference in new issue
Block a user