aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Gramner <henrik@gramner.com>2015-07-16 00:10:28 +0200
committerLuca Barbato <lu_zero@gentoo.org>2015-07-17 20:03:55 +0200
commitd37f23263584774e1798e9ac909a398304a05091 (patch)
tree9ea14cc1a20ebaa2cfa06d306b1d3a434da3c5a7
parenta344e5d094ebcf9a23acf3a27c56cbbbc829db42 (diff)
downloadffmpeg-d37f23263584774e1798e9ac909a398304a05091.tar.gz
checkasm: Add unit tests for bswapdsp
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
-rw-r--r--tests/checkasm/Makefile1
-rw-r--r--tests/checkasm/bswapdsp.c73
-rw-r--r--tests/checkasm/checkasm.c3
-rw-r--r--tests/checkasm/checkasm.h1
4 files changed, 78 insertions, 0 deletions
diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 0758746bc4..483ad136f0 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -1,4 +1,5 @@
# libavcodec tests
+AVCODECOBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o
AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o
AVCODECOBJS-$(CONFIG_H264QPEL) += h264qpel.o
diff --git a/tests/checkasm/bswapdsp.c b/tests/checkasm/bswapdsp.c
new file mode 100644
index 0000000000..7b1566bf84
--- /dev/null
+++ b/tests/checkasm/bswapdsp.c
@@ -0,0 +1,73 @@
+/*
+ * 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/bswapdsp.h"
+#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
+
+#define BUF_SIZE 512
+
+#define randomize_buffers()\
+ do {\
+ int i;\
+ for (i = 0; i < BUF_SIZE; i += 4) {\
+ uint32_t r = rnd();\
+ AV_WN32A(src0+i, r);\
+ AV_WN32A(src1+i, r);\
+ r = rnd();\
+ AV_WN32A(dst0+i, r);\
+ AV_WN32A(dst1+i, r);\
+ }\
+ } while (0)
+
+#define check_bswap(type)\
+ do {\
+ int w;\
+ for (w = 0; w < BUF_SIZE/sizeof(type); w++) {\
+ int offset = (BUF_SIZE/sizeof(type) - w) & 15; /* Test various alignments */\
+ randomize_buffers();\
+ call_ref((type*)dst0+offset, (type*)src0+offset, w);\
+ call_new((type*)dst1+offset, (type*)src1+offset, w);\
+ if (memcmp(src0, src1, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE))\
+ fail();\
+ bench_new((type*)dst1+offset, (type*)src1+offset, w);\
+ }\
+ } while (0)
+
+void checkasm_check_bswapdsp(void)
+{
+ DECLARE_ALIGNED(16, uint8_t, src0)[BUF_SIZE];
+ DECLARE_ALIGNED(16, uint8_t, src1)[BUF_SIZE];
+ DECLARE_ALIGNED(16, uint8_t, dst0)[BUF_SIZE];
+ DECLARE_ALIGNED(16, uint8_t, dst1)[BUF_SIZE];
+ BswapDSPContext h;
+
+ ff_bswapdsp_init(&h);
+
+ if (check_func(h.bswap_buf, "bswap_buf"))
+ check_bswap(uint32_t);
+
+ if (check_func(h.bswap16_buf, "bswap16_buf"))
+ check_bswap(uint16_t);
+
+ report("bswap");
+}
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 7b1ea8fa1e..ce7377807f 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -54,6 +54,9 @@
/* List of tests to invoke */
static void (* const tests[])(void) = {
+#if CONFIG_BSWAPDSP
+ checkasm_check_bswapdsp,
+#endif
#if CONFIG_H264PRED
checkasm_check_h264pred,
#endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 1a46e9bb0a..c2e359faa6 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -29,6 +29,7 @@
#include "libavutil/lfg.h"
#include "libavutil/timer.h"
+void checkasm_check_bswapdsp(void);
void checkasm_check_h264pred(void);
void checkasm_check_h264qpel(void);