From 35d1d011fda4a92bcaf42d30ed137583b27d7f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 19 Feb 2021 11:30:45 +0200 Subject: checkasm: Add macros for allocating and checking padded pixel buffers --- tests/checkasm/checkasm.c | 67 +++++++++++++++++++++++++++++++++++------------ tests/checkasm/checkasm.h | 17 ++++++++++-- 2 files changed, 65 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index b6a21b7..69cb9d9 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -772,32 +772,65 @@ void checkasm_set_signal_handler_state(const int enabled) { int checkasm_check_##type(const char *const file, const int line, \ const type *buf1, ptrdiff_t stride1, \ const type *buf2, ptrdiff_t stride2, \ - const int w, int h, const char *const name) \ + const int w, int h, const char *const name, \ + const int padding) \ { \ stride1 /= sizeof(*buf1); \ stride2 /= sizeof(*buf2); \ int y = 0; \ - for (y = 0; y < h; y++) \ - if (memcmp(&buf1[y*stride1], &buf2[y*stride2], w*sizeof(*buf1))) \ + for (y = -padding; y < h + padding; y++) \ + if (memcmp(&buf1[y*stride1 - padding], &buf2[y*stride2 - padding], \ + (w + 2*padding)*sizeof(*buf1))) \ break; \ - if (y == h) \ + if (y == h + padding) \ return 0; \ if (!checkasm_fail_func("%s:%d", file, line)) \ return 1; \ - fprintf(stderr, "%s:\n", name); \ - while (h--) { \ - for (int x = 0; x < w; x++) \ - fprintf(stderr, " " fmt, buf1[x]); \ - fprintf(stderr, " "); \ - for (int x = 0; x < w; x++) \ - fprintf(stderr, " " fmt, buf2[x]); \ - fprintf(stderr, " "); \ - for (int x = 0; x < w; x++) \ - fprintf(stderr, "%c", buf1[x] != buf2[x] ? 'x' : '.'); \ - buf1 += stride1; \ - buf2 += stride2; \ - fprintf(stderr, "\n"); \ + fprintf(stderr, "%s (%dx%d):\n", name, w, h); \ + for (y = 0; y < h; y++) \ + if (memcmp(&buf1[y*stride1], &buf2[y*stride2], w*sizeof(*buf1))) \ + break; \ + if (y != h) { \ + for (y = 0; y < h; y++) { \ + for (int x = 0; x < w; x++) \ + fprintf(stderr, " " fmt, buf1[x]); \ + fprintf(stderr, " "); \ + for (int x = 0; x < w; x++) \ + fprintf(stderr, " " fmt, buf2[x]); \ + fprintf(stderr, " "); \ + for (int x = 0; x < w; x++) \ + fprintf(stderr, "%c", buf1[x] != buf2[x] ? 'x' : '.'); \ + buf1 += stride1; \ + buf2 += stride2; \ + fprintf(stderr, "\n"); \ + } \ + buf1 -= h*stride1; \ + buf2 -= h*stride2; \ } \ + for (y = -padding; y < 0; y++) \ + if (memcmp(&buf1[y*stride1 - padding], &buf2[y*stride2 - padding], \ + (w + 2*padding)*sizeof(*buf1))) { \ + fprintf(stderr, " overwrite above\n"); \ + break; \ + } \ + for (y = h; y < h + padding; y++) \ + if (memcmp(&buf1[y*stride1 - padding], &buf2[y*stride2 - padding], \ + (w + 2*padding)*sizeof(*buf1))) { \ + fprintf(stderr, " overwrite below\n"); \ + break; \ + } \ + for (y = 0; y < h; y++) \ + if (memcmp(&buf1[y*stride1 - padding], &buf2[y*stride2 - padding], \ + padding*sizeof(*buf1))) { \ + fprintf(stderr, " overwrite left\n"); \ + break; \ + } \ + for (y = 0; y < h; y++) \ + if (memcmp(&buf1[y*stride1 + w], &buf2[y*stride2 + w], \ + padding*sizeof(*buf1))) { \ + fprintf(stderr, " overwrite right\n"); \ + break; \ + } \ return 1; \ } diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index e077c50..b22a9f0 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -307,11 +307,22 @@ void checkasm_stack_clobber(uint64_t clobber, ...); #define bench_new(...) do {} while (0) #endif + +#define PIXEL_RECT(name, w, h) \ + ALIGN_STK_64(pixel, name##_buf, ((h)+32)*((w)+64) + 64,); \ + ptrdiff_t name##_stride = sizeof(pixel)*((w)+64); \ + (void)name##_stride; \ + pixel *name = name##_buf + ((w)+64)*16 + 64 + +#define CLEAR_PIXEL_RECT(name) \ + memset(name##_buf, 0x99, sizeof(name##_buf)) \ + #define DECL_CHECKASM_CHECK_FUNC(type) \ int checkasm_check_##type(const char *const file, const int line, \ const type *const buf1, const ptrdiff_t stride1, \ const type *const buf2, const ptrdiff_t stride2, \ - const int w, const int h, const char *const name) + const int w, const int h, const char *const name, \ + const int padding) DECL_CHECKASM_CHECK_FUNC(uint8_t); DECL_CHECKASM_CHECK_FUNC(uint16_t); @@ -321,10 +332,12 @@ DECL_CHECKASM_CHECK_FUNC(int32_t); #define CONCAT(a,b) a ## b -#define checkasm_check(prefix, ...) CONCAT(checkasm_check_, prefix)(__FILE__, __LINE__, __VA_ARGS__) +#define checkasm_check2(prefix, ...) CONCAT(checkasm_check_, prefix)(__FILE__, __LINE__, __VA_ARGS__) +#define checkasm_check(prefix, ...) checkasm_check2(prefix, __VA_ARGS__, 0) #ifdef BITDEPTH #define checkasm_check_pixel(...) checkasm_check(PIXEL_TYPE, __VA_ARGS__) +#define checkasm_check_pixel_padded(...) checkasm_check2(PIXEL_TYPE, __VA_ARGS__, 8) #define checkasm_check_coef(...) checkasm_check(COEF_TYPE, __VA_ARGS__) #endif -- cgit v1.2.3