1 /*
2  * Copyright (c) 2021 Stephanos Ioannidis <root@stephanos.io>
3  * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <zephyr/ztest.h>
9 #include <zephyr/kernel.h>
10 #include <stdlib.h>
11 #include <arm_math.h>
12 #include <arm_const_structs.h>
13 #include "../../common/test_common.h"
14 
15 #include "cf64.pat"
16 
17 #define SNR_ERROR_THRESH	((float64_t)250)
18 
test_arm_cfft_f64_cmplx_backend(bool inverse,const uint64_t * input,const uint64_t * ref,size_t length)19 static void test_arm_cfft_f64_cmplx_backend(
20 	bool inverse, const uint64_t *input, const uint64_t *ref, size_t length)
21 {
22 	arm_cfft_instance_f64 inst;
23 	float64_t *output;
24 	arm_status status;
25 
26 	/* Initialise instance */
27 	status = arm_cfft_init_f64(&inst, length / 2);
28 
29 	zassert_equal(status, ARM_MATH_SUCCESS,
30 		      ASSERT_MSG_INCORRECT_COMP_RESULT);
31 
32 	/* Allocate output buffer */
33 	output = malloc(length * sizeof(float64_t));
34 	zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
35 
36 	/* Load data in place */
37 	memcpy(output, input, length * sizeof(float64_t));
38 
39 	/* Run test function */
40 	arm_cfft_f64(&inst, output, inverse, true);
41 
42 	/* Validate output */
43 	zassert_true(
44 		test_snr_error_f64(length, output, (float64_t *)ref,
45 			SNR_ERROR_THRESH),
46 		ASSERT_MSG_SNR_LIMIT_EXCEED);
47 
48 	/* Free output buffer */
49 	free(output);
50 }
51 
test_arm_cfft_f64_cmplx(const uint64_t * input,const uint64_t * ref,size_t length)52 static void test_arm_cfft_f64_cmplx(
53 	const uint64_t *input, const uint64_t *ref, size_t length)
54 {
55 	test_arm_cfft_f64_cmplx_backend(false, input, ref, length);
56 }
57 
58 DEFINE_TEST_VARIANT3(transform_cf64,
59 	arm_cfft_f64_cmplx, noisy_16,
60 	in_cfft_noisy_16, ref_cfft_noisy_16, 32);
61 
62 DEFINE_TEST_VARIANT3(transform_cf64,
63 	arm_cfft_f64_cmplx, noisy_32,
64 	in_cfft_noisy_32, ref_cfft_noisy_32, 64);
65 
66 DEFINE_TEST_VARIANT3(transform_cf64,
67 	arm_cfft_f64_cmplx, noisy_64,
68 	in_cfft_noisy_64, ref_cfft_noisy_64, 128);
69 
70 DEFINE_TEST_VARIANT3(transform_cf64,
71 	arm_cfft_f64_cmplx, noisy_128,
72 	in_cfft_noisy_128, ref_cfft_noisy_128, 256);
73 
74 DEFINE_TEST_VARIANT3(transform_cf64,
75 	arm_cfft_f64_cmplx, noisy_256,
76 	in_cfft_noisy_256, ref_cfft_noisy_256, 512);
77 
78 DEFINE_TEST_VARIANT3(transform_cf64,
79 	arm_cfft_f64_cmplx, noisy_512,
80 	in_cfft_noisy_512, ref_cfft_noisy_512, 1024);
81 
82 DEFINE_TEST_VARIANT3(transform_cf64,
83 	arm_cfft_f64_cmplx, noisy_1024,
84 	in_cfft_noisy_1024, ref_cfft_noisy_1024, 2048);
85 
86 DEFINE_TEST_VARIANT3(transform_cf64,
87 	arm_cfft_f64_cmplx, noisy_2048,
88 	in_cfft_noisy_2048, ref_cfft_noisy_2048, 4096);
89 
90 DEFINE_TEST_VARIANT3(transform_cf64,
91 	arm_cfft_f64_cmplx, noisy_4096,
92 	in_cfft_noisy_4096, ref_cfft_noisy_4096, 8192);
93 
94 DEFINE_TEST_VARIANT3(transform_cf64,
95 	arm_cfft_f64_cmplx, step_16,
96 	in_cfft_step_16, ref_cfft_step_16, 32);
97 
98 DEFINE_TEST_VARIANT3(transform_cf64,
99 	arm_cfft_f64_cmplx, step_32,
100 	in_cfft_step_32, ref_cfft_step_32, 64);
101 
102 DEFINE_TEST_VARIANT3(transform_cf64,
103 	arm_cfft_f64_cmplx, step_64,
104 	in_cfft_step_64, ref_cfft_step_64, 128);
105 
106 DEFINE_TEST_VARIANT3(transform_cf64,
107 	arm_cfft_f64_cmplx, step_128,
108 	in_cfft_step_128, ref_cfft_step_128, 256);
109 
110 DEFINE_TEST_VARIANT3(transform_cf64,
111 	arm_cfft_f64_cmplx, step_256,
112 	in_cfft_step_256, ref_cfft_step_256, 512);
113 
114 DEFINE_TEST_VARIANT3(transform_cf64,
115 	arm_cfft_f64_cmplx, step_512,
116 	in_cfft_step_512, ref_cfft_step_512, 1024);
117 
118 DEFINE_TEST_VARIANT3(transform_cf64,
119 	arm_cfft_f64_cmplx, step_1024,
120 	in_cfft_step_1024, ref_cfft_step_1024, 2048);
121 
122 DEFINE_TEST_VARIANT3(transform_cf64,
123 	arm_cfft_f64_cmplx, step_2048,
124 	in_cfft_step_2048, ref_cfft_step_2048, 4096);
125 
126 DEFINE_TEST_VARIANT3(transform_cf64,
127 	arm_cfft_f64_cmplx, step_4096,
128 	in_cfft_step_4096, ref_cfft_step_4096, 8192);
129 
test_arm_cifft_f64_cmplx(const uint64_t * input,const uint64_t * ref,size_t length)130 static void test_arm_cifft_f64_cmplx(
131 	const uint64_t *input, const uint64_t *ref, size_t length)
132 {
133 	test_arm_cfft_f64_cmplx_backend(true, input, ref, length);
134 }
135 
136 DEFINE_TEST_VARIANT3(transform_cf64,
137 	arm_cifft_f64_cmplx, noisy_16,
138 	in_cifft_noisy_16, in_cfft_noisy_16, 32);
139 
140 DEFINE_TEST_VARIANT3(transform_cf64,
141 	arm_cifft_f64_cmplx, noisy_32,
142 	in_cifft_noisy_32, in_cfft_noisy_32, 64);
143 
144 DEFINE_TEST_VARIANT3(transform_cf64,
145 	arm_cifft_f64_cmplx, noisy_64,
146 	in_cifft_noisy_64, in_cfft_noisy_64, 128);
147 
148 DEFINE_TEST_VARIANT3(transform_cf64,
149 	arm_cifft_f64_cmplx, noisy_128,
150 	in_cifft_noisy_128, in_cfft_noisy_128, 256);
151 
152 DEFINE_TEST_VARIANT3(transform_cf64,
153 	arm_cifft_f64_cmplx, noisy_256,
154 	in_cifft_noisy_256, in_cfft_noisy_256, 512);
155 
156 DEFINE_TEST_VARIANT3(transform_cf64,
157 	arm_cifft_f64_cmplx, noisy_512,
158 	in_cifft_noisy_512, in_cfft_noisy_512, 1024);
159 
160 DEFINE_TEST_VARIANT3(transform_cf64,
161 	arm_cifft_f64_cmplx, noisy_1024,
162 	in_cifft_noisy_1024, in_cfft_noisy_1024, 2048);
163 
164 DEFINE_TEST_VARIANT3(transform_cf64,
165 	arm_cifft_f64_cmplx, noisy_2048,
166 	in_cifft_noisy_2048, in_cfft_noisy_2048, 4096);
167 
168 DEFINE_TEST_VARIANT3(transform_cf64,
169 	arm_cifft_f64_cmplx, noisy_4096,
170 	in_cifft_noisy_4096, in_cfft_noisy_4096, 8192);
171 
172 DEFINE_TEST_VARIANT3(transform_cf64,
173 	arm_cifft_f64_cmplx, step_16,
174 	in_cifft_step_16, in_cfft_step_16, 32);
175 
176 DEFINE_TEST_VARIANT3(transform_cf64,
177 	arm_cifft_f64_cmplx, step_32,
178 	in_cifft_step_32, in_cfft_step_32, 64);
179 
180 DEFINE_TEST_VARIANT3(transform_cf64,
181 	arm_cifft_f64_cmplx, step_64,
182 	in_cifft_step_64, in_cfft_step_64, 128);
183 
184 DEFINE_TEST_VARIANT3(transform_cf64,
185 	arm_cifft_f64_cmplx, step_128,
186 	in_cifft_step_128, in_cfft_step_128, 256);
187 
188 DEFINE_TEST_VARIANT3(transform_cf64,
189 	arm_cifft_f64_cmplx, step_256,
190 	in_cifft_step_256, in_cfft_step_256, 512);
191 
192 DEFINE_TEST_VARIANT3(transform_cf64,
193 	arm_cifft_f64_cmplx, step_512,
194 	in_cifft_step_512, in_cfft_step_512, 1024);
195 
196 DEFINE_TEST_VARIANT3(transform_cf64,
197 	arm_cifft_f64_cmplx, step_1024,
198 	in_cifft_step_1024, in_cfft_step_1024, 2048);
199 
200 DEFINE_TEST_VARIANT3(transform_cf64,
201 	arm_cifft_f64_cmplx, step_2048,
202 	in_cifft_step_2048, in_cfft_step_2048, 4096);
203 
204 DEFINE_TEST_VARIANT3(transform_cf64,
205 	arm_cifft_f64_cmplx, step_4096,
206 	in_cifft_step_4096, in_cfft_step_4096, 8192);
207 
208 ZTEST_SUITE(transform_cf64, NULL, NULL, NULL, NULL, NULL);
209