test_opus_common.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (c) 2011 Xiph.Org Foundation
  2. Written by Gregory Maxwell */
  3. /*
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  16. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. static OPUS_INLINE void deb2_impl(unsigned char *_t,unsigned char **_p,int _k,int _x,int _y)
  25. {
  26. int i;
  27. if(_x>2){
  28. if(_y<3)for(i=0;i<_y;i++)*(--*_p)=_t[i+1];
  29. }else{
  30. _t[_x]=_t[_x-_y];
  31. deb2_impl(_t,_p,_k,_x+1,_y);
  32. for(i=_t[_x-_y]+1;i<_k;i++){
  33. _t[_x]=i;
  34. deb2_impl(_t,_p,_k,_x+1,_x);
  35. }
  36. }
  37. }
  38. /*Generates a De Bruijn sequence (k,2) with length k^2*/
  39. static OPUS_INLINE void debruijn2(int _k, unsigned char *_res)
  40. {
  41. unsigned char *p;
  42. unsigned char *t;
  43. t=malloc(sizeof(unsigned char)*_k*2);
  44. memset(t,0,sizeof(unsigned char)*_k*2);
  45. p=&_res[_k*_k];
  46. deb2_impl(t,&p,_k,1,1);
  47. free(t);
  48. }
  49. /*MWC RNG of George Marsaglia*/
  50. static opus_uint32 Rz, Rw;
  51. static OPUS_INLINE opus_uint32 fast_rand(void)
  52. {
  53. Rz=36969*(Rz&65535)+(Rz>>16);
  54. Rw=18000*(Rw&65535)+(Rw>>16);
  55. return (Rz<<16)+Rw;
  56. }
  57. static opus_uint32 iseed;
  58. #ifdef __GNUC__
  59. __attribute__((noreturn))
  60. #elif defined(_MSC_VER)
  61. __declspec(noreturn)
  62. #endif
  63. static OPUS_INLINE void _test_failed(const char *file, int line)
  64. {
  65. fprintf(stderr,"\n ***************************************************\n");
  66. fprintf(stderr," *** A fatal error was detected. ***\n");
  67. fprintf(stderr," ***************************************************\n");
  68. fprintf(stderr,"Please report this failure and include\n");
  69. fprintf(stderr,"'make check SEED=%u fails %s at line %d for %s'\n",iseed,file,line,opus_get_version_string());
  70. fprintf(stderr,"and any relevant details about your system.\n\n");
  71. #if defined(_MSC_VER)
  72. _set_abort_behavior( 0, _WRITE_ABORT_MSG);
  73. #endif
  74. abort();
  75. }
  76. #define test_failed() _test_failed(__FILE__, __LINE__);
  77. void regression_test(void);