1 #include "ExampleCategoryF32.h"
2 #include <stdio.h>
3 #include "Error.h"
4 
5 /*
6 
7 Tests to write and test criteria depend on the algorithm.
8 When SNR is meaningful, SNR threshold depends on the type.
9 CMSIS-DSP tests are using similar SNR values for different type (f32, q31, q15, q7)
10 
11 */
12 #define SNR_THRESHOLD 120
13 
14 /*
15 
16 With thie threshold, the test will fail
17 
18 #define REL_ERROR (2.0e-6)
19 
20 */
21 
22 #define REL_ERROR (5.0e-6)
23 
test_op_f32()24     void ExampleCategoryF32::test_op_f32()
25     {
26         /* Get a pointer to the input data.
27            For benchmark, getting pointers should be done in the setUp function
28            since there is an overhead. Lot of checks are done before returning a pointer.
29         */
30         const float32_t *inp1=input1.ptr();
31         const float32_t *inp2=input2.ptr();
32 
33         /* Get a pointer to the output buffer */
34         float32_t *outp=output.ptr();
35 
36         /* Run the test */
37         arm_add_f32(inp1,inp2,outp,input1.nbSamples());
38 
39         /* Check there is no buffer overflow on the output */
40         ASSERT_EMPTY_TAIL(output);
41 
42         /* Check SNR error */
43         ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
44 
45         /* Check relative error */
46         ASSERT_REL_ERROR(output,ref,REL_ERROR);
47 
48     }
49 
50 
51 
52     /*
53 
54      setUp function is used to load the patterns and create required buffers
55 
56     */
setUp(Testing::testID_t id,std::vector<Testing::param_t> & params,Client::PatternMgr * mgr)57     void ExampleCategoryF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
58     {
59 
60        Testing::nbSamples_t nb=MAX_NB_SAMPLES;
61        (void)params;
62 
63        /*
64 
65          All IDs can be found in GeneratedInclude/ExampleCategoryF32_decl.h
66 
67        */
68 
69        /*
70            Different allocations depending on the test.
71        */
72        switch(id)
73        {
74           /* In both tests, the same function is tested as defined in desc.txt.
75              But different configurations are used.
76           */
77           case ExampleCategoryF32::TEST_OP_F32_1:
78              /* Load  patterns with all samples */
79              input1.reload(ExampleCategoryF32::INPUT1_F32_ID,mgr);
80              input2.reload(ExampleCategoryF32::INPUT2_F32_ID,mgr);
81              ref.reload(ExampleCategoryF32::REF_OUT_F32_ID,mgr);
82           break;
83 
84           case ExampleCategoryF32::TEST_OP_F32_2:
85              nb = 9;
86              /* Load  patterns with 9 samples */
87              input1.reload(ExampleCategoryF32::INPUT1_F32_ID,mgr,nb);
88              input2.reload(ExampleCategoryF32::INPUT2_F32_ID,mgr,nb);
89              ref.reload(ExampleCategoryF32::REF_OUT_F32_ID,mgr,nb);
90           break;
91 
92        }
93 
94        /* Create output buffer with same size as reference pattern */
95        output.create(ref.nbSamples(),ExampleCategoryF32::OUT_F32_ID,mgr);
96     }
97 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)98     void ExampleCategoryF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
99     {
100        (void)id;
101         /*
102            Dump output buffer into a file.
103 
104            Location of the file is defined by Folder directives in desc.txt test
105            description file and relative to the Output folder.
106 
107         */
108         output.dump(mgr);
109     }
110