SupportTestsQ15.cpp 8.6 KB

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