History

video: separate repacking code from zimg and make it independent

For whatever purpose. If anything, this makes the zimg wrapper cleaner. The added tests are not particular exhaustive, but nice to have. This also makes the scale_zimg.c test pretty useless, because it only tests repacking (going through the zimg wrapper). In theory, the repack_tests things could also be used on scalers, but I guess it doesn't matter. Some things are added over the previous zimg wrapper code. For example, some fringe formats can now be expanded to 8 bit per component for convenience.

wm4 committed 6 years ago

Commit d8002f11 parent d61ced39 files · +1688 −895Browse files

Showing the changes to test (4 of 9 files). Show all

Unified · Split

4 files
  1. test/ref/repack.txt +163 −0
  2. test/repack.c +249 −0
  3. test/tests.c +23 −0
  4. test/tests.h +7 −0
test/ref/repack.txt+163−0
@@ -0,0 +1,163 @@
1+0bgr => [pa] [un] gbrp | a=1:1 [tu] [tp]
2+0rgb => [pa] [un] gbrp | a=1:1 [tu] [tp]
3+abgr => [pa] [un] gbrap | a=1:1 [tu] [tp]
4+argb => [pa] [un] gbrap | a=1:1 [tu] [tp]
5+ayuv64 => [pa] [un] yuva444p16 | a=1:1 [tu] [tp]
6+ayuv64be => [pa] [un] yuva444p16 | a=1:1 [tu] [tp]
7+bayer_bggr16 => no
8+bayer_bggr16be => no
9+bayer_bggr8 => no
10+bayer_gbrg16 => no
11+bayer_gbrg16be => no
12+bayer_gbrg8 => no
13+bayer_grbg16 => no
14+bayer_grbg16be => no
15+bayer_grbg8 => no
16+bayer_rggb16 => no
17+bayer_rggb16be => no
18+bayer_rggb8 => no
19+bgr0 => [pa] [un] gbrp | a=1:1 [tu] [tp]
20+bgr24 => [pa] [un] gbrp | a=1:1
21+bgr4 => no
22+bgr444 => [pa] [un] gbrp4 | a=1:1
23+bgr444 => [pa] [un] gbrp | a=1:1 [expand-8bit]
24+bgr444be => [pa] [un] gbrp4 | a=1:1
25+bgr444be => [pa] [un] gbrp | a=1:1 [expand-8bit]
26+bgr48 => [pa] [un] gbrp16 | a=1:1
27+bgr48be => [pa] [un] gbrp16 | a=1:1
28+bgr4_byte => [pa] [un] gbrp2 | a=1:1
29+bgr4_byte => [pa] [un] gbrp1 | a=1:1 [round-down]
30+bgr4_byte => [pa] [un] gbrp | a=1:1 [expand-8bit]
31+bgr555 => [pa] [un] gbrp5 | a=1:1
32+bgr555 => [pa] [un] gbrp | a=1:1 [expand-8bit]
33+bgr555be => [pa] [un] gbrp5 | a=1:1
34+bgr555be => [pa] [un] gbrp | a=1:1 [expand-8bit]
35+bgr565 => [pa] [un] gbrp6 | a=1:1
36+bgr565 => [pa] [un] gbrp5 | a=1:1 [round-down]
37+bgr565 => [pa] [un] gbrp | a=1:1 [expand-8bit]
38+bgr565be => [pa] [un] gbrp6 | a=1:1
39+bgr565be => [pa] [un] gbrp5 | a=1:1 [round-down]
40+bgr565be => [pa] [un] gbrp | a=1:1 [expand-8bit]
41+bgr8 => [pa] [un] gbrp3 | a=1:1
42+bgr8 => [pa] [un] gbrp2 | a=1:1 [round-down]
43+bgr8 => [pa] [un] gbrp | a=1:1 [expand-8bit]
44+bgra => [pa] [un] gbrap | a=1:1 [tu] [tp]
45+bgra64 => [pa] [un] gbrap16 | a=1:1
46+bgra64be => [pa] [un] gbrap16 | a=1:1
47+cuda => no
48+d3d11 => no
49+d3d11va_vld => no
50+drm_prime => no
51+dxva2_vld => no
52+gbrap10be => [pa] [un] gbrap10 | a=1:1
53+gbrap12be => [pa] [un] gbrap12 | a=1:1
54+gbrap16be => [pa] [un] gbrap16 | a=1:1
55+gbrapf32be => [pa] [un] gbrapf32 | a=1:1
56+gbrp10be => [pa] [un] gbrp10 | a=1:1
57+gbrp12be => [pa] [un] gbrp12 | a=1:1
58+gbrp14be => [pa] [un] gbrp14 | a=1:1
59+gbrp16be => [pa] [un] gbrp16 | a=1:1
60+gbrp9be => [pa] [un] gbrp9 | a=1:1
61+gbrpf32be => [pa] [un] gbrpf32 | a=1:1
62+gray10be => [pa] [un] gray10 | a=1:1
63+gray12be => [pa] [un] gray12 | a=1:1
64+gray14be => [pa] [un] gray14 | a=1:1
65+gray16be => [pa] [un] gray16 | a=1:1
66+gray9be => [pa] [un] gray9 | a=1:1
67+grayf32be => [pa] [un] grayf32 | a=1:1
68+mediacodec => no
69+mmal => no
70+monob => [pa] [un] y1 | a=8:1 [tu] [tp]
71+monob => [pa] [un] gray | a=8:1 [expand-8bit]
72+monow => [pa] [un] y1 | a=8:1 [tu] [tp]
73+monow => [pa] [un] gray | a=8:1 [expand-8bit]
74+nv12 => [pa] [un] yuv420p | a=2:2 [tu] [tp]
75+nv16 => [pa] [un] yuv422p | a=2:1
76+nv20 => [pa] [un] yuv422p10 | a=2:1
77+nv20be => [pa] [un] yuv422p10 | a=2:1
78+nv21 => [pa] [un] yuv420p | a=2:2 [tu] [tp]
79+nv24 => [pa] [un] yuv444p | a=1:1
80+nv42 => [pa] [un] yuv444p | a=1:1
81+opencl => no
82+p010 => [pa] [un] yuv420p16 | a=2:2
83+p010be => [pa] [un] yuv420p16 | a=2:2
84+p016 => [pa] [un] yuv420p16 | a=2:2
85+p016be => [pa] [un] yuv420p16 | a=2:2
86+pal8 => [un] gbrap | a=1:1
87+qsv => no
88+rgb0 => [pa] [un] gbrp | a=1:1 [tu] [tp]
89+rgb24 => [pa] [un] gbrp | a=1:1
90+rgb30 => [pa] [un] gbrp10 | a=1:1
91+rgb4 => no
92+rgb444 => [pa] [un] gbrp4 | a=1:1
93+rgb444 => [pa] [un] gbrp | a=1:1 [expand-8bit]
94+rgb444be => [pa] [un] gbrp4 | a=1:1
95+rgb444be => [pa] [un] gbrp | a=1:1 [expand-8bit]
96+rgb48 => [pa] [un] gbrp16 | a=1:1
97+rgb48be => [pa] [un] gbrp16 | a=1:1 [tu] [tp]
98+rgb4_byte => [pa] [un] gbrp2 | a=1:1
99+rgb4_byte => [pa] [un] gbrp1 | a=1:1 [round-down]
100+rgb4_byte => [pa] [un] gbrp | a=1:1 [expand-8bit]
101+rgb555 => [pa] [un] gbrp5 | a=1:1
102+rgb555 => [pa] [un] gbrp | a=1:1 [expand-8bit]
103+rgb555be => [pa] [un] gbrp5 | a=1:1
104+rgb555be => [pa] [un] gbrp | a=1:1 [expand-8bit]
105+rgb565 => [pa] [un] gbrp6 | a=1:1
106+rgb565 => [pa] [un] gbrp5 | a=1:1 [round-down]
107+rgb565 => [pa] [un] gbrp | a=1:1 [expand-8bit]
108+rgb565be => [pa] [un] gbrp6 | a=1:1
109+rgb565be => [pa] [un] gbrp5 | a=1:1 [round-down]
110+rgb565be => [pa] [un] gbrp | a=1:1 [expand-8bit]
111+rgb8 => [pa] [un] gbrp3 | a=1:1
112+rgb8 => [pa] [un] gbrp2 | a=1:1 [round-down]
113+rgb8 => [pa] [un] gbrp | a=1:1 [expand-8bit]
114+rgba => [pa] [un] gbrap | a=1:1 [tu] [tp]
115+rgba64 => [pa] [un] gbrap16 | a=1:1 [tu] [tp]
116+rgba64be => [pa] [un] gbrap16 | a=1:1
117+uyvy422 => [pa] [un] yuv422p | a=2:1
118+uyyvyy411 => no
119+vaapi => no
120+vaapi_idct => no
121+vaapi_moco => no
122+vdpau => no
123+vdpau_output => no
124+videotoolbox => no
125+vulkan => no
126+xvmc => no
127+xyz12 => [pa] [un] gbrp16 | a=1:1
128+xyz12be => [pa] [un] gbrp16 | a=1:1
129+y210 => [pa] [un] yuv422p16 | a=2:1
130+y210be => [pa] [un] yuv422p16 | a=2:1
131+ya16 => [pa] [un] yap16 | a=1:1 [tu] [tp]
132+ya16be => [pa] [un] yap16 | a=1:1
133+ya8 => [pa] [un] yap8 | a=1:1
134+yuv420p10be => [pa] [un] yuv420p10 | a=2:2
135+yuv420p12be => [pa] [un] yuv420p12 | a=2:2
136+yuv420p14be => [pa] [un] yuv420p14 | a=2:2
137+yuv420p16be => [pa] [un] yuv420p16 | a=2:2
138+yuv420p9be => [pa] [un] yuv420p9 | a=2:2
139+yuv422p10be => [pa] [un] yuv422p10 | a=2:1
140+yuv422p12be => [pa] [un] yuv422p12 | a=2:1
141+yuv422p14be => [pa] [un] yuv422p14 | a=2:1
142+yuv422p16be => [pa] [un] yuv422p16 | a=2:1 [tu] [tp]
143+yuv422p9be => [pa] [un] yuv422p9 | a=2:1
144+yuv440p10be => [pa] [un] yuv440p10 | a=1:2
145+yuv440p12be => [pa] [un] yuv440p12 | a=1:2
146+yuv444p10be => [pa] [un] yuv444p10 | a=1:1
147+yuv444p12be => [pa] [un] yuv444p12 | a=1:1
148+yuv444p14be => [pa] [un] yuv444p14 | a=1:1
149+yuv444p16be => [pa] [un] yuv444p16 | a=1:1
150+yuv444p9be => [pa] [un] yuv444p9 | a=1:1
151+yuva420p10be => [pa] [un] yuva420p10 | a=2:2
152+yuva420p16be => [pa] [un] yuva420p16 | a=2:2
153+yuva420p9be => [pa] [un] yuva420p9 | a=2:2
154+yuva422p10be => [pa] [un] yuva422p10 | a=2:1
155+yuva422p12be => [pa] [un] yuva422p12 | a=2:1
156+yuva422p16be => [pa] [un] yuva422p16 | a=2:1
157+yuva422p9be => [pa] [un] yuva422p9 | a=2:1
158+yuva444p10be => [pa] [un] yuva444p10 | a=1:1
159+yuva444p12be => [pa] [un] yuva444p12 | a=1:1
160+yuva444p16be => [pa] [un] yuva444p16 | a=1:1
161+yuva444p9be => [pa] [un] yuva444p9 | a=1:1
162+yuyv422 => [pa] [un] yuv422p | a=2:1
163+yvyu422 => [pa] [un] yuv422p | a=2:1 [tu] [tp]
test/repack.c+249−0
@@ -0,0 +1,249 @@
1+#include <libavutil/pixfmt.h>
2+
3+#include "common/common.h"
4+#include "tests.h"
5+#include "video/fmt-conversion.h"
6+#include "video/img_format.h"
7+#include "video/repack.h"
8+#include "video/zimg.h"
9+
10+// Excuse the utter stupidity.
11+#define UNFUCK(v) ((v) > 0 ? (v) : pixfmt2imgfmt(-(v)))
12+static_assert(IMGFMT_START > 0, "");
13+#define IMGFMT_GBRP (-AV_PIX_FMT_GBRP)
14+#define IMGFMT_GBRAP (-AV_PIX_FMT_GBRAP)
15+
16+struct entry {
17+ int w, h;
18+ int fmt_a;
19+ const void *const a[4];
20+ int fmt_b;
21+ const void *const b[4];
22+ int flags;
23+};
24+
25+#define P8(...) (const uint8_t[]){__VA_ARGS__}
26+#define P16(...) (const uint16_t[]){__VA_ARGS__}
27+
28+// Warning: only entries that match existing conversions are tested.
29+static const struct entry repack_tests[] = {
30+ // Note: the '0' tests rely on 0 being written, although by definition the
31+ // contents of this padding is undefined. The repacker always writes
32+ // it this way, though.
33+ {1, 1, IMGFMT_RGB0, {P8(1, 2, 3, 0)},
34+ IMGFMT_GBRP, {P8(2), P8(3), P8(1)}},
35+ {1, 1, IMGFMT_BGR0, {P8(1, 2, 3, 0)},
36+ IMGFMT_GBRP, {P8(2), P8(1), P8(3)}},
37+ {1, 1, IMGFMT_0RGB, {P8(0, 1, 2, 3)},
38+ IMGFMT_GBRP, {P8(2), P8(3), P8(1)}},
39+ {1, 1, IMGFMT_0BGR, {P8(0, 1, 2, 3)},
40+ IMGFMT_GBRP, {P8(2), P8(1), P8(3)}},
41+ {1, 1, IMGFMT_RGBA, {P8(1, 2, 3, 4)},
42+ IMGFMT_GBRAP, {P8(2), P8(3), P8(1), P8(4)}},
43+ {1, 1, IMGFMT_BGRA, {P8(1, 2, 3, 4)},
44+ IMGFMT_GBRAP, {P8(2), P8(1), P8(3), P8(4)}},
45+ {1, 1, IMGFMT_ARGB, {P8(4, 1, 2, 3)},
46+ IMGFMT_GBRAP, {P8(2), P8(3), P8(1), P8(4)}},
47+ {1, 1, IMGFMT_ABGR, {P8(4, 1, 2, 3)},
48+ IMGFMT_GBRAP, {P8(2), P8(1), P8(3), P8(4)}},
49+ {1, 1, IMGFMT_RGBA64, {P16(0x1a1b, 0x2a2b, 0x3a3b, 0x4a4b)},
50+ -AV_PIX_FMT_GBRAP16, {P16(0x2a2b), P16(0x3a3b),
51+ P16(0x1a1b), P16(0x4a4b)}},
52+ {1, 1, -AV_PIX_FMT_RGB48BE, {P16(0x1a1b, 0x2a2b, 0x3a3b)},
53+ -AV_PIX_FMT_GBRP16, {P16(0x2b2a), P16(0x3b3a),
54+ P16(0x1b1a)}},
55+ {8, 1, -AV_PIX_FMT_MONOWHITE, {P8(0xAA)},
56+ IMGFMT_Y1, {P8(0, 1, 0, 1, 0, 1, 0, 1)}},
57+ {8, 1, -AV_PIX_FMT_MONOBLACK, {P8(0xAA)},
58+ IMGFMT_Y1, {P8(1, 0, 1, 0, 1, 0, 1, 0)}},
59+ {2, 2, IMGFMT_NV12, {P8(1, 2, 3, 4), P8(5, 6)},
60+ IMGFMT_420P, {P8(1, 2, 3, 4), P8(5), P8(6)}},
61+ {2, 2, -AV_PIX_FMT_NV21, {P8(1, 2, 3, 4), P8(5, 6)},
62+ IMGFMT_420P, {P8(1, 2, 3, 4), P8(6), P8(5)}},
63+ {1, 1, -AV_PIX_FMT_AYUV64, {P16(1, 2, 3, 4)},
64+ -AV_PIX_FMT_YUVA444P16, {P16(2), P16(3), P16(4), P16(1)}},
65+ {1, 1, -AV_PIX_FMT_AYUV64BE, {P16(0x0100, 0x0200, 0x0300, 0x0400)},
66+ -AV_PIX_FMT_YUVA444P16, {P16(2), P16(3), P16(4), P16(1)}},
67+ {2, 1, -AV_PIX_FMT_YVYU422, {P8(1, 2, 3, 4)},
68+ -AV_PIX_FMT_YUV422P, {P8(1, 3), P8(4), P8(2)}},
69+ {1, 1, -AV_PIX_FMT_YA16, {P16(1, 2)},
70+ IMGFMT_YAP16, {P16(1), P16(2)}},
71+ {2, 1, -AV_PIX_FMT_YUV422P16BE, {P16(0x1a1b, 0x2a2b), P16(0x3a3b),
72+ P16(0x4a4b)},
73+ -AV_PIX_FMT_YUV422P16, {P16(0x1b1a, 0x2b2a), P16(0x3b3a),
74+ P16(0x4b4a)}},
75+};
76+
77+static bool is_true_planar(int imgfmt)
78+{
79+ struct mp_regular_imgfmt desc;
80+ if (!mp_get_regular_imgfmt(&desc, imgfmt))
81+ return false;
82+
83+ for (int n = 0; n < desc.num_planes; n++) {
84+ if (desc.planes[n].num_components != 1)
85+ return false;
86+ }
87+
88+ return true;
89+}
90+
91+static int try_repack(struct test_ctx *ctx, FILE *f, int imgfmt, int flags,
92+ int not_if_fmt)
93+{
94+ char *head = mp_tprintf(80, "%-15s =>", mp_imgfmt_to_name(imgfmt));
95+ struct mp_repack *un = mp_repack_create_planar(imgfmt, false, flags);
96+ struct mp_repack *pa = mp_repack_create_planar(imgfmt, true, flags);
97+
98+ // If both exists, they must be always symmetric.
99+ if (un && pa) {
100+ assert(mp_repack_get_format_src(pa) == mp_repack_get_format_dst(un));
101+ assert(mp_repack_get_format_src(un) == mp_repack_get_format_dst(pa));
102+ assert(mp_repack_get_align_x(pa) == mp_repack_get_align_x(un));
103+ assert(mp_repack_get_align_y(pa) == mp_repack_get_align_y(un));
104+ }
105+
106+ int a = 0;
107+ int b = 0;
108+ if (un) {
109+ a = mp_repack_get_format_src(un);
110+ b = mp_repack_get_format_dst(un);
111+ } else if (pa) {
112+ a = mp_repack_get_format_dst(pa);
113+ b = mp_repack_get_format_src(pa);
114+ }
115+
116+ // Skip the identity ones because they're uninteresting, and add too much
117+ // noise. But still make sure they behave as expected.
118+ if (is_true_planar(imgfmt)) {
119+ // (note that we require alpha-enabled zimg)
120+ assert(mp_zimg_supports_in_format(imgfmt));
121+ assert(un && pa);
122+ assert(a == imgfmt && b == imgfmt);
123+ talloc_free(pa);
124+ talloc_free(un);
125+ return 0;
126+ }
127+
128+ struct mp_repack *rp = pa ? pa : un;
129+ if (!rp) {
130+ if (!flags)
131+ fprintf(f, "%s no\n", head);
132+ return 0;
133+ }
134+
135+ assert(a == imgfmt);
136+ if (b && b == not_if_fmt) {
137+ talloc_free(pa);
138+ talloc_free(un);
139+ return 0;
140+ }
141+
142+ fprintf(f, "%s %4s %4s %-15s |", head, pa ? "[pa]" : "", un ? "[un]" : "",
143+ mp_imgfmt_to_name(b));
144+
145+ fprintf(f, " a=%d:%d", mp_repack_get_align_x(rp), mp_repack_get_align_y(rp));
146+
147+ if (flags & REPACK_CREATE_ROUND_DOWN)
148+ fprintf(f, " [round-down]");
149+ if (flags & REPACK_CREATE_EXPAND_8BIT)
150+ fprintf(f, " [expand-8bit]");
151+
152+ // LCM of alignment of all packers.
153+ int ax = mp_repack_get_align_x(rp);
154+ int ay = mp_repack_get_align_y(rp);
155+ if (pa && un) {
156+ ax = MPMAX(mp_repack_get_align_x(pa), mp_repack_get_align_x(un));
157+ ay = MPMAX(mp_repack_get_align_y(pa), mp_repack_get_align_y(un));
158+ }
159+
160+ for (int n = 0; n < MP_ARRAY_SIZE(repack_tests); n++) {
161+ const struct entry *e = &repack_tests[n];
162+ int fmt_a = UNFUCK(e->fmt_a);
163+ int fmt_b = UNFUCK(e->fmt_b);
164+ if (!(fmt_a == a && fmt_b == b && e->flags == flags))
165+ continue;
166+
167+ // We convert a "random" macro pixel to catch potential addressing bugs
168+ // that might be ignored with (0, 0) origins.
169+ struct mp_image *ia = mp_image_alloc(fmt_a, e->w * 5 * ax, e->h * 5 * ay);
170+ struct mp_image *ib = mp_image_alloc(fmt_b, e->w * 7 * ax, e->h * 6 * ay);
171+ int sx = 4 * ax, sy = 3 * ay, dx = 3 * ax, dy = 2 * ay;
172+
173+ assert(ia && ib);
174+
175+ for (int pack = 0; pack < 2; pack++) {
176+ struct mp_repack *repacker = pack ? pa : un;
177+ if (!repacker)
178+ continue;
179+
180+ mp_image_clear(ia, 0, 0, ia->w, ia->h);
181+ mp_image_clear(ib, 0, 0, ib->w, ib->h);
182+
183+ const void *const *dstd = pack ? e->a : e->b;
184+ const void *const *srcd = pack ? e->b : e->a;
185+ struct mp_image *dsti = pack ? ia : ib;
186+ struct mp_image *srci = pack ? ib : ia;
187+
188+ bool r = repack_config_buffers(repacker, 0, dsti, 0, srci, NULL);
189+ assert(r);
190+
191+ for (int p = 0; p < srci->num_planes; p++) {
192+ uint8_t *ptr = mp_image_pixel_ptr(srci, p, sx, sy);
193+ for (int y = 0; y < e->h >> srci->fmt.ys[p]; y++) {
194+ int w = e->w >> srci->fmt.xs[p];
195+ int wb = (w * srci->fmt.bpp[p] + 7) / 8;
196+ const void *cptr = (uint8_t *)srcd[p] + wb * y;
197+ memcpy(ptr + srci->stride[p] * y, cptr, wb);
198+ }
199+ }
200+
201+ repack_line(repacker, dx, dy, sx, sy, e->w);
202+
203+ for (int p = 0; p < dsti->num_planes; p++) {
204+ uint8_t *ptr = mp_image_pixel_ptr(dsti, p, dx, dy);
205+ for (int y = 0; y < e->h >> dsti->fmt.ys[p]; y++) {
206+ int w = e->w >> dsti->fmt.xs[p];
207+ int wb = (w * dsti->fmt.bpp[p] + 7) / 8;
208+ const void *cptr = (uint8_t *)dstd[p] + wb * y;
209+ assert_memcmp(ptr + dsti->stride[p] * y, cptr, wb);
210+ }
211+ }
212+
213+ fprintf(f, " [t%s]", pack ? "p" : "u");
214+ }
215+
216+ talloc_free(ia);
217+ talloc_free(ib);
218+ }
219+
220+ fprintf(f, "\n");
221+
222+ talloc_free(pa);
223+ talloc_free(un);
224+ return b;
225+}
226+
227+static void run(struct test_ctx *ctx)
228+{
229+ FILE *f = test_open_out(ctx, "repack.txt");
230+
231+ init_imgfmts_list();
232+ for (int n = 0; n < num_imgfmts; n++) {
233+ int imgfmt = imgfmts[n];
234+
235+ int other = try_repack(ctx, f, imgfmt, 0, 0);
236+ try_repack(ctx, f, imgfmt, REPACK_CREATE_ROUND_DOWN, other);
237+ try_repack(ctx, f, imgfmt, REPACK_CREATE_EXPAND_8BIT, other);
238+ }
239+
240+ fclose(f);
241+
242+ assert_text_files_equal(ctx, "repack.txt", "repack.txt",
243+ "This can fail if FFmpeg/libswscale adds or removes pixfmts.");
244+}
245+
246+const struct unittest test_repack = {
247+ .name = "repack",
248+ .run = run,
249+};
test/tests.c+23−0
@@ -12,6 +12,7 @@ static const struct unittest *unittests[] = { · 11 unmodified lines
1212 &test_paths,
1313 &test_repack_sws,
1414 #if HAVE_ZIMG
15+ &test_repack, // zimg only due to cross-checking with zimg.c
1516 &test_repack_zimg,
1617 #endif
1718 NULL
@@ -128,3 +129,25 @@ void assert_text_files_equal_impl(const char *file, int line, · 110 unmodified lines
128129 abort();
129130 }
130131 }
132+
133+static void hexdump(const uint8_t *d, size_t size)
134+{
135+ printf("|");
136+ while (size--) {
137+ printf(" %02x", d[0]);
138+ d++;
139+ }
140+ printf(" |\n");
141+}
142+
143+void assert_memcmp_impl(const char *file, int line,
144+ const void *a, const void *b, size_t size)
145+{
146+ if (memcmp(a, b, size) == 0)
147+ return;
148+
149+ printf("%s:%d: mismatching data:\n", file, line);
150+ hexdump(a, size);
151+ hexdump(b, size);
152+ abort();
153+}
test/tests.h+7−0
@@ -43,6 +43,7 @@ extern const struct unittest test_json; · 42 unmodified lines
4343 extern const struct unittest test_linked_list;
4444 extern const struct unittest test_repack_sws;
4545 extern const struct unittest test_repack_zimg;
46+extern const struct unittest test_repack;
4647 extern const struct unittest test_paths;
4748
4849 #define assert_true(x) assert(x)
@@ -54,6 +55,10 @@ extern const struct unittest test_paths; · 5 unmodified lines
5455 #define assert_float_equal(a, b, tolerance) \
5556 assert_float_equal_impl(__FILE__, __LINE__, (a), (b), (tolerance))
5657
58+// Assert that memcmp(a,b,s)==0, or hexdump output on failure.
59+#define assert_memcmp(a, b, s) \
60+ assert_memcmp_impl(__FILE__, __LINE__, (a), (b), (s))
61+
5762 // Require that the files "ref" and "new" are the same. The paths can be
5863 // relative to ref_path and out_path respectively. If they're not the same,
5964 // the output of "diff" is shown, the err message (if not NULL), and the test
@@ -69,6 +74,8 @@ void assert_float_equal_impl(const char *file, int line, · 9 unmodified lines
6974 void assert_text_files_equal_impl(const char *file, int line,
7075 struct test_ctx *ctx, const char *ref,
7176 const char *new, const char *err);
77+void assert_memcmp_impl(const char *file, int line,
78+ const void *a, const void *b, size_t size);
7279
7380 // Open a new file in the out_path. Always succeeds.
7481 FILE *test_open_out(struct test_ctx *ctx, const char *name);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t