SupportTestsQ7.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #include "SupportTestsQ7.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)(1<<8))
  8. #define ABS_Q31_ERROR ((q31_t)(1<<24))
  9. #define ABS_Q7_ERROR ((q7_t)10)
  10. #if defined ( __CC_ARM )
  11. #pragma diag_suppress 170
  12. #endif
  13. void SupportTestsQ7::test_copy_q7()
  14. {
  15. const q7_t *inp = inputQ7.ptr();
  16. q7_t *outp = outputQ7.ptr();
  17. arm_copy_q7(inp, outp,this->nbSamples);
  18. ASSERT_EQ(inputQ7,outputQ7);
  19. ASSERT_EMPTY_TAIL(outputQ7);
  20. }
  21. void SupportTestsQ7::test_fill_q7()
  22. {
  23. q7_t *outp = outputQ7.ptr();
  24. q7_t val = 0x40;
  25. int i;
  26. arm_fill_q7(val, outp,this->nbSamples);
  27. for(i=0 ; i < this->nbSamples; i++)
  28. {
  29. ASSERT_EQ(val,outp[i]);
  30. }
  31. ASSERT_EMPTY_TAIL(outputQ7);
  32. }
  33. void SupportTestsQ7::test_q7_float()
  34. {
  35. const q7_t *inp = inputQ7.ptr();
  36. float32_t *outp = outputF32.ptr();
  37. arm_q7_to_float(inp, outp,this->nbSamples);
  38. ASSERT_CLOSE_ERROR(refF32,outputF32,0.01,REL_ERROR);
  39. ASSERT_EMPTY_TAIL(outputF32);
  40. }
  41. void SupportTestsQ7::test_q7_q31()
  42. {
  43. const q7_t *inp = inputQ7.ptr();
  44. q31_t *outp = outputQ31.ptr();
  45. arm_q7_to_q31(inp, outp,this->nbSamples);
  46. ASSERT_NEAR_EQ(refQ31,outputQ31,ABS_Q31_ERROR);
  47. ASSERT_EMPTY_TAIL(outputQ31);
  48. }
  49. void SupportTestsQ7::test_q7_q15()
  50. {
  51. const q7_t *inp = inputQ7.ptr();
  52. q15_t *outp = outputQ15.ptr();
  53. arm_q7_to_q15(inp, outp,this->nbSamples);
  54. ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
  55. ASSERT_EMPTY_TAIL(outputQ15);
  56. }
  57. static const q7_t testReadQ7[4]={-4,-3,-2,1};
  58. static q7_t testWriteQ7[4]={0,0,0,0};
  59. void SupportTestsQ7::test_read_q7x4_ia()
  60. {
  61. q31_t result=0;
  62. q7_t *p = (q7_t*)testReadQ7;
  63. result = read_q7x4_ia(&p);
  64. ASSERT_TRUE(result == 0x01FEFDFC);
  65. ASSERT_TRUE(p == testReadQ7 + 4);
  66. }
  67. void SupportTestsQ7::test_read_q7x4_da()
  68. {
  69. q31_t result=0;
  70. q7_t *p = (q7_t*)testReadQ7;
  71. result = read_q7x4_da(&p);
  72. ASSERT_TRUE(result == 0x01FEFDFC);
  73. ASSERT_TRUE(p == testReadQ7 - 4);
  74. }
  75. void SupportTestsQ7::test_write_q7x4_ia()
  76. {
  77. q31_t val = 0x01FEFDFC;
  78. q7_t *p = (q7_t*)testWriteQ7;
  79. testWriteQ7[0] = 0;
  80. testWriteQ7[1] = 0;
  81. testWriteQ7[2] = 0;
  82. testWriteQ7[3] = 0;
  83. write_q7x4_ia(&p,val);
  84. ASSERT_TRUE(testWriteQ7[0] == -4);
  85. ASSERT_TRUE(testWriteQ7[1] == -3);
  86. ASSERT_TRUE(testWriteQ7[2] == -2);
  87. ASSERT_TRUE(testWriteQ7[3] == 1);
  88. ASSERT_TRUE(p == testWriteQ7 + 4);
  89. }
  90. void SupportTestsQ7::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  91. {
  92. (void)paramsArgs;
  93. switch(id)
  94. {
  95. case TEST_COPY_Q7_1:
  96. this->nbSamples = 15;
  97. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  98. outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
  99. break;
  100. case TEST_COPY_Q7_2:
  101. this->nbSamples = 32;
  102. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  103. outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
  104. break;
  105. case TEST_COPY_Q7_3:
  106. this->nbSamples = 47;
  107. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  108. outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
  109. break;
  110. case TEST_FILL_Q7_4:
  111. this->nbSamples = 15;
  112. outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  113. break;
  114. case TEST_FILL_Q7_5:
  115. this->nbSamples = 32;
  116. outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  117. break;
  118. case TEST_FILL_Q7_6:
  119. this->nbSamples = 47;
  120. outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  121. break;
  122. case TEST_Q7_FLOAT_7:
  123. this->nbSamples = 15;
  124. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  125. refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
  126. outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  127. break;
  128. case TEST_Q7_FLOAT_8:
  129. this->nbSamples = 32;
  130. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  131. refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
  132. outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  133. break;
  134. case TEST_Q7_FLOAT_9:
  135. this->nbSamples = 47;
  136. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  137. refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
  138. outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  139. break;
  140. case TEST_Q7_Q31_10:
  141. this->nbSamples = 15;
  142. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  143. refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
  144. outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  145. break;
  146. case TEST_Q7_Q31_11:
  147. this->nbSamples = 32;
  148. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  149. refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
  150. outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  151. break;
  152. case TEST_Q7_Q31_12:
  153. this->nbSamples = 47;
  154. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  155. refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
  156. outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  157. break;
  158. case TEST_Q7_Q15_13:
  159. this->nbSamples = 15;
  160. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  161. refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
  162. outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  163. break;
  164. case TEST_Q7_Q15_14:
  165. this->nbSamples = 32;
  166. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  167. refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
  168. outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  169. break;
  170. case TEST_Q7_Q15_15:
  171. this->nbSamples = 47;
  172. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  173. refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
  174. outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  175. break;
  176. }
  177. }
  178. void SupportTestsQ7::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  179. {
  180. (void)id;
  181. switch(id)
  182. {
  183. case TEST_COPY_Q7_1:
  184. case TEST_COPY_Q7_2:
  185. case TEST_COPY_Q7_3:
  186. case TEST_FILL_Q7_4:
  187. case TEST_FILL_Q7_5:
  188. case TEST_FILL_Q7_6:
  189. outputQ7.dump(mgr);
  190. break;
  191. case TEST_Q7_FLOAT_7:
  192. case TEST_Q7_FLOAT_8:
  193. case TEST_Q7_FLOAT_9:
  194. outputF32.dump(mgr);
  195. break;
  196. case TEST_Q7_Q31_10:
  197. case TEST_Q7_Q31_11:
  198. case TEST_Q7_Q31_12:
  199. outputQ31.dump(mgr);
  200. break;
  201. case TEST_Q7_Q15_13:
  202. case TEST_Q7_Q15_14:
  203. case TEST_Q7_Q15_15:
  204. outputQ15.dump(mgr);
  205. break;
  206. }
  207. }