SupportTestsQ31.cpp 7.1 KB

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