1 #include "SupportTestsQ7.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)(1<<8))
9 #define ABS_Q31_ERROR ((q31_t)(1<<24))
10 #define ABS_Q7_ERROR ((q7_t)10)
11 
12 #if defined ( __CC_ARM )
13 #pragma diag_suppress 170
14 #endif
15 
test_copy_q7()16     void SupportTestsQ7::test_copy_q7()
17     {
18        const q7_t *inp = inputQ7.ptr();
19        q7_t *outp = outputQ7.ptr();
20 
21 
22        arm_copy_q7(inp, outp,this->nbSamples);
23 
24 
25        ASSERT_EQ(inputQ7,outputQ7);
26        ASSERT_EMPTY_TAIL(outputQ7);
27 
28     }
29 
test_fill_q7()30     void SupportTestsQ7::test_fill_q7()
31     {
32        q7_t *outp = outputQ7.ptr();
33        q7_t val = 0x40;
34        int i;
35 
36 
37        arm_fill_q7(val, outp,this->nbSamples);
38 
39 
40        for(i=0 ; i < this->nbSamples; i++)
41        {
42           ASSERT_EQ(val,outp[i]);
43        }
44 
45        ASSERT_EMPTY_TAIL(outputQ7);
46 
47     }
48 
test_q7_f64()49     void SupportTestsQ7::test_q7_f64()
50     {
51        const q7_t *inp = inputQ7.ptr();
52        float64_t *outp = outputF64.ptr();
53 
54 
55        arm_q7_to_f64(inp, outp,this->nbSamples);
56 
57 
58        ASSERT_CLOSE_ERROR(refF64,outputF64,0.01,REL_ERROR);
59        ASSERT_EMPTY_TAIL(outputF64);
60 
61     }
62 
test_q7_float()63     void SupportTestsQ7::test_q7_float()
64     {
65        const q7_t *inp = inputQ7.ptr();
66        float32_t *outp = outputF32.ptr();
67 
68 
69        arm_q7_to_float(inp, outp,this->nbSamples);
70 
71 
72        ASSERT_CLOSE_ERROR(refF32,outputF32,0.01,REL_ERROR);
73 
74        ASSERT_EMPTY_TAIL(outputF32);
75 
76     }
77 
test_q7_q31()78     void SupportTestsQ7::test_q7_q31()
79     {
80        const q7_t *inp = inputQ7.ptr();
81        q31_t *outp = outputQ31.ptr();
82 
83 
84        arm_q7_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_q7_q15()92     void SupportTestsQ7::test_q7_q15()
93     {
94        const q7_t *inp = inputQ7.ptr();
95        q15_t *outp = outputQ15.ptr();
96 
97 
98        arm_q7_to_q15(inp, outp,this->nbSamples);
99 
100 
101        ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
102        ASSERT_EMPTY_TAIL(outputQ15);
103 
104     }
105 
106     static const q7_t testReadQ7[4]={-4,-3,-2,1};
107     static q7_t testWriteQ7[4]={0,0,0,0};
108 
test_read_q7x4_ia()109     void SupportTestsQ7::test_read_q7x4_ia()
110     {
111         q31_t result=0;
112         q7_t *p = (q7_t*)testReadQ7;
113 
114         result = read_q7x4_ia(&p);
115 
116         ASSERT_TRUE(result == 0x01FEFDFC);
117         ASSERT_TRUE(p == testReadQ7 + 4);
118     }
119 
test_read_q7x4_da()120    void SupportTestsQ7::test_read_q7x4_da()
121     {
122 
123         q31_t result=0;
124         q7_t *p = (q7_t*)testReadQ7;
125 
126         result = read_q7x4_da(&p);
127 
128         ASSERT_TRUE(result == 0x01FEFDFC);
129         ASSERT_TRUE(p == testReadQ7 - 4);
130     }
131 
test_write_q7x4_ia()132     void SupportTestsQ7::test_write_q7x4_ia()
133     {
134         q31_t val = 0x01FEFDFC;
135         q7_t *p = (q7_t*)testWriteQ7;
136 
137         testWriteQ7[0] = 0;
138         testWriteQ7[1] = 0;
139         testWriteQ7[2] = 0;
140         testWriteQ7[3] = 0;
141 
142         write_q7x4_ia(&p,val);
143 
144         ASSERT_TRUE(testWriteQ7[0] == -4);
145         ASSERT_TRUE(testWriteQ7[1] == -3);
146         ASSERT_TRUE(testWriteQ7[2] == -2);
147         ASSERT_TRUE(testWriteQ7[3] == 1);
148         ASSERT_TRUE(p == testWriteQ7 + 4);
149 
150     }
151 
152 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)153     void SupportTestsQ7::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
154     {
155 
156         (void)paramsArgs;
157         switch(id)
158         {
159 
160             case TEST_COPY_Q7_1:
161               this->nbSamples = 15;
162               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
163 
164               outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
165 
166             break;
167 
168             case TEST_COPY_Q7_2:
169               this->nbSamples = 32;
170               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
171 
172               outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
173 
174             break;
175 
176             case TEST_COPY_Q7_3:
177               this->nbSamples = 47;
178               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
179 
180               outputQ7.create(inputQ7.nbSamples(),SupportTestsQ7::OUT_ID,mgr);
181 
182             break;
183 
184             case TEST_FILL_Q7_4:
185               this->nbSamples = 15;
186 
187               outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
188 
189             break;
190 
191             case TEST_FILL_Q7_5:
192               this->nbSamples = 32;
193 
194               outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
195 
196             break;
197 
198             case TEST_FILL_Q7_6:
199               this->nbSamples = 47;
200 
201               outputQ7.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
202 
203             break;
204 
205             case TEST_Q7_FLOAT_7:
206               this->nbSamples = 15;
207               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
208               refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
209               outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
210 
211             break;
212 
213             case TEST_Q7_FLOAT_8:
214               this->nbSamples = 32;
215               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
216               refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
217               outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
218 
219             break;
220 
221             case TEST_Q7_FLOAT_9:
222               this->nbSamples = 47;
223               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
224               refF32.reload(SupportTestsQ7::SAMPLES_F32_ID,mgr,this->nbSamples);
225               outputF32.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
226 
227             break;
228 
229             case TEST_Q7_Q31_10:
230               this->nbSamples = 15;
231               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
232               refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
233               outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
234 
235             break;
236 
237             case TEST_Q7_Q31_11:
238               this->nbSamples = 32;
239               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
240               refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
241               outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
242 
243             break;
244 
245             case TEST_Q7_Q31_12:
246               this->nbSamples = 47;
247               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
248               refQ31.reload(SupportTestsQ7::SAMPLES_Q31_ID,mgr,this->nbSamples);
249               outputQ31.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
250 
251             break;
252 
253             case TEST_Q7_Q15_13:
254               this->nbSamples = 15;
255               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
256               refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
257               outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
258 
259             break;
260 
261             case TEST_Q7_Q15_14:
262               this->nbSamples = 32;
263               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
264               refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
265               outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
266 
267             break;
268 
269             case TEST_Q7_Q15_15:
270               this->nbSamples = 47;
271               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
272               refQ15.reload(SupportTestsQ7::SAMPLES_Q15_ID,mgr,this->nbSamples);
273               outputQ15.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
274 
275             break;
276 
277             case TEST_Q7_F64_19:
278               this->nbSamples = 15;
279               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
280               refF64.reload(SupportTestsQ7::SAMPLES_F64_ID,mgr,this->nbSamples);
281               outputF64.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
282 
283             break;
284 
285             case TEST_Q7_F64_20:
286               this->nbSamples = 32;
287               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
288               refF64.reload(SupportTestsQ7::SAMPLES_F64_ID,mgr,this->nbSamples);
289               outputF64.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
290 
291             break;
292 
293             case TEST_Q7_F64_21:
294               this->nbSamples = 47;
295               inputQ7.reload(SupportTestsQ7::SAMPLES_Q7_ID,mgr,this->nbSamples);
296               refF64.reload(SupportTestsQ7::SAMPLES_F64_ID,mgr,this->nbSamples);
297               outputF64.create(this->nbSamples,SupportTestsQ7::OUT_ID,mgr);
298 
299             break;
300 
301         }
302 
303 
304 
305     }
306 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)307     void SupportTestsQ7::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
308     {
309       (void)id;
310       switch(id)
311       {
312 
313             case TEST_COPY_Q7_1:
314             case TEST_COPY_Q7_2:
315             case TEST_COPY_Q7_3:
316             case TEST_FILL_Q7_4:
317             case TEST_FILL_Q7_5:
318             case TEST_FILL_Q7_6:
319                outputQ7.dump(mgr);
320             break;
321 
322             case TEST_Q7_FLOAT_7:
323             case TEST_Q7_FLOAT_8:
324             case TEST_Q7_FLOAT_9:
325                outputF32.dump(mgr);
326             break;
327 
328             case TEST_Q7_Q31_10:
329             case TEST_Q7_Q31_11:
330             case TEST_Q7_Q31_12:
331                outputQ31.dump(mgr);
332             break;
333 
334             case TEST_Q7_Q15_13:
335             case TEST_Q7_Q15_14:
336             case TEST_Q7_Q15_15:
337                outputQ15.dump(mgr);
338             break;
339       }
340     }
341