SupportTestsQ7.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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_f64()
  34. {
  35. const q7_t *inp = inputQ7.ptr();
  36. float64_t *outp = outputF64.ptr();
  37. arm_q7_to_f64(inp, outp,this->nbSamples);
  38. ASSERT_CLOSE_ERROR(refF64,outputF64,0.01,REL_ERROR);
  39. ASSERT_EMPTY_TAIL(outputF64);
  40. }
  41. void SupportTestsQ7::test_q7_float()
  42. {
  43. const q7_t *inp = inputQ7.ptr();
  44. float32_t *outp = outputF32.ptr();
  45. arm_q7_to_float(inp, outp,this->nbSamples);
  46. ASSERT_CLOSE_ERROR(refF32,outputF32,0.01,REL_ERROR);
  47. ASSERT_EMPTY_TAIL(outputF32);
  48. }
  49. void SupportTestsQ7::test_q7_q31()
  50. {
  51. const q7_t *inp = inputQ7.ptr();
  52. q31_t *outp = outputQ31.ptr();
  53. arm_q7_to_q31(inp, outp,this->nbSamples);
  54. ASSERT_NEAR_EQ(refQ31,outputQ31,ABS_Q31_ERROR);
  55. ASSERT_EMPTY_TAIL(outputQ31);
  56. }
  57. void SupportTestsQ7::test_q7_q15()
  58. {
  59. const q7_t *inp = inputQ7.ptr();
  60. q15_t *outp = outputQ15.ptr();
  61. arm_q7_to_q15(inp, outp,this->nbSamples);
  62. ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
  63. ASSERT_EMPTY_TAIL(outputQ15);
  64. }
  65. static const q7_t testReadQ7[4]={-4,-3,-2,1};
  66. static q7_t testWriteQ7[4]={0,0,0,0};
  67. void SupportTestsQ7::test_read_q7x4_ia()
  68. {
  69. q31_t result=0;
  70. q7_t *p = (q7_t*)testReadQ7;
  71. result = read_q7x4_ia(&p);
  72. ASSERT_TRUE(result == 0x01FEFDFC);
  73. ASSERT_TRUE(p == testReadQ7 + 4);
  74. }
  75. void SupportTestsQ7::test_read_q7x4_da()
  76. {
  77. q31_t result=0;
  78. q7_t *p = (q7_t*)testReadQ7;
  79. result = read_q7x4_da(&p);
  80. ASSERT_TRUE(result == 0x01FEFDFC);
  81. ASSERT_TRUE(p == testReadQ7 - 4);
  82. }
  83. void SupportTestsQ7::test_write_q7x4_ia()
  84. {
  85. q31_t val = 0x01FEFDFC;
  86. q7_t *p = (q7_t*)testWriteQ7;
  87. testWriteQ7[0] = 0;
  88. testWriteQ7[1] = 0;
  89. testWriteQ7[2] = 0;
  90. testWriteQ7[3] = 0;
  91. write_q7x4_ia(&p,val);
  92. ASSERT_TRUE(testWriteQ7[0] == -4);
  93. ASSERT_TRUE(testWriteQ7[1] == -3);
  94. ASSERT_TRUE(testWriteQ7[2] == -2);
  95. ASSERT_TRUE(testWriteQ7[3] == 1);
  96. ASSERT_TRUE(p == testWriteQ7 + 4);
  97. }
  98. void SupportTestsQ7::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  99. {
  100. (void)paramsArgs;
  101. switch(id)
  102. {
  103. case TEST_COPY_Q7_1:
  104. this->nbSamples = 15;
  105. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  106. outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
  107. break;
  108. case TEST_COPY_Q7_2:
  109. this->nbSamples = 32;
  110. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  111. outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
  112. break;
  113. case TEST_COPY_Q7_3:
  114. this->nbSamples = 47;
  115. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  116. outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
  117. break;
  118. case TEST_FILL_Q7_4:
  119. this->nbSamples = 15;
  120. outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  121. break;
  122. case TEST_FILL_Q7_5:
  123. this->nbSamples = 32;
  124. outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  125. break;
  126. case TEST_FILL_Q7_6:
  127. this->nbSamples = 47;
  128. outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  129. break;
  130. case TEST_Q7_FLOAT_7:
  131. this->nbSamples = 15;
  132. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  133. refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
  134. outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  135. break;
  136. case TEST_Q7_FLOAT_8:
  137. this->nbSamples = 32;
  138. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  139. refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
  140. outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  141. break;
  142. case TEST_Q7_FLOAT_9:
  143. this->nbSamples = 47;
  144. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  145. refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
  146. outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  147. break;
  148. case TEST_Q7_Q31_10:
  149. this->nbSamples = 15;
  150. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  151. refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
  152. outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  153. break;
  154. case TEST_Q7_Q31_11:
  155. this->nbSamples = 32;
  156. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  157. refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
  158. outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  159. break;
  160. case TEST_Q7_Q31_12:
  161. this->nbSamples = 47;
  162. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  163. refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
  164. outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  165. break;
  166. case TEST_Q7_Q15_13:
  167. this->nbSamples = 15;
  168. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  169. refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
  170. outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  171. break;
  172. case TEST_Q7_Q15_14:
  173. this->nbSamples = 32;
  174. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  175. refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
  176. outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  177. break;
  178. case TEST_Q7_Q15_15:
  179. this->nbSamples = 47;
  180. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  181. refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
  182. outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  183. break;
  184. case TEST_Q7_F64_19:
  185. this->nbSamples = 15;
  186. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  187. refF64.reload(SupportTestsQ7::SAMPLES_F64_ID,mgr,this->nbSamples);
  188. outputF64.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  189. break;
  190. case TEST_Q7_F64_20:
  191. this->nbSamples = 32;
  192. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  193. refF64.reload(SupportTestsQ7::SAMPLES_F64_ID,mgr,this->nbSamples);
  194. outputF64.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  195. break;
  196. case TEST_Q7_F64_21:
  197. this->nbSamples = 47;
  198. inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
  199. refF64.reload(SupportTestsQ7::SAMPLES_F64_ID,mgr,this->nbSamples);
  200. outputF64.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
  201. break;
  202. }
  203. }
  204. void SupportTestsQ7::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  205. {
  206. (void)id;
  207. switch(id)
  208. {
  209. case TEST_COPY_Q7_1:
  210. case TEST_COPY_Q7_2:
  211. case TEST_COPY_Q7_3:
  212. case TEST_FILL_Q7_4:
  213. case TEST_FILL_Q7_5:
  214. case TEST_FILL_Q7_6:
  215. outputQ7.dump(mgr);
  216. break;
  217. case TEST_Q7_FLOAT_7:
  218. case TEST_Q7_FLOAT_8:
  219. case TEST_Q7_FLOAT_9:
  220. outputF32.dump(mgr);
  221. break;
  222. case TEST_Q7_Q31_10:
  223. case TEST_Q7_Q31_11:
  224. case TEST_Q7_Q31_12:
  225. outputQ31.dump(mgr);
  226. break;
  227. case TEST_Q7_Q15_13:
  228. case TEST_Q7_Q15_14:
  229. case TEST_Q7_Q15_15:
  230. outputQ15.dump(mgr);
  231. break;
  232. }
  233. }