chore: update

This commit is contained in:
skdhg committed 2023-08-09 23:22:32 +05:45
1 parent 345a8c44ca
commit 71b3dc90ee
136 files changed
+3928 -2157

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
# Tests that link to libopus
opus_tests = [
['test_opus_api'],
['test_opus_decode', [], 60],
['test_opus_encode', 'opus_encode_regressions.c', 120],
['test_opus_padding'],
['test_opus_projection'],
]
foreach t : opus_tests
test_name = t.get(0)
extra_srcs = t.get(1, [])
test_kwargs = {}
if t.length() > 2
test_kwargs += {'timeout': t[2]}
endif
exe_kwargs = {}
# This test uses private symbols
if test_name == 'test_opus_projection'
exe_kwargs = {
'link_with': [celt_lib, silk_lib],
'objects': opus_lib.extract_all_objects(),
}
endif
exe = executable(test_name, '@[email protected]'.format(test_name), extra_srcs,
include_directories: opus_includes,
dependencies: [libm, opus_dep],
install: false,
kwargs: exe_kwargs)
test(test_name, exe, kwargs: test_kwargs)
endforeach
+29
View File
@@ -0,0 +1,29 @@
#!/bin/sh
tarball=`realpath "$1"`
nb_tests="$2"
oldvectors=`realpath "$3"`
newvectors=`realpath "$4"`
base=`basename "$tarball" .tar.gz`
tar xvf "$tarball" > /dev/null 2>&1
cd "$base"
if [ $? -ne 0 ]
then
echo cannot go to "$base"
exit 1
fi
mkdir build_tests
configure_dir=`pwd`
seq -w "$nb_tests" | parallel --halt now,fail=10 -j +2 -q ../random_config.sh "build_tests/run_{}" "$configure_dir" "$oldvectors" "$newvectors"
if [ $? -ne 0 ]
then
echo Check found errors
exit 1
else
echo No error found
fi
+17 -19
View File
@@ -40,6 +40,8 @@
/* 4 bytes: packet length, 4 bytes: encoder final range */
#define SETUP_BYTE_COUNT 8
#define MAX_DECODES 12
typedef struct {
int fs;
int channels;
@@ -62,9 +64,11 @@ static void ParseToc(const uint8_t *toc, TocInfo *const info) {
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
OpusDecoder *dec;
opus_int16 *pcm;
uint8_t *packet;
uint8_t *temp_data;
TocInfo toc;
int i, err;
int i = 0;
int err = OPUS_OK;
int num_decodes = 0;
/* Not enough data to setup the decoder (+1 for the ToC) */
if (size < SETUP_BYTE_COUNT + 1) {
@@ -75,26 +79,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
ParseToc(&data[SETUP_BYTE_COUNT], &toc);
dec = opus_decoder_create(toc.fs, toc.channels, &err);
if (err != OPUS_OK | dec == NULL) {
if (err != OPUS_OK || dec == NULL) {
return 0;
}
pcm = (opus_int16*) malloc(sizeof(*pcm) * MAX_FRAME_SAMP * toc.channels);
packet = (uint8_t*) calloc(MAX_PACKET, sizeof(*packet));
i = 0;
while (1) {
while (i + SETUP_BYTE_COUNT < size && num_decodes++ < MAX_DECODES) {
int len, fec;
if (i + SETUP_BYTE_COUNT >= size) {
break;
}
len = (opus_uint32) data[i ] << 24 |
(opus_uint32) data[i + 1] << 16 |
(opus_uint32) data[i + 2] << 8 |
(opus_uint32) data[i + 3];
if (len > MAX_PACKET || len < 0) {
if (len > MAX_PACKET || len < 0 || i + SETUP_BYTE_COUNT + len > size) {
break;
}
@@ -102,17 +100,18 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
* Instead, byte 4 is repurposed to determine if FEC is used. */
fec = data[i + 4] & 1;
/* Lost packet */
if (len == 0) {
/* Lost packet */
int frame_size;
opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&frame_size));
(void) opus_decode(dec, NULL, size, pcm, frame_size, fec);
(void) opus_decode(dec, NULL, len, pcm, frame_size, fec);
} else {
if (i + SETUP_BYTE_COUNT + len > size) {
break;
}
memcpy(pcm, &data[i + SETUP_BYTE_COUNT], len);
(void) opus_decode(dec, data, size, pcm, MAX_FRAME_SAMP, fec);
temp_data = (uint8_t*) malloc(len);
memcpy(temp_data, &data[i + SETUP_BYTE_COUNT], len);
(void) opus_decode(dec, temp_data, len, pcm, MAX_FRAME_SAMP, fec);
free(temp_data);
}
i += SETUP_BYTE_COUNT + len;
@@ -120,7 +119,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
opus_decoder_destroy(dec);
free(pcm);
free(packet);
return 0;
}
+17 -18
View File
@@ -35,7 +35,6 @@
#include <stdint.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include "opus_multistream.h"
#include "opus.h"
#include "test_opus_common.h"
@@ -106,7 +105,7 @@ static int celt_ec_internal_error(void)
1799, 1799, 1799, 1799, -9721
};
err = opus_multistream_encode(enc, pcm, 320, data, 2460);
assert(err > 0);
opus_test_assert(err > 0);
}
opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0));
@@ -144,7 +143,7 @@ static int celt_ec_internal_error(void)
-9510, -9510, -9510, -9510, -9510, -9510, -9510
};
err = opus_multistream_encode(enc, pcm, 160, data, 2460);
assert(err > 0);
opus_test_assert(err > 0);
}
opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0));
@@ -182,7 +181,7 @@ static int celt_ec_internal_error(void)
-9510, -9510, -9510, -9510, -9510, -9510, -9510
};
err = opus_multistream_encode(enc, pcm, 160, data, 2460);
assert(err > 0);
opus_test_assert(err > 0);
}
opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0));
@@ -220,7 +219,7 @@ static int celt_ec_internal_error(void)
-9510, -9510, -9510, -9510, -9510, -9510, -9510
};
err = opus_multistream_encode(enc, pcm, 160, data, 2460);
assert(err > 0);
opus_test_assert(err > 0);
}
opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0));
@@ -256,7 +255,7 @@ static int celt_ec_internal_error(void)
5632
};
err = opus_multistream_encode(enc, pcm, 160, data, 2460);
assert(err > 0);
opus_test_assert(err > 0);
}
opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));
opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0));
@@ -281,7 +280,7 @@ static int celt_ec_internal_error(void)
0, 0, -256, 226
};
err = opus_multistream_encode(enc, pcm, 40, data, 2460);
assert(err > 0);
opus_test_assert(err > 0);
/* returns -3 */
}
opus_multistream_encoder_destroy(enc);
@@ -334,7 +333,7 @@ static int mscbr_encode_fail10(void)
0
};
err = opus_multistream_encode(enc, pcm, 20, data, 627300);
assert(err > 0);
opus_test_assert(err > 0);
/* returns -1 */
}
opus_multistream_encoder_destroy(enc);
@@ -384,7 +383,7 @@ static int mscbr_encode_fail(void)
0
};
err = opus_multistream_encode(enc, pcm, 20, data, 472320);
assert(err > 0);
opus_test_assert(err > 0);
/* returns -1 */
}
opus_multistream_encoder_destroy(enc);
@@ -740,7 +739,7 @@ static int surround_analysis_uninit(void)
-20992, 25859, 5372, 12040, 13307, -4355,-30213, -9, -6019
};
err = opus_multistream_encode(enc, pcm, 960, data, 7380);
assert(err > 0);
opus_test_assert(err > 0);
}
opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(1));
@@ -885,7 +884,7 @@ static int surround_analysis_uninit(void)
};
err = opus_multistream_encode(enc, pcm, 1440, data, 7380);
/* reads uninitialized data at src/opus_multistream_encoder.c:293 */
assert(err > 0);
opus_test_assert(err > 0);
}
opus_multistream_encoder_destroy(enc);
return 0;
@@ -935,7 +934,7 @@ static int ec_enc_shrink_assert(void)
opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(6));
opus_encoder_ctl(enc, OPUS_SET_BITRATE(6000));
data_len = opus_encode(enc, pcm1, 960, data, 2000);
assert(data_len > 0);
opus_test_assert(data_len > 0);
opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));
opus_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1));
@@ -943,12 +942,12 @@ static int ec_enc_shrink_assert(void)
opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(1));
opus_encoder_ctl(enc, OPUS_SET_BITRATE(15600));
data_len = opus_encode(enc, pcm2, 2880, data, 122);
assert(data_len > 0);
opus_test_assert(data_len > 0);
opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
opus_encoder_ctl(enc, OPUS_SET_BITRATE(27000));
data_len = opus_encode(enc, pcm3, 2880, data, 122); /* assertion failure */
assert(data_len > 0);
opus_test_assert(data_len > 0);
opus_encoder_destroy(enc);
return 0;
@@ -970,7 +969,7 @@ static int ec_enc_shrink_assert2(void)
{
static const short pcm[960] = { 0 };
data_len = opus_encode(enc, pcm, 960, data, 2000);
assert(data_len > 0);
opus_test_assert(data_len > 0);
}
opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
{
@@ -980,7 +979,7 @@ static int ec_enc_shrink_assert2(void)
-32768, -32768, 0, 0, -32768, -32768, 0, 0, -32768, -32768
};
data_len = opus_encode(enc, pcm, 480, data, 19);
assert(data_len > 0);
opus_test_assert(data_len > 0);
}
opus_encoder_destroy(enc);
return 0;
@@ -1009,14 +1008,14 @@ static int silk_gain_assert(void)
opus_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND));
opus_encoder_ctl(enc, OPUS_SET_BITRATE(6000));
data_len = opus_encode(enc, pcm1, 160, data, 1000);
assert(data_len > 0);
opus_test_assert(data_len > 0);
opus_encoder_ctl(enc, OPUS_SET_VBR(0));
opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(0));
opus_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_MEDIUMBAND));
opus_encoder_ctl(enc, OPUS_SET_BITRATE(2867));
data_len = opus_encode(enc, pcm2, 960, data, 1000);
assert(data_len > 0);
opus_test_assert(data_len > 0);
opus_encoder_destroy(enc);
return 0;
+126
View File
@@ -0,0 +1,126 @@
#!/bin/bash
dir="$1"
mkdir "$dir"
if [ $? -ne 0 ]
then
exit 1
fi
cd "$dir"
if [ $? -ne 0 ]
then
exit 1
fi
configure_path="$2"
config="random_config.txt"
case `seq 3 | shuf -n1` in
1)
approx=--enable-float-approx
math=-ffast-math
;;
2)
approx=--enable-float-approx
;;
*)
approx=
math=
;;
esac
CFLAGS='-g'
opt=`echo -e "-O1\n-O2\n-O3" | shuf -n1`
#arch=-march=`echo -e "core2\nsandybridge\nbroadwell\nskylake" | shuf -n1`
arch=`echo -e "\n-march=core2\n-march=sandybridge\n-march=broadwell\n-march=skylake\n-march=native" | shuf -n1`
footprint=`echo -e "\n-DSMALL_FOOTPRINT" | shuf -n1`
std=`echo -e "\n-std=c90\n-std=c99\n-std=c11\n-std=c17" | shuf -n1`
sanitize=`echo -e "\n-fsanitize=address -fno-sanitize-recover=all\n-fsanitize=undefined -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow" | shuf -n1`
CFLAGS="$CFLAGS $std $opt $arch $footprint $math $sanitize"
echo "CFLAGS=$CFLAGS" > "$config"
lib=`echo -e "\n--disable-static\n--disable-shared" | shuf -n1`
arithmetic=`echo -e "\n--enable-fixed-point\n--enable-fixed-point --enable-fixed-point-debug\n--enable-fixed-point --disable-float-api\n--enable-fixed-point --enable-fixed-point-debug --disable-float-api" | shuf -n1`
custom=`echo -e "\n--enable-custom-modes" | shuf -n1`
asm=`echo -e "\n--disable-asm\n--disable-rtcd\n--disable-intrinsics" | shuf -n1`
#asm=`echo -e "\n--disable-asm\n--disable-intrinsics" | shuf -n1`
assert=`echo -e "\n--enable-assertions" | shuf -n1`
harden=`echo -e "\n--enable-hardening" | shuf -n1`
fuzz=`echo -e "\n--enable-fuzzing" | shuf -n1`
checkasm=`echo -e "\n--enable-check-asm" | shuf -n1`
rfc8251=`echo -e "\n--disable-rfc8251" | shuf -n1`
if [ "$rfc8251" = --disable-rfc8251 ]
then
vectors="$3"
else
vectors="$4"
fi
echo using testvectors at "$vectors" >> "$config"
config_opt="$lib $arithmetic $custom $asm $assert $harden $fuzz $checkasm $rfc8251 $approx"
echo configure $config_opt >> "$config"
export CFLAGS
"$configure_path/configure" $config_opt > configure_output.txt 2>&1
if [ $? -ne 0 ]
then
echo configure FAIL >> "$config"
exit 1
fi
make > make_output.txt 2>&1
if [ $? -ne 0 ]
then
echo make FAIL >> "$config"
exit 1
fi
#Run valgrind 5% of the time (minus the asan cases)
if [ "`seq 20 | shuf -n1`" -ne 1 -o "$sanitize" = "-fsanitize=address -fno-sanitize-recover=all" ]
then
make check > makecheck_output.txt 2>&1
else
echo valgrind enabled >> "$config"
valgrind --trace-children=yes --error-exitcode=128 make check > makecheck_output.txt 2>&1
fi
if [ $? -ne 0 ]
then
echo check FAIL >> "$config"
exit 1
fi
rate=`echo -e "8000\n12000\n16000\n24000\n48000" | shuf -n1`
echo testvectors for "$rate" Hz > testvectors_output.txt
../../../run_vectors.sh . "$vectors" "$rate" >> testvectors_output.txt 2>&1
if [ $? -ne 0 ]
then
echo testvectors FAIL >> "$config"
exit 1
fi
echo all tests PASS >> "$config"
#When everything's good, do some cleaning up to save space
make distclean > /dev/null 2>&1
rm -f tmp.out
gzip make_output.txt
+1 -1
View File
@@ -1298,7 +1298,7 @@ opus_int32 test_enc_api(void)
err=opus_encoder_ctl(enc,OPUS_GET_INBAND_FEC(null_int_ptr));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
CHECK_SETGET(OPUS_SET_INBAND_FEC(i),OPUS_GET_INBAND_FEC(&i),-1,2,
CHECK_SETGET(OPUS_SET_INBAND_FEC(i),OPUS_GET_INBAND_FEC(&i),-1,3,
1,0,
" OPUS_SET_INBAND_FEC .......................... OK.\n",
" OPUS_GET_INBAND_FEC .......................... OK.\n")
+4 -1
View File
@@ -75,8 +75,11 @@ static OPUS_INLINE void _test_failed(const char *file, int line)
fprintf(stderr,"Please report this failure and include\n");
fprintf(stderr,"'make check SEED=%u fails %s at line %d for %s'\n",iseed,file,line,opus_get_version_string());
fprintf(stderr,"and any relevant details about your system.\n\n");
#if defined(_MSC_VER)
_set_abort_behavior( 0, _WRITE_ABORT_MSG);
#endif
abort();
}
#define test_failed() _test_failed(__FILE__, __LINE__);
#define opus_test_assert(cond) {if (!(cond)) {test_failed();}}
void regression_test(void);
+1 -1
View File
@@ -36,7 +36,7 @@
#include <math.h>
#include <string.h>
#include <time.h>
#if (!defined WIN32 && !defined _WIN32) || defined(__MINGW32__)
#ifndef _WIN32
#include <unistd.h>
#else
#include <process.h>
+4
View File
@@ -297,6 +297,7 @@ int run_test1(int no_fuzz)
/*FIXME: encoder api tests, fs!=48k, mono, VBR*/
fprintf(stdout," Encode+Decode tests.\n");
fflush(stdout);
enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &err);
if(err != OPUS_OK || enc==NULL)test_failed();
@@ -466,6 +467,7 @@ int run_test1(int no_fuzz)
count++;
}while(i<(SSAMPLES-MAX_FRAME_SAMP));
fprintf(stdout," Mode %s FB encode %s, %6d bps OK.\n",mstrings[modes[j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate);
fflush(stdout);
}
}
@@ -543,6 +545,7 @@ int run_test1(int no_fuzz)
count++;
}while(i<(SSAMPLES/12-MAX_FRAME_SAMP));
fprintf(stdout," Mode %s NB dual-mono MS encode %s, %6d bps OK.\n",mstrings[modes[j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate);
fflush(stdout);
}
}
@@ -612,6 +615,7 @@ int run_test1(int no_fuzz)
i+=frame_size;
}while(i<SAMPLES*4);
fprintf(stdout," All framesize pairs switching encode, %d frames OK.\n",count);
fflush(stdout);
if(opus_encoder_ctl(enc, OPUS_RESET_STATE)!=OPUS_OK)test_failed();
opus_encoder_destroy(enc);
+3 -6
View File
@@ -39,7 +39,7 @@
#define CHANNELS 2
#define FRAMESIZE 5760
int test_overflow(void)
void test_overflow(void)
{
OpusDecoder *decoder;
int result;
@@ -51,7 +51,7 @@ int test_overflow(void)
fprintf(stderr, " Checking for padding overflow... ");
if (!in || !out) {
fprintf(stderr, "FAIL (out of memory)\n");
return -1;
test_failed();
}
in[0] = 0xff;
in[1] = 0x41;
@@ -71,21 +71,18 @@ int test_overflow(void)
}
fprintf(stderr, "OK.\n");
return 1;
}
int main(void)
{
const char *oversion;
int tests = 0;;
iseed = 0;
oversion = opus_get_version_string();
if (!oversion) test_failed();
fprintf(stderr, "Testing %s padding.\n", oversion);
tests += test_overflow();
test_overflow();
fprintf(stderr, "All padding tests passed.\n");
-1
View File
@@ -29,7 +29,6 @@
#include "config.h"
#endif
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>