SupportTestsQ15.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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_f64()
  34. {
  35. const q15_t *inp = inputQ15.ptr();
  36. float64_t *outp = outputF64.ptr();
  37. arm_q15_to_f64(inp, outp,this->nbSamples);
  38. ASSERT_REL_ERROR(refF64,outputF64,REL_ERROR);
  39. ASSERT_EMPTY_TAIL(outputF64);
  40. }
  41. void SupportTestsQ15::test_q15_float()
  42. {
  43. const q15_t *inp = inputQ15.ptr();
  44. float32_t *outp = outputF32.ptr();
  45. arm_q15_to_float(inp, outp,this->nbSamples);
  46. ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR);
  47. ASSERT_EMPTY_TAIL(outputF32);
  48. }
  49. void SupportTestsQ15::test_q15_q31()
  50. {
  51. const q15_t *inp = inputQ15.ptr();
  52. q31_t *outp = outputQ31.ptr();
  53. arm_q15_to_q31(inp, outp,this->nbSamples);
  54. ASSERT_NEAR_EQ(refQ31,outputQ31,ABS_Q31_ERROR);
  55. ASSERT_EMPTY_TAIL(outputQ31);
  56. }
  57. void SupportTestsQ15::test_q15_q7()
  58. {
  59. const q15_t *inp = inputQ15.ptr();
  60. q7_t *outp = outputQ7.ptr();
  61. arm_q15_to_q7(inp, outp,this->nbSamples);
  62. ASSERT_NEAR_EQ(refQ7,outputQ7,ABS_Q7_ERROR);
  63. ASSERT_EMPTY_TAIL(outputQ7);
  64. }
  65. __ALIGNED(2) static const q15_t testReadQ15[2]={-2,1};
  66. __ALIGNED(2) static q15_t testWriteQ15[2]={0,0};
  67. void SupportTestsQ15::test_read_q15x2()
  68. {
  69. q31_t result=0;
  70. result = read_q15x2((q15_t*)testReadQ15);
  71. ASSERT_TRUE(result == 0x0001FFFE);
  72. }
  73. void SupportTestsQ15::test_read_q15x2_ia()
  74. {
  75. q31_t result=0;
  76. q15_t *p = (q15_t*)testReadQ15;
  77. result = read_q15x2_ia(&p);
  78. ASSERT_TRUE(result == 0x0001FFFE);
  79. ASSERT_TRUE(p == testReadQ15 + 2);
  80. }
  81. void SupportTestsQ15::test_read_q15x2_da()
  82. {
  83. q31_t result=0;
  84. q15_t *p = (q15_t*)testReadQ15;
  85. result = read_q15x2_da(&p);
  86. ASSERT_TRUE(result == 0x0001FFFE);
  87. ASSERT_TRUE(p == testReadQ15 - 2);
  88. }
  89. void SupportTestsQ15::test_write_q15x2_ia()
  90. {
  91. q31_t val = 0x0001FFFE;
  92. q15_t *p = testWriteQ15;
  93. testWriteQ15[0] = 0;
  94. testWriteQ15[1] = 0;
  95. write_q15x2_ia(&p,val);
  96. ASSERT_TRUE(testWriteQ15[0] == -2);
  97. ASSERT_TRUE(testWriteQ15[1] == 1);
  98. ASSERT_TRUE(p == testWriteQ15 + 2);
  99. }
  100. void SupportTestsQ15::test_write_q15x2()
  101. {
  102. q31_t val = 0x0001FFFE;
  103. testWriteQ15[0] = 0;
  104. testWriteQ15[1] = 0;
  105. write_q15x2(testWriteQ15,val);
  106. ASSERT_TRUE(testWriteQ15[0] == -2);
  107. ASSERT_TRUE(testWriteQ15[1] == 1);
  108. }
  109. void SupportTestsQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  110. {
  111. (void)paramsArgs;
  112. switch(id)
  113. {
  114. case TEST_COPY_Q15_1:
  115. this->nbSamples = 7;
  116. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  117. outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
  118. break;
  119. case TEST_COPY_Q15_2:
  120. this->nbSamples = 16;
  121. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  122. outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
  123. break;
  124. case TEST_COPY_Q15_3:
  125. this->nbSamples = 23;
  126. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  127. outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
  128. break;
  129. case TEST_FILL_Q15_4:
  130. this->nbSamples = 7;
  131. outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  132. break;
  133. case TEST_FILL_Q15_5:
  134. this->nbSamples = 16;
  135. outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  136. break;
  137. case TEST_FILL_Q15_6:
  138. this->nbSamples = 23;
  139. outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  140. break;
  141. case TEST_Q15_FLOAT_7:
  142. this->nbSamples = 7;
  143. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  144. refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
  145. outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  146. break;
  147. case TEST_Q15_FLOAT_8:
  148. this->nbSamples = 16;
  149. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  150. refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
  151. outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  152. break;
  153. case TEST_Q15_FLOAT_9:
  154. this->nbSamples = 23;
  155. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  156. refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
  157. outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  158. break;
  159. case TEST_Q15_Q31_10:
  160. this->nbSamples = 7;
  161. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  162. refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
  163. outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  164. break;
  165. case TEST_Q15_Q31_11:
  166. this->nbSamples = 16;
  167. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  168. refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
  169. outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  170. break;
  171. case TEST_Q15_Q31_12:
  172. this->nbSamples = 23;
  173. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  174. refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
  175. outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  176. break;
  177. case TEST_Q15_Q7_13:
  178. this->nbSamples = 7;
  179. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  180. refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
  181. outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  182. break;
  183. case TEST_Q15_Q7_14:
  184. this->nbSamples = 16;
  185. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  186. refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
  187. outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  188. break;
  189. case TEST_Q15_Q7_15:
  190. this->nbSamples = 23;
  191. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  192. refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
  193. outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  194. break;
  195. case TEST_Q15_F64_21:
  196. this->nbSamples = 7;
  197. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  198. refF64.reload(SupportTestsQ15::SAMPLES_F64_ID,mgr,this->nbSamples);
  199. outputF64.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  200. break;
  201. case TEST_Q15_F64_22:
  202. this->nbSamples = 16;
  203. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  204. refF64.reload(SupportTestsQ15::SAMPLES_F64_ID,mgr,this->nbSamples);
  205. outputF64.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  206. break;
  207. case TEST_Q15_F64_23:
  208. this->nbSamples = 23;
  209. inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
  210. refF64.reload(SupportTestsQ15::SAMPLES_F64_ID,mgr,this->nbSamples);
  211. outputF64.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
  212. break;
  213. }
  214. }
  215. void SupportTestsQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  216. {
  217. (void)id;
  218. switch(id)
  219. {
  220. case TEST_COPY_Q15_1:
  221. case TEST_COPY_Q15_2:
  222. case TEST_COPY_Q15_3:
  223. case TEST_FILL_Q15_4:
  224. case TEST_FILL_Q15_5:
  225. case TEST_FILL_Q15_6:
  226. outputQ15.dump(mgr);
  227. break;
  228. case TEST_Q15_FLOAT_7:
  229. case TEST_Q15_FLOAT_8:
  230. case TEST_Q15_FLOAT_9:
  231. outputF32.dump(mgr);
  232. break;
  233. case TEST_Q15_Q31_10:
  234. case TEST_Q15_Q31_11:
  235. case TEST_Q15_Q31_12:
  236. outputQ31.dump(mgr);
  237. break;
  238. case TEST_Q15_Q7_13:
  239. case TEST_Q15_Q7_14:
  240. case TEST_Q15_Q7_15:
  241. outputQ7.dump(mgr);
  242. break;
  243. }
  244. }