[FFmpeg-devel] [PATCH 2/2] Add pixblockdsp checkasm tests

Timothy Gu timothygu99 at gmail.com
Sun Nov 1 17:59:43 CET 2015


---
 tests/checkasm/Makefile      |   1 +
 tests/checkasm/checkasm.c    |   3 ++
 tests/checkasm/checkasm.h    |   1 +
 tests/checkasm/pixblockdsp.c | 107 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 112 insertions(+)
 create mode 100644 tests/checkasm/pixblockdsp.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index c29ceef..1c0290b 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -5,6 +5,7 @@ AVCODECOBJS-$(CONFIG_FLACDSP)  += flacdsp.o
 AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
 AVCODECOBJS-$(CONFIG_H264QPEL) += h264qpel.o
 AVCODECOBJS-$(CONFIG_JPEG2000_DECODER) += jpeg2000dsp.o
+AVCODECOBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER) += v210enc.o
 AVCODECOBJS-$(CONFIG_VP9_DECODER) += vp9dsp.o
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index e875120..3548bb3 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -76,6 +76,9 @@ static const struct {
     #if CONFIG_JPEG2000_DECODER
         { "jpeg2000dsp", checkasm_check_jpeg2000dsp },
     #endif
+    #if CONFIG_PIXBLOCKDSP
+        { "pixblockdsp", checkasm_check_pixblockdsp },
+    #endif
     #if CONFIG_V210_ENCODER
         { "v210enc", checkasm_check_v210enc },
     #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 1775a25..73b7e42 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -35,6 +35,7 @@ void checkasm_check_flacdsp(void);
 void checkasm_check_h264pred(void);
 void checkasm_check_h264qpel(void);
 void checkasm_check_jpeg2000dsp(void);
+void checkasm_check_pixblockdsp(void);
 void checkasm_check_v210enc(void);
 void checkasm_check_vp9dsp(void);
 
diff --git a/tests/checkasm/pixblockdsp.c b/tests/checkasm/pixblockdsp.c
new file mode 100644
index 0000000..d59d162
--- /dev/null
+++ b/tests/checkasm/pixblockdsp.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2015 Tiancheng "Timothy" Gu
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+#include "checkasm.h"
+#include "libavcodec/pixblockdsp.h"
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+
+#define BUF_SIZE 512
+#define TOTAL_BUF_SIZE FFALIGN(BUF_SIZE * 2 + BUF_SIZE / 64, 4)
+
+#define randomize_buffers()                 \
+    do {                                    \
+        int i;                              \
+        for (i = 0; i < TOTAL_BUF_SIZE; i += 4) { \
+            uint32_t r = rnd();             \
+            AV_WN32A(src10 + i, r);         \
+            AV_WN32A(src11 + i, r);         \
+            r = rnd();                      \
+            AV_WN32A(src20 + i, r);         \
+            AV_WN32A(src21 + i, r);         \
+            r = rnd();                      \
+            AV_WN32A(dst0_ + i, r);         \
+            AV_WN32A(dst1_ + i, r);         \
+        }                                   \
+    } while (0)
+
+#define check_get_pixels(type)                                                             \
+    do {                                                                                   \
+        int i;                                                                             \
+        declare_func(void, int16_t *block, const uint8_t *pixels, ptrdiff_t line_size);    \
+                                                                                           \
+        for (i = 0; i < BUF_SIZE / 64; i++) {                                              \
+            int src_offset = i * 64 * sizeof(type) + i; /* Test various alignments */      \
+            int dst_offset = i * 64; /* dst must be aligned */                             \
+            randomize_buffers();                                                           \
+            call_ref(dst0 + dst_offset, src10 + src_offset, 8);                            \
+            call_new(dst1 + dst_offset, src11 + src_offset, 8);                            \
+            if (memcmp(src10, src11, TOTAL_BUF_SIZE)|| memcmp(dst0, dst1, TOTAL_BUF_SIZE)) \
+                fail();                                                                    \
+            bench_new(dst1 + dst_offset, src11 + src_offset, 8);                           \
+        }                                                                                  \
+    } while (0)
+
+#define check_diff_pixels(type)                                                            \
+    do {                                                                                   \
+        int i;                                                                             \
+        declare_func(void, int16_t *av_restrict block, const uint8_t *s1, const uint8_t *s2, int stride); \
+                                                                                           \
+        for (i = 0; i < BUF_SIZE / 64; i++) {                                              \
+            int src_offset = i * 64 * sizeof(type) + i; /* Test various alignments */      \
+            int dst_offset = i * 64; /* dst must be aligned */                             \
+            randomize_buffers();                                                           \
+            call_ref(dst0 + dst_offset, src10 + src_offset, src20 + src_offset, 8);        \
+            call_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8);        \
+            if (memcmp(src10, src11, TOTAL_BUF_SIZE) || memcmp(src20, src21, TOTAL_BUF_SIZE) || memcmp(dst0, dst1, TOTAL_BUF_SIZE)) \
+                fail();                                                                    \
+            bench_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8);       \
+        }                                                                                  \
+    } while (0)
+
+void checkasm_check_pixblockdsp(void)
+{
+    LOCAL_ALIGNED_16(uint8_t, src10, [TOTAL_BUF_SIZE]);
+    LOCAL_ALIGNED_16(uint8_t, src11, [TOTAL_BUF_SIZE]);
+    LOCAL_ALIGNED_16(uint8_t, src20, [TOTAL_BUF_SIZE]);
+    LOCAL_ALIGNED_16(uint8_t, src21, [TOTAL_BUF_SIZE]);
+    LOCAL_ALIGNED_16(uint8_t, dst0_, [TOTAL_BUF_SIZE]);
+    LOCAL_ALIGNED_16(uint8_t, dst1_, [TOTAL_BUF_SIZE]);
+    uint16_t *dst0 = (uint16_t *)dst0_;
+    uint16_t *dst1 = (uint16_t *)dst1_;
+    PixblockDSPContext h;
+    AVCodecContext avctx = {
+        .bits_per_raw_sample = 8,
+    };
+
+    ff_pixblockdsp_init(&h, &avctx);
+
+    if (check_func(h.get_pixels, "get_pixels"))
+        check_get_pixels(uint8_t);
+
+    report("get_pixels");
+
+    if (check_func(h.diff_pixels, "diff_pixels"))
+        check_diff_pixels(uint8_t);
+
+    report("diff_pixels");
+}
-- 
2.1.4



More information about the ffmpeg-devel mailing list