shithub: opus

Download patch

ref: a26b2be2f922502b821e81e2cb084393f1ccf405
parent: 286f11efeaad88aec51559cd423322c3ab8206bc
author: Gregory Maxwell <[email protected]>
date: Tue Dec 13 21:03:50 EST 2011

Improvements to the tests, add a TEST_OPUS_NOFUZZ to disable testing corrupted input.

No changes to the codec itself.

--- 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 @@
       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 @@
    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;
 }
--- a/tests/test_opus_encode.c
+++ b/tests/test_opus_encode.c
@@ -107,7 +107,7 @@
 }
 #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 @@
          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 @@
    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");