shithub: dav1d

Download patch

ref: 13a7d78655f8747c2cd01e8a48d44dcc7f60a8e5
parent: 7107c2f14f8fc522997148e9317171851c69af90
author: Martin Storsjö <martin@martin.st>
date: Sat Jun 29 19:24:42 EDT 2019

checkasm: cdef: Add verbose prints for output data (and relevant input)

For the cdef_filter tests, one could also extend the buffer to
contain 16*11 pixels, to simplify printing it as one rectangular
section.

Extend the common hex_dump function to allow dumping to an arbitrary
FILE* pointer, to reuse it for printing the source pixel buffer in
case of errors.

--- a/include/common/dump.h
+++ b/include/common/dump.h
@@ -45,17 +45,23 @@
     fclose(f);
 }
 
-static inline void hex_dump(const pixel *buf, ptrdiff_t stride,
-                            int w, int h, const char *what)
+static inline void hex_fdump(FILE *out, const pixel *buf, ptrdiff_t stride,
+                             int w, int h, const char *what)
 {
-    printf("%s\n", what);
+    fprintf(out, "%s\n", what);
     while (h--) {
         int x;
         for (x = 0; x < w; x++)
-            printf(" " PIX_HEX_FMT, buf[x]);
+            fprintf(out, " " PIX_HEX_FMT, buf[x]);
         buf += PXSTRIDE(stride);
-        printf("\n");
+        fprintf(out, "\n");
     }
+}
+
+static inline void hex_dump(const pixel *buf, ptrdiff_t stride,
+                            int w, int h, const char *what)
+{
+    hex_fdump(stdout, buf, stride, w, h, what);
 }
 
 static inline void coef_dump(const coef *buf, const int w, const int h,
--- a/tests/checkasm/cdef.c
+++ b/tests/checkasm/cdef.c
@@ -28,7 +28,10 @@
 #include "tests/checkasm/checkasm.h"
 
 #include <string.h>
+#include <stdio.h>
 
+#include "common/dump.h"
+
 #include "src/levels.h"
 #include "src/cdef.h"
 
@@ -80,7 +83,12 @@
                          (pixel *[2]) { top_ptr, top_ptr + 16 },
                          pri_strength, sec_strength, dir, damping, edges
                          HIGHBD_TAIL_SUFFIX);
-                if (memcmp(a_src, c_src, (10 * 16 + 8) * sizeof(pixel))) fail();
+                checkasm_check_pixel(c_src, 16 * sizeof(pixel),
+                                     a_src, 16 * sizeof(pixel),
+                                     16, 10, "src");
+                checkasm_check_pixel(c_src + 16 * 10, 16 * sizeof(pixel),
+                                     a_src + 16 * 10, 16 * sizeof(pixel),
+                                     8, 1, "src last row");
                 bench_new(a_src_ptr, 16 * sizeof(pixel), left,
                           (pixel *[2]) { top_ptr, top_ptr + 16 },
                           pri_strength, sec_strength, dir, damping, edges
@@ -108,7 +116,12 @@
 
         const int c_dir = call_ref(src, 8 * sizeof(pixel), &c_var HIGHBD_TAIL_SUFFIX);
         const int a_dir = call_new(src, 8 * sizeof(pixel), &a_var HIGHBD_TAIL_SUFFIX);
-        if (c_var != a_var || c_dir != a_dir) fail();
+        if (c_var != a_var || c_dir != a_dir) {
+            if (fail()) {
+                hex_fdump(stderr, src, 8 * sizeof(pixel), 8, 8, "src");
+                fprintf(stderr, "c_dir %d a_dir %d\n", c_dir, a_dir);
+            }
+        }
         bench_new(src, 8 * sizeof(pixel), &a_var HIGHBD_TAIL_SUFFIX);
     }
     report("cdef_dir");
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -629,8 +629,9 @@
                     state.bench_pattern_len);
 }
 
-/* Indicate that the current test has failed */
-void checkasm_fail_func(const char *const msg, ...) {
+/* Indicate that the current test has failed, return whether verbose printing
+ * is requested. */
+int checkasm_fail_func(const char *const msg, ...) {
     if (state.current_func_ver->cpu && state.current_func_ver->ok) {
         va_list arg;
 
@@ -645,6 +646,7 @@
         state.current_func_ver->ok = 0;
         state.num_failed++;
     }
+    return state.verbose;
 }
 
 /* Update benchmark results of the current function */
@@ -721,8 +723,7 @@
             break; \
     if (y == h) \
         return 0; \
-    checkasm_fail_func("%s:%d", file, line); \
-    if (!state.verbose) \
+    if (!checkasm_fail_func("%s:%d", file, line)) \
         return 1; \
     fprintf(stderr, "%s:\n", name); \
     while (h--) { \
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -68,7 +68,7 @@
 
 void *checkasm_check_func(void *func, const char *name, ...);
 int checkasm_bench_func(void);
-void checkasm_fail_func(const char *msg, ...);
+int checkasm_fail_func(const char *msg, ...);
 void checkasm_update_bench(int iterations, uint64_t cycles);
 void checkasm_report(const char *name, ...);
 void checkasm_set_signal_handler_state(int enabled);