SupportTestsQ7.cpp 8.1 KB

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