shithub: dav1d

Download patch

ref: c950e7101bdf5f7117bfca816984a21e550509f0
parent: 46980237595c3065f15106b0c3483cdd57fd3153
author: Martin Storsjö <[email protected]>
date: Thu Jun 20 19:38:06 EDT 2019

checkasm: Add functions for printing pixel buffers

--- a/include/common/bitdepth.h
+++ b/include/common/bitdepth.h
@@ -40,6 +40,8 @@
 #elif BITDEPTH == 8
 typedef uint8_t pixel;
 typedef int16_t coef;
+#define PIXEL_TYPE uint8_t
+#define COEF_TYPE int16_t
 #define pixel_copy memcpy
 #define pixel_set memset
 #define iclip_pixel iclip_u8
@@ -54,6 +56,8 @@
 #elif BITDEPTH == 16
 typedef uint16_t pixel;
 typedef int32_t coef;
+#define PIXEL_TYPE uint16_t
+#define COEF_TYPE int32_t
 #define pixel_copy(a, b, c) memcpy(a, b, (c) << 1)
 static inline void pixel_set(pixel *const dst, const int val, const int num) {
     for (int n = 0; n < num; n++)
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -139,6 +139,7 @@
     const char *test_name;
     unsigned int seed;
     int bench_c;
+    int verbose;
 } state;
 
 /* float compare support code */
@@ -513,7 +514,8 @@
                     "    --test=<test_name>  Test only <test_name>\n"
                     "    --bench=<pattern>   Test and benchmark the functions matching <pattern>\n"
                     "    --list              List the available tests\n"
-                    "    --bench-c           Benchmark the C-only functions\n");
+                    "    --bench-c           Benchmark the C-only functions\n"
+                    "    --verbose -v        Print failures verbosely\n");
             return 0;
         } else if (!strncmp(argv[1], "--bench-c", 9)) {
             state.bench_c = 1;
@@ -536,6 +538,8 @@
                 fprintf(stderr, "%s%s", i ? ", ": "", tests[i].name);
             fprintf(stderr, "]\n");
             return 0;
+        } else if (!strcmp(argv[1], "--verbose") || !strcmp(argv[1], "-v")) {
+            state.verbose = 1;
         } else {
             state.seed = (unsigned int) strtoul(argv[1], NULL, 10);
         }
@@ -702,3 +706,42 @@
     signal(SIGSEGV, handler);
 #endif
 }
+
+#define DEF_CHECKASM_CHECK_FUNC(type, fmt) \
+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) \
+{ \
+    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))) \
+            break; \
+    if (y == h) \
+        return 0; \
+    checkasm_fail_func("%s:%d", file, line); \
+    if (!state.verbose) \
+        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"); \
+    } \
+    return 1; \
+}
+
+DEF_CHECKASM_CHECK_FUNC(uint8_t,  "%02x")
+DEF_CHECKASM_CHECK_FUNC(uint16_t, "%04x")
+DEF_CHECKASM_CHECK_FUNC(int16_t,  "%6d")
+DEF_CHECKASM_CHECK_FUNC(int32_t,  "%9d")
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -48,6 +48,7 @@
 #endif
 
 #include "include/common/attributes.h"
+#include "include/common/bitdepth.h"
 #include "include/common/intops.h"
 
 int xor128_rand(void);
@@ -279,6 +280,28 @@
     } while (0)
 #else
 #define bench_new(...) while (0)
+#endif
+
+#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)
+
+DECL_CHECKASM_CHECK_FUNC(uint8_t);
+DECL_CHECKASM_CHECK_FUNC(uint16_t);
+DECL_CHECKASM_CHECK_FUNC(int16_t);
+DECL_CHECKASM_CHECK_FUNC(int32_t);
+
+
+#define PASTE(a,b) a ## b
+#define CONCAT(a,b) PASTE(a,b)
+
+#define checkasm_check(prefix, ...) CONCAT(checkasm_check_, prefix)(__FILE__, __LINE__, __VA_ARGS__)
+
+#ifdef BITDEPTH
+#define checkasm_check_pixel(...) checkasm_check(PIXEL_TYPE, __VA_ARGS__)
+#define checkasm_check_coef(...)  checkasm_check(COEF_TYPE,  __VA_ARGS__)
 #endif
 
 #endif /* DAV1D_TESTS_CHECKASM_CHECKASM_H */