summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorDiego Biurrun <diego@biurrun.de>2016-03-17 19:13:17 +0100
committerDiego Biurrun <diego@biurrun.de>2016-04-07 16:14:42 +0200
commitd12b5b2f135aade4099f4b26b0fe678656158c13 (patch)
treed5b44fd428a1c68213fe51aca21b5819bce3d33a /libavutil
parent330177b508420a553083df94f22cbd5142de0f4a (diff)
build: Split test programs off into separate files
This avoids spurious library rebuilds when only the test program code is changed and simplifies the build system.
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/adler32-test.c51
-rw-r--r--libavutil/adler32.c33
-rw-r--r--libavutil/aes-test.c92
-rw-r--r--libavutil/aes.c75
-rw-r--r--libavutil/atomic-test.c35
-rw-r--r--libavutil/atomic.c18
-rw-r--r--libavutil/avstring-test.c69
-rw-r--r--libavutil/avstring.c52
-rw-r--r--libavutil/base64-test.c84
-rw-r--r--libavutil/base64.c65
-rw-r--r--libavutil/blowfish-test.c190
-rw-r--r--libavutil/blowfish.c170
-rw-r--r--libavutil/cpu-test.c136
-rw-r--r--libavutil/cpu.c119
-rw-r--r--libavutil/crc-test.c45
-rw-r--r--libavutil/crc.c25
-rw-r--r--libavutil/des-test.c128
-rw-r--r--libavutil/des.c111
-rw-r--r--libavutil/eval-test.c144
-rw-r--r--libavutil/eval.c124
-rw-r--r--libavutil/fifo-test.c51
-rw-r--r--libavutil/fifo.c34
-rw-r--r--libavutil/float_dsp-test.c296
-rw-r--r--libavutil/float_dsp.c285
-rw-r--r--libavutil/hmac-test.c92
-rw-r--r--libavutil/hmac.c74
-rw-r--r--libavutil/lfg-test.c56
-rw-r--r--libavutil/lfg.c40
-rw-r--r--libavutil/lls-test.c54
-rw-r--r--libavutil/lls.c38
-rw-r--r--libavutil/md5-test.c54
-rw-r--r--libavutil/md5.c36
-rw-r--r--libavutil/opt-test.c110
-rw-r--r--libavutil/opt.c87
-rw-r--r--libavutil/parseutils-test.c116
-rw-r--r--libavutil/parseutils.c95
-rw-r--r--libavutil/sha-test.c69
-rw-r--r--libavutil/sha.c52
-rw-r--r--libavutil/tree-test.c110
-rw-r--r--libavutil/tree.c92
-rw-r--r--libavutil/xtea-test.c120
-rw-r--r--libavutil/xtea.c100
42 files changed, 2103 insertions, 1724 deletions
diff --git a/libavutil/adler32-test.c b/libavutil/adler32-test.c
new file mode 100644
index 0000000000..ab109f9175
--- /dev/null
+++ b/libavutil/adler32-test.c
@@ -0,0 +1,51 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "log.h"
+#include "timer.h"
+#include "adler32.h"
+
+#define LEN 7001
+
+static volatile int checksum;
+
+int main(int argc, char **argv)
+{
+ int i;
+ char data[LEN];
+
+ av_log_set_level(AV_LOG_DEBUG);
+
+ for (i = 0; i < LEN; i++)
+ data[i] = ((i * i) >> 3) + 123 * i;
+
+ if (argc > 1 && !strcmp(argv[1], "-t")) {
+ for (i = 0; i < 1000; i++) {
+ START_TIMER;
+ checksum = av_adler32_update(1, data, LEN);
+ STOP_TIMER("adler");
+ }
+ } else {
+ checksum = av_adler32_update(1, data, LEN);
+ }
+
+ av_log(NULL, AV_LOG_DEBUG, "%X (expected 50E6E508)\n", checksum);
+ return checksum == 0x50e6e508 ? 0 : 1;
+}
diff --git a/libavutil/adler32.c b/libavutil/adler32.c
index 8a8065c4a3..8dfe2ce451 100644
--- a/libavutil/adler32.c
+++ b/libavutil/adler32.c
@@ -63,36 +63,3 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf,
}
return (s2 << 16) | s1;
}
-
-#ifdef TEST
-#include <string.h>
-#include "log.h"
-#include "timer.h"
-#define LEN 7001
-
-static volatile int checksum;
-
-int main(int argc, char **argv)
-{
- int i;
- char data[LEN];
-
- av_log_set_level(AV_LOG_DEBUG);
-
- for (i = 0; i < LEN; i++)
- data[i] = ((i * i) >> 3) + 123 * i;
-
- if (argc > 1 && !strcmp(argv[1], "-t")) {
- for (i = 0; i < 1000; i++) {
- START_TIMER;
- checksum = av_adler32_update(1, data, LEN);
- STOP_TIMER("adler");
- }
- } else {
- checksum = av_adler32_update(1, data, LEN);
- }
-
- av_log(NULL, AV_LOG_DEBUG, "%X (expected 50E6E508)\n", checksum);
- return checksum == 0x50e6e508 ? 0 : 1;
-}
-#endif
diff --git a/libavutil/aes-test.c b/libavutil/aes-test.c
new file mode 100644
index 0000000000..92404e4cc2
--- /dev/null
+++ b/libavutil/aes-test.c
@@ -0,0 +1,92 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "aes.c"
+
+#include <string.h>
+
+#include "lfg.h"
+#include "log.h"
+
+int main(int argc, char **argv)
+{
+ int i, j;
+ AVAES b;
+ uint8_t rkey[2][16] = {
+ { 0 },
+ { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
+ 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
+ };
+ uint8_t pt[16], rpt[2][16] = {
+ { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
+ 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
+ { 0 }
+ };
+ uint8_t rct[2][16] = {
+ { 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7,
+ 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf },
+ { 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0,
+ 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65 }
+ };
+ uint8_t temp[16];
+ int err = 0;
+
+ av_log_set_level(AV_LOG_DEBUG);
+
+ for (i = 0; i < 2; i++) {
+ av_aes_init(&b, rkey[i], 128, 1);
+ av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
+ for (j = 0; j < 16; j++) {
+ if (rpt[i][j] != temp[j]) {
+ av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n",
+ j, rpt[i][j], temp[j]);
+ err = 1;
+ }
+ }
+ }
+
+ if (argc > 1 && !strcmp(argv[1], "-t")) {
+ AVAES ae, ad;
+ AVLFG prng;
+
+ av_aes_init(&ae, "PI=3.141592654..", 128, 0);
+ av_aes_init(&ad, "PI=3.141592654..", 128, 1);
+ av_lfg_init(&prng, 1);
+
+ for (i = 0; i < 10000; i++) {
+ for (j = 0; j < 16; j++)
+ pt[j] = av_lfg_get(&prng);
+ {
+ START_TIMER;
+ av_aes_crypt(&ae, temp, pt, 1, NULL, 0);
+ if (!(i & (i - 1)))
+ av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
+ temp[0], temp[5], temp[10], temp[15]);
+ av_aes_crypt(&ad, temp, temp, 1, NULL, 1);
+ STOP_TIMER("aes");
+ }
+ for (j = 0; j < 16; j++) {
+ if (pt[j] != temp[j]) {
+ av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n",
+ i, j, pt[j], temp[j]);
+ }
+ }
+ }
+ }
+ return err;
+}
diff --git a/libavutil/aes.c b/libavutil/aes.c
index d534bc78a7..e93fb0565c 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -262,78 +262,3 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
return 0;
}
-
-#ifdef TEST
-#include <string.h>
-
-#include "lfg.h"
-#include "log.h"
-
-int main(int argc, char **argv)
-{
- int i, j;
- AVAES b;
- uint8_t rkey[2][16] = {
- { 0 },
- { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
- 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
- };
- uint8_t pt[16], rpt[2][16] = {
- { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
- 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
- { 0 }
- };
- uint8_t rct[2][16] = {
- { 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7,
- 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf },
- { 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0,
- 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65 }
- };
- uint8_t temp[16];
- int err = 0;
-
- av_log_set_level(AV_LOG_DEBUG);
-
- for (i = 0; i < 2; i++) {
- av_aes_init(&b, rkey[i], 128, 1);
- av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
- for (j = 0; j < 16; j++) {
- if (rpt[i][j] != temp[j]) {
- av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n",
- j, rpt[i][j], temp[j]);
- err = 1;
- }
- }
- }
-
- if (argc > 1 && !strcmp(argv[1], "-t")) {
- AVAES ae, ad;
- AVLFG prng;
-
- av_aes_init(&ae, "PI=3.141592654..", 128, 0);
- av_aes_init(&ad, "PI=3.141592654..", 128, 1);
- av_lfg_init(&prng, 1);
-
- for (i = 0; i < 10000; i++) {
- for (j = 0; j < 16; j++)
- pt[j] = av_lfg_get(&prng);
- {
- START_TIMER;
- av_aes_crypt(&ae, temp, pt, 1, NULL, 0);
- if (!(i & (i - 1)))
- av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n",
- temp[0], temp[5], temp[10], temp[15]);
- av_aes_crypt(&ad, temp, temp, 1, NULL, 1);
- STOP_TIMER("aes");
- }
- for (j = 0; j < 16; j++) {
- if (pt[j] != temp[j]) {
- av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n",
- i, j, pt[j], temp[j]);
- }
- }
- }
- }
- return err;
-}
-#endif
diff --git a/libavutil/atomic-test.c b/libavutil/atomic-test.c
new file mode 100644
index 0000000000..c0a89a461e
--- /dev/null
+++ b/libavutil/atomic-test.c
@@ -0,0 +1,35 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <assert.h>
+
+#include "atomic.h"
+
+int main(void)
+{
+ volatile int val = 1;
+ int res;
+
+ res = avpriv_atomic_int_add_and_fetch(&val, 1);
+ assert(res == 2);
+ avpriv_atomic_int_set(&val, 3);
+ res = avpriv_atomic_int_get(&val);
+ assert(res == 3);
+
+ return 0;
+}
diff --git a/libavutil/atomic.c b/libavutil/atomic.c
index 83740396d4..e175a9f8ed 100644
--- a/libavutil/atomic.c
+++ b/libavutil/atomic.c
@@ -107,21 +107,3 @@ void *avpriv_atomic_ptr_cas(void * volatile *ptr, void *oldval, void *newval)
#endif /* HAVE_PTHREADS */
#endif /* !HAVE_ATOMICS_NATIVE */
-
-#ifdef TEST
-#include <assert.h>
-
-int main(void)
-{
- volatile int val = 1;
- int res;
-
- res = avpriv_atomic_int_add_and_fetch(&val, 1);
- assert(res == 2);
- avpriv_atomic_int_set(&val, 3);
- res = avpriv_atomic_int_get(&val);
- assert(res == 3);
-
- return 0;
-}
-#endif
diff --git a/libavutil/avstring-test.c b/libavutil/avstring-test.c
new file mode 100644
index 0000000000..7732c22f0e
--- /dev/null
+++ b/libavutil/avstring-test.c
@@ -0,0 +1,69 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <stdio.h>
+
+#include "common.h"
+#include "mem.h"
+#include "avstring.h"
+
+int main(void)
+{
+ int i;
+ const char *strings[] = {
+ "''",
+ "",
+ ":",
+ "\\",
+ "'",
+ " '' :",
+ " '' '' :",
+ "foo '' :",
+ "'foo'",
+ "foo ",
+ " ' foo ' ",
+ "foo\\",
+ "foo': blah:blah",
+ "foo\\: blah:blah",
+ "foo\'",
+ "'foo : ' :blahblah",
+ "\\ :blah",
+ " foo",
+ " foo ",
+ " foo \\ ",
+ "foo ':blah",
+ " foo bar : blahblah",
+ "\\f\\o\\o",
+ "'foo : \\ \\ ' : blahblah",
+ "'\\fo\\o:': blahblah",
+ "\\'fo\\o\\:': foo ' :blahblah"
+ };
+
+ printf("Testing av_get_token()\n");
+ for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
+ const char *p = strings[i];
+ char *q;
+ printf("|%s|", p);
+ q = av_get_token(&p, ":");
+ printf(" -> |%s|", q);
+ printf(" + |%s|\n", p);
+ av_free(q);
+ }
+
+ return 0;
+}
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 5a443ab11b..bc7d0bcb98 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -229,55 +229,3 @@ int av_match_name(const char *name, const char *names)
}
return !av_strcasecmp(name, names);
}
-
-
-
-#ifdef TEST
-
-int main(void)
-{
- int i;
- const char *strings[] = {
- "''",
- "",
- ":",
- "\\",
- "'",
- " '' :",
- " '' '' :",
- "foo '' :",
- "'foo'",
- "foo ",
- " ' foo ' ",
- "foo\\",
- "foo': blah:blah",
- "foo\\: blah:blah",
- "foo\'",
- "'foo : ' :blahblah",
- "\\ :blah",
- " foo",
- " foo ",
- " foo \\ ",
- "foo ':blah",
- " foo bar : blahblah",
- "\\f\\o\\o",
- "'foo : \\ \\ ' : blahblah",
- "'\\fo\\o:': blahblah",
- "\\'fo\\o\\:': foo ' :blahblah"
- };
-
- printf("Testing av_get_token()\n");
- for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
- const char *p = strings[i];
- char *q;
- printf("|%s|", p);
- q = av_get_token(&p, ":");
- printf(" -> |%s|", q);
- printf(" + |%s|\n", p);
- av_free(q);
- }
-
- return 0;
-}
-
-#endif /* TEST */
diff --git a/libavutil/base64-test.c b/libavutil/base64-test.c
new file mode 100644
index 0000000000..3ce0518a84
--- /dev/null
+++ b/libavutil/base64-test.c
@@ -0,0 +1,84 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <stdint.h>
+#include <stdio.h>
+
+#include "common.h"
+#include "base64.h"
+
+#define MAX_DATA_SIZE 1024
+#define MAX_ENCODED_SIZE 2048
+
+static int test_encode_decode(const uint8_t *data, unsigned int data_size,
+ const char *encoded_ref)
+{
+ char encoded[MAX_ENCODED_SIZE];
+ uint8_t data2[MAX_DATA_SIZE];
+ int data2_size, max_data2_size = MAX_DATA_SIZE;
+
+ if (!av_base64_encode(encoded, MAX_ENCODED_SIZE, data, data_size)) {
+ printf("Failed: cannot encode the input data\n");
+ return 1;
+ }
+ if (encoded_ref && strcmp(encoded, encoded_ref)) {
+ printf("Failed: encoded string differs from reference\n"
+ "Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref);
+ return 1;
+ }
+
+ if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) < 0) {
+ printf("Failed: cannot decode the encoded string\n"
+ "Encoded:\n%s\n", encoded);
+ return 1;
+ }
+ if (memcmp(data2, data, data_size)) {
+ printf("Failed: encoded/decoded data differs from original data\n");
+ return 1;
+ }
+
+ printf("Passed!\n");
+ return 0;
+}
+
+int main(void)
+{
+ int i, error_count = 0;
+ struct test {
+ const uint8_t *data;
+ const char *encoded_ref;
+ } tests[] = {
+ { "", ""},
+ { "1", "MQ=="},
+ { "22", "MjI="},
+ { "333", "MzMz"},
+ { "4444", "NDQ0NA=="},
+ { "55555", "NTU1NTU="},
+ { "666666", "NjY2NjY2"},
+ { "abc:def", "YWJjOmRlZg=="},
+ };
+
+ printf("Encoding/decoding tests\n");
+ for (i = 0; i < FF_ARRAY_ELEMS(tests); i++)
+ error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref);
+
+ if (error_count)
+ printf("Error Count: %d.\n", error_count);
+
+ return !!error_count;
+}
diff --git a/libavutil/base64.c b/libavutil/base64.c
index 725b03504d..29677a646b 100644
--- a/libavutil/base64.c
+++ b/libavutil/base64.c
@@ -98,68 +98,3 @@ char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
return ret;
}
-
-#ifdef TEST
-
-#define MAX_DATA_SIZE 1024
-#define MAX_ENCODED_SIZE 2048
-
-static int test_encode_decode(const uint8_t *data, unsigned int data_size,
- const char *encoded_ref)
-{
- char encoded[MAX_ENCODED_SIZE];
- uint8_t data2[MAX_DATA_SIZE];
- int data2_size, max_data2_size = MAX_DATA_SIZE;
-
- if (!av_base64_encode(encoded, MAX_ENCODED_SIZE, data, data_size)) {
- printf("Failed: cannot encode the input data\n");
- return 1;
- }
- if (encoded_ref && strcmp(encoded, encoded_ref)) {
- printf("Failed: encoded string differs from reference\n"
- "Encoded:\n%s\nReference:\n%s\n", encoded, encoded_ref);
- return 1;
- }
-
- if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) < 0) {
- printf("Failed: cannot decode the encoded string\n"
- "Encoded:\n%s\n", encoded);
- return 1;
- }
- if (memcmp(data2, data, data_size)) {
- printf("Failed: encoded/decoded data differs from original data\n");
- return 1;
- }
-
- printf("Passed!\n");
- return 0;
-}
-
-int main(void)
-{
- int i, error_count = 0;
- struct test {
- const uint8_t *data;
- const char *encoded_ref;
- } tests[] = {
- { "", ""},
- { "1", "MQ=="},
- { "22", "MjI="},
- { "333", "MzMz"},
- { "4444", "NDQ0NA=="},
- { "55555", "NTU1NTU="},
- { "666666", "NjY2NjY2"},
- { "abc:def", "YWJjOmRlZg=="},
- };
-
- printf("Encoding/decoding tests\n");
- for (i = 0; i < FF_ARRAY_ELEMS(tests); i++)
- error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref);
-
- if (error_count)
- printf("Error Count: %d.\n", error_count);
-
- return !!error_count;
-}
-
-#endif
diff --git a/libavutil/blowfish-test.c b/libavutil/blowfish-test.c
new file mode 100644
index 0000000000..4281ca29bd
--- /dev/null
+++ b/libavutil/blowfish-test.c
@@ -0,0 +1,190 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "blowfish.h"
+
+#define NUM_VARIABLE_KEY_TESTS 34
+
+/* plaintext bytes -- left halves */
+static const uint32_t plaintext_l[NUM_VARIABLE_KEY_TESTS] = {
+ 0x00000000, 0xFFFFFFFF, 0x10000000, 0x11111111, 0x11111111,
+ 0x01234567, 0x00000000, 0x01234567, 0x01A1D6D0, 0x5CD54CA8,
+ 0x0248D438, 0x51454B58, 0x42FD4430, 0x059B5E08, 0x0756D8E0,
+ 0x762514B8, 0x3BDD1190, 0x26955F68, 0x164D5E40, 0x6B056E18,
+ 0x004BD6EF, 0x480D3900, 0x437540C8, 0x072D43A0, 0x02FE5577,
+ 0x1D9D5C50, 0x30553228, 0x01234567, 0x01234567, 0x01234567,
+ 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
+};
+
+/* plaintext bytes -- right halves */
+static const uint32_t plaintext_r[NUM_VARIABLE_KEY_TESTS] = {
+ 0x00000000, 0xFFFFFFFF, 0x00000001, 0x11111111, 0x11111111,
+ 0x89ABCDEF, 0x00000000, 0x89ABCDEF, 0x39776742, 0x3DEF57DA,
+ 0x06F67172, 0x2DDF440A, 0x59577FA2, 0x51CF143A, 0x774761D2,
+ 0x29BF486A, 0x49372802, 0x35AF609A, 0x4F275232, 0x759F5CCA,
+ 0x09176062, 0x6EE762F2, 0x698F3CFA, 0x77075292, 0x8117F12A,
+ 0x18F728C2, 0x6D6F295A, 0x89ABCDEF, 0x89ABCDEF, 0x89ABCDEF,
+ 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
+};
+
+/* key bytes for variable key tests */
+static const uint8_t variable_key[NUM_VARIABLE_KEY_TESTS][8] = {
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
+ { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
+ { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
+ { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
+ { 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
+ { 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
+ { 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
+ { 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
+ { 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
+ { 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
+ { 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
+ { 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
+ { 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
+ { 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
+ { 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
+ { 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
+ { 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
+ { 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
+ { 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
+ { 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
+ { 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
+ { 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
+ { 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
+ { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
+ { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
+ { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
+ { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
+ { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }
+};
+
+/* ciphertext bytes -- left halves */
+static const uint32_t ciphertext_l[NUM_VARIABLE_KEY_TESTS] = {
+ 0x4EF99745, 0x51866FD5, 0x7D856F9A, 0x2466DD87, 0x61F9C380,
+ 0x7D0CC630, 0x4EF99745, 0x0ACEAB0F, 0x59C68245, 0xB1B8CC0B,
+ 0x1730E577, 0xA25E7856, 0x353882B1, 0x48F4D088, 0x432193B7,
+ 0x13F04154, 0x2EEDDA93, 0xD887E039, 0x5F99D04F, 0x4A057A3B,
+ 0x452031C1, 0x7555AE39, 0x53C55F9C, 0x7A8E7BFA, 0xCF9C5D7A,
+ 0xD1ABB290, 0x55CB3774, 0xFA34EC48, 0xA7907951, 0xC39E072D,
+ 0x014933E0, 0xF21E9A77, 0x24594688, 0x6B5C5A9C
+};
+
+/* ciphertext bytes -- right halves */
+static const uint32_t ciphertext_r[NUM_VARIABLE_KEY_TESTS] = {
+ 0x6198DD78, 0xB85ECB8A, 0x613063F2, 0x8B963C9D, 0x2281B096,
+ 0xAFDA1EC7, 0x6198DD78, 0xC6A0A28D, 0xEB05282B, 0x250F09A0,
+ 0x8BEA1DA4, 0xCF2651EB, 0x09CE8F1A, 0x4C379918, 0x8951FC98,
+ 0xD69D1AE5, 0xFFD39C79, 0x3C2DA6E3, 0x5B163969, 0x24D3977B,
+ 0xE4FADA8E, 0xF59B87BD, 0xB49FC019, 0x937E89A3, 0x4986ADB5,
+ 0x658BC778, 0xD13EF201, 0x47B268B2, 0x08EA3CAE, 0x9FAC631D,
+ 0xCDAFF6E4, 0xB71C49BC, 0x5754369A, 0x5D9E0A5A
+};
+
+/* plaintext bytes */
+static const uint8_t plaintext[8] = "BLOWFISH";
+
+static const uint8_t plaintext2[16] = "BLOWFISHBLOWFISH";
+
+/* ciphertext bytes */
+static const uint8_t ciphertext[8] = {
+ 0x32, 0x4E, 0xD0, 0xFE, 0xF4, 0x13, 0xA2, 0x03
+};
+
+static const uint8_t ciphertext2[16] = {
+ 0x53, 0x00, 0x40, 0x06, 0x63, 0xf2, 0x1d, 0x99,
+ 0x3b, 0x9b, 0x27, 0x64, 0x46, 0xfd, 0x20, 0xc1,
+};
+
+#define IV "blowfish"
+
+static void test_blowfish(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
+ const uint8_t *ref, int len, uint8_t *iv, int dir,
+ const char *test)
+{
+ av_blowfish_crypt(ctx, dst, src, len, iv, dir);
+ if (memcmp(dst, ref, 8*len)) {
+ int i;
+ printf("%s failed\ngot ", test);
+ for (i = 0; i < 8*len; i++)
+ printf("%02x ", dst[i]);
+ printf("\nexpected ");
+ for (i = 0; i < 8*len; i++)
+ printf("%02x ", ref[i]);
+ printf("\n");
+ exit(1);
+ }
+}
+
+int main(void)
+{
+ AVBlowfish ctx;
+ uint32_t tmptext_l[NUM_VARIABLE_KEY_TESTS];
+ uint32_t tmptext_r[NUM_VARIABLE_KEY_TESTS];
+ uint8_t tmp[16], iv[8];
+ int i;
+
+ av_blowfish_init(&ctx, "abcdefghijklmnopqrstuvwxyz", 26);
+
+ test_blowfish(&ctx, tmp, plaintext, ciphertext, 1, NULL, 0, "encryption");
+ test_blowfish(&ctx, tmp, ciphertext, plaintext, 1, NULL, 1, "decryption");
+ test_blowfish(&ctx, tmp, tmp, ciphertext, 1, NULL, 0, "Inplace encryption");
+ test_blowfish(&ctx, tmp, tmp, plaintext, 1, NULL, 1, "Inplace decryption");
+ memcpy(iv, IV, 8);
+ test_blowfish(&ctx, tmp, plaintext2, ciphertext2, 2, iv, 0, "CBC encryption");
+ memcpy(iv, IV, 8);
+ test_blowfish(&ctx, tmp, ciphertext2, plaintext2, 2, iv, 1, "CBC decryption");
+ memcpy(iv, IV, 8);
+ test_blowfish(&ctx, tmp, tmp, ciphertext2, 2, iv, 0, "Inplace CBC encryption");
+ memcpy(iv, IV, 8);
+ test_blowfish(&ctx, tmp, tmp, plaintext2, 2, iv, 1, "Inplace CBC decryption");
+
+ memcpy(tmptext_l, plaintext_l, sizeof(*plaintext_l) * NUM_VARIABLE_KEY_TESTS);
+ memcpy(tmptext_r, plaintext_r, sizeof(*plaintext_r) * NUM_VARIABLE_KEY_TESTS);
+
+ for (i = 0; i < NUM_VARIABLE_KEY_TESTS; i++) {
+ av_blowfish_init(&ctx, variable_key[i], 8);
+
+ av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 0);
+ if (tmptext_l[i] != ciphertext_l[i] || tmptext_r[i] != ciphertext_r[i]) {
+ printf("Test encryption failed.\n");
+ return 1;
+ }
+
+ av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 1);
+ if (tmptext_l[i] != plaintext_l[i] || tmptext_r[i] != plaintext_r[i]) {
+ printf("Test decryption failed.\n");
+ return 1;
+ }
+ }
+ printf("Test encryption/decryption success.\n");
+
+ return 0;
+}
+
diff --git a/libavutil/blowfish.c b/libavutil/blowfish.c
index a392459397..87315766d7 100644
--- a/libavutil/blowfish.c
+++ b/libavutil/blowfish.c
@@ -439,173 +439,3 @@ void av_blowfish_crypt(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
}
}
}
-
-#ifdef TEST
-#include <stdio.h>
-
-#define NUM_VARIABLE_KEY_TESTS 34
-
-/* plaintext bytes -- left halves */
-static const uint32_t plaintext_l[NUM_VARIABLE_KEY_TESTS] = {
- 0x00000000, 0xFFFFFFFF, 0x10000000, 0x11111111, 0x11111111,
- 0x01234567, 0x00000000, 0x01234567, 0x01A1D6D0, 0x5CD54CA8,
- 0x0248D438, 0x51454B58, 0x42FD4430, 0x059B5E08, 0x0756D8E0,
- 0x762514B8, 0x3BDD1190, 0x26955F68, 0x164D5E40, 0x6B056E18,
- 0x004BD6EF, 0x480D3900, 0x437540C8, 0x072D43A0, 0x02FE5577,
- 0x1D9D5C50, 0x30553228, 0x01234567, 0x01234567, 0x01234567,
- 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
-};
-
-/* plaintext bytes -- right halves */
-static const uint32_t plaintext_r[NUM_VARIABLE_KEY_TESTS] = {
- 0x00000000, 0xFFFFFFFF, 0x00000001, 0x11111111, 0x11111111,
- 0x89ABCDEF, 0x00000000, 0x89ABCDEF, 0x39776742, 0x3DEF57DA,
- 0x06F67172, 0x2DDF440A, 0x59577FA2, 0x51CF143A, 0x774761D2,
- 0x29BF486A, 0x49372802, 0x35AF609A, 0x4F275232, 0x759F5CCA,
- 0x09176062, 0x6EE762F2, 0x698F3CFA, 0x77075292, 0x8117F12A,
- 0x18F728C2, 0x6D6F295A, 0x89ABCDEF, 0x89ABCDEF, 0x89ABCDEF,
- 0xFFFFFFFF, 0x00000000, 0x00000000, 0xFFFFFFFF
-};
-
-/* key bytes for variable key tests */
-static const uint8_t variable_key[NUM_VARIABLE_KEY_TESTS][8] = {
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
- { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
- { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
- { 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
- { 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
- { 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
- { 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
- { 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
- { 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
- { 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
- { 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
- { 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
- { 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
- { 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
- { 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
- { 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
- { 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
- { 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
- { 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
- { 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
- { 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
- { 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
- { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
- { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
- { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
- { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
- { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }
-};
-
-/* ciphertext bytes -- left halves */
-static const uint32_t ciphertext_l[NUM_VARIABLE_KEY_TESTS] = {
- 0x4EF99745, 0x51866FD5, 0x7D856F9A, 0x2466DD87, 0x61F9C380,
- 0x7D0CC630, 0x4EF99745, 0x0ACEAB0F, 0x59C68245, 0xB1B8CC0B,
- 0x1730E577, 0xA25E7856, 0x353882B1, 0x48F4D088, 0x432193B7,
- 0x13F04154, 0x2EEDDA93, 0xD887E039, 0x5F99D04F, 0x4A057A3B,
- 0x452031C1, 0x7555AE39, 0x53C55F9C, 0x7A8E7BFA, 0xCF9C5D7A,
- 0xD1ABB290, 0x55CB3774, 0xFA34EC48, 0xA7907951, 0xC39E072D,
- 0x014933E0, 0xF21E9A77, 0x24594688, 0x6B5C5A9C
-};
-
-/* ciphertext bytes -- right halves */
-static const uint32_t ciphertext_r[NUM_VARIABLE_KEY_TESTS] = {
- 0x6198DD78, 0xB85ECB8A, 0x613063F2, 0x8B963C9D, 0x2281B096,
- 0xAFDA1EC7, 0x6198DD78, 0xC6A0A28D, 0xEB05282B, 0x250F09A0,
- 0x8BEA1DA4, 0xCF2651EB, 0x09CE8F1A, 0x4C379918, 0x8951FC98,
- 0xD69D1AE5, 0xFFD39C79, 0x3C2DA6E3, 0x5B163969, 0x24D3977B,
- 0xE4FADA8E, 0xF59B87BD, 0xB49FC019, 0x937E89A3, 0x4986ADB5,
- 0x658BC778, 0xD13EF201, 0x47B268B2, 0x08EA3CAE, 0x9FAC631D,
- 0xCDAFF6E4, 0xB71C49BC, 0x5754369A, 0x5D9E0A5A
-};
-
-/* plaintext bytes */
-static const uint8_t plaintext[8] = "BLOWFISH";
-
-static const uint8_t plaintext2[16] = "BLOWFISHBLOWFISH";
-
-/* ciphertext bytes */
-static const uint8_t ciphertext[8] = {
- 0x32, 0x4E, 0xD0, 0xFE, 0xF4, 0x13, 0xA2, 0x03
-};
-
-static const uint8_t ciphertext2[16] = {
- 0x53, 0x00, 0x40, 0x06, 0x63, 0xf2, 0x1d, 0x99,
- 0x3b, 0x9b, 0x27, 0x64, 0x46, 0xfd, 0x20, 0xc1,
-};
-
-#define IV "blowfish"
-
-static void test_blowfish(AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
- const uint8_t *ref, int len, uint8_t *iv, int dir,
- const char *test)
-{
- av_blowfish_crypt(ctx, dst, src, len, iv, dir);
- if (memcmp(dst, ref, 8*len)) {
- int i;
- printf("%s failed\ngot ", test);
- for (i = 0; i < 8*len; i++)
- printf("%02x ", dst[i]);
- printf("\nexpected ");
- for (i = 0; i < 8*len; i++)
- printf("%02x ", ref[i]);
- printf("\n");
- exit(1);
- }
-}
-
-int main(void)
-{
- AVBlowfish ctx;
- uint32_t tmptext_l[NUM_VARIABLE_KEY_TESTS];
- uint32_t tmptext_r[NUM_VARIABLE_KEY_TESTS];
- uint8_t tmp[16], iv[8];
- int i;
-
- av_blowfish_init(&ctx, "abcdefghijklmnopqrstuvwxyz", 26);
-
- test_blowfish(&ctx, tmp, plaintext, ciphertext, 1, NULL, 0, "encryption");
- test_blowfish(&ctx, tmp, ciphertext, plaintext, 1, NULL, 1, "decryption");
- test_blowfish(&ctx, tmp, tmp, ciphertext, 1, NULL, 0, "Inplace encryption");
- test_blowfish(&ctx, tmp, tmp, plaintext, 1, NULL, 1, "Inplace decryption");
- memcpy(iv, IV, 8);
- test_blowfish(&ctx, tmp, plaintext2, ciphertext2, 2, iv, 0, "CBC encryption");
- memcpy(iv, IV, 8);
- test_blowfish(&ctx, tmp, ciphertext2, plaintext2, 2, iv, 1, "CBC decryption");
- memcpy(iv, IV, 8);
- test_blowfish(&ctx, tmp, tmp, ciphertext2, 2, iv, 0, "Inplace CBC encryption");
- memcpy(iv, IV, 8);
- test_blowfish(&ctx, tmp, tmp, plaintext2, 2, iv, 1, "Inplace CBC decryption");
-
- memcpy(tmptext_l, plaintext_l, sizeof(*plaintext_l) * NUM_VARIABLE_KEY_TESTS);
- memcpy(tmptext_r, plaintext_r, sizeof(*plaintext_r) * NUM_VARIABLE_KEY_TESTS);
-
- for (i = 0; i < NUM_VARIABLE_KEY_TESTS; i++) {
- av_blowfish_init(&ctx, variable_key[i], 8);
-
- av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 0);
- if (tmptext_l[i] != ciphertext_l[i] || tmptext_r[i] != ciphertext_r[i]) {
- printf("Test encryption failed.\n");
- return 1;
- }
-
- av_blowfish_crypt_ecb(&ctx, &tmptext_l[i], &tmptext_r[i], 1);
- if (tmptext_l[i] != plaintext_l[i] || tmptext_r[i] != plaintext_r[i]) {
- printf("Test decryption failed.\n");
- return 1;
- }
- }
- printf("Test encryption/decryption success.\n");
-
- return 0;
-}
-
-#endif
diff --git a/libavutil/cpu-test.c b/libavutil/cpu-test.c
new file mode 100644
index 0000000000..a2c3b38c0d
--- /dev/null
+++ b/libavutil/cpu-test.c
@@ -0,0 +1,136 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "config.h"
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#elif !HAVE_GETOPT
+#include "compat/getopt.c"
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include "avstring.h"
+#include "common.h"
+#include "cpu.h"
+
+static const struct {
+ int flag;
+ const char *name;
+} cpu_flag_tab[] = {
+#if ARCH_AARCH64
+ { AV_CPU_FLAG_ARMV8, "armv8" },
+ { AV_CPU_FLAG_NEON, "neon" },
+ { AV_CPU_FLAG_VFP, "vfp" },
+#elif ARCH_ARM
+ { AV_CPU_FLAG_ARMV5TE, "armv5te" },
+ { AV_CPU_FLAG_ARMV6, "armv6" },
+ { AV_CPU_FLAG_ARMV6T2, "armv6t2" },
+ { AV_CPU_FLAG_VFP, "vfp" },
+ { AV_CPU_FLAG_VFP_VM, "vfp_vm" },
+ { AV_CPU_FLAG_VFPV3, "vfpv3" },
+ { AV_CPU_FLAG_NEON, "neon" },
+#elif ARCH_PPC
+ { AV_CPU_FLAG_ALTIVEC, "altivec" },
+#elif ARCH_X86
+ { AV_CPU_FLAG_MMX, "mmx" },
+ { AV_CPU_FLAG_MMXEXT, "mmxext" },
+ { AV_CPU_FLAG_SSE, "sse" },
+ { AV_CPU_FLAG_SSE2, "sse2" },
+ { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" },
+ { AV_CPU_FLAG_SSE3, "sse3" },
+ { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" },
+ { AV_CPU_FLAG_SSSE3, "ssse3" },
+ { AV_CPU_FLAG_ATOM, "atom" },
+ { AV_CPU_FLAG_SSE4, "sse4.1" },
+ { AV_CPU_FLAG_SSE42, "sse4.2" },
+ { AV_CPU_FLAG_AVX, "avx" },
+ { AV_CPU_FLAG_AVXSLOW, "avxslow" },
+ { AV_CPU_FLAG_XOP, "xop" },
+ { AV_CPU_FLAG_FMA3, "fma3" },
+ { AV_CPU_FLAG_FMA4, "fma4" },
+ { AV_CPU_FLAG_3DNOW, "3dnow" },
+ { AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
+ { AV_CPU_FLAG_CMOV, "cmov" },
+ { AV_CPU_FLAG_AVX2, "avx2" },
+ { AV_CPU_FLAG_BMI1, "bmi1" },
+ { AV_CPU_FLAG_BMI2, "bmi2" },
+#endif
+ { 0 }
+};
+
+static void print_cpu_flags(int cpu_flags, const char *type)
+{
+ int i;
+
+ fprintf(stderr, "cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
+ fprintf(stderr, "cpu_flags_str(%s) =", type);
+ for (i = 0; cpu_flag_tab[i].flag; i++)
+ if (cpu_flags & cpu_flag_tab[i].flag)
+ fprintf(stderr, " %s", cpu_flag_tab[i].name);
+ fprintf(stderr, "\n");
+}
+
+
+int main(int argc, char **argv)
+{
+ int cpu_flags_raw = av_get_cpu_flags();
+ int cpu_flags_eff;
+ int cpu_count = av_cpu_count();
+ char threads[5] = "auto";
+
+ if (cpu_flags_raw < 0)
+ return 1;
+
+ for (;;) {
+ int c = getopt(argc, argv, "c:t:");
+ if (c == -1)
+ break;
+ switch (c) {
+ case 'c':
+ {
+ int cpuflags = av_parse_cpu_flags(optarg);
+ if (cpuflags < 0)
+ return 2;
+ av_set_cpu_flags_mask(cpuflags);
+ break;
+ }
+ case 't':
+ {
+ int len = av_strlcpy(threads, optarg, sizeof(threads));
+ if (len >= sizeof(threads)) {
+ fprintf(stderr, "Invalid thread count '%s'\n", optarg);
+ return 2;
+ }
+ }
+ }
+ }
+
+ cpu_flags_eff = av_get_cpu_flags();
+
+ if (cpu_flags_eff < 0)
+ return 3;
+
+ print_cpu_flags(cpu_flags_raw, "raw");
+ print_cpu_flags(cpu_flags_eff, "effective");
+ fprintf(stderr, "threads = %s (cpu_count = %d)\n", threads, cpu_count);
+
+ return 0;
+}
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index 5f04461f6b..7d7390a756 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -178,122 +178,3 @@ int av_cpu_count(void)
return nb_cpus;
}
-
-#ifdef TEST
-
-#include <stdio.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "avstring.h"
-
-#if !HAVE_GETOPT
-#include "compat/getopt.c"
-#endif
-
-static const struct {
- int flag;
- const char *name;
-} cpu_flag_tab[] = {
-#if ARCH_AARCH64
- { AV_CPU_FLAG_ARMV8, "armv8" },
- { AV_CPU_FLAG_NEON, "neon" },
- { AV_CPU_FLAG_VFP, "vfp" },
-#elif ARCH_ARM
- { AV_CPU_FLAG_ARMV5TE, "armv5te" },
- { AV_CPU_FLAG_ARMV6, "armv6" },
- { AV_CPU_FLAG_ARMV6T2, "armv6t2" },
- { AV_CPU_FLAG_VFP, "vfp" },
- { AV_CPU_FLAG_VFP_VM, "vfp_vm" },
- { AV_CPU_FLAG_VFPV3, "vfpv3" },
- { AV_CPU_FLAG_NEON, "neon" },
-#elif ARCH_PPC
- { AV_CPU_FLAG_ALTIVEC, "altivec" },
-#elif ARCH_X86
- { AV_CPU_FLAG_MMX, "mmx" },
- { AV_CPU_FLAG_MMXEXT, "mmxext" },
- { AV_CPU_FLAG_SSE, "sse" },
- { AV_CPU_FLAG_SSE2, "sse2" },
- { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" },
- { AV_CPU_FLAG_SSE3, "sse3" },
- { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" },
- { AV_CPU_FLAG_SSSE3, "ssse3" },
- { AV_CPU_FLAG_ATOM, "atom" },
- { AV_CPU_FLAG_SSE4, "sse4.1" },
- { AV_CPU_FLAG_SSE42, "sse4.2" },
- { AV_CPU_FLAG_AVX, "avx" },
- { AV_CPU_FLAG_AVXSLOW, "avxslow" },
- { AV_CPU_FLAG_XOP, "xop" },
- { AV_CPU_FLAG_FMA3, "fma3" },
- { AV_CPU_FLAG_FMA4, "fma4" },
- { AV_CPU_FLAG_3DNOW, "3dnow" },
- { AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
- { AV_CPU_FLAG_CMOV, "cmov" },
- { AV_CPU_FLAG_AVX2, "avx2" },
- { AV_CPU_FLAG_BMI1, "bmi1" },
- { AV_CPU_FLAG_BMI2, "bmi2" },
-#endif
- { 0 }
-};
-
-static void print_cpu_flags(int cpu_flags, const char *type)
-{
- int i;
-
- fprintf(stderr, "cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
- fprintf(stderr, "cpu_flags_str(%s) =", type);
- for (i = 0; cpu_flag_tab[i].flag; i++)
- if (cpu_flags & cpu_flag_tab[i].flag)
- fprintf(stderr, " %s", cpu_flag_tab[i].name);
- fprintf(stderr, "\n");
-}
-
-
-int main(int argc, char **argv)
-{
- int cpu_flags_raw = av_get_cpu_flags();
- int cpu_flags_eff;
- int cpu_count = av_cpu_count();
- char threads[5] = "auto";
-
- if (cpu_flags_raw < 0)
- return 1;
-
- for (;;) {
- int c = getopt(argc, argv, "c:t:");
- if (c == -1)
- break;
- switch (c) {
- case 'c':
- {
- int cpuflags = av_parse_cpu_flags(optarg);
- if (cpuflags < 0)
- return 2;
- av_set_cpu_flags_mask(cpuflags);
- break;
- }
- case 't':
- {
- int len = av_strlcpy(threads, optarg, sizeof(threads));
- if (len >= sizeof(threads)) {
- fprintf(stderr, "Invalid thread count '%s'\n", optarg);
- return 2;
- }
- }
- }
- }
-
- cpu_flags_eff = av_get_cpu_flags();
-
- if (cpu_flags_eff < 0)
- return 3;
-
- print_cpu_flags(cpu_flags_raw, "raw");
- print_cpu_flags(cpu_flags_eff, "effective");
- fprintf(stderr, "threads = %s (cpu_count = %d)\n", threads, cpu_count);
-
- return 0;
-}
-
-#endif
diff --git a/libavutil/crc-test.c b/libavutil/crc-test.c
new file mode 100644
index 0000000000..41601c5ed8
--- /dev/null
+++ b/libavutil/crc-test.c
@@ -0,0 +1,45 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <stdint.h>
+#include <stdio.h>
+
+#include "crc.h"
+
+int main(void)
+{
+ uint8_t buf[1999];
+ int i;
+ int p[5][3] = {
+ { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
+ { AV_CRC_32_IEEE, 0x04C11DB7, 0xC0F5BAE0 },
+ { AV_CRC_16_ANSI_LE, 0xA001, 0xBFD8 },
+ { AV_CRC_16_ANSI, 0x8005, 0x1FBB },
+ { AV_CRC_8_ATM, 0x07, 0xE3 }
+ };
+ const AVCRC *ctx;
+
+ for (i = 0; i < sizeof(buf); i++)
+ buf[i] = i + i * i;
+
+ for (i = 0; i < 5; i++) {
+ ctx = av_crc_get_table(p[i][0]);
+ printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
+ }
+ return 0;
+}
diff --git a/libavutil/crc.c b/libavutil/crc.c
index ad43c73ec1..5428f8c0b6 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -333,28 +333,3 @@ uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
return crc;
}
-
-#ifdef TEST
-int main(void)
-{
- uint8_t buf[1999];
- int i;
- int p[5][3] = {
- { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
- { AV_CRC_32_IEEE, 0x04C11DB7, 0xC0F5BAE0 },
- { AV_CRC_16_ANSI_LE, 0xA001, 0xBFD8 },
- { AV_CRC_16_ANSI, 0x8005, 0x1FBB },
- { AV_CRC_8_ATM, 0x07, 0xE3 }
- };
- const AVCRC *ctx;
-
- for (i = 0; i < sizeof(buf); i++)
- buf[i] = i + i * i;
-
- for (i = 0; i < 5; i++) {
- ctx = av_crc_get_table(p[i][0]);
- printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
- }
- return 0;
-}
-#endif
diff --git a/libavutil/des-test.c b/libavutil/des-test.c
new file mode 100644
index 0000000000..a372035a54
--- /dev/null
+++ b/libavutil/des-test.c
@@ -0,0 +1,128 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "des.c"
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "time.h"
+
+static uint64_t rand64(void)
+{
+ uint64_t r = rand();
+ r = (r << 32) | rand();
+ return r;
+}
+
+static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
+static const DECLARE_ALIGNED(8, uint8_t, plain)[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
+static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = { 0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18 };
+static DECLARE_ALIGNED(8, uint8_t, tmp)[8];
+static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8];
+static const uint8_t cbc_key[] = {
+ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+ 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
+ 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
+};
+
+static int run_test(int cbc, int decrypt)
+{
+ AVDES d;
+ int delay = cbc && !decrypt ? 2 : 1;
+ uint64_t res;
+ AV_WB64(large_buffer[0], 0x4e6f772069732074ULL);
+ AV_WB64(large_buffer[1], 0x1234567890abcdefULL);
+ AV_WB64(tmp, 0x1234567890abcdefULL);
+ av_des_init(&d, cbc_key, 192, decrypt);
+ av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt);
+ res = AV_RB64(large_buffer[9999 + delay]);
+ if (cbc) {
+ if (decrypt)
+ return res == 0xc5cecf63ecec514cULL;
+ else
+ return res == 0xcb191f85d1ed8439ULL;
+ } else {
+ if (decrypt)
+ return res == 0x8325397644091a0aULL;
+ else
+ return res == 0xdd17e8b8b437d232ULL;
+ }
+}
+
+int main(void)
+{
+ AVDES d;
+ int i;
+ uint64_t key[3];
+ uint64_t data;
+ uint64_t ct;
+ uint64_t roundkeys[16];
+ srand(av_gettime());
+ key[0] = AV_RB64(test_key);
+ data = AV_RB64(plain);
+ gen_roundkeys(roundkeys, key[0]);
+ if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) {
+ printf("Test 1 failed\n");
+ return 1;
+ }
+ av_des_init(&d, test_key, 64, 0);
+ av_des_crypt(&d, tmp, plain, 1, NULL, 0);
+ if (memcmp(tmp, crypt, sizeof(crypt))) {
+ printf("Public API decryption failed\n");
+ return 1;
+ }
+ if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) {
+ printf("Partial Monte-Carlo test failed\n");
+ return 1;
+ }
+ for (i = 0; i < 1000; i++) {
+ key[0] = rand64();
+ key[1] = rand64();
+ key[2] = rand64();
+ data = rand64();
+ av_des_init(&d, key, 192, 0);
+ av_des_crypt(&d, &ct, &data, 1, NULL, 0);
+ av_des_init(&d, key, 192, 1);
+ av_des_crypt(&d, &ct, &ct, 1, NULL, 1);
+ if (ct != data) {
+ printf("Test 2 failed\n");
+ return 1;
+ }
+ }
+#ifdef GENTABLES
+ printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n");
+ for (i = 0; i < 8; i++) {
+ int j;
+ printf(" {");
+ for (j = 0; j < 64; j++) {
+ uint32_t v = S_boxes[i][j >> 1];
+ v = j & 1 ? v >> 4 : v & 0xf;
+ v <<= 28 - 4 * i;
+ v = shuffle(v, P_shuffle, sizeof(P_shuffle));
+ printf((j & 7) == 0 ? "\n " : " ");
+ printf("0x%08X,", v);
+ }
+ printf("\n },\n");
+ }
+ printf("};\n");
+#endif
+ return 0;
+}
diff --git a/libavutil/des.c b/libavutil/des.c
index 7d9458c81f..1dbedd92cd 100644
--- a/libavutil/des.c
+++ b/libavutil/des.c
@@ -111,7 +111,7 @@ static const uint8_t S_boxes[8][32] = {
#else
/**
* This table contains the results of applying both the S-box and P-shuffle.
- * It can be regenerated by compiling this file with -DCONFIG_SMALL -DTEST -DGENTABLES
+ * It can be regenerated by compiling des-test.c with "-DCONFIG_SMALL -DGENTABLES".
*/
static const uint32_t S_boxes_P_shuffle[8][64] = {
{ 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
@@ -337,112 +337,3 @@ void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count)
{
av_des_crypt_mac(d, dst, src, count, (uint8_t[8]) { 0 }, 0, 1);
}
-
-#ifdef TEST
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "time.h"
-
-static uint64_t rand64(void)
-{
- uint64_t r = rand();
- r = (r << 32) | rand();
- return r;
-}
-
-static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
-static const DECLARE_ALIGNED(8, uint8_t, plain)[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
-static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = { 0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18 };
-static DECLARE_ALIGNED(8, uint8_t, tmp)[8];
-static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8];
-static const uint8_t cbc_key[] = {
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
- 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
-};
-
-static int run_test(int cbc, int decrypt)
-{
- AVDES d;
- int delay = cbc && !decrypt ? 2 : 1;
- uint64_t res;
- AV_WB64(large_buffer[0], 0x4e6f772069732074ULL);
- AV_WB64(large_buffer[1], 0x1234567890abcdefULL);
- AV_WB64(tmp, 0x1234567890abcdefULL);
- av_des_init(&d, cbc_key, 192, decrypt);
- av_des_crypt(&d, large_buffer[delay], large_buffer[0], 10000, cbc ? tmp : NULL, decrypt);
- res = AV_RB64(large_buffer[9999 + delay]);
- if (cbc) {
- if (decrypt)
- return res == 0xc5cecf63ecec514cULL;
- else
- return res == 0xcb191f85d1ed8439ULL;
- } else {
- if (decrypt)
- return res == 0x8325397644091a0aULL;
- else
- return res == 0xdd17e8b8b437d232ULL;
- }
-}
-
-int main(void)
-{
- AVDES d;
- int i;
- uint64_t key[3];
- uint64_t data;
- uint64_t ct;
- uint64_t roundkeys[16];
- srand(av_gettime());
- key[0] = AV_RB64(test_key);
- data = AV_RB64(plain);
- gen_roundkeys(roundkeys, key[0]);
- if (des_encdec(data, roundkeys, 0) != AV_RB64(crypt)) {
- printf("Test 1 failed\n");
- return 1;
- }
- av_des_init(&d, test_key, 64, 0);
- av_des_crypt(&d, tmp, plain, 1, NULL, 0);
- if (memcmp(tmp, crypt, sizeof(crypt))) {
- printf("Public API decryption failed\n");
- return 1;
- }
- if (!run_test(0, 0) || !run_test(0, 1) || !run_test(1, 0) || !run_test(1, 1)) {
- printf("Partial Monte-Carlo test failed\n");
- return 1;
- }
- for (i = 0; i < 1000; i++) {
- key[0] = rand64();
- key[1] = rand64();
- key[2] = rand64();
- data = rand64();
- av_des_init(&d, key, 192, 0);
- av_des_crypt(&d, &ct, &data, 1, NULL, 0);
- av_des_init(&d, key, 192, 1);
- av_des_crypt(&d, &ct, &ct, 1, NULL, 1);
- if (ct != data) {
- printf("Test 2 failed\n");
- return 1;
- }
- }
-#ifdef GENTABLES
- printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n");
- for (i = 0; i < 8; i++) {
- int j;
- printf(" {");
- for (j = 0; j < 64; j++) {
- uint32_t v = S_boxes[i][j >> 1];
- v = j & 1 ? v >> 4 : v & 0xf;
- v <<= 28 - 4 * i;
- v = shuffle(v, P_shuffle, sizeof(P_shuffle));
- printf((j & 7) == 0 ? "\n " : " ");
- printf("0x%08X,", v);
- }
- printf("\n },\n");
- }
- printf("};\n");
-#endif
- return 0;
-}
-#endif
diff --git a/libavutil/eval-test.c b/libavutil/eval-test.c
new file mode 100644
index 0000000000..da8721de7c
--- /dev/null
+++ b/libavutil/eval-test.c
@@ -0,0 +1,144 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <math.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "timer.h"
+#include "eval.h"
+
+static const double const_values[] = {
+ M_PI,
+ M_E,
+ 0
+};
+
+static const char *const const_names[] = {
+ "PI",
+ "E",
+ 0
+};
+
+int main(int argc, char **argv)
+{
+ int i;
+ double d;
+ const char *const *expr;
+ static const char *const exprs[] = {
+ "",
+ "1;2",
+ "-20",
+ "-PI",
+ "+PI",
+ "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
+ "80G/80Gi",
+ "1k",
+ "1Gi",
+ "1gi",
+ "1GiFoo",
+ "1k+1k",
+ "1Gi*3foo",
+ "foo",
+ "foo(",
+ "foo()",
+ "foo)",
+ "sin",
+ "sin(",
+ "sin()",
+ "sin)",
+ "sin 10",
+ "sin(1,2,3)",
+ "sin(1 )",
+ "1",
+ "1foo",
+ "bar + PI + E + 100f*2 + foo",
+ "13k + 12f - foo(1, 2)",
+ "1gi",
+ "1Gi",
+ "st(0, 123)",
+ "st(1, 123); ld(1)",
+ "lte(0, 1)",
+ "lte(1, 1)",
+ "lte(1, 0)",
+ "lt(0, 1)",
+ "lt(1, 1)",
+ "gt(1, 0)",
+ "gt(2, 7)",
+ "gte(122, 122)",
+ /* compute 1+2+...+N */
+ "st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
+ /* compute Fib(N) */
+ "st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
+ "while(0, 10)",
+ "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
+ "isnan(1)",
+ "isnan(NAN)",
+ "isnan(INF)",
+ "isinf(1)",
+ "isinf(NAN)",
+ "isinf(INF)",
+ "floor(NAN)",
+ "floor(123.123)",
+ "floor(-123.123)",
+ "trunc(123.123)",
+ "trunc(-123.123)",
+ "ceil(123.123)",
+ "ceil(-123.123)",
+ "sqrt(1764)",
+ "isnan(sqrt(-1))",
+ "not(1)",
+ "not(NAN)",
+ "not(0)",
+ "6.0206dB",
+ "-3.0103dB",
+ NULL
+ };
+
+ for (expr = exprs; *expr; expr++) {
+ printf("Evaluating '%s'\n", *expr);
+ av_expr_parse_and_eval(&d, *expr,
+ const_names, const_values,
+ NULL, NULL, NULL, NULL, NULL, 0, NULL);
+ if (isnan(d))
+ printf("'%s' -> nan\n\n", *expr);
+ else
+ printf("'%s' -> %f\n\n", *expr, d);
+ }
+
+ av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
+ const_names, const_values,
+ NULL, NULL, NULL, NULL, NULL, 0, NULL);
+ printf("%f == 12.7\n", d);
+ av_expr_parse_and_eval(&d, "80G/80Gi",
+ const_names, const_values,
+ NULL, NULL, NULL, NULL, NULL, 0, NULL);
+ printf("%f == 0.931322575\n", d);
+
+ if (argc > 1 && !strcmp(argv[1], "-t")) {
+ for (i = 0; i < 1050; i++) {
+ START_TIMER;
+ av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
+ const_names, const_values,
+ NULL, NULL, NULL, NULL, NULL, 0, NULL);
+ STOP_TIMER("av_expr_parse_and_eval");
+ }
+ }
+
+ return 0;
+}
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 31e9ebbc9c..b5d71c6000 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -565,127 +565,3 @@ int av_expr_parse_and_eval(double *d, const char *s,
av_expr_free(e);
return isnan(*d) ? AVERROR(EINVAL) : 0;
}
-
-#ifdef TEST
-#include <string.h>
-
-static const double const_values[] = {
- M_PI,
- M_E,
- 0
-};
-
-static const char *const const_names[] = {
- "PI",
- "E",
- 0
-};
-
-int main(int argc, char **argv)
-{
- int i;
- double d;
- const char *const *expr;
- static const char *const exprs[] = {
- "",
- "1;2",
- "-20",
- "-PI",
- "+PI",
- "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
- "80G/80Gi",
- "1k",
- "1Gi",
- "1gi",
- "1GiFoo",
- "1k+1k",
- "1Gi*3foo",
- "foo",
- "foo(",
- "foo()",
- "foo)",
- "sin",
- "sin(",
- "sin()",
- "sin)",
- "sin 10",
- "sin(1,2,3)",
- "sin(1 )",
- "1",
- "1foo",
- "bar + PI + E + 100f*2 + foo",
- "13k + 12f - foo(1, 2)",
- "1gi",
- "1Gi",
- "st(0, 123)",
- "st(1, 123); ld(1)",
- "lte(0, 1)",
- "lte(1, 1)",
- "lte(1, 0)",
- "lt(0, 1)",
- "lt(1, 1)",
- "gt(1, 0)",
- "gt(2, 7)",
- "gte(122, 122)",
- /* compute 1+2+...+N */
- "st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
- /* compute Fib(N) */
- "st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
- "while(0, 10)",
- "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
- "isnan(1)",
- "isnan(NAN)",
- "isnan(INF)",
- "isinf(1)",
- "isinf(NAN)",
- "isinf(INF)",
- "floor(NAN)",
- "floor(123.123)",
- "floor(-123.123)",
- "trunc(123.123)",
- "trunc(-123.123)",
- "ceil(123.123)",
- "ceil(-123.123)",
- "sqrt(1764)",
- "isnan(sqrt(-1))",
- "not(1)",
- "not(NAN)",
- "not(0)",
- "6.0206dB",
- "-3.0103dB",
- NULL
- };
-
- for (expr = exprs; *expr; expr++) {
- printf("Evaluating '%s'\n", *expr);
- av_expr_parse_and_eval(&d, *expr,
- const_names, const_values,
- NULL, NULL, NULL, NULL, NULL, 0, NULL);
- if (isnan(d))
- printf("'%s' -> nan\n\n", *expr);
- else
- printf("'%s' -> %f\n\n", *expr, d);
- }
-
- av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
- const_names, const_values,
- NULL, NULL, NULL, NULL, NULL, 0, NULL);
- printf("%f == 12.7\n", d);
- av_expr_parse_and_eval(&d, "80G/80Gi",
- const_names, const_values,
- NULL, NULL, NULL, NULL, NULL, 0, NULL);
- printf("%f == 0.931322575\n", d);
-
- if (argc > 1 && !strcmp(argv[1], "-t")) {
- for (i = 0; i < 1050; i++) {
- START_TIMER;
- av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
- const_names, const_values,
- NULL, NULL, NULL, NULL, NULL, 0, NULL);
- STOP_TIMER("av_expr_parse_and_eval");
- }
- }
-
- return 0;
-}
-#endif
diff --git a/libavutil/fifo-test.c b/libavutil/fifo-test.c
new file mode 100644
index 0000000000..f6615b1034
--- /dev/null
+++ b/libavutil/fifo-test.c
@@ -0,0 +1,51 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <stdio.h>
+
+#include "fifo.h"
+
+int main(void)
+{
+ /* create a FIFO buffer */
+ AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
+ int i, j, n;
+
+ /* fill data */
+ for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
+ av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
+
+ /* peek at FIFO */
+ n = av_fifo_size(fifo) / sizeof(int);
+ for (i = -n + 1; i < n; i++) {
+ int *v = (int *)av_fifo_peek2(fifo, i * sizeof(int));
+ printf("%d: %d\n", i, *v);
+ }
+ printf("\n");
+
+ /* read data */
+ for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
+ av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
+ printf("%d ", j);
+ }
+ printf("\n");
+
+ av_fifo_free(fifo);
+
+ return 0;
+}
diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index dffaf54533..a42899c2b3 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -131,37 +131,3 @@ void av_fifo_drain(AVFifoBuffer *f, int size)
f->rptr -= f->end - f->buffer;
f->rndx += size;
}
-
-#ifdef TEST
-
-int main(void)
-{
- /* create a FIFO buffer */
- AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int));
- int i, j, n;
-
- /* fill data */
- for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++)
- av_fifo_generic_write(fifo, &i, sizeof(int), NULL);
-
- /* peek at FIFO */
- n = av_fifo_size(fifo) / sizeof(int);
- for (i = -n + 1; i < n; i++) {
- int *v = (int *)av_fifo_peek2(fifo, i * sizeof(int));
- printf("%d: %d\n", i, *v);
- }
- printf("\n");
-
- /* read data */
- for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) {
- av_fifo_generic_read(fifo, &j, sizeof(int), NULL);
- printf("%d ", j);
- }
- printf("\n");
-
- av_fifo_free(fifo);
-
- return 0;
-}
-
-#endif
diff --git a/libavutil/float_dsp-test.c b/libavutil/float_dsp-test.c
new file mode 100644
index 0000000000..e24018c07d
--- /dev/null
+++ b/libavutil/float_dsp-test.c
@@ -0,0 +1,296 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <float.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cpu.h"
+#include "internal.h"
+#include "lfg.h"
+#include "log.h"
+#include "random_seed.h"
+#include "float_dsp.h"
+
+#define LEN 240
+
+static void fill_float_array(AVLFG *lfg, float *a, int len)
+{
+ int i;
+ double bmg[2], stddev = 10.0, mean = 0.0;
+
+ for (i = 0; i < len; i += 2) {
+ av_bmg_get(lfg, bmg);
+ a[i] = bmg[0] * stddev + mean;
+ a[i + 1] = bmg[1] * stddev + mean;
+ }
+}
+static int compare_floats(const float *a, const float *b, int len,
+ float max_diff)
+{
+ int i;
+ for (i = 0; i < len; i++) {
+ if (fabsf(a[i] - b[i]) > max_diff) {
+ av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n",
+ i, a[i], b[i], a[i] - b[i]);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static void fill_double_array(AVLFG *lfg, double *a, int len)
+{
+ int i;
+ double bmg[2], stddev = 10.0, mean = 0.0;
+
+ for (i = 0; i < len; i += 2) {
+ av_bmg_get(lfg, bmg);
+ a[i] = bmg[0] * stddev + mean;
+ a[i + 1] = bmg[1] * stddev + mean;
+ }
+}
+
+static int compare_doubles(const double *a, const double *b, int len,
+ double max_diff)
+{
+ int i;
+
+ for (i = 0; i < len; i++) {
+ if (fabs(a[i] - b[i]) > max_diff) {
+ av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n",
+ i, a[i], b[i], a[i] - b[i]);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int test_vector_fmul(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const float *v1, const float *v2)
+{
+ LOCAL_ALIGNED(32, float, cdst, [LEN]);
+ LOCAL_ALIGNED(32, float, odst, [LEN]);
+ int ret;
+
+ cdsp->vector_fmul(cdst, v1, v2, LEN);
+ fdsp->vector_fmul(odst, v1, v2, LEN);
+
+ if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
+ av_log(NULL, AV_LOG_ERROR, "vector_fmul failed\n");
+
+ return ret;
+}
+
+#define ARBITRARY_FMAC_SCALAR_CONST 0.005
+static int test_vector_fmac_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const float *v1, const float *src0, float scale)
+{
+ LOCAL_ALIGNED(32, float, cdst, [LEN]);
+ LOCAL_ALIGNED(32, float, odst, [LEN]);
+ int ret;
+
+ memcpy(cdst, v1, LEN * sizeof(*v1));
+ memcpy(odst, v1, LEN * sizeof(*v1));
+
+ cdsp->vector_fmac_scalar(cdst, src0, scale, LEN);
+ fdsp->vector_fmac_scalar(odst, src0, scale, LEN);
+
+ if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMAC_SCALAR_CONST))
+ av_log(NULL, AV_LOG_ERROR, "vector_fmac_scalar failed\n");
+
+ return ret;
+}
+
+static int test_vector_fmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const float *v1, float scale)
+{
+ LOCAL_ALIGNED(32, float, cdst, [LEN]);
+ LOCAL_ALIGNED(32, float, odst, [LEN]);
+ int ret;
+
+ cdsp->vector_fmul_scalar(cdst, v1, scale, LEN);
+ fdsp->vector_fmul_scalar(odst, v1, scale, LEN);
+
+ if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
+ av_log(NULL, AV_LOG_ERROR, "vector_fmul_scalar failed\n");
+
+ return ret;
+}
+
+static int test_vector_dmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const double *v1, double scale)
+{
+ LOCAL_ALIGNED(32, double, cdst, [LEN]);
+ LOCAL_ALIGNED(32, double, odst, [LEN]);
+ int ret;
+
+ cdsp->vector_dmul_scalar(cdst, v1, scale, LEN);
+ fdsp->vector_dmul_scalar(odst, v1, scale, LEN);
+
+ if (ret = compare_doubles(cdst, odst, LEN, DBL_EPSILON))
+ av_log(NULL, AV_LOG_ERROR, "vector_dmul_scalar failed\n");
+
+ return ret;
+}
+
+#define ARBITRARY_FMUL_WINDOW_CONST 0.008
+static int test_vector_fmul_window(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const float *v1, const float *v2, const float *v3)
+{
+ LOCAL_ALIGNED(32, float, cdst, [LEN]);
+ LOCAL_ALIGNED(32, float, odst, [LEN]);
+ int ret;
+
+ cdsp->vector_fmul_window(cdst, v1, v2, v3, LEN / 2);
+ fdsp->vector_fmul_window(odst, v1, v2, v3, LEN / 2);
+
+ if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_WINDOW_CONST))
+ av_log(NULL, AV_LOG_ERROR, "vector_fmul_window failed\n");
+
+ return ret;
+}
+
+#define ARBITRARY_FMUL_ADD_CONST 0.005
+static int test_vector_fmul_add(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const float *v1, const float *v2, const float *v3)
+{
+ LOCAL_ALIGNED(32, float, cdst, [LEN]);
+ LOCAL_ALIGNED(32, float, odst, [LEN]);
+ int ret;
+
+ cdsp->vector_fmul_add(cdst, v1, v2, v3, LEN);
+ fdsp->vector_fmul_add(odst, v1, v2, v3, LEN);
+
+ if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_ADD_CONST))
+ av_log(NULL, AV_LOG_ERROR, "vector_fmul_add failed\n");
+
+ return ret;
+}
+
+static int test_vector_fmul_reverse(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const float *v1, const float *v2)
+{
+ LOCAL_ALIGNED(32, float, cdst, [LEN]);
+ LOCAL_ALIGNED(32, float, odst, [LEN]);
+ int ret;
+
+ cdsp->vector_fmul_reverse(cdst, v1, v2, LEN);
+ fdsp->vector_fmul_reverse(odst, v1, v2, LEN);
+
+ if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
+ av_log(NULL, AV_LOG_ERROR, "vector_fmul_reverse failed\n");
+
+ return ret;
+}
+
+static int test_butterflies_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const float *v1, const float *v2)
+{
+ LOCAL_ALIGNED(32, float, cv1, [LEN]);
+ LOCAL_ALIGNED(32, float, cv2, [LEN]);
+ LOCAL_ALIGNED(32, float, ov1, [LEN]);
+ LOCAL_ALIGNED(32, float, ov2, [LEN]);
+ int ret;
+
+ memcpy(cv1, v1, LEN * sizeof(*v1));
+ memcpy(cv2, v2, LEN * sizeof(*v2));
+ memcpy(ov1, v1, LEN * sizeof(*v1));
+ memcpy(ov2, v2, LEN * sizeof(*v2));
+
+ cdsp->butterflies_float(cv1, cv2, LEN);
+ fdsp->butterflies_float(ov1, ov2, LEN);
+
+ if ((ret = compare_floats(cv1, ov1, LEN, FLT_EPSILON)) ||
+ (ret = compare_floats(cv2, ov2, LEN, FLT_EPSILON)))
+ av_log(NULL, AV_LOG_ERROR, "butterflies_float failed\n");
+
+ return ret;
+}
+
+#define ARBITRARY_SCALARPRODUCT_CONST 0.2
+static int test_scalarproduct_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const float *v1, const float *v2)
+{
+ float cprod, oprod;
+ int ret;
+
+ cprod = cdsp->scalarproduct_float(v1, v2, LEN);
+ oprod = fdsp->scalarproduct_float(v1, v2, LEN);
+
+ if (ret = compare_floats(&cprod, &oprod, 1, ARBITRARY_SCALARPRODUCT_CONST))
+ av_log(NULL, AV_LOG_ERROR, "scalarproduct_float failed\n");
+
+ return ret;
+}
+
+int main(int argc, char **argv)
+{
+ int ret = 0;
+ uint32_t seed;
+ AVFloatDSPContext fdsp, cdsp;
+ AVLFG lfg;
+
+ LOCAL_ALIGNED(32, float, src0, [LEN]);
+ LOCAL_ALIGNED(32, float, src1, [LEN]);
+ LOCAL_ALIGNED(32, float, src2, [LEN]);
+ LOCAL_ALIGNED(32, double, dbl_src0, [LEN]);
+ LOCAL_ALIGNED(32, double, dbl_src1, [LEN]);
+
+ if (argc > 2 && !strcmp(argv[1], "-s"))
+ seed = strtoul(argv[2], NULL, 10);
+ else
+ seed = av_get_random_seed();
+
+ av_log(NULL, AV_LOG_INFO, "float_dsp-test: random seed %u\n", seed);
+
+ av_lfg_init(&lfg, seed);
+
+ fill_float_array(&lfg, src0, LEN);
+ fill_float_array(&lfg, src1, LEN);
+ fill_float_array(&lfg, src2, LEN);
+
+ fill_double_array(&lfg, dbl_src0, LEN);
+ fill_double_array(&lfg, dbl_src1, LEN);
+
+ avpriv_float_dsp_init(&fdsp, 1);
+ av_set_cpu_flags_mask(0);
+ avpriv_float_dsp_init(&cdsp, 1);
+
+ if (test_vector_fmul(&fdsp, &cdsp, src0, src1))
+ ret -= 1 << 0;
+ if (test_vector_fmac_scalar(&fdsp, &cdsp, src2, src0, src1[0]))
+ ret -= 1 << 1;
+ if (test_vector_fmul_scalar(&fdsp, &cdsp, src0, src1[0]))
+ ret -= 1 << 2;
+ if (test_vector_fmul_window(&fdsp, &cdsp, src0, src1, src2))
+ ret -= 1 << 3;
+ if (test_vector_fmul_add(&fdsp, &cdsp, src0, src1, src2))
+ ret -= 1 << 4;
+ if (test_vector_fmul_reverse(&fdsp, &cdsp, src0, src1))
+ ret -= 1 << 5;
+ if (test_butterflies_float(&fdsp, &cdsp, src0, src1))
+ ret -= 1 << 6;
+ if (test_scalarproduct_float(&fdsp, &cdsp, src0, src1))
+ ret -= 1 << 7;
+ if (test_vector_dmul_scalar(&fdsp, &cdsp, dbl_src0, dbl_src1[0]))
+ ret -= 1 << 8;
+
+ return ret;
+}
diff --git a/libavutil/float_dsp.c b/libavutil/float_dsp.c
index aabc800db6..d31fc3d166 100644
--- a/libavutil/float_dsp.c
+++ b/libavutil/float_dsp.c
@@ -133,288 +133,3 @@ av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
if (ARCH_X86)
ff_float_dsp_init_x86(fdsp);
}
-
-#ifdef TEST
-
-#include <float.h>
-#include <math.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "common.h"
-#include "cpu.h"
-#include "internal.h"
-#include "lfg.h"
-#include "log.h"
-#include "mem.h"
-#include "random_seed.h"
-
-#define LEN 240
-
-static void fill_float_array(AVLFG *lfg, float *a, int len)
-{
- int i;
- double bmg[2], stddev = 10.0, mean = 0.0;
-
- for (i = 0; i < len; i += 2) {
- av_bmg_get(lfg, bmg);
- a[i] = bmg[0] * stddev + mean;
- a[i + 1] = bmg[1] * stddev + mean;
- }
-}
-static int compare_floats(const float *a, const float *b, int len,
- float max_diff)
-{
- int i;
- for (i = 0; i < len; i++) {
- if (fabsf(a[i] - b[i]) > max_diff) {
- av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n",
- i, a[i], b[i], a[i] - b[i]);
- return -1;
- }
- }
- return 0;
-}
-
-static void fill_double_array(AVLFG *lfg, double *a, int len)
-{
- int i;
- double bmg[2], stddev = 10.0, mean = 0.0;
-
- for (i = 0; i < len; i += 2) {
- av_bmg_get(lfg, bmg);
- a[i] = bmg[0] * stddev + mean;
- a[i + 1] = bmg[1] * stddev + mean;
- }
-}
-
-static int compare_doubles(const double *a, const double *b, int len,
- double max_diff)
-{
- int i;
-
- for (i = 0; i < len; i++) {
- if (fabs(a[i] - b[i]) > max_diff) {
- av_log(NULL, AV_LOG_ERROR, "%d: %- .12f - %- .12f = % .12g\n",
- i, a[i], b[i], a[i] - b[i]);
- return -1;
- }
- }
- return 0;
-}
-
-static int test_vector_fmul(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const float *v1, const float *v2)
-{
- LOCAL_ALIGNED(32, float, cdst, [LEN]);
- LOCAL_ALIGNED(32, float, odst, [LEN]);
- int ret;
-
- cdsp->vector_fmul(cdst, v1, v2, LEN);
- fdsp->vector_fmul(odst, v1, v2, LEN);
-
- if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
- av_log(NULL, AV_LOG_ERROR, "vector_fmul failed\n");
-
- return ret;
-}
-
-#define ARBITRARY_FMAC_SCALAR_CONST 0.005
-static int test_vector_fmac_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const float *v1, const float *src0, float scale)
-{
- LOCAL_ALIGNED(32, float, cdst, [LEN]);
- LOCAL_ALIGNED(32, float, odst, [LEN]);
- int ret;
-
- memcpy(cdst, v1, LEN * sizeof(*v1));
- memcpy(odst, v1, LEN * sizeof(*v1));
-
- cdsp->vector_fmac_scalar(cdst, src0, scale, LEN);
- fdsp->vector_fmac_scalar(odst, src0, scale, LEN);
-
- if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMAC_SCALAR_CONST))
- av_log(NULL, AV_LOG_ERROR, "vector_fmac_scalar failed\n");
-
- return ret;
-}
-
-static int test_vector_fmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const float *v1, float scale)
-{
- LOCAL_ALIGNED(32, float, cdst, [LEN]);
- LOCAL_ALIGNED(32, float, odst, [LEN]);
- int ret;
-
- cdsp->vector_fmul_scalar(cdst, v1, scale, LEN);
- fdsp->vector_fmul_scalar(odst, v1, scale, LEN);
-
- if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
- av_log(NULL, AV_LOG_ERROR, "vector_fmul_scalar failed\n");
-
- return ret;
-}
-
-static int test_vector_dmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const double *v1, double scale)
-{
- LOCAL_ALIGNED(32, double, cdst, [LEN]);
- LOCAL_ALIGNED(32, double, odst, [LEN]);
- int ret;
-
- cdsp->vector_dmul_scalar(cdst, v1, scale, LEN);
- fdsp->vector_dmul_scalar(odst, v1, scale, LEN);
-
- if (ret = compare_doubles(cdst, odst, LEN, DBL_EPSILON))
- av_log(NULL, AV_LOG_ERROR, "vector_dmul_scalar failed\n");
-
- return ret;
-}
-
-#define ARBITRARY_FMUL_WINDOW_CONST 0.008
-static int test_vector_fmul_window(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const float *v1, const float *v2, const float *v3)
-{
- LOCAL_ALIGNED(32, float, cdst, [LEN]);
- LOCAL_ALIGNED(32, float, odst, [LEN]);
- int ret;
-
- cdsp->vector_fmul_window(cdst, v1, v2, v3, LEN / 2);
- fdsp->vector_fmul_window(odst, v1, v2, v3, LEN / 2);
-
- if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_WINDOW_CONST))
- av_log(NULL, AV_LOG_ERROR, "vector_fmul_window failed\n");
-
- return ret;
-}
-
-#define ARBITRARY_FMUL_ADD_CONST 0.005
-static int test_vector_fmul_add(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const float *v1, const float *v2, const float *v3)
-{
- LOCAL_ALIGNED(32, float, cdst, [LEN]);
- LOCAL_ALIGNED(32, float, odst, [LEN]);
- int ret;
-
- cdsp->vector_fmul_add(cdst, v1, v2, v3, LEN);
- fdsp->vector_fmul_add(odst, v1, v2, v3, LEN);
-
- if (ret = compare_floats(cdst, odst, LEN, ARBITRARY_FMUL_ADD_CONST))
- av_log(NULL, AV_LOG_ERROR, "vector_fmul_add failed\n");
-
- return ret;
-}
-
-static int test_vector_fmul_reverse(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const float *v1, const float *v2)
-{
- LOCAL_ALIGNED(32, float, cdst, [LEN]);
- LOCAL_ALIGNED(32, float, odst, [LEN]);
- int ret;
-
- cdsp->vector_fmul_reverse(cdst, v1, v2, LEN);
- fdsp->vector_fmul_reverse(odst, v1, v2, LEN);
-
- if (ret = compare_floats(cdst, odst, LEN, FLT_EPSILON))
- av_log(NULL, AV_LOG_ERROR, "vector_fmul_reverse failed\n");
-
- return ret;
-}
-
-static int test_butterflies_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const float *v1, const float *v2)
-{
- LOCAL_ALIGNED(32, float, cv1, [LEN]);
- LOCAL_ALIGNED(32, float, cv2, [LEN]);
- LOCAL_ALIGNED(32, float, ov1, [LEN]);
- LOCAL_ALIGNED(32, float, ov2, [LEN]);
- int ret;
-
- memcpy(cv1, v1, LEN * sizeof(*v1));
- memcpy(cv2, v2, LEN * sizeof(*v2));
- memcpy(ov1, v1, LEN * sizeof(*v1));
- memcpy(ov2, v2, LEN * sizeof(*v2));
-
- cdsp->butterflies_float(cv1, cv2, LEN);
- fdsp->butterflies_float(ov1, ov2, LEN);
-
- if ((ret = compare_floats(cv1, ov1, LEN, FLT_EPSILON)) ||
- (ret = compare_floats(cv2, ov2, LEN, FLT_EPSILON)))
- av_log(NULL, AV_LOG_ERROR, "butterflies_float failed\n");
-
- return ret;
-}
-
-#define ARBITRARY_SCALARPRODUCT_CONST 0.2
-static int test_scalarproduct_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
- const float *v1, const float *v2)
-{
- float cprod, oprod;
- int ret;
-
- cprod = cdsp->scalarproduct_float(v1, v2, LEN);
- oprod = fdsp->scalarproduct_float(v1, v2, LEN);
-
- if (ret = compare_floats(&cprod, &oprod, 1, ARBITRARY_SCALARPRODUCT_CONST))
- av_log(NULL, AV_LOG_ERROR, "scalarproduct_float failed\n");
-
- return ret;
-}
-
-int main(int argc, char **argv)
-{
- int ret = 0;
- uint32_t seed;
- AVFloatDSPContext fdsp, cdsp;
- AVLFG lfg;
-
- LOCAL_ALIGNED(32, float, src0, [LEN]);
- LOCAL_ALIGNED(32, float, src1, [LEN]);
- LOCAL_ALIGNED(32, float, src2, [LEN]);
- LOCAL_ALIGNED(32, double, dbl_src0, [LEN]);
- LOCAL_ALIGNED(32, double, dbl_src1, [LEN]);
-
- if (argc > 2 && !strcmp(argv[1], "-s"))
- seed = strtoul(argv[2], NULL, 10);
- else
- seed = av_get_random_seed();
-
- av_log(NULL, AV_LOG_INFO, "float_dsp-test: random seed %u\n", seed);
-
- av_lfg_init(&lfg, seed);
-
- fill_float_array(&lfg, src0, LEN);
- fill_float_array(&lfg, src1, LEN);
- fill_float_array(&lfg, src2, LEN);
-
- fill_double_array(&lfg, dbl_src0, LEN);
- fill_double_array(&lfg, dbl_src1, LEN);
-
- avpriv_float_dsp_init(&fdsp, 1);
- av_set_cpu_flags_mask(0);
- avpriv_float_dsp_init(&cdsp, 1);
-
- if (test_vector_fmul(&fdsp, &cdsp, src0, src1))
- ret -= 1 << 0;
- if (test_vector_fmac_scalar(&fdsp, &cdsp, src2, src0, src1[0]))
- ret -= 1 << 1;
- if (test_vector_fmul_scalar(&fdsp, &cdsp, src0, src1[0]))
- ret -= 1 << 2;
- if (test_vector_fmul_window(&fdsp, &cdsp, src0, src1, src2))
- ret -= 1 << 3;
- if (test_vector_fmul_add(&fdsp, &cdsp, src0, src1, src2))
- ret -= 1 << 4;
- if (test_vector_fmul_reverse(&fdsp, &cdsp, src0, src1))
- ret -= 1 << 5;
- if (test_butterflies_float(&fdsp, &cdsp, src0, src1))
- ret -= 1 << 6;
- if (test_scalarproduct_float(&fdsp, &cdsp, src0, src1))
- ret -= 1 << 7;
- if (test_vector_dmul_scalar(&fdsp, &cdsp, dbl_src0, dbl_src1[0]))
- ret -= 1 << 8;
-
- return ret;
-}
-
-#endif /* TEST */
diff --git a/libavutil/hmac-test.c b/libavutil/hmac-test.c
new file mode 100644
index 0000000000..fb6bf87cff
--- /dev/null
+++ b/libavutil/hmac-test.c
@@ -0,0 +1,92 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "hmac.c"
+
+#include <stdio.h>
+#include <string.h>
+
+static void test(AVHMAC *hmac, const uint8_t *key, int keylen,
+ const uint8_t *data, int datalen)
+{
+ uint8_t buf[MAX_HASHLEN];
+ int out, i;
+ // Some of the test vectors are strings, where sizeof() includes the
+ // trailing null byte - remove that.
+ if (!key[keylen - 1])
+ keylen--;
+ if (!data[datalen - 1])
+ datalen--;
+ out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf));
+ for (i = 0; i < out; i++)
+ printf("%02x", buf[i]);
+ printf("\n");
+}
+
+int main(void)
+{
+ uint8_t key1[20], key3[131], data3[50];
+ enum AVHMACType i = AV_HMAC_SHA224;
+ const uint8_t key2[] = "Jefe";
+ const uint8_t data1[] = "Hi There";
+ const uint8_t data2[] = "what do ya want for nothing?";
+ const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First";
+ const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
+ const uint8_t data6[] = "This is a test using a larger than block-size key and a larger "
+ "than block-size data. The key needs to be hashed before being used"
+ " by the HMAC algorithm.";
+ AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5);
+ if (!hmac)
+ return 1;
+ memset(key1, 0x0b, sizeof(key1));
+ memset(key3, 0xaa, sizeof(key3));
+ memset(data3, 0xdd, sizeof(data3));
+ // RFC 2202 test vectors
+ test(hmac, key1, 16, data1, sizeof(data1));
+ test(hmac, key2, sizeof(key2), data2, sizeof(data2));
+ test(hmac, key3, 16, data3, sizeof(data3));
+ test(hmac, key3, 80, data4, sizeof(data4));
+ test(hmac, key3, 80, data5, sizeof(data5));
+ av_hmac_free(hmac);
+
+ /* SHA-1 */
+ hmac = av_hmac_alloc(AV_HMAC_SHA1);
+ if (!hmac)
+ return 1;
+ // RFC 2202 test vectors
+ test(hmac, key1, sizeof(key1), data1, sizeof(data1));
+ test(hmac, key2, sizeof(key2), data2, sizeof(data2));
+ test(hmac, key3, 20, data3, sizeof(data3));
+ test(hmac, key3, 80, data4, sizeof(data4));
+ test(hmac, key3, 80, data5, sizeof(data5));
+ av_hmac_free(hmac);
+
+ /* SHA-2 */
+ while (i <= AV_HMAC_SHA256) {
+ hmac = av_hmac_alloc(i);
+ // RFC 4231 test vectors
+ test(hmac, key1, sizeof(key1), data1, sizeof(data1));
+ test(hmac, key2, sizeof(key2), data2, sizeof(data2));
+ test(hmac, key3, 20, data3, sizeof(data3));
+ test(hmac, key3, sizeof(key3), data4, sizeof(data4));
+ test(hmac, key3, sizeof(key3), data6, sizeof(data6));
+ av_hmac_free(hmac);
+ i++;
+ }
+ return 0;
+}
diff --git a/libavutil/hmac.c b/libavutil/hmac.c
index abbee368b0..378be62fd3 100644
--- a/libavutil/hmac.c
+++ b/libavutil/hmac.c
@@ -158,77 +158,3 @@ int av_hmac_calc(AVHMAC *c, const uint8_t *data, unsigned int len,
av_hmac_update(c, data, len);
return av_hmac_final(c, out, outlen);
}
-
-#ifdef TEST
-#include <stdio.h>
-
-static void test(AVHMAC *hmac, const uint8_t *key, int keylen,
- const uint8_t *data, int datalen)
-{
- uint8_t buf[MAX_HASHLEN];
- int out, i;
- // Some of the test vectors are strings, where sizeof() includes the
- // trailing null byte - remove that.
- if (!key[keylen - 1])
- keylen--;
- if (!data[datalen - 1])
- datalen--;
- out = av_hmac_calc(hmac, data, datalen, key, keylen, buf, sizeof(buf));
- for (i = 0; i < out; i++)
- printf("%02x", buf[i]);
- printf("\n");
-}
-
-int main(void)
-{
- uint8_t key1[20], key3[131], data3[50];
- enum AVHMACType i = AV_HMAC_SHA224;
- const uint8_t key2[] = "Jefe";
- const uint8_t data1[] = "Hi There";
- const uint8_t data2[] = "what do ya want for nothing?";
- const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First";
- const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
- const uint8_t data6[] = "This is a test using a larger than block-size key and a larger "
- "than block-size data. The key needs to be hashed before being used"
- " by the HMAC algorithm.";
- AVHMAC *hmac = av_hmac_alloc(AV_HMAC_MD5);
- if (!hmac)
- return 1;
- memset(key1, 0x0b, sizeof(key1));
- memset(key3, 0xaa, sizeof(key3));
- memset(data3, 0xdd, sizeof(data3));
- // RFC 2202 test vectors
- test(hmac, key1, 16, data1, sizeof(data1));
- test(hmac, key2, sizeof(key2), data2, sizeof(data2));
- test(hmac, key3, 16, data3, sizeof(data3));
- test(hmac, key3, 80, data4, sizeof(data4));
- test(hmac, key3, 80, data5, sizeof(data5));
- av_hmac_free(hmac);
-
- /* SHA-1 */
- hmac = av_hmac_alloc(AV_HMAC_SHA1);
- if (!hmac)
- return 1;
- // RFC 2202 test vectors
- test(hmac, key1, sizeof(key1), data1, sizeof(data1));
- test(hmac, key2, sizeof(key2), data2, sizeof(data2));
- test(hmac, key3, 20, data3, sizeof(data3));
- test(hmac, key3, 80, data4, sizeof(data4));
- test(hmac, key3, 80, data5, sizeof(data5));
- av_hmac_free(hmac);
-
- /* SHA-2 */
- while (i <= AV_HMAC_SHA256) {
- hmac = av_hmac_alloc(i);
- // RFC 4231 test vectors
- test(hmac, key1, sizeof(key1), data1, sizeof(data1));
- test(hmac, key2, sizeof(key2), data2, sizeof(data2));
- test(hmac, key3, 20, data3, sizeof(data3));
- test(hmac, key3, sizeof(key3), data4, sizeof(data4));
- test(hmac, key3, sizeof(key3), data6, sizeof(data6));
- av_hmac_free(hmac);
- i++;
- }
- return 0;
-}
-#endif /* TEST */
diff --git a/libavutil/lfg-test.c b/libavutil/lfg-test.c
new file mode 100644
index 0000000000..92b4259a3c
--- /dev/null
+++ b/libavutil/lfg-test.c
@@ -0,0 +1,56 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "log.h"
+#include "timer.h"
+#include "lfg.h"
+
+int main(void)
+{
+ int x = 0;
+ int i, j;
+ AVLFG state;
+
+ av_lfg_init(&state, 0xdeadbeef);
+ for (j = 0; j < 10000; j++) {
+ START_TIMER
+ for (i = 0; i < 624; i++)
+ x += av_lfg_get(&state);
+ STOP_TIMER("624 calls of av_lfg_get");
+ }
+ av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
+
+ /* BMG usage example */
+ {
+ double mean = 1000;
+ double stddev = 53;
+
+ av_lfg_init(&state, 42);
+
+ for (i = 0; i < 1000; i += 2) {
+ double bmg_out[2];
+ av_bmg_get(&state, bmg_out);
+ av_log(NULL, AV_LOG_INFO,
+ "%f\n%f\n",
+ bmg_out[0] * stddev + mean,
+ bmg_out[1] * stddev + mean);
+ }
+ }
+
+ return 0;
+}
diff --git a/libavutil/lfg.c b/libavutil/lfg.c
index 4221e6228b..20900570a2 100644
--- a/libavutil/lfg.c
+++ b/libavutil/lfg.c
@@ -58,43 +58,3 @@ void av_bmg_get(AVLFG *lfg, double out[2])
out[0] = x1 * w;
out[1] = x2 * w;
}
-
-#ifdef TEST
-#include "log.h"
-#include "timer.h"
-
-int main(void)
-{
- int x = 0;
- int i, j;
- AVLFG state;
-
- av_lfg_init(&state, 0xdeadbeef);
- for (j = 0; j < 10000; j++) {
- START_TIMER
- for (i = 0; i < 624; i++)
- x += av_lfg_get(&state);
- STOP_TIMER("624 calls of av_lfg_get");
- }
- av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x);
-
- /* BMG usage example */
- {
- double mean = 1000;
- double stddev = 53;
-
- av_lfg_init(&state, 42);
-
- for (i = 0; i < 1000; i += 2) {
- double bmg_out[2];
- av_bmg_get(&state, bmg_out);
- av_log(NULL, AV_LOG_INFO,
- "%f\n%f\n",
- bmg_out[0] * stddev + mean,
- bmg_out[1] * stddev + mean);
- }
- }
-
- return 0;
-}
-#endif
diff --git a/libavutil/lls-test.c b/libavutil/lls-test.c
new file mode 100644
index 0000000000..f9814b3863
--- /dev/null
+++ b/libavutil/lls-test.c
@@ -0,0 +1,54 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <limits.h>
+#include <stdio.h>
+
+#include "internal.h"
+#include "lfg.h"
+#include "lls.h"
+
+int main(void)
+{
+ LLSModel m;
+ int i, order;
+ AVLFG lfg;
+
+ av_lfg_init(&lfg, 1);
+ avpriv_init_lls(&m, 3);
+
+ for (i = 0; i < 100; i++) {
+ LOCAL_ALIGNED(32, double, var, [4]);
+ double eval;
+
+ var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
+ var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
+ var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
+ var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
+ m.update_lls(&m, var);
+ avpriv_solve_lls(&m, 0.001, 0);
+ for (order = 0; order < 3; order++) {
+ eval = m.evaluate_lls(&m, var + 1, order);
+ printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
+ var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
+ m.coeff[order][0], m.coeff[order][1],
+ m.coeff[order][2]);
+ }
+ }
+ return 0;
+}
diff --git a/libavutil/lls.c b/libavutil/lls.c
index 37bfc4e679..97bffb4018 100644
--- a/libavutil/lls.c
+++ b/libavutil/lls.c
@@ -121,41 +121,3 @@ av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
if (ARCH_X86)
ff_init_lls_x86(m);
}
-
-#ifdef TEST
-
-#include <stdio.h>
-#include <limits.h>
-#include "lfg.h"
-
-int main(void)
-{
- LLSModel m;
- int i, order;
- AVLFG lfg;
-
- av_lfg_init(&lfg, 1);
- avpriv_init_lls(&m, 3);
-
- for (i = 0; i < 100; i++) {
- LOCAL_ALIGNED(32, double, var, [4]);
- double eval;
-
- var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
- var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
- var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
- var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
- m.update_lls(&m, var);
- avpriv_solve_lls(&m, 0.001, 0);
- for (order = 0; order < 3; order++) {
- eval = m.evaluate_lls(&m, var + 1, order);
- printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
- var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
- m.coeff[order][0], m.coeff[order][1],
- m.coeff[order][2]);
- }
- }
- return 0;
-}
-
-#endif
diff --git a/libavutil/md5-test.c b/libavutil/md5-test.c
new file mode 100644
index 0000000000..8d5dd1e104
--- /dev/null
+++ b/libavutil/md5-test.c
@@ -0,0 +1,54 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <stdint.h>
+#include <stdio.h>
+
+#include "md5.h"
+
+static void print_md5(uint8_t *md5)
+{
+ int i;
+ for (i = 0; i < 16; i++)
+ printf("%02x", md5[i]);
+ printf("\n");
+}
+
+int main(void)
+{
+ uint8_t md5val[16];
+ int i;
+ uint8_t in[1000];
+
+ for (i = 0; i < 1000; i++)
+ in[i] = i * i;
+ av_md5_sum(md5val, in, 1000);
+ print_md5(md5val);
+ av_md5_sum(md5val, in, 63);
+ print_md5(md5val);
+ av_md5_sum(md5val, in, 64);
+ print_md5(md5val);
+ av_md5_sum(md5val, in, 65);
+ print_md5(md5val);
+ for (i = 0; i < 1000; i++)
+ in[i] = i % 127;
+ av_md5_sum(md5val, in, 999);
+ print_md5(md5val);
+
+ return 0;
+}
diff --git a/libavutil/md5.c b/libavutil/md5.c
index 79224ed7b2..e02a9ba0bf 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -185,39 +185,3 @@ void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
av_md5_update(&ctx, src, len);
av_md5_final(&ctx, dst);
}
-
-#ifdef TEST
-#include <stdio.h>
-
-static void print_md5(uint8_t *md5)
-{
- int i;
- for (i = 0; i < 16; i++)
- printf("%02x", md5[i]);
- printf("\n");
-}
-
-int main(void)
-{
- uint8_t md5val[16];
- int i;
- uint8_t in[1000];
-
- for (i = 0; i < 1000; i++)
- in[i] = i * i;
- av_md5_sum(md5val, in, 1000);
- print_md5(md5val);
- av_md5_sum(md5val, in, 63);
- print_md5(md5val);
- av_md5_sum(md5val, in, 64);
- print_md5(md5val);
- av_md5_sum(md5val, in, 65);
- print_md5(md5val);
- for (i = 0; i < 1000; i++)
- in[i] = i % 127;
- av_md5_sum(md5val, in, 999);
- print_md5(md5val);
-
- return 0;
-}
-#endif
diff --git a/libavutil/opt-test.c b/libavutil/opt-test.c
new file mode 100644
index 0000000000..14a144cb86
--- /dev/null
+++ b/libavutil/opt-test.c
@@ -0,0 +1,110 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <limits.h>
+#include <stdio.h>
+
+#include "common.h"
+#include "error.h"
+#include "log.h"
+#include "mem.h"
+#include "rational.h"
+#include "opt.h"
+
+typedef struct TestContext {
+ const AVClass *class;
+ int num;
+ int toggle;
+ char *string;
+ int flags;
+ AVRational rational;
+} TestContext;
+
+#define OFFSET(x) offsetof(TestContext, x)
+
+#define TEST_FLAG_COOL 01
+#define TEST_FLAG_LAME 02
+#define TEST_FLAG_MU 04
+
+static const AVOption test_options[] = {
+ { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100 },
+ { "toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1 },
+ { "rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, 10 },
+ { "string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { 0 }, CHAR_MIN, CHAR_MAX },
+ { "flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX, 0, "flags"},
+ { "cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 0, "flags"},
+ { "lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 0, "flags"},
+ { "mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 0, "flags"},
+ { NULL },
+};
+
+static const char *test_get_name(void *ctx)
+{
+ return "test";
+}
+
+static const AVClass test_class = {
+ "TestContext",
+ test_get_name,
+ test_options
+};
+
+int main(void)
+{
+ int i;
+ TestContext test_ctx = { .class = &test_class };
+ const char *options[] = {
+ "",
+ ":",
+ "=",
+ "foo=:",
+ ":=foo",
+ "=foo",
+ "foo=",
+ "foo",
+ "foo=val",
+ "foo==val",
+ "toggle=:",
+ "string=:",
+ "toggle=1 : foo",
+ "toggle=100",
+ "toggle==1",
+ "flags=+mu-lame : num=42: toggle=0",
+ "num=42 : string=blahblah",
+ "rational=0 : rational=1/2 : rational=1/-1",
+ "rational=-1/0",
+ };
+
+ printf("\nTesting av_set_options_string()\n");
+
+ av_opt_set_defaults(&test_ctx);
+ test_ctx.string = av_strdup("default");
+ if (!test_ctx.string)
+ return AVERROR(ENOMEM);
+
+ av_log_set_level(AV_LOG_DEBUG);
+
+ for (i = 0; i < FF_ARRAY_ELEMS(options); i++) {
+ av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
+ if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
+ av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);
+ printf("\n");
+ }
+
+ return 0;
+}
diff --git a/libavutil/opt.c b/libavutil/opt.c
index df3cc0884f..7cb3d66557 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -885,90 +885,3 @@ int av_opt_copy(void *dst, const void *src)
}
return ret;
}
-
-#ifdef TEST
-
-typedef struct TestContext {
- const AVClass *class;
- int num;
- int toggle;
- char *string;
- int flags;
- AVRational rational;
-} TestContext;
-
-#define OFFSET(x) offsetof(TestContext, x)
-
-#define TEST_FLAG_COOL 01
-#define TEST_FLAG_LAME 02
-#define TEST_FLAG_MU 04
-
-static const AVOption test_options[] = {
- { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100 },
- { "toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1 },
- { "rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, 10 },
- { "string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { 0 }, CHAR_MIN, CHAR_MAX },
- { "flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX, 0, "flags"},
- { "cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 0, "flags"},
- { "lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 0, "flags"},
- { "mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 0, "flags"},
- { NULL },
-};
-
-static const char *test_get_name(void *ctx)
-{
- return "test";
-}
-
-static const AVClass test_class = {
- "TestContext",
- test_get_name,
- test_options
-};
-
-int main(void)
-{
- int i;
- TestContext test_ctx = { .class = &test_class };
- const char *options[] = {
- "",
- ":",
- "=",
- "foo=:",
- ":=foo",
- "=foo",
- "foo=",
- "foo",
- "foo=val",
- "foo==val",
- "toggle=:",
- "string=:",
- "toggle=1 : foo",
- "toggle=100",
- "toggle==1",
- "flags=+mu-lame : num=42: toggle=0",
- "num=42 : string=blahblah",
- "rational=0 : rational=1/2 : rational=1/-1",
- "rational=-1/0",
- };
-
- printf("\nTesting av_set_options_string()\n");
-
- av_opt_set_defaults(&test_ctx);
- test_ctx.string = av_strdup("default");
- if (!test_ctx.string)
- return AVERROR(ENOMEM);
-
- av_log_set_level(AV_LOG_DEBUG);
-
- for (i = 0; i < FF_ARRAY_ELEMS(options); i++) {
- av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
- if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
- av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);
- printf("\n");
- }
-
- return 0;
-}
-
-#endif
diff --git a/libavutil/parseutils-test.c b/libavutil/parseutils-test.c
new file mode 100644
index 0000000000..149861f1d5
--- /dev/null
+++ b/libavutil/parseutils-test.c
@@ -0,0 +1,116 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <stdint.h>
+#include <stdio.h>
+
+#include "common.h"
+#include "log.h"
+#include "rational.h"
+#include "parseutils.h"
+
+int main(void)
+{
+ int i;
+ uint8_t rgba[4];
+ static const char *const rates[] = {
+ "-inf",
+ "inf",
+ "nan",
+ "123/0",
+ "-123 / 0",
+ "",
+ "/",
+ " 123 / 321",
+ "foo/foo",
+ "foo/1",
+ "1/foo",
+ "0/0",
+ "/0",
+ "1/",
+ "1",
+ "0",
+ "-123/123",
+ "-foo",
+ "123.23",
+ ".23",
+ "-.23",
+ "-0.234",
+ "-0.0000001",
+ " 21332.2324 ",
+ " -21332.2324 ",
+ };
+ static const char *const color_names[] = {
+ "foo",
+ "red",
+ "Red ",
+ "RED",
+ "Violet",
+ "Yellow",
+ "Red",
+ "0x000000",
+ "0x0000000",
+ "0xff000000",
+ "0x3e34ff",
+ "0x3e34ffaa",
+ "0xffXXee",
+ "0xfoobar",
+ "0xffffeeeeeeee",
+ "#ff0000",
+ "#ffXX00",
+ "ff0000",
+ "ffXX00",
+ "red@foo",
+ "random@10",
+ "0xff0000@1.0",
+ "red@",
+ "red@0xfff",
+ "red@0xf",
+ "red@2",
+ "red@0.1",
+ "red@-1",
+ "red@0.5",
+ "red@1.0",
+ "red@256",
+ "red@10foo",
+ "red@-1.0",
+ "red@-0.0",
+ };
+
+ printf("Testing av_parse_video_rate()\n");
+
+ for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
+ int ret;
+ AVRational q = { 0, 0 };
+ ret = av_parse_video_rate(&q, rates[i]);
+ printf("'%s' -> %d/%d %s\n",
+ rates[i], q.num, q.den, ret ? "ERROR" : "OK");
+ }
+
+ printf("\nTesting av_parse_color()\n");
+
+ av_log_set_level(AV_LOG_DEBUG);
+
+ for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
+ if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
+ printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
+ color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
+ }
+
+ return 0;
+}
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index ba21a2ee5b..f4248114b5 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -654,98 +654,3 @@ int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info
}
return 0;
}
-
-#ifdef TEST
-
-int main(void)
-{
- int i;
- uint8_t rgba[4];
- static const char *const rates[] = {
- "-inf",
- "inf",
- "nan",
- "123/0",
- "-123 / 0",
- "",
- "/",
- " 123 / 321",
- "foo/foo",
- "foo/1",
- "1/foo",
- "0/0",
- "/0",
- "1/",
- "1",
- "0",
- "-123/123",
- "-foo",
- "123.23",
- ".23",
- "-.23",
- "-0.234",
- "-0.0000001",
- " 21332.2324 ",
- " -21332.2324 ",
- };
- static const char *const color_names[] = {
- "foo",
- "red",
- "Red ",
- "RED",
- "Violet",
- "Yellow",
- "Red",
- "0x000000",
- "0x0000000",
- "0xff000000",
- "0x3e34ff",
- "0x3e34ffaa",
- "0xffXXee",
- "0xfoobar",
- "0xffffeeeeeeee",
- "#ff0000",
- "#ffXX00",
- "ff0000",
- "ffXX00",
- "red@foo",
- "random@10",
- "0xff0000@1.0",
- "red@",
- "red@0xfff",
- "red@0xf",
- "red@2",
- "red@0.1",
- "red@-1",
- "red@0.5",
- "red@1.0",
- "red@256",
- "red@10foo",
- "red@-1.0",
- "red@-0.0",
- };
-
- printf("Testing av_parse_video_rate()\n");
-
- for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
- int ret;
- AVRational q = { 0, 0 };
- ret = av_parse_video_rate(&q, rates[i]);
- printf("'%s' -> %d/%d %s\n",
- rates[i], q.num, q.den, ret ? "ERROR" : "OK");
- }
-
- printf("\nTesting av_parse_color()\n");
-
- av_log_set_level(AV_LOG_DEBUG);
-
- for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
- if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
- printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
- color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
- }
-
- return 0;
-}
-
-#endif /* TEST */
diff --git a/libavutil/sha-test.c b/libavutil/sha-test.c
new file mode 100644
index 0000000000..e43a5a53d5
--- /dev/null
+++ b/libavutil/sha-test.c
@@ -0,0 +1,69 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "sha.c"
+
+#include <stdio.h>
+
+int main(void)
+{
+ int i, j, k;
+ AVSHA ctx;
+ unsigned char digest[32];
+ const int lengths[3] = { 160, 224, 256 };
+
+ for (j = 0; j < 3; j++) {
+ printf("Testing SHA-%d\n", lengths[j]);
+ for (k = 0; k < 3; k++) {
+ av_sha_init(&ctx, lengths[j]);
+ if (k == 0)
+ av_sha_update(&ctx, "abc", 3);
+ else if (k == 1)
+ av_sha_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
+ else
+ for (i = 0; i < 1000*1000; i++)
+ av_sha_update(&ctx, "a", 1);
+ av_sha_final(&ctx, digest);
+ for (i = 0; i < lengths[j] >> 3; i++)
+ printf("%02X", digest[i]);
+ putchar('\n');
+ }
+ switch (j) {
+ case 0:
+ //test vectors (from FIPS PUB 180-1)
+ printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n"
+ "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n"
+ "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n");
+ break;
+ case 1:
+ //test vectors (from FIPS PUB 180-2 Appendix A)
+ printf("23097d22 3405d822 8642a477 bda255b3 2aadbce4 bda0b3f7 e36c9da7\n"
+ "75388b16 512776cc 5dba5da1 fd890150 b0c6455c b4f58b19 52522525\n"
+ "20794655 980c91d8 bbb4c1ea 97618a4b f03f4258 1948b2ee 4ee7ad67\n");
+ break;
+ case 2:
+ //test vectors (from FIPS PUB 180-2)
+ printf("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad\n"
+ "248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1\n"
+ "cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0\n");
+ break;
+ }
+ }
+
+ return 0;
+}
diff --git a/libavutil/sha.c b/libavutil/sha.c
index 9e78d19d83..404effade2 100644
--- a/libavutil/sha.c
+++ b/libavutil/sha.c
@@ -329,55 +329,3 @@ void av_sha_final(AVSHA* ctx, uint8_t *digest)
for (i = 0; i < ctx->digest_len; i++)
AV_WB32(digest + i*4, ctx->state[i]);
}
-
-#ifdef TEST
-#include <stdio.h>
-
-int main(void)
-{
- int i, j, k;
- AVSHA ctx;
- unsigned char digest[32];
- const int lengths[3] = { 160, 224, 256 };
-
- for (j = 0; j < 3; j++) {
- printf("Testing SHA-%d\n", lengths[j]);
- for (k = 0; k < 3; k++) {
- av_sha_init(&ctx, lengths[j]);
- if (k == 0)
- av_sha_update(&ctx, "abc", 3);
- else if (k == 1)
- av_sha_update(&ctx, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
- else
- for (i = 0; i < 1000*1000; i++)
- av_sha_update(&ctx, "a", 1);
- av_sha_final(&ctx, digest);
- for (i = 0; i < lengths[j] >> 3; i++)
- printf("%02X", digest[i]);
- putchar('\n');
- }
- switch (j) {
- case 0:
- //test vectors (from FIPS PUB 180-1)
- printf("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n"
- "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1\n"
- "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F\n");
- break;
- case 1:
- //test vectors (from FIPS PUB 180-2 Appendix A)
- printf("23097d22 3405d822 8642a477 bda255b3 2aadbce4 bda0b3f7 e36c9da7\n"
- "75388b16 512776cc 5dba5da1 fd890150 b0c6455c b4f58b19 52522525\n"
- "20794655 980c91d8 bbb4c1ea 97618a4b f03f4258 1948b2ee 4ee7ad67\n");
- break;
- case 2:
- //test vectors (from FIPS PUB 180-2)
- printf("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad\n"
- "248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1\n"
- "cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0\n");
- break;
- }
- }
-
- return 0;
-}
-#endif
diff --git a/libavutil/tree-test.c b/libavutil/tree-test.c
new file mode 100644
index 0000000000..f93e53409d
--- /dev/null
+++ b/libavutil/tree-test.c
@@ -0,0 +1,110 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 "tree.c"
+
+#include <stdint.h>
+
+#include "common.h"
+#include "lfg.h"
+#include "log.h"
+
+static int check(AVTreeNode *t)
+{
+ if (t) {
+ int left = check(t->child[0]);
+ int right = check(t->child[1]);
+
+ if (left > 999 || right > 999)
+ return 1000;
+ if (right - left != t->state)
+ return 1000;
+ if (t->state > 1 || t->state < -1)
+ return 1000;
+ return FFMAX(left, right) + 1;
+ }
+ return 0;
+}
+
+static void print(AVTreeNode *t, int depth)
+{
+ int i;
+ for (i = 0; i < depth * 4; i++)
+ av_log(NULL, AV_LOG_ERROR, " ");
+ if (t) {
+ av_log(NULL, AV_LOG_ERROR, "Node %p %2d %p\n", t, t->state, t->elem);
+ print(t->child[0], depth + 1);
+ print(t->child[1], depth + 1);
+ } else
+ av_log(NULL, AV_LOG_ERROR, "NULL\n");
+}
+
+static int cmp(void *a, const void *b)
+{
+ return (uint8_t *) a - (const uint8_t *) b;
+}
+
+int main(void)
+{
+ int i;
+ AVTreeNode *root = NULL, *node = NULL;
+ AVLFG prng;
+
+ av_lfg_init(&prng, 1);
+
+ for (i = 0; i < 10000; i++) {
+ AVTreeNode *node2 = NULL;
+ intptr_t j = av_lfg_get(&prng) % 86294;
+ void *ret, *jj = (void *)(j + 1);
+
+ while (ret = av_tree_find(root, jj, cmp, NULL)) {
+ j = av_lfg_get(&prng) % 86294;
+ jj = (void *)(j + 1);
+ }
+
+ if (check(root) > 999) {
+ av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i);
+ print(root, 0);
+ return 1;
+ }
+
+ if (!node)
+ node = av_tree_node_alloc();
+ if (!node) {
+ av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n");
+ return 1;
+ }
+ av_tree_insert(&root, jj, cmp, &node);
+
+ while (ret = av_tree_find(root, jj, cmp, NULL)) {
+ j = av_lfg_get(&prng) % 86294;
+ jj = (void *)(j + 1);
+ }
+
+ ret = av_tree_insert(&root, jj, cmp, &node2);
+ if (ret != jj)
+ av_tree_destroy(node2);
+ ret = av_tree_find(root, jj, cmp, NULL);
+ if (ret)
+ av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i);
+ }
+
+ av_tree_destroy(root);
+
+ return 0;
+}
diff --git a/libavutil/tree.c b/libavutil/tree.c
index 998851f7f2..a65d728f86 100644
--- a/libavutil/tree.c
+++ b/libavutil/tree.c
@@ -19,7 +19,6 @@
*/
#include "error.h"
-#include "log.h"
#include "mem.h"
#include "tree.h"
@@ -164,94 +163,3 @@ void av_tree_enumerate(AVTreeNode *t, void *opaque,
av_tree_enumerate(t->child[1], opaque, cmp, enu);
}
}
-
-#ifdef TEST
-
-#include "common.h"
-#include "lfg.h"
-
-static int check(AVTreeNode *t)
-{
- if (t) {
- int left = check(t->child[0]);
- int right = check(t->child[1]);
-
- if (left > 999 || right > 999)
- return 1000;
- if (right - left != t->state)
- return 1000;
- if (t->state > 1 || t->state < -1)
- return 1000;
- return FFMAX(left, right) + 1;
- }
- return 0;
-}
-
-static void print(AVTreeNode *t, int depth)
-{
- int i;
- for (i = 0; i < depth * 4; i++)
- av_log(NULL, AV_LOG_ERROR, " ");
- if (t) {
- av_log(NULL, AV_LOG_ERROR, "Node %p %2d %p\n", t, t->state, t->elem);
- print(t->child[0], depth + 1);
- print(t->child[1], depth + 1);
- } else
- av_log(NULL, AV_LOG_ERROR, "NULL\n");
-}
-
-static int cmp(void *a, const void *b)
-{
- return (uint8_t *) a - (const uint8_t *) b;
-}
-
-int main(void)
-{
- int i;
- AVTreeNode *root = NULL, *node = NULL;
- AVLFG prng;
-
- av_lfg_init(&prng, 1);
-
- for (i = 0; i < 10000; i++) {
- AVTreeNode *node2 = NULL;
- intptr_t j = av_lfg_get(&prng) % 86294;
- void *ret, *jj = (void *)(j + 1);
-
- while (ret = av_tree_find(root, jj, cmp, NULL)) {
- j = av_lfg_get(&prng) % 86294;
- jj = (void *)(j + 1);
- }
-
- if (check(root) > 999) {
- av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i);
- print(root, 0);
- return 1;
- }
-
- if (!node)
- node = av_tree_node_alloc();
- if (!node) {
- av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n");
- return 1;
- }
- av_tree_insert(&root, jj, cmp, &node);
-
- while (ret = av_tree_find(root, jj, cmp, NULL)) {
- j = av_lfg_get(&prng) % 86294;
- jj = (void *)(j + 1);
- }
-
- ret = av_tree_insert(&root, jj, cmp, &node2);
- if (ret != jj)
- av_tree_destroy(node2);
- ret = av_tree_find(root, jj, cmp, NULL);
- if (ret)
- av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i);
- }
-
- av_tree_destroy(root);
-
- return 0;
-}
-#endif
diff --git a/libavutil/xtea-test.c b/libavutil/xtea-test.c
new file mode 100644
index 0000000000..f81cfdc3e8
--- /dev/null
+++ b/libavutil/xtea-test.c
@@ -0,0 +1,120 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "intreadwrite.h"
+#include "xtea.h"
+
+#define XTEA_NUM_TESTS 6
+
+static const uint8_t xtea_test_key[XTEA_NUM_TESTS][16] = {
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+};
+
+static const uint8_t xtea_test_pt[XTEA_NUM_TESTS][8] = {
+ { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
+ { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
+ { 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f },
+ { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
+ { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
+ { 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 }
+};
+
+static const uint8_t xtea_test_ct[XTEA_NUM_TESTS][8] = {
+ { 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 },
+ { 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 },
+ { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
+ { 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 },
+ { 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d },
+ { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }
+};
+
+static void test_xtea(AVXTEA *ctx, uint8_t *dst, const uint8_t *src,
+ const uint8_t *ref, int len, uint8_t *iv, int dir,
+ const char *test,
+ void (*crypt)(AVXTEA *, uint8_t *, const uint8_t *, int, uint8_t *, int))
+{
+ crypt(ctx, dst, src, len, iv, dir);
+ if (memcmp(dst, ref, 8*len)) {
+ int i;
+ printf("%s failed\ngot ", test);
+ for (i = 0; i < 8*len; i++)
+ printf("%02x ", dst[i]);
+ printf("\nexpected ");
+ for (i = 0; i < 8*len; i++)
+ printf("%02x ", ref[i]);
+ printf("\n");
+ exit(1);
+ }
+}
+
+int main(void)
+{
+ AVXTEA ctx;
+ uint8_t buf[16], iv[8];
+ int i, j;
+ const uint8_t src[32] = "HelloWorldHelloWorldHelloWorld";
+ uint8_t ct[32];
+ uint8_t pl[32];
+
+ for (i = 0; i < XTEA_NUM_TESTS; i++) {
+ av_xtea_init(&ctx, xtea_test_key[i]);
+
+ test_xtea(&ctx, buf, xtea_test_pt[i], xtea_test_ct[i], 1, NULL, 0, "encryption", av_xtea_crypt);
+ test_xtea(&ctx, buf, xtea_test_ct[i], xtea_test_pt[i], 1, NULL, 1, "decryption", av_xtea_crypt);
+
+ for (j = 0; j < 4; j++)
+ AV_WL32(&buf[4*j], AV_RB32(&xtea_test_key[i][4*j]));
+ av_xtea_le_init(&ctx, buf);
+ for (j = 0; j < 2; j++) {
+ AV_WL32(&ct[4*j], AV_RB32(&xtea_test_ct[i][4*j]));
+ AV_WL32(&pl[4*j], AV_RB32(&xtea_test_pt[i][4*j]));
+ }
+ test_xtea(&ctx, buf, pl, ct, 1, NULL, 0, "encryption", av_xtea_le_crypt);
+ test_xtea(&ctx, buf, ct, pl, 1, NULL, 1, "decryption", av_xtea_le_crypt);
+
+ /* encrypt */
+ memcpy(iv, "HALLO123", 8);
+ av_xtea_crypt(&ctx, ct, src, 4, iv, 0);
+
+ /* decrypt into pl */
+ memcpy(iv, "HALLO123", 8);
+ test_xtea(&ctx, pl, ct, src, 4, iv, 1, "CBC decryption", av_xtea_crypt);
+
+ memcpy(iv, "HALLO123", 8);
+ test_xtea(&ctx, ct, ct, src, 4, iv, 1, "CBC inplace decryption", av_xtea_crypt);
+ }
+ printf("Test encryption/decryption success.\n");
+
+ return 0;
+}
diff --git a/libavutil/xtea.c b/libavutil/xtea.c
index 25fd2f07b1..3e222365b3 100644
--- a/libavutil/xtea.c
+++ b/libavutil/xtea.c
@@ -173,103 +173,3 @@ void av_xtea_le_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
{
xtea_crypt(ctx, dst, src, count, iv, decrypt, xtea_le_crypt_ecb);
}
-
-#ifdef TEST
-#include <stdio.h>
-
-#define XTEA_NUM_TESTS 6
-
-static const uint8_t xtea_test_key[XTEA_NUM_TESTS][16] = {
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
-};
-
-static const uint8_t xtea_test_pt[XTEA_NUM_TESTS][8] = {
- { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
- { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
- { 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f },
- { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
- { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
- { 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 }
-};
-
-static const uint8_t xtea_test_ct[XTEA_NUM_TESTS][8] = {
- { 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 },
- { 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 },
- { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
- { 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 },
- { 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d },
- { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }
-};
-
-static void test_xtea(AVXTEA *ctx, uint8_t *dst, const uint8_t *src,
- const uint8_t *ref, int len, uint8_t *iv, int dir,
- const char *test,
- void (*crypt)(AVXTEA *, uint8_t *, const uint8_t *, int, uint8_t *, int))
-{
- crypt(ctx, dst, src, len, iv, dir);
- if (memcmp(dst, ref, 8*len)) {
- int i;
- printf("%s failed\ngot ", test);
- for (i = 0; i < 8*len; i++)
- printf("%02x ", dst[i]);
- printf("\nexpected ");
- for (i = 0; i < 8*len; i++)
- printf("%02x ", ref[i]);
- printf("\n");
- exit(1);
- }
-}
-
-int main(void)
-{
- AVXTEA ctx;
- uint8_t buf[16], iv[8];
- int i, j;
- const uint8_t src[32] = "HelloWorldHelloWorldHelloWorld";
- uint8_t ct[32];
- uint8_t pl[32];
-
- for (i = 0; i < XTEA_NUM_TESTS; i++) {
- av_xtea_init(&ctx, xtea_test_key[i]);
-
- test_xtea(&ctx, buf, xtea_test_pt[i], xtea_test_ct[i], 1, NULL, 0, "encryption", av_xtea_crypt);
- test_xtea(&ctx, buf, xtea_test_ct[i], xtea_test_pt[i], 1, NULL, 1, "decryption", av_xtea_crypt);
-
- for (j = 0; j < 4; j++)
- AV_WL32(&buf[4*j], AV_RB32(&xtea_test_key[i][4*j]));
- av_xtea_le_init(&ctx, buf);
- for (j = 0; j < 2; j++) {
- AV_WL32(&ct[4*j], AV_RB32(&xtea_test_ct[i][4*j]));
- AV_WL32(&pl[4*j], AV_RB32(&xtea_test_pt[i][4*j]));
- }
- test_xtea(&ctx, buf, pl, ct, 1, NULL, 0, "encryption", av_xtea_le_crypt);
- test_xtea(&ctx, buf, ct, pl, 1, NULL, 1, "decryption", av_xtea_le_crypt);
-
- /* encrypt */
- memcpy(iv, "HALLO123", 8);
- av_xtea_crypt(&ctx, ct, src, 4, iv, 0);
-
- /* decrypt into pl */
- memcpy(iv, "HALLO123", 8);
- test_xtea(&ctx, pl, ct, src, 4, iv, 1, "CBC decryption", av_xtea_crypt);
-
- memcpy(iv, "HALLO123", 8);
- test_xtea(&ctx, ct, ct, src, 4, iv, 1, "CBC inplace decryption", av_xtea_crypt);
- }
- printf("Test encryption/decryption success.\n");
-
- return 0;
-}
-
-#endif