SupportTestsQ31.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #include "SupportTestsQ31.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #include "Test.h"
  5. #define SNR_THRESHOLD 120
  6. #define REL_ERROR (1.0e-5)
  7. #define ABS_Q15_ERROR ((q15_t)10)
  8. #define ABS_Q31_ERROR ((q31_t)80)
  9. #define ABS_Q7_ERROR ((q7_t)10)
  10. void SupportTestsQ31::test_copy_q31()
  11. {
  12. const q31_t *inp = inputQ31.ptr();
  13. q31_t *outp = outputQ31.ptr();
  14. arm_copy_q31(inp, outp,this->nbSamples);
  15. ASSERT_EQ(inputQ31,outputQ31);
  16. ASSERT_EMPTY_TAIL(outputQ31);
  17. }
  18. void SupportTestsQ31::test_fill_q31()
  19. {
  20. q31_t *outp = outputQ31.ptr();
  21. q31_t val = 0x4000;
  22. int i;
  23. arm_fill_q31(val, outp,this->nbSamples);
  24. for(i=0 ; i < this->nbSamples; i++)
  25. {
  26. ASSERT_EQ(val,outp[i]);
  27. }
  28. ASSERT_EMPTY_TAIL(outputQ31);
  29. }
  30. void SupportTestsQ31::test_q31_float()
  31. {
  32. const q31_t *inp = inputQ31.ptr();
  33. float32_t *outp = outputF32.ptr();
  34. arm_q31_to_float(inp, outp,this->nbSamples);
  35. ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR);
  36. ASSERT_EMPTY_TAIL(outputF32);
  37. }
  38. void SupportTestsQ31::test_q31_q15()
  39. {
  40. const q31_t *inp = inputQ31.ptr();
  41. q15_t *outp = outputQ15.ptr();
  42. arm_q31_to_q15(inp, outp,this->nbSamples);
  43. ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
  44. ASSERT_EMPTY_TAIL(outputQ15);
  45. }
  46. void SupportTestsQ31::test_q31_q7()
  47. {
  48. const q31_t *inp = inputQ31.ptr();
  49. q7_t *outp = outputQ7.ptr();
  50. arm_q31_to_q7(inp, outp,this->nbSamples);
  51. ASSERT_NEAR_EQ(refQ7,outputQ7,ABS_Q7_ERROR);
  52. ASSERT_EMPTY_TAIL(outputQ7);
  53. }
  54. void SupportTestsQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  55. {
  56. (void)paramsArgs;
  57. switch(id)
  58. {
  59. case TEST_COPY_Q31_1:
  60. this->nbSamples = 3;
  61. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  62. outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
  63. break;
  64. case TEST_COPY_Q31_2:
  65. this->nbSamples = 8;
  66. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  67. outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
  68. break;
  69. case TEST_COPY_Q31_3:
  70. this->nbSamples = 11;
  71. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  72. outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
  73. break;
  74. case TEST_FILL_Q31_4:
  75. this->nbSamples = 3;
  76. outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  77. break;
  78. case TEST_FILL_Q31_5:
  79. this->nbSamples = 8;
  80. outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  81. break;
  82. case TEST_FILL_Q31_6:
  83. this->nbSamples = 11;
  84. outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  85. break;
  86. case TEST_Q31_FLOAT_7:
  87. this->nbSamples = 7;
  88. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  89. refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
  90. outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  91. break;
  92. case TEST_Q31_FLOAT_8:
  93. this->nbSamples = 16;
  94. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  95. refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
  96. outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  97. break;
  98. case TEST_Q31_FLOAT_9:
  99. this->nbSamples = 17;
  100. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  101. refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
  102. outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  103. break;
  104. case TEST_Q31_Q15_10:
  105. this->nbSamples = 3;
  106. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  107. refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
  108. outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  109. break;
  110. case TEST_Q31_Q15_11:
  111. this->nbSamples = 8;
  112. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  113. refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
  114. outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  115. break;
  116. case TEST_Q31_Q15_12:
  117. this->nbSamples = 11;
  118. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  119. refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
  120. outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  121. break;
  122. case TEST_Q31_Q7_13:
  123. this->nbSamples = 15;
  124. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  125. refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
  126. outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  127. break;
  128. case TEST_Q31_Q7_14:
  129. this->nbSamples = 32;
  130. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  131. refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
  132. outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  133. break;
  134. case TEST_Q31_Q7_15:
  135. this->nbSamples = 33;
  136. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  137. refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
  138. outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  139. break;
  140. }
  141. }
  142. void SupportTestsQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  143. {
  144. (void)id;
  145. switch(id)
  146. {
  147. case TEST_COPY_Q31_1:
  148. case TEST_COPY_Q31_2:
  149. case TEST_COPY_Q31_3:
  150. case TEST_FILL_Q31_4:
  151. case TEST_FILL_Q31_5:
  152. case TEST_FILL_Q31_6:
  153. outputQ31.dump(mgr);
  154. break;
  155. case TEST_Q31_FLOAT_7:
  156. case TEST_Q31_FLOAT_8:
  157. case TEST_Q31_FLOAT_9:
  158. outputF32.dump(mgr);
  159. break;
  160. case TEST_Q31_Q15_10:
  161. case TEST_Q31_Q15_11:
  162. case TEST_Q31_Q15_12:
  163. outputQ15.dump(mgr);
  164. break;
  165. case TEST_Q31_Q7_13:
  166. case TEST_Q31_Q7_14:
  167. case TEST_Q31_Q7_15:
  168. outputQ7.dump(mgr);
  169. break;
  170. }
  171. }