SupportTestsQ31.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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_f64()
  31. {
  32. const q31_t *inp = inputQ31.ptr();
  33. float64_t *outp = outputF64.ptr();
  34. arm_q31_to_f64(inp, outp,this->nbSamples);
  35. ASSERT_REL_ERROR(refF64,outputF64,REL_ERROR);
  36. ASSERT_EMPTY_TAIL(outputF64);
  37. }
  38. void SupportTestsQ31::test_q31_float()
  39. {
  40. const q31_t *inp = inputQ31.ptr();
  41. float32_t *outp = outputF32.ptr();
  42. arm_q31_to_float(inp, outp,this->nbSamples);
  43. ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR);
  44. ASSERT_EMPTY_TAIL(outputF32);
  45. }
  46. void SupportTestsQ31::test_q31_q15()
  47. {
  48. const q31_t *inp = inputQ31.ptr();
  49. q15_t *outp = outputQ15.ptr();
  50. arm_q31_to_q15(inp, outp,this->nbSamples);
  51. ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
  52. ASSERT_EMPTY_TAIL(outputQ15);
  53. }
  54. void SupportTestsQ31::test_q31_q7()
  55. {
  56. const q31_t *inp = inputQ31.ptr();
  57. q7_t *outp = outputQ7.ptr();
  58. arm_q31_to_q7(inp, outp,this->nbSamples);
  59. ASSERT_NEAR_EQ(refQ7,outputQ7,ABS_Q7_ERROR);
  60. ASSERT_EMPTY_TAIL(outputQ7);
  61. }
  62. void SupportTestsQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  63. {
  64. (void)paramsArgs;
  65. switch(id)
  66. {
  67. case TEST_COPY_Q31_1:
  68. this->nbSamples = 3;
  69. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  70. outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
  71. break;
  72. case TEST_COPY_Q31_2:
  73. this->nbSamples = 8;
  74. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  75. outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
  76. break;
  77. case TEST_COPY_Q31_3:
  78. this->nbSamples = 11;
  79. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  80. outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
  81. break;
  82. case TEST_FILL_Q31_4:
  83. this->nbSamples = 3;
  84. outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  85. break;
  86. case TEST_FILL_Q31_5:
  87. this->nbSamples = 8;
  88. outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  89. break;
  90. case TEST_FILL_Q31_6:
  91. this->nbSamples = 11;
  92. outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  93. break;
  94. case TEST_Q31_FLOAT_7:
  95. this->nbSamples = 7;
  96. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  97. refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
  98. outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  99. break;
  100. case TEST_Q31_FLOAT_8:
  101. this->nbSamples = 16;
  102. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  103. refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
  104. outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  105. break;
  106. case TEST_Q31_FLOAT_9:
  107. this->nbSamples = 17;
  108. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  109. refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
  110. outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  111. break;
  112. case TEST_Q31_Q15_10:
  113. this->nbSamples = 3;
  114. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  115. refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
  116. outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  117. break;
  118. case TEST_Q31_Q15_11:
  119. this->nbSamples = 8;
  120. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  121. refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
  122. outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  123. break;
  124. case TEST_Q31_Q15_12:
  125. this->nbSamples = 11;
  126. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  127. refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
  128. outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  129. break;
  130. case TEST_Q31_Q7_13:
  131. this->nbSamples = 15;
  132. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  133. refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
  134. outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  135. break;
  136. case TEST_Q31_Q7_14:
  137. this->nbSamples = 32;
  138. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  139. refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
  140. outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  141. break;
  142. case TEST_Q31_Q7_15:
  143. this->nbSamples = 33;
  144. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  145. refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
  146. outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  147. break;
  148. case TEST_Q31_F64_16:
  149. this->nbSamples = 3;
  150. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  151. refF64.reload(SupportTestsQ31::SAMPLES_F64_ID,mgr,this->nbSamples);
  152. outputF64.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  153. break;
  154. case TEST_Q31_F64_17:
  155. this->nbSamples = 8;
  156. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  157. refF64.reload(SupportTestsQ31::SAMPLES_F64_ID,mgr,this->nbSamples);
  158. outputF64.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  159. break;
  160. case TEST_Q31_F64_18:
  161. this->nbSamples = 11;
  162. inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
  163. refF64.reload(SupportTestsQ31::SAMPLES_F64_ID,mgr,this->nbSamples);
  164. outputF64.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
  165. break;
  166. }
  167. }
  168. void SupportTestsQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  169. {
  170. (void)id;
  171. switch(id)
  172. {
  173. case TEST_COPY_Q31_1:
  174. case TEST_COPY_Q31_2:
  175. case TEST_COPY_Q31_3:
  176. case TEST_FILL_Q31_4:
  177. case TEST_FILL_Q31_5:
  178. case TEST_FILL_Q31_6:
  179. outputQ31.dump(mgr);
  180. break;
  181. case TEST_Q31_FLOAT_7:
  182. case TEST_Q31_FLOAT_8:
  183. case TEST_Q31_FLOAT_9:
  184. outputF32.dump(mgr);
  185. break;
  186. case TEST_Q31_Q15_10:
  187. case TEST_Q31_Q15_11:
  188. case TEST_Q31_Q15_12:
  189. outputQ15.dump(mgr);
  190. break;
  191. case TEST_Q31_Q7_13:
  192. case TEST_Q31_Q7_14:
  193. case TEST_Q31_Q7_15:
  194. outputQ7.dump(mgr);
  195. break;
  196. }
  197. }