Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@amazon.com>2023-05-27 00:29:57 +0300
committerJean-Marc Valin <jmvalin@amazon.com>2023-06-16 20:02:19 +0300
commit4fbf6dcaf46bbc13ddd91a5762a486981fd0a14a (patch)
tree4754e28b957b070cea84748905386e435d86b7fe /tests
parent5eefa61adcc8ac34849eadb93db4e943d59ae019 (diff)
Adding DRED garbage decoding test
Diffstat (limited to 'tests')
-rw-r--r--tests/test_opus_dred.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/tests/test_opus_dred.c b/tests/test_opus_dred.c
new file mode 100644
index 00000000..d7ebe1e6
--- /dev/null
+++ b/tests/test_opus_dred.c
@@ -0,0 +1,105 @@
+/* Copyright (c) 2023 Amazon
+ Written by Michael Klingbeil */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#ifndef _WIN32
+#include <unistd.h>
+#else
+#include <process.h>
+#define getpid _getpid
+#endif
+
+/* including sources directly to test internal APIs */
+#define CELT_C /* to make celt_assert work */
+#include "opus.h"
+#include "test_opus_common.h"
+
+
+
+#define NB_RANDOM_EXTENSIONS 10000000
+#define MAX_EXTENSION_SIZE 200
+#define MAX_NB_EXTENSIONS 100
+
+void test_random_dred(void)
+{
+ int error;
+ int i;
+ OpusDREDDecoder *dred_dec;
+ OpusDRED *dred;
+ dred_dec = opus_dred_decoder_create(&error);
+ expect_true(error == OPUS_OK, "opus_dred_decoder_create() failed");
+ dred = opus_dred_alloc(&error);
+ expect_true(error == OPUS_OK, "opus_dred_create() failed");
+ for (i=0;i<NB_RANDOM_EXTENSIONS;i++)
+ {
+ unsigned char payload[MAX_EXTENSION_SIZE];
+ int len;
+ int j;
+ int res1, res2;
+ len = fast_rand()%(MAX_EXTENSION_SIZE+1);
+ for (j=0;j<len;j++)
+ payload[j] = fast_rand()&0xFF;
+ res1 = opus_dred_parse(dred_dec, dred, payload, len, 48000, 48000, fast_rand()&0x1);
+ if (res1 > 0)
+ {
+ res2 = opus_dred_process(dred_dec, dred, dred);
+ expect_true(res2 == OPUS_OK, "process should succeed if parse succeeds");
+ }
+ }
+ opus_dred_free(dred);
+ opus_dred_decoder_destroy(dred_dec);
+}
+
+int main(int argc, char **argv)
+{
+ int env_used;
+ char *env_seed;
+ env_used=0;
+ env_seed=getenv("SEED");
+ if(argc>1)iseed=atoi(argv[1]);
+ else if(env_seed)
+ {
+ iseed=atoi(env_seed);
+ env_used=1;
+ }
+ else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16);
+ Rw=Rz=iseed;
+
+ fprintf(stderr,"Testing extensions. Random seed: %u (%.4X)\n", iseed, fast_rand() % 65535);
+ if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed);
+
+ test_random_dred();
+ fprintf(stderr,"Tests completed successfully.\n");
+ return 0;
+}