1 #include "SupportTestsQ31.h"
2 #include <stdio.h>
3 #include "Error.h"
4 #include "Test.h"
5 
6 #define SNR_THRESHOLD 120
7 #define REL_ERROR (1.0e-5)
8 #define ABS_Q15_ERROR ((q15_t)10)
9 #define ABS_Q31_ERROR ((q31_t)80)
10 #define ABS_Q7_ERROR ((q7_t)10)
11 
test_copy_q31()12     void SupportTestsQ31::test_copy_q31()
13     {
14        const q31_t *inp = inputQ31.ptr();
15        q31_t *outp = outputQ31.ptr();
16 
17 
18        arm_copy_q31(inp, outp,this->nbSamples);
19 
20 
21        ASSERT_EQ(inputQ31,outputQ31);
22        ASSERT_EMPTY_TAIL(outputQ31);
23 
24     }
25 
test_fill_q31()26     void SupportTestsQ31::test_fill_q31()
27     {
28        q31_t *outp = outputQ31.ptr();
29        q31_t val = 0x4000;
30        int i;
31 
32 
33        arm_fill_q31(val, outp,this->nbSamples);
34 
35 
36        for(i=0 ; i < this->nbSamples; i++)
37        {
38           ASSERT_EQ(val,outp[i]);
39        }
40        ASSERT_EMPTY_TAIL(outputQ31);
41 
42     }
43 
test_q31_f64()44     void SupportTestsQ31::test_q31_f64()
45     {
46        const q31_t *inp = inputQ31.ptr();
47        float64_t *outp = outputF64.ptr();
48 
49 
50        arm_q31_to_f64(inp, outp,this->nbSamples);
51 
52 
53        ASSERT_REL_ERROR(refF64,outputF64,REL_ERROR);
54        ASSERT_EMPTY_TAIL(outputF64);
55 
56     }
57 
test_q31_float()58     void SupportTestsQ31::test_q31_float()
59     {
60        const q31_t *inp = inputQ31.ptr();
61        float32_t *outp = outputF32.ptr();
62 
63 
64        arm_q31_to_float(inp, outp,this->nbSamples);
65 
66 
67        ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR);
68        ASSERT_EMPTY_TAIL(outputF32);
69 
70     }
71 
test_q31_q15()72     void SupportTestsQ31::test_q31_q15()
73     {
74        const q31_t *inp = inputQ31.ptr();
75        q15_t *outp = outputQ15.ptr();
76 
77 
78        arm_q31_to_q15(inp, outp,this->nbSamples);
79 
80 
81        ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
82        ASSERT_EMPTY_TAIL(outputQ15);
83 
84     }
85 
test_q31_q7()86     void SupportTestsQ31::test_q31_q7()
87     {
88        const q31_t *inp = inputQ31.ptr();
89        q7_t *outp = outputQ7.ptr();
90 
91 
92        arm_q31_to_q7(inp, outp,this->nbSamples);
93 
94 
95        ASSERT_NEAR_EQ(refQ7,outputQ7,ABS_Q7_ERROR);
96        ASSERT_EMPTY_TAIL(outputQ7);
97 
98     }
99 
100 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)101     void SupportTestsQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
102     {
103 
104         (void)paramsArgs;
105         switch(id)
106         {
107 
108             case TEST_COPY_Q31_1:
109               this->nbSamples = 3;
110               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
111 
112               outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
113 
114             break;
115 
116             case TEST_COPY_Q31_2:
117               this->nbSamples = 8;
118               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
119 
120               outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
121 
122             break;
123 
124             case TEST_COPY_Q31_3:
125               this->nbSamples = 11;
126               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
127 
128               outputQ31.create(inputQ31.nbSamples(),SupportTestsQ31::OUT_ID,mgr);
129 
130             break;
131 
132             case TEST_FILL_Q31_4:
133               this->nbSamples = 3;
134 
135               outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
136 
137             break;
138 
139             case TEST_FILL_Q31_5:
140               this->nbSamples = 8;
141 
142               outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
143 
144             break;
145 
146             case TEST_FILL_Q31_6:
147               this->nbSamples = 11;
148 
149               outputQ31.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
150 
151             break;
152 
153             case TEST_Q31_FLOAT_7:
154               this->nbSamples = 7;
155               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
156               refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
157               outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
158 
159             break;
160 
161             case TEST_Q31_FLOAT_8:
162               this->nbSamples = 16;
163               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
164               refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
165               outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
166 
167             break;
168 
169             case TEST_Q31_FLOAT_9:
170               this->nbSamples = 17;
171               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
172               refF32.reload(SupportTestsQ31::SAMPLES_F32_ID,mgr,this->nbSamples);
173               outputF32.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
174 
175             break;
176 
177             case TEST_Q31_Q15_10:
178               this->nbSamples = 3;
179               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
180               refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
181               outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
182 
183             break;
184 
185             case TEST_Q31_Q15_11:
186               this->nbSamples = 8;
187               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
188               refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
189               outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
190 
191             break;
192 
193             case TEST_Q31_Q15_12:
194               this->nbSamples = 11;
195               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
196               refQ15.reload(SupportTestsQ31::SAMPLES_Q15_ID,mgr,this->nbSamples);
197               outputQ15.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
198 
199             break;
200 
201             case TEST_Q31_Q7_13:
202               this->nbSamples = 15;
203               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
204               refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
205               outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
206 
207             break;
208 
209             case TEST_Q31_Q7_14:
210               this->nbSamples = 32;
211               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
212               refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
213               outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
214 
215             break;
216 
217             case TEST_Q31_Q7_15:
218               this->nbSamples = 33;
219               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
220               refQ7.reload(SupportTestsQ31::SAMPLES_Q7_ID,mgr,this->nbSamples);
221               outputQ7.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
222 
223             break;
224 
225             case TEST_Q31_F64_16:
226               this->nbSamples = 3;
227               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
228               refF64.reload(SupportTestsQ31::SAMPLES_F64_ID,mgr,this->nbSamples);
229               outputF64.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
230 
231             break;
232 
233             case TEST_Q31_F64_17:
234               this->nbSamples = 8;
235               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
236               refF64.reload(SupportTestsQ31::SAMPLES_F64_ID,mgr,this->nbSamples);
237               outputF64.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
238 
239             break;
240 
241             case TEST_Q31_F64_18:
242               this->nbSamples = 11;
243               inputQ31.reload(SupportTestsQ31::SAMPLES_Q31_ID,mgr,this->nbSamples);
244               refF64.reload(SupportTestsQ31::SAMPLES_F64_ID,mgr,this->nbSamples);
245               outputF64.create(this->nbSamples,SupportTestsQ31::OUT_ID,mgr);
246 
247             break;
248 
249         }
250 
251 
252 
253     }
254 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)255     void SupportTestsQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
256     {
257       (void)id;
258       switch(id)
259       {
260 
261             case TEST_COPY_Q31_1:
262             case TEST_COPY_Q31_2:
263             case TEST_COPY_Q31_3:
264             case TEST_FILL_Q31_4:
265             case TEST_FILL_Q31_5:
266             case TEST_FILL_Q31_6:
267                outputQ31.dump(mgr);
268             break;
269 
270             case TEST_Q31_FLOAT_7:
271             case TEST_Q31_FLOAT_8:
272             case TEST_Q31_FLOAT_9:
273                outputF32.dump(mgr);
274             break;
275 
276             case TEST_Q31_Q15_10:
277             case TEST_Q31_Q15_11:
278             case TEST_Q31_Q15_12:
279                outputQ15.dump(mgr);
280             break;
281 
282             case TEST_Q31_Q7_13:
283             case TEST_Q31_Q7_14:
284             case TEST_Q31_Q7_15:
285                outputQ7.dump(mgr);
286             break;
287       }
288     }
289