ref: e699c1989c88fcff8c4bcf0f073966094be2d2cc
parent: 10ebc02ecf20d81502995fa92c58dc136ddff45a
author: Gregory Maxwell <[email protected]>
date: Fri Nov 25 18:53:15 EST 2011
Testing tools improvements (no impact on draft)
--- a/celt/tests/test_unit_entropy.c
+++ b/celt/tests/test_unit_entropy.c
@@ -35,6 +35,7 @@
unsigned int sym;
unsigned int seed;
unsigned char *ptr;
+ const char *env_seed;
ret=0;
entropy=0;
if (_argc > 2) {
@@ -41,10 +42,13 @@
fprintf(stderr, "Usage: %s [<seed>]\n", _argv[0]);
return 1;
}
- if (_argc > 1)
- seed = atoi(_argv[1]);
- else
- seed = time(NULL);
+ env_seed = getenv("SEED");
+ if (_argc > 1)
+ seed = atoi(_argv[1]);
+ else if (env_seed)
+ seed = atoi(env_seed);
+ else
+ seed = time(NULL);
/*Testing encoding of raw bit values.*/
ptr = (unsigned char *)malloc(DATA_SIZE);
ec_enc_init(&enc,ptr, DATA_SIZE);
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -753,6 +753,8 @@
int ret, i;
ALLOC_STACK;
+ if(frame_size<0)return OPUS_BAD_ARG;
+
ALLOC(out, frame_size*st->channels, float);
ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL);
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1206,6 +1206,8 @@
VARDECL(opus_int16, in);
ALLOC_STACK;
+ if(frame_size<0)return OPUS_BAD_ARG;
+
ALLOC(in, frame_size*st->channels, opus_int16);
for (i=0;i<frame_size*st->channels;i++)
--- a/tests/test_opus_api.c
+++ b/tests/test_opus_api.c
@@ -92,8 +92,8 @@
#endif
short sbuf[960*2];
int c,err;
- int *nullptr;
- nullptr=0;
+ int *nullvalue;
+ nullvalue=0;
cfgs=0;
/*First test invalid configurations which should fail*/
@@ -163,7 +163,7 @@
cfgs++;
/*GET_PITCH has different execution paths depending on the previously decoded frame.*/
- err=opus_decoder_ctl(dec, OPUS_GET_PITCH(nullptr));
+ err=opus_decoder_ctl(dec, OPUS_GET_PITCH(nullvalue));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
@@ -297,8 +297,11 @@
#endif
short sbuf[960*2];
int a,b,c,err;
- int *nullptr;
- nullptr=0;
+#if 0
+ /*Relevant test not enabled for multistream*/
+ int *nullvalue;
+ nullvalue=0;
+#endif
cfgs=0;
/*First test invalid configurations which should fail*/
@@ -414,7 +417,7 @@
fprintf(stdout," OPUS_GET_BANDWIDTH ........................... OK.\n");
cfgs++;
/*GET_PITCH has different execution paths depending on the previously decoded frame.*/
- err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(nullptr));
+ err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(nullvalue));
if(err!=OPUS_BAD_ARG)test_failed();
cfgs++;
VG_UNDEF(&i,sizeof(i));
--- a/tests/test_opus_decode.c
+++ b/tests/test_opus_decode.c
@@ -91,7 +91,7 @@
}
}
- decsize=opus_decoder_get_size(2);
+ decsize=opus_decoder_get_size(1);
decbak=(OpusDecoder *)malloc(decsize);
if(decbak==NULL)test_failed();
@@ -335,6 +335,9 @@
int main(int _argc, char **_argv)
{
const char * oversion;
+ const char * env_seed;
+ int env_used;
+
if(_argc>2)
{
fprintf(stderr,"Usage: %s [<seed>]\n",_argv[0]);
@@ -341,7 +344,14 @@
return 1;
}
+ 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)^((getpid()&65535)<<16);
Rw=Rz=iseed;
@@ -348,6 +358,7 @@
oversion=opus_get_version_string();
if(!oversion)test_failed();
fprintf(stderr,"Testing %s decoder. Random seed: %u (%.4X)\n", oversion, iseed, fast_rand() % 65535);
+ if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed);
test_decoder_code0();
--- a/tests/test_opus_encode.c
+++ b/tests/test_opus_encode.c
@@ -366,6 +366,9 @@
int main(int _argc, char **_argv)
{
const char * oversion;
+ const char * env_seed;
+ int env_used;
+
if(_argc>2)
{
fprintf(stderr,"Usage: %s [<seed>]\n",_argv[0]);
@@ -372,7 +375,14 @@
return 1;
}
+ 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)^((getpid()&65535)<<16);
Rw=Rz=iseed;
@@ -379,6 +389,7 @@
oversion=opus_get_version_string();
if(!oversion)test_failed();
fprintf(stderr,"Testing %s encoder. Random seed: %u (%.4X)\n", oversion, iseed, fast_rand() % 65535);
+ if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed);
run_test1();