summaryrefslogtreecommitdiff
path: root/libavutil/tests
diff options
context:
space:
mode:
authorDiego Biurrun <diego@biurrun.de>2016-04-20 11:40:40 +0200
committerDiego Biurrun <diego@biurrun.de>2016-05-13 14:55:56 +0200
commita6a750c7ef240b72ce01e9653343a0ddf247d196 (patch)
tree5c472bb92b5264f19b9270b0caf8a8565b071cef /libavutil/tests
parent257f00ec1ab06a2a161f535036c6512f3fc8e801 (diff)
tests: Move all test programs to a subdirectory
Diffstat (limited to 'libavutil/tests')
-rw-r--r--libavutil/tests/.gitignore21
-rw-r--r--libavutil/tests/adler32.c51
-rw-r--r--libavutil/tests/aes.c92
-rw-r--r--libavutil/tests/atomic.c35
-rw-r--r--libavutil/tests/avstring.c69
-rw-r--r--libavutil/tests/base64.c84
-rw-r--r--libavutil/tests/blowfish.c190
-rw-r--r--libavutil/tests/cpu.c136
-rw-r--r--libavutil/tests/crc.c45
-rw-r--r--libavutil/tests/des.c128
-rw-r--r--libavutil/tests/eval.c145
-rw-r--r--libavutil/tests/fifo.c51
-rw-r--r--libavutil/tests/float_dsp.c296
-rw-r--r--libavutil/tests/hmac.c92
-rw-r--r--libavutil/tests/lfg.c56
-rw-r--r--libavutil/tests/lls.c54
-rw-r--r--libavutil/tests/md5.c54
-rw-r--r--libavutil/tests/opt.c110
-rw-r--r--libavutil/tests/parseutils.c116
-rw-r--r--libavutil/tests/sha.c69
-rw-r--r--libavutil/tests/tree.c110
-rw-r--r--libavutil/tests/xtea.c120
22 files changed, 2124 insertions, 0 deletions
diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore
new file mode 100644
index 0000000000..c4d1d065fb
--- /dev/null
+++ b/libavutil/tests/.gitignore
@@ -0,0 +1,21 @@
+/adler32
+/aes
+/atomic
+/avstring
+/base64
+/blowfish
+/cpu
+/crc
+/des
+/eval
+/fifo
+/float_dsp
+/hmac
+/lfg
+/lls
+/md5
+/opt
+/parseutils
+/sha
+/tree
+/xtea
diff --git a/libavutil/tests/adler32.c b/libavutil/tests/adler32.c
new file mode 100644
index 0000000000..323690056c
--- /dev/null
+++ b/libavutil/tests/adler32.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 "libavutil/log.h"
+#include "libavutil/timer.h"
+#include "libavutil/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/tests/aes.c b/libavutil/tests/aes.c
new file mode 100644
index 0000000000..49ca553e0a
--- /dev/null
+++ b/libavutil/tests/aes.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 "libavutil/aes.c"
+
+#include <string.h>
+
+#include "libavutil/lfg.h"
+#include "libavutil/log.h"
+
+int main(int argc, char **argv)
+{
+ int i, j;
+ AVAES b;
+ static const uint8_t rkey[2][16] = {
+ { 0 },
+ { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
+ 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
+ };
+ static const uint8_t rpt[2][16] = {
+ { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
+ 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
+ { 0 }
+ };
+ static const 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 pt[16], 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/tests/atomic.c b/libavutil/tests/atomic.c
new file mode 100644
index 0000000000..70636f42fb
--- /dev/null
+++ b/libavutil/tests/atomic.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 "libavutil/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/tests/avstring.c b/libavutil/tests/avstring.c
new file mode 100644
index 0000000000..2e5ee2d44a
--- /dev/null
+++ b/libavutil/tests/avstring.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 "libavutil/common.h"
+#include "libavutil/mem.h"
+#include "libavutil/avstring.h"
+
+int main(void)
+{
+ int i;
+ static 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/tests/base64.c b/libavutil/tests/base64.c
new file mode 100644
index 0000000000..16ea399788
--- /dev/null
+++ b/libavutil/tests/base64.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 "libavutil/common.h"
+#include "libavutil/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/tests/blowfish.c b/libavutil/tests/blowfish.c
new file mode 100644
index 0000000000..acaab70aeb
--- /dev/null
+++ b/libavutil/tests/blowfish.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 "libavutil/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/tests/cpu.c b/libavutil/tests/cpu.c
new file mode 100644
index 0000000000..176b7eb030
--- /dev/null
+++ b/libavutil/tests/cpu.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 "libavutil/avstring.h"
+#include "libavutil/common.h"
+#include "libavutil/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/tests/crc.c b/libavutil/tests/crc.c
new file mode 100644
index 0000000000..c2c609fba8
--- /dev/null
+++ b/libavutil/tests/crc.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 "libavutil/crc.h"
+
+int main(void)
+{
+ uint8_t buf[1999];
+ int i;
+ static const 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/tests/des.c b/libavutil/tests/des.c
new file mode 100644
index 0000000000..1e7a2fa50a
--- /dev/null
+++ b/libavutil/tests/des.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 "libavutil/des.c"
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "libavutil/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/tests/eval.c b/libavutil/tests/eval.c
new file mode 100644
index 0000000000..818c59ccdb
--- /dev/null
+++ b/libavutil/tests/eval.c
@@ -0,0 +1,145 @@
+/*
+ * 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 "libavutil/libm.h"
+#include "libavutil/timer.h"
+#include "libavutil/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/tests/fifo.c b/libavutil/tests/fifo.c
new file mode 100644
index 0000000000..4c4b37a501
--- /dev/null
+++ b/libavutil/tests/fifo.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 "libavutil/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/tests/float_dsp.c b/libavutil/tests/float_dsp.c
new file mode 100644
index 0000000000..ab6bf6a569
--- /dev/null
+++ b/libavutil/tests/float_dsp.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 "libavutil/cpu.h"
+#include "libavutil/internal.h"
+#include "libavutil/lfg.h"
+#include "libavutil/log.h"
+#include "libavutil/random_seed.h"
+#include "libavutil/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/tests/hmac.c b/libavutil/tests/hmac.c
new file mode 100644
index 0000000000..600240fe97
--- /dev/null
+++ b/libavutil/tests/hmac.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 "libavutil/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;
+ static const uint8_t key2[] = "Jefe";
+ static const uint8_t data1[] = "Hi There";
+ static const uint8_t data2[] = "what do ya want for nothing?";
+ static const uint8_t data4[] = "Test Using Larger Than Block-Size Key - Hash Key First";
+ static const uint8_t data5[] = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
+ static 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/tests/lfg.c b/libavutil/tests/lfg.c
new file mode 100644
index 0000000000..9a0c47c4de
--- /dev/null
+++ b/libavutil/tests/lfg.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 "libavutil/log.h"
+#include "libavutil/timer.h"
+#include "libavutil/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/tests/lls.c b/libavutil/tests/lls.c
new file mode 100644
index 0000000000..7866b38998
--- /dev/null
+++ b/libavutil/tests/lls.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 "libavutil/internal.h"
+#include "libavutil/lfg.h"
+#include "libavutil/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/tests/md5.c b/libavutil/tests/md5.c
new file mode 100644
index 0000000000..9fb7006dd8
--- /dev/null
+++ b/libavutil/tests/md5.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 "libavutil/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/tests/opt.c b/libavutil/tests/opt.c
new file mode 100644
index 0000000000..350ce3d820
--- /dev/null
+++ b/libavutil/tests/opt.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 "libavutil/common.h"
+#include "libavutil/error.h"
+#include "libavutil/log.h"
+#include "libavutil/mem.h"
+#include "libavutil/rational.h"
+#include "libavutil/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 };
+ static 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/tests/parseutils.c b/libavutil/tests/parseutils.c
new file mode 100644
index 0000000000..805c01ff5a
--- /dev/null
+++ b/libavutil/tests/parseutils.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 "libavutil/common.h"
+#include "libavutil/log.h"
+#include "libavutil/rational.h"
+#include "libavutil/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/tests/sha.c b/libavutil/tests/sha.c
new file mode 100644
index 0000000000..0f1d514b44
--- /dev/null
+++ b/libavutil/tests/sha.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 "libavutil/sha.c"
+
+#include <stdio.h>
+
+int main(void)
+{
+ int i, j, k;
+ AVSHA ctx;
+ unsigned char digest[32];
+ static 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/tests/tree.c b/libavutil/tests/tree.c
new file mode 100644
index 0000000000..fb19b27896
--- /dev/null
+++ b/libavutil/tests/tree.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 "libavutil/tree.c"
+
+#include <stdint.h>
+
+#include "libavutil/common.h"
+#include "libavutil/lfg.h"
+#include "libavutil/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/tests/xtea.c b/libavutil/tests/xtea.c
new file mode 100644
index 0000000000..326f2714a9
--- /dev/null
+++ b/libavutil/tests/xtea.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 "libavutil/intreadwrite.h"
+#include "libavutil/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;
+ static 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;
+}