1 /*
2 * Copyright (c) 2020 Stephanos Ioannidis <root@stephanos.io>
3 * Copyright (C) 2010-2020 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 "rf64.pat"
16
17 #define SNR_ERROR_THRESH ((float64_t)250)
18
test_arm_rfft_f64_real_backend(bool inverse,const uint64_t * input,const uint64_t * ref,size_t length)19 static void test_arm_rfft_f64_real_backend(
20 bool inverse, const uint64_t *input, const uint64_t *ref, size_t length)
21 {
22 arm_rfft_fast_instance_f64 inst;
23 float64_t *output, *scratch;
24
25 /* Initialise instance */
26 arm_rfft_fast_init_f64(&inst, length);
27
28 /* Allocate output buffer */
29 output = malloc(length * sizeof(float64_t));
30 zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
31
32 scratch = calloc(length + 2, sizeof(float64_t)); /* see #24701 */
33 zassert_not_null(scratch, ASSERT_MSG_BUFFER_ALLOC_FAILED);
34
35 /* Load data in place */
36 memcpy(scratch, input, length * sizeof(float64_t));
37
38 /* Run test function */
39 arm_rfft_fast_f64(&inst, scratch, output, inverse);
40
41 /* Validate output */
42 zassert_true(
43 test_snr_error_f64(length, output, (float64_t *)ref,
44 SNR_ERROR_THRESH),
45 ASSERT_MSG_SNR_LIMIT_EXCEED);
46
47 /* Free output buffer */
48 free(output);
49 free(scratch);
50 }
51
test_arm_rfft_f64_real(const uint64_t * input,const uint64_t * ref,size_t length)52 static void test_arm_rfft_f64_real(
53 const uint64_t *input, const uint64_t *ref, size_t length)
54 {
55 test_arm_rfft_f64_real_backend(false, input, ref, length);
56 }
57
58 DEFINE_TEST_VARIANT3(transform_rf64,
59 arm_rfft_f64_real, noisy_32,
60 in_rfft_noisy_32, ref_rfft_noisy_32, 32);
61
62 DEFINE_TEST_VARIANT3(transform_rf64,
63 arm_rfft_f64_real, noisy_64,
64 in_rfft_noisy_64, ref_rfft_noisy_64, 64);
65
66 DEFINE_TEST_VARIANT3(transform_rf64,
67 arm_rfft_f64_real, noisy_128,
68 in_rfft_noisy_128, ref_rfft_noisy_128, 128);
69
70 DEFINE_TEST_VARIANT3(transform_rf64,
71 arm_rfft_f64_real, noisy_256,
72 in_rfft_noisy_256, ref_rfft_noisy_256, 256);
73
74 DEFINE_TEST_VARIANT3(transform_rf64,
75 arm_rfft_f64_real, noisy_512,
76 in_rfft_noisy_512, ref_rfft_noisy_512, 512);
77
78 DEFINE_TEST_VARIANT3(transform_rf64,
79 arm_rfft_f64_real, noisy_1024,
80 in_rfft_noisy_1024, ref_rfft_noisy_1024, 1024);
81
82 DEFINE_TEST_VARIANT3(transform_rf64,
83 arm_rfft_f64_real, noisy_2048,
84 in_rfft_noisy_2048, ref_rfft_noisy_2048, 2048);
85
86 DEFINE_TEST_VARIANT3(transform_rf64,
87 arm_rfft_f64_real, noisy_4096,
88 in_rfft_noisy_4096, ref_rfft_noisy_4096, 4096);
89
90 DEFINE_TEST_VARIANT3(transform_rf64,
91 arm_rfft_f64_real, step_32,
92 in_rfft_step_32, ref_rfft_step_32, 32);
93
94 DEFINE_TEST_VARIANT3(transform_rf64,
95 arm_rfft_f64_real, step_64,
96 in_rfft_step_64, ref_rfft_step_64, 64);
97
98 DEFINE_TEST_VARIANT3(transform_rf64,
99 arm_rfft_f64_real, step_128,
100 in_rfft_step_128, ref_rfft_step_128, 128);
101
102 DEFINE_TEST_VARIANT3(transform_rf64,
103 arm_rfft_f64_real, step_256,
104 in_rfft_step_256, ref_rfft_step_256, 256);
105
106 DEFINE_TEST_VARIANT3(transform_rf64,
107 arm_rfft_f64_real, step_512,
108 in_rfft_step_512, ref_rfft_step_512, 512);
109
110 DEFINE_TEST_VARIANT3(transform_rf64,
111 arm_rfft_f64_real, step_1024,
112 in_rfft_step_1024, ref_rfft_step_1024, 1024);
113
114 DEFINE_TEST_VARIANT3(transform_rf64,
115 arm_rfft_f64_real, step_2048,
116 in_rfft_step_2048, ref_rfft_step_2048, 2048);
117
118 DEFINE_TEST_VARIANT3(transform_rf64,
119 arm_rfft_f64_real, step_4096,
120 in_rfft_step_4096, ref_rfft_step_4096, 4096);
121
test_arm_rifft_f64_real(const uint64_t * input,const uint64_t * ref,size_t length)122 static void test_arm_rifft_f64_real(
123 const uint64_t *input, const uint64_t *ref, size_t length)
124 {
125 test_arm_rfft_f64_real_backend(true, input, ref, length);
126 }
127
128 DEFINE_TEST_VARIANT3(transform_rf64,
129 arm_rifft_f64_real, noisy_32,
130 in_rifft_noisy_32, in_rfft_noisy_32, 32);
131
132 DEFINE_TEST_VARIANT3(transform_rf64,
133 arm_rifft_f64_real, noisy_64,
134 in_rifft_noisy_64, in_rfft_noisy_64, 64);
135
136 DEFINE_TEST_VARIANT3(transform_rf64,
137 arm_rifft_f64_real, noisy_128,
138 in_rifft_noisy_128, in_rfft_noisy_128, 128);
139
140 DEFINE_TEST_VARIANT3(transform_rf64,
141 arm_rifft_f64_real, noisy_256,
142 in_rifft_noisy_256, in_rfft_noisy_256, 256);
143
144 DEFINE_TEST_VARIANT3(transform_rf64,
145 arm_rifft_f64_real, noisy_512,
146 in_rifft_noisy_512, in_rfft_noisy_512, 512);
147
148 DEFINE_TEST_VARIANT3(transform_rf64,
149 arm_rifft_f64_real, noisy_1024,
150 in_rifft_noisy_1024, in_rfft_noisy_1024, 1024);
151
152 DEFINE_TEST_VARIANT3(transform_rf64,
153 arm_rifft_f64_real, noisy_2048,
154 in_rifft_noisy_2048, in_rfft_noisy_2048, 2048);
155
156 DEFINE_TEST_VARIANT3(transform_rf64,
157 arm_rifft_f64_real, noisy_4096,
158 in_rifft_noisy_4096, in_rfft_noisy_4096, 4096);
159
160 DEFINE_TEST_VARIANT3(transform_rf64,
161 arm_rifft_f64_real, step_32,
162 in_rifft_step_32, in_rfft_step_32, 32);
163
164 DEFINE_TEST_VARIANT3(transform_rf64,
165 arm_rifft_f64_real, step_64,
166 in_rifft_step_64, in_rfft_step_64, 64);
167
168 DEFINE_TEST_VARIANT3(transform_rf64,
169 arm_rifft_f64_real, step_128,
170 in_rifft_step_128, in_rfft_step_128, 128);
171
172 DEFINE_TEST_VARIANT3(transform_rf64,
173 arm_rifft_f64_real, step_256,
174 in_rifft_step_256, in_rfft_step_256, 256);
175
176 DEFINE_TEST_VARIANT3(transform_rf64,
177 arm_rifft_f64_real, step_512,
178 in_rifft_step_512, in_rfft_step_512, 512);
179
180 DEFINE_TEST_VARIANT3(transform_rf64,
181 arm_rifft_f64_real, step_1024,
182 in_rifft_step_1024, in_rfft_step_1024, 1024);
183
184 DEFINE_TEST_VARIANT3(transform_rf64,
185 arm_rifft_f64_real, step_2048,
186 in_rifft_step_2048, in_rfft_step_2048, 2048);
187
188 DEFINE_TEST_VARIANT3(transform_rf64,
189 arm_rifft_f64_real, step_4096,
190 in_rifft_step_4096, in_rfft_step_4096, 4096);
191
192 ZTEST_SUITE(transform_rf64, NULL, NULL, NULL, NULL, NULL);
193