diff mbox series

[FFmpeg-devel] checkasm: Add functions for printing pixel buffers

Message ID 20200514143334.31313-1-josh@itanimul.li
State New
Headers show
Series [FFmpeg-devel] checkasm: Add functions for printing pixel buffers
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Josh de Kock May 14, 2020, 2:33 p.m. UTC
From: Martin Storsjö <martin@martin.st>

This was ported from dav1d (c950e7101bdf5f7117bfca816984a21e550509f0).

Signed-off-by: Josh de Kock <josh@itanimul.li>
---
 tests/checkasm/checkasm.c | 42 +++++++++++++++++++++++++++++++++++++++
 tests/checkasm/checkasm.h | 16 +++++++++++++++
 2 files changed, 58 insertions(+)

Comments

Martin Storsjö May 14, 2020, 9:28 p.m. UTC | #1
On Thu, 14 May 2020, Josh de Kock wrote:

> From: Martin Storsjö <martin@martin.st>
>
> This was ported from dav1d (c950e7101bdf5f7117bfca816984a21e550509f0).
>
> Signed-off-by: Josh de Kock <josh@itanimul.li>
> ---
> tests/checkasm/checkasm.c | 42 +++++++++++++++++++++++++++++++++++++++
> tests/checkasm/checkasm.h | 16 +++++++++++++++
> 2 files changed, 58 insertions(+)

This looks good to me, although I might be biased :-)

// Martin
Josh de Kock May 15, 2020, 10:29 a.m. UTC | #2
On 14/05/2020 22:28, Martin Storsjö wrote:
> On Thu, 14 May 2020, Josh de Kock wrote:
> 
>> From: Martin Storsjö <martin@martin.st>
>>
>> This was ported from dav1d (c950e7101bdf5f7117bfca816984a21e550509f0).
>>
>> Signed-off-by: Josh de Kock <josh@itanimul.li>
>> ---
>> tests/checkasm/checkasm.c | 42 +++++++++++++++++++++++++++++++++++++++
>> tests/checkasm/checkasm.h | 16 +++++++++++++++
>> 2 files changed, 58 insertions(+)
> 
> This looks good to me, although I might be biased :-)
> 

Pushed with amended commit message (I don't think it's necessary to 
mention pixels as it's a more general function for checking and diffing 
rectangular sections of memory).
diff mbox series

Patch

diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 91066514f6..120052a816 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -269,6 +269,7 @@  static struct {
     int cpu_flag;
     const char *cpu_flag_name;
     const char *test_name;
+    int verbose;
 } state;
 
 /* PRNG state */
@@ -687,6 +688,8 @@  int main(int argc, char *argv[])
                 state.bench_pattern = "";
         } else if (!strncmp(argv[1], "--test=", 7)) {
             state.test_name = argv[1] + 7;
+        } else if (!strcmp(argv[1], "--verbose") || !strcmp(argv[1], "-v")) {
+            state.verbose = 1;
         } else {
             seed = strtoul(argv[1], NULL, 10);
         }
@@ -837,3 +840,42 @@  void checkasm_report(const char *name, ...)
             max_length = length;
     }
 }
+
+#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")
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 77e573774f..e98a800c50 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -258,4 +258,20 @@  typedef struct CheckasmPerf {
 #define PERF_STOP(t)   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__)
+
 #endif /* TESTS_CHECKASM_CHECKASM_H */