SupportTestsQ15.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #include "SupportTestsQ15.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #include "Test.h"
  5. #define SNR_THRESHOLD 120
  6. #define REL_ERROR (1.0e-3)
  7. #define ABS_Q15_ERROR ((q15_t)10)
  8. #define ABS_Q31_ERROR ((q31_t)40000)
  9. #define ABS_Q7_ERROR ((q7_t)10)
  10. #if defined ( __CC_ARM )
  11. #pragma diag_suppress 170
  12. #endif
  13. void SupportTestsQ15::test_copy_q15()
  14. {
  15. const q15_t *inp = inputQ15.ptr();
  16. q15_t *outp = outputQ15.ptr();
  17. arm_copy_q15(inp, outp,this->nbSamples);
  18. ASSERT_EQ(inputQ15,outputQ15);
  19. ASSERT_EMPTY_TAIL(outputQ15);
  20. }
  21. void SupportTestsQ15::test_fill_q15()
  22. {
  23. q15_t *outp = outputQ15.ptr();
  24. q15_t val = 0x4000;
  25. int i;
  26. arm_fill_q15(val, outp,this->nbSamples);
  27. for(i=0 ; i < this->nbSamples; i++)
  28. {
  29. ASSERT_EQ(val,outp[i]);
  30. }
  31. ASSERT_EMPTY_TAIL(outputQ15);
  32. }
  33. void SupportTestsQ15::test_q15_float()
  34. {
  35. const q15_t *inp = inputQ15.ptr();
  36. float32_t *outp = outputF32.ptr();
  37. arm_q15_to_float(inp, outp,this->nbSamples);
  38. ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR);
  39. ASSERT_EMPTY_TAIL(outputF32);
  40. }
  41. void SupportTestsQ15::test_q15_q31()
  42. {
  43. const q15_t *inp = inputQ15.ptr();
  44. q31_t *outp = outputQ31.ptr();
  45. arm_q15_to_q31(inp, outp,this->nbSamples);
  46. ASSERT_NEAR_EQ(refQ31,outputQ31,ABS_Q31_ERROR);
  47. ASSERT_EMPTY_TAIL(outputQ31);
  48. }
  49. void SupportTestsQ15::test_q15_q7()
  50. {
  51. const q15_t *inp = inputQ15.ptr();
  52. q7_t *outp = outputQ7.ptr();
  53. arm_q15_to_q7(inp, outp,this->nbSamples);
  54. ASSERT_NEAR_EQ(refQ7,outputQ7,ABS_Q7_ERROR);
  55. ASSERT_EMPTY_TAIL(outputQ7);
  56. }
  57. __ALIGNED(2) static const q15_t testReadQ15[2]={-2,1};
  58. __ALIGNED(2) static q15_t testWriteQ15[2]={0,0};
  59. void SupportTestsQ15::test_read_q15x2()
  60. {
  61. q31_t result=0;
  62. result = read_q15x2((q15_t*)testReadQ15);
  63. ASSERT_TRUE(result == 0x0001FFFE);
  64. }
  65. void SupportTestsQ15::test_read_q15x2_ia()
  66. {
  67. q31_t result=0;
  68. q15_t *p = (q15_t*)testReadQ15;
  69. result = read_q15x2_ia(&p);
  70. ASSERT_TRUE(result == 0x0001FFFE);
  71. ASSERT_TRUE(p == testReadQ15 + 2);
  72. }
  73. void SupportTestsQ15::test_read_q15x2_da()
  74. {
  75. q31_t result=0;
  76. q15_t *p = (q15_t*)testReadQ15;
  77. result = read_q15x2_da(&p);
  78. ASSERT_TRUE(result == 0x0001FFFE);
  79. ASSERT_TRUE(p == testReadQ15 - 2);
  80. }
  81. void SupportTestsQ15::test_write_q15x2_ia()
  82. {
  83. q31_t val = 0x0001FFFE;
  84. q15_t *p = testWriteQ15;
  85. testWriteQ15[0] = 0;
  86. testWriteQ15[1] = 0;
  87. write_q15x2_ia(&p,val);
  88. ASSERT_TRUE(testWriteQ15[0] == -2);
  89. ASSERT_TRUE(testWriteQ15[1] == 1);
  90. ASSERT_TRUE(p == testWriteQ15 + 2);
  91. }
  92. void SupportTestsQ15::test_write_q15x2()
  93. {
  94. q31_t val = 0x0001FFFE;
  95. testWriteQ15[0] = 0;
  96. testWriteQ15[1] = 0;
  97. write_q15x2(testWriteQ15,val);
  98. ASSERT_TRUE(testWriteQ15[0] == -2);
  99. ASSERT_TRUE(testWriteQ15[1] == 1);
  100. }
  101. void SupportTestsQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  102. {
  103. (void)paramsArgs;
  104. switch(id)
  105. {
  106. case TEST_COPY_Q15_1:
  107. this->nbSamples = 7;
  108. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  109. outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
  110. break;
  111. case TEST_COPY_Q15_2:
  112. this->nbSamples = 16;
  113. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  114. outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
  115. break;
  116. case TEST_COPY_Q15_3:
  117. this->nbSamples = 23;
  118. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  119. outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
  120. break;
  121. case TEST_FILL_Q15_4:
  122. this->nbSamples = 7;
  123. outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  124. break;
  125. case TEST_FILL_Q15_5:
  126. this->nbSamples = 16;
  127. outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  128. break;
  129. case TEST_FILL_Q15_6:
  130. this->nbSamples = 23;
  131. outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  132. break;
  133. case TEST_Q15_FLOAT_7:
  134. this->nbSamples = 7;
  135. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  136. refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
  137. outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  138. break;
  139. case TEST_Q15_FLOAT_8:
  140. this->nbSamples = 16;
  141. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  142. refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
  143. outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  144. break;
  145. case TEST_Q15_FLOAT_9:
  146. this->nbSamples = 23;
  147. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  148. refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
  149. outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  150. break;
  151. case TEST_Q15_Q31_10:
  152. this->nbSamples = 7;
  153. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  154. refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
  155. outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  156. break;
  157. case TEST_Q15_Q31_11:
  158. this->nbSamples = 16;
  159. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  160. refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
  161. outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  162. break;
  163. case TEST_Q15_Q31_12:
  164. this->nbSamples = 23;
  165. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  166. refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
  167. outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  168. break;
  169. case TEST_Q15_Q7_13:
  170. this->nbSamples = 7;
  171. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  172. refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
  173. outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  174. break;
  175. case TEST_Q15_Q7_14:
  176. this->nbSamples = 16;
  177. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  178. refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
  179. outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  180. break;
  181. case TEST_Q15_Q7_15:
  182. this->nbSamples = 23;
  183. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  184. refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
  185. outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  186. break;
  187. }
  188. }
  189. void SupportTestsQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  190. {
  191. (void)id;
  192. switch(id)
  193. {
  194. case TEST_COPY_Q15_1:
  195. case TEST_COPY_Q15_2:
  196. case TEST_COPY_Q15_3:
  197. case TEST_FILL_Q15_4:
  198. case TEST_FILL_Q15_5:
  199. case TEST_FILL_Q15_6:
  200. outputQ15.dump(mgr);
  201. break;
  202. case TEST_Q15_FLOAT_7:
  203. case TEST_Q15_FLOAT_8:
  204. case TEST_Q15_FLOAT_9:
  205. outputF32.dump(mgr);
  206. break;
  207. case TEST_Q15_Q31_10:
  208. case TEST_Q15_Q31_11:
  209. case TEST_Q15_Q31_12:
  210. outputQ31.dump(mgr);
  211. break;
  212. case TEST_Q15_Q7_13:
  213. case TEST_Q15_Q7_14:
  214. case TEST_Q15_Q7_15:
  215. outputQ7.dump(mgr);
  216. break;
  217. }
  218. }