1 #include "SupportTestsQ15.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-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 
12 #if defined ( __CC_ARM )
13 #pragma diag_suppress 170
14 #endif
15 
test_copy_q15()16     void SupportTestsQ15::test_copy_q15()
17     {
18        const q15_t *inp = inputQ15.ptr();
19        q15_t *outp = outputQ15.ptr();
20 
21 
22        arm_copy_q15(inp, outp,this->nbSamples);
23 
24 
25        ASSERT_EQ(inputQ15,outputQ15);
26        ASSERT_EMPTY_TAIL(outputQ15);
27 
28     }
29 
test_fill_q15()30     void SupportTestsQ15::test_fill_q15()
31     {
32        q15_t *outp = outputQ15.ptr();
33        q15_t val = 0x4000;
34        int i;
35 
36 
37        arm_fill_q15(val, outp,this->nbSamples);
38 
39 
40        for(i=0 ; i < this->nbSamples; i++)
41        {
42           ASSERT_EQ(val,outp[i]);
43        }
44        ASSERT_EMPTY_TAIL(outputQ15);
45 
46     }
47 
test_q15_f64()48     void SupportTestsQ15::test_q15_f64()
49     {
50        const q15_t *inp = inputQ15.ptr();
51        float64_t *outp = outputF64.ptr();
52 
53 
54        arm_q15_to_f64(inp, outp,this->nbSamples);
55 
56 
57        ASSERT_REL_ERROR(refF64,outputF64,REL_ERROR);
58        ASSERT_EMPTY_TAIL(outputF64);
59 
60     }
61 
test_q15_float()62     void SupportTestsQ15::test_q15_float()
63     {
64        const q15_t *inp = inputQ15.ptr();
65        float32_t *outp = outputF32.ptr();
66 
67 
68        arm_q15_to_float(inp, outp,this->nbSamples);
69 
70 
71        ASSERT_REL_ERROR(refF32,outputF32,REL_ERROR);
72        ASSERT_EMPTY_TAIL(outputF32);
73 
74     }
75 
76 
77 
test_q15_q31()78     void SupportTestsQ15::test_q15_q31()
79     {
80        const q15_t *inp = inputQ15.ptr();
81        q31_t *outp = outputQ31.ptr();
82 
83 
84        arm_q15_to_q31(inp, outp,this->nbSamples);
85 
86 
87        ASSERT_NEAR_EQ(refQ31,outputQ31,ABS_Q31_ERROR);
88        ASSERT_EMPTY_TAIL(outputQ31);
89 
90     }
91 
test_q15_q7()92     void SupportTestsQ15::test_q15_q7()
93     {
94        const q15_t *inp = inputQ15.ptr();
95        q7_t *outp = outputQ7.ptr();
96 
97 
98        arm_q15_to_q7(inp, outp,this->nbSamples);
99 
100 
101        ASSERT_NEAR_EQ(refQ7,outputQ7,ABS_Q7_ERROR);
102        ASSERT_EMPTY_TAIL(outputQ7);
103 
104     }
105 
106     __ALIGNED(2) static const q15_t testReadQ15[2]={-2,1};
107     __ALIGNED(2) static q15_t testWriteQ15[2]={0,0};
108 
test_read_q15x2()109     void SupportTestsQ15::test_read_q15x2()
110     {
111         q31_t result=0;
112 
113         result = read_q15x2((q15_t*)testReadQ15);
114 
115         ASSERT_TRUE(result == 0x0001FFFE);
116 
117     }
118 
test_read_q15x2_ia()119     void SupportTestsQ15::test_read_q15x2_ia()
120     {
121         q31_t result=0;
122         q15_t *p = (q15_t*)testReadQ15;
123 
124         result = read_q15x2_ia(&p);
125 
126         ASSERT_TRUE(result == 0x0001FFFE);
127         ASSERT_TRUE(p == testReadQ15 + 2);
128     }
129 
test_read_q15x2_da()130     void SupportTestsQ15::test_read_q15x2_da()
131     {
132         q31_t result=0;
133         q15_t *p = (q15_t*)testReadQ15;
134 
135         result = read_q15x2_da(&p);
136 
137         ASSERT_TRUE(result == 0x0001FFFE);
138         ASSERT_TRUE(p == testReadQ15 - 2);
139     }
140 
test_write_q15x2_ia()141     void SupportTestsQ15::test_write_q15x2_ia()
142     {
143          q31_t val = 0x0001FFFE;
144          q15_t *p = testWriteQ15;
145 
146          testWriteQ15[0] = 0;
147          testWriteQ15[1] = 0;
148 
149          write_q15x2_ia(&p,val);
150 
151          ASSERT_TRUE(testWriteQ15[0] == -2);
152          ASSERT_TRUE(testWriteQ15[1] == 1);
153          ASSERT_TRUE(p == testWriteQ15 + 2);
154 
155     }
156 
test_write_q15x2()157     void SupportTestsQ15::test_write_q15x2()
158     {
159          q31_t val = 0x0001FFFE;
160 
161          testWriteQ15[0] = 0;
162          testWriteQ15[1] = 0;
163 
164          write_q15x2(testWriteQ15,val);
165 
166          ASSERT_TRUE(testWriteQ15[0] == -2);
167          ASSERT_TRUE(testWriteQ15[1] == 1);
168     }
169 
170 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)171     void SupportTestsQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
172     {
173 
174         (void)paramsArgs;
175         switch(id)
176         {
177 
178             case TEST_COPY_Q15_1:
179               this->nbSamples = 7;
180               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
181 
182               outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
183 
184             break;
185 
186             case TEST_COPY_Q15_2:
187               this->nbSamples = 16;
188               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
189 
190               outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
191 
192             break;
193 
194             case TEST_COPY_Q15_3:
195               this->nbSamples = 23;
196               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
197 
198               outputQ15.create(inputQ15.nbSamples(),SupportTestsQ15::OUT_ID,mgr);
199 
200             break;
201 
202             case TEST_FILL_Q15_4:
203               this->nbSamples = 7;
204 
205               outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
206 
207             break;
208 
209             case TEST_FILL_Q15_5:
210               this->nbSamples = 16;
211 
212               outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
213 
214             break;
215 
216             case TEST_FILL_Q15_6:
217               this->nbSamples = 23;
218 
219               outputQ15.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
220 
221             break;
222 
223             case TEST_Q15_FLOAT_7:
224               this->nbSamples = 7;
225               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
226               refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
227               outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
228 
229             break;
230 
231             case TEST_Q15_FLOAT_8:
232               this->nbSamples = 16;
233               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
234               refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
235               outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
236 
237             break;
238 
239             case TEST_Q15_FLOAT_9:
240               this->nbSamples = 23;
241               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
242               refF32.reload(SupportTestsQ15::SAMPLES_F32_ID,mgr,this->nbSamples);
243               outputF32.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
244 
245             break;
246 
247             case TEST_Q15_Q31_10:
248               this->nbSamples = 7;
249               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
250               refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
251               outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
252 
253             break;
254 
255             case TEST_Q15_Q31_11:
256               this->nbSamples = 16;
257               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
258               refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
259               outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
260 
261             break;
262 
263             case TEST_Q15_Q31_12:
264               this->nbSamples = 23;
265               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
266               refQ31.reload(SupportTestsQ15::SAMPLES_Q31_ID,mgr,this->nbSamples);
267               outputQ31.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
268 
269             break;
270 
271             case TEST_Q15_Q7_13:
272               this->nbSamples = 7;
273               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
274               refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
275               outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
276 
277             break;
278 
279             case TEST_Q15_Q7_14:
280               this->nbSamples = 16;
281               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
282               refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
283               outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
284 
285             break;
286 
287             case TEST_Q15_Q7_15:
288               this->nbSamples = 23;
289               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
290               refQ7.reload(SupportTestsQ15::SAMPLES_Q7_ID,mgr,this->nbSamples);
291               outputQ7.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
292 
293             break;
294 
295             case TEST_Q15_F64_21:
296               this->nbSamples = 7;
297               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
298               refF64.reload(SupportTestsQ15::SAMPLES_F64_ID,mgr,this->nbSamples);
299               outputF64.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
300 
301             break;
302 
303             case TEST_Q15_F64_22:
304               this->nbSamples = 16;
305               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
306               refF64.reload(SupportTestsQ15::SAMPLES_F64_ID,mgr,this->nbSamples);
307               outputF64.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
308 
309             break;
310 
311             case TEST_Q15_F64_23:
312               this->nbSamples = 23;
313               inputQ15.reload(SupportTestsQ15::SAMPLES_Q15_ID,mgr,this->nbSamples);
314               refF64.reload(SupportTestsQ15::SAMPLES_F64_ID,mgr,this->nbSamples);
315               outputF64.create(this->nbSamples,SupportTestsQ15::OUT_ID,mgr);
316 
317             break;
318 
319         }
320 
321 
322 
323     }
324 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)325     void SupportTestsQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
326     {
327       (void)id;
328       switch(id)
329       {
330 
331             case TEST_COPY_Q15_1:
332             case TEST_COPY_Q15_2:
333             case TEST_COPY_Q15_3:
334             case TEST_FILL_Q15_4:
335             case TEST_FILL_Q15_5:
336             case TEST_FILL_Q15_6:
337                outputQ15.dump(mgr);
338             break;
339 
340             case TEST_Q15_FLOAT_7:
341             case TEST_Q15_FLOAT_8:
342             case TEST_Q15_FLOAT_9:
343                outputF32.dump(mgr);
344             break;
345 
346             case TEST_Q15_Q31_10:
347             case TEST_Q15_Q31_11:
348             case TEST_Q15_Q31_12:
349                outputQ31.dump(mgr);
350             break;
351 
352             case TEST_Q15_Q7_13:
353             case TEST_Q15_Q7_14:
354             case TEST_Q15_Q7_15:
355                outputQ7.dump(mgr);
356             break;
357       }
358     }
359