[FFmpeg-cvslog] checkasm: add unit tests for v210enc

Henrik Gramner git at videolan.org
Tue Sep 8 14:30:08 CEST 2015


ffmpeg | branch: master | Henrik Gramner <henrik at gramner.com> | Sun Sep  6 01:06:12 2015 +0200| [3cdda78deb19b39dbbf8961ae0aec44dbb19bf6d] | committer: Luca Barbato

checkasm: add unit tests for v210enc

Signed-off-by: Luca Barbato <lu_zero at gentoo.org>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3cdda78deb19b39dbbf8961ae0aec44dbb19bf6d
---

 libavcodec/v210enc.c      |   15 +++++---
 libavcodec/v210enc.h      |    2 +
 tests/checkasm/Makefile   |    1 +
 tests/checkasm/checkasm.c |    3 ++
 tests/checkasm/checkasm.h |    1 +
 tests/checkasm/v210enc.c  |   94 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 111 insertions(+), 5 deletions(-)

diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
index 42cbb86..ca6ad2e 100644
--- a/libavcodec/v210enc.c
+++ b/libavcodec/v210enc.c
@@ -82,6 +82,15 @@ static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
     }
 }
 
+av_cold void ff_v210enc_init(V210EncContext *s)
+{
+    s->pack_line_8  = v210_planar_pack_8_c;
+    s->pack_line_10 = v210_planar_pack_10_c;
+
+    if (ARCH_X86)
+        ff_v210enc_init_x86(s);
+}
+
 static av_cold int encode_init(AVCodecContext *avctx)
 {
     V210EncContext *s = avctx->priv_data;
@@ -97,11 +106,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-    s->pack_line_8  = v210_planar_pack_8_c;
-    s->pack_line_10 = v210_planar_pack_10_c;
-
-    if (ARCH_X86)
-        ff_v210enc_init_x86(s);
+    ff_v210enc_init(s);
 
     return 0;
 }
diff --git a/libavcodec/v210enc.h b/libavcodec/v210enc.h
index be9b66d..81a3531 100644
--- a/libavcodec/v210enc.h
+++ b/libavcodec/v210enc.h
@@ -30,6 +30,8 @@ typedef struct V210EncContext {
                          const uint16_t *v, uint8_t *dst, ptrdiff_t width);
 } V210EncContext;
 
+void ff_v210enc_init(V210EncContext *s);
+
 void ff_v210enc_init_x86(V210EncContext *s);
 
 #endif /* AVCODEC_V210ENC_H */
diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index ff57aa8..5fccad9 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -2,6 +2,7 @@
 AVCODECOBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o
 AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
 AVCODECOBJS-$(CONFIG_H264QPEL) += h264qpel.o
+AVCODECOBJS-$(CONFIG_V210_ENCODER) += v210enc.o
 
 CHECKASMOBJS-$(CONFIG_AVCODEC) += $(AVCODECOBJS-yes)
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index a120bc3..3d47a43 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -66,6 +66,9 @@ static const struct {
 #if CONFIG_H264QPEL
     { "h264qpel", checkasm_check_h264qpel },
 #endif
+#if CONFIG_V210_ENCODER
+    { "v210enc", checkasm_check_v210enc },
+#endif
     { NULL }
 };
 
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index cbf3dca..aa32655 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -32,6 +32,7 @@
 void checkasm_check_bswapdsp(void);
 void checkasm_check_h264pred(void);
 void checkasm_check_h264qpel(void);
+void checkasm_check_v210enc(void);
 
 void *checkasm_check_func(void *func, const char *name, ...) av_printf_format(2, 3);
 int checkasm_bench_func(void);
diff --git a/tests/checkasm/v210enc.c b/tests/checkasm/v210enc.c
new file mode 100644
index 0000000..cdb8e76
--- /dev/null
+++ b/tests/checkasm/v210enc.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2015 Henrik Gramner
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; 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/v210enc.h"
+#include "libavutil/common.h"
+#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
+
+#define BUF_SIZE 512
+
+#define randomize_buffers(mask)                        \
+    do {                                               \
+        int i, size = sizeof(*y0);                     \
+        for (i = 0; i < BUF_SIZE; i += 4 / size) {     \
+            uint32_t r = rnd() & mask;                 \
+            AV_WN32A(y0 + i, r);                       \
+            AV_WN32A(y1 + i, r);                       \
+        }                                              \
+        for (i = 0; i < BUF_SIZE / 2; i += 4 / size) { \
+            uint32_t r = rnd() & mask;                 \
+            AV_WN32A(u0 + i, r);                       \
+            AV_WN32A(u1 + i, r);                       \
+            r = rnd() & mask;                          \
+            AV_WN32A(v0 + i, r);                       \
+            AV_WN32A(v1 + i, r);                       \
+        }                                              \
+        for (i = 0; i < BUF_SIZE * 8 / 3; i += 4) {    \
+            uint32_t r = rnd();                        \
+            AV_WN32A(dst0 + i, r);                     \
+            AV_WN32A(dst1 + i, r);                     \
+        }                                              \
+    } while (0)
+
+#define check_pack_line(type, mask)                                                \
+    do {                                                                           \
+        LOCAL_ALIGNED_16(type, y0, [BUF_SIZE]);                                    \
+        LOCAL_ALIGNED_16(type, y1, [BUF_SIZE]);                                    \
+        LOCAL_ALIGNED_16(type, u0, [BUF_SIZE / 2]);                                \
+        LOCAL_ALIGNED_16(type, u1, [BUF_SIZE / 2]);                                \
+        LOCAL_ALIGNED_16(type, v0, [BUF_SIZE / 2]);                                \
+        LOCAL_ALIGNED_16(type, v1, [BUF_SIZE / 2]);                                \
+        LOCAL_ALIGNED_16(uint8_t, dst0, [BUF_SIZE * 8 / 3]);                       \
+        LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE * 8 / 3]);                       \
+                                                                                   \
+        declare_func(void, const type * y, const type * u, const type * v,         \
+                     uint8_t * dst, ptrdiff_t width);                              \
+        ptrdiff_t width, step = 12 / sizeof(type);                                 \
+                                                                                   \
+        for (width = step; width < BUF_SIZE - 15; width += step) {                 \
+            int y_offset  = rnd() & 15;                                            \
+            int uv_offset = y_offset / 2;                                          \
+            randomize_buffers(mask);                                               \
+            call_ref(y0 + y_offset, u0 + uv_offset, v0 + uv_offset, dst0, width);  \
+            call_new(y1 + y_offset, u1 + uv_offset, v1 + uv_offset, dst1, width);  \
+            if (memcmp(y0, y1, BUF_SIZE) || memcmp(u0, u1, BUF_SIZE / 2) ||        \
+                memcmp(v0, v1, BUF_SIZE / 2) || memcmp(dst0, dst1, width * 8 / 3)) \
+                fail();                                                            \
+            bench_new(y1 + y_offset, u1 + uv_offset, v1 + uv_offset, dst1, width); \
+        }                                                                          \
+    } while (0)
+
+void checkasm_check_v210enc(void)
+{
+    V210EncContext h;
+
+    ff_v210enc_init(&h);
+
+    if (check_func(h.pack_line_8, "v210_planar_pack_8"))
+        check_pack_line(uint8_t, 0xffffffff);
+
+    if (check_func(h.pack_line_10, "v210_planar_pack_10"))
+        check_pack_line(uint16_t, 0x03ff03ff);
+
+    report("planar_pack");
+}



More information about the ffmpeg-cvslog mailing list