summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2011-12-14 02:03:50 -0500
committerJean-Marc Valin <jmvalin@jmvalin.ca>2012-01-25 12:04:17 +1300
commita26b2be2f922502b821e81e2cb084393f1ccf405 (patch)
tree0e56888cad2cc7bf3bcfd09dbd7284aded2755ce /tests
parent286f11efeaad88aec51559cd423322c3ab8206bc (diff)
downloadopus-a26b2be2f922502b821e81e2cb084393f1ccf405.tar.gz
Improvements to the tests, add a TEST_OPUS_NOFUZZ to disable testing corrupted input.
No changes to the codec itself.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_opus_decode.c17
-rw-r--r--tests/test_opus_encode.c9
2 files changed, 21 insertions, 5 deletions
diff --git a/tests/test_opus_decode.c b/tests/test_opus_decode.c
index b2f78e31..8f37ddc0 100644
--- a/tests/test_opus_decode.c
+++ b/tests/test_opus_decode.c
@@ -44,7 +44,7 @@
#define MAX_FRAME_SAMP (5760)
extern int jackpot;
-int test_decoder_code0(void)
+int test_decoder_code0(int no_fuzz)
{
static const opus_int32 fsv[5]={48000,24000,16000,12000,8000};
int err,skip,plen;
@@ -239,6 +239,16 @@ int test_decoder_code0(void)
fprintf(stdout," dec[%3d] all 3-byte prefix for length 4, mode %2d OK.\n",t,lmodes[mode]);
}
+ if(no_fuzz)
+ {
+ fprintf(stdout," Skipping many tests which fuzz the decoder as requested.\n");
+ for(t=0;t<5*2;t++)opus_decoder_destroy(dec[t]);
+ printf(" Decoders stopped.\n");
+ free(outbuf_int);
+ free(packet);
+ return 0;
+ }
+
skip=fast_rand()%7;
for(i=0;i<64;i++)
{
@@ -360,7 +370,10 @@ int main(int _argc, char **_argv)
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();
+ /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data
+ into the decoders. This is helpful because garbage data
+ may cause the decoders to clip, which angers CLANG IOC.*/
+ test_decoder_code0(getenv("TEST_OPUS_NOFUZZ")!=NULL);
return 0;
}
diff --git a/tests/test_opus_encode.c b/tests/test_opus_encode.c
index 315790c6..70c28d84 100644
--- a/tests/test_opus_encode.c
+++ b/tests/test_opus_encode.c
@@ -107,7 +107,7 @@ static inline void save_packet(unsigned char* p, int len, opus_uint32 rng)
}
#endif
-int run_test1(void)
+int run_test1(int no_fuzz)
{
static const int fsizes[6]={960*3,960*2,120,240,480,960};
static const char *mstrings[3] = {" LP","Hybrid"," MDCT"};
@@ -323,7 +323,7 @@ int run_test1(void)
the decoders in order to compare them. */
if(opus_packet_parse(packet,len,&toc,frames,size,&payload_offset)<=0)test_failed();
if((fast_rand()&1023)==0)len=0;
- for(j=payload_offset;j<len;j++)for(jj=0;jj<8;jj++)packet[j]^=((fast_rand()&1023)==0)<<jj;
+ for(j=(frames[0]-packet);j<len;j++)for(jj=0;jj<8;jj++)packet[j]^=((!no_fuzz)&&((fast_rand()&1023)==0))<<jj;
out_samples = opus_decode(dec_err[0], len>0?packet:NULL, len, out2buf, MAX_FRAME_SAMP, 0);
if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed();
if((len>0&&out_samples!=frame_size))test_failed(); /*FIXME use lastframe*/
@@ -391,7 +391,10 @@ int main(int _argc, char **_argv)
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();
+ /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data
+ into the decoders. This is helpful because garbage data
+ may cause the decoders to clip, which angers CLANG IOC.*/
+ run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL);
fprintf(stderr,"Tests completed successfully.\n");