mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
fftwEnvironment_test.cpp
Go to the documentation of this file.
1/** \file fftwEnvironment_test.cpp
2 * \brief Tests FFTW environment lifecycle management.
3 */
4#include "../../../catch2/catch.hpp"
5
6#include <stdlib.h>
7#include <Eigen/Dense>
8
9#define MX_NO_ERROR_REPORTS
10
14
15/// Create and destroy fftwEnvironment, no threads, environment set
16/**
17 * \ingroup fftwEnvironment_unit_tests
18 */
19TEST_CASE( "Create and destroy fftwEnvironment, no threads, environment set", "[math::ft]" )
20{
21 int rv = setenv( "MXFFTW_WISDOM", "/tmp/.fftw", 1 );
22
23 REQUIRE( rv == 0 );
24
25 SECTION( "float" )
26 {
27 // first remove any existing file
29 REQUIRE( fname == "/tmp/.fftw/fftw_wisdom.float" );
30 remove( fname.c_str() );
31 mx::ioutils::createDirectories( "/tmp/.fftw" );
32
33 {
35 }
36
37 mx::error_t errc;
38 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
39
40 REQUIRE( errc == mx::error_t::noerror );
41
42 REQUIRE( ex == true );
43 }
44
45 SECTION( "double" )
46 {
47 // first remove any existing file
49 REQUIRE( fname == "/tmp/.fftw/fftw_wisdom.double" );
50 remove( fname.c_str() );
51 mx::ioutils::createDirectories( "/tmp/.fftw" );
52
53 {
55 }
56
57 mx::error_t errc;
58 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
59
60 REQUIRE( errc == mx::error_t::noerror );
61
62 REQUIRE( ex == true );
63 }
64
65 SECTION( "long double" )
66 {
67 // first remove any existing file
69 REQUIRE( fname == "/tmp/.fftw/fftw_wisdom.long_double" );
70 remove( fname.c_str() );
71 mx::ioutils::createDirectories( "/tmp/.fftw" );
72
73 {
75 }
76
77 mx::error_t errc;
78 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
79
80 REQUIRE( errc == mx::error_t::noerror );
81
82 REQUIRE( ex == true );
83 }
84
85 // clang-format off
86 #ifdef HASQUAD // clang-format on
87
88 SECTION( "quad" )
89 {
90 // first remove any existing file
92 REQUIRE( fname == "/tmp/.fftw/fftw_wisdom.quad" );
93 remove( fname.c_str() );
94 mx::ioutils::createDirectories( "/tmp/.fftw" );
95
96 {
98 }
99
100 mx::error_t errc;
101 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
102
103 REQUIRE( errc == mx::error_t::noerror );
104
105 REQUIRE( ex == true );
106 }
107
108 // clang-format off
109 #endif // clang-format on
110}
111
112/// Create and destroy fftwEnvironment, no threads, environment not set
113/**
114 * \ingroup fftwEnvironment_unit_tests
115 */
116TEST_CASE( "Create and destroy fftwEnvironment, no threads, environment not set", "[math::ft]" )
117{
118 int rv = setenv( "MXFFTW_WISDOM", "", 1 );
119
120 REQUIRE( rv == 0 );
121
122 SECTION( "float" )
123 {
124 // first remove any existing file
125 std::string fname = mx::math::ft::fftw_wisdom_filename<float>();
126 REQUIRE( fname == "./.fftw_wisdom.float" );
127 remove( fname.c_str() );
128
129 {
131 }
132
133 mx::error_t errc;
134 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
135
136 REQUIRE( errc == mx::error_t::noerror );
137
138 REQUIRE( ex == true );
139 }
140
141 SECTION( "double" )
142 {
143 // first remove any existing file
144 std::string fname = mx::math::ft::fftw_wisdom_filename<double>();
145 REQUIRE( fname == "./.fftw_wisdom.double" );
146 remove( fname.c_str() );
147
148 {
150 }
151
152 mx::error_t errc;
153 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
154
155 REQUIRE( errc == mx::error_t::noerror );
156
157 REQUIRE( ex == true );
158 }
159
160 SECTION( "long double" )
161 {
162 // first remove any existing file
164 REQUIRE( fname == "./.fftw_wisdom.long_double" );
165 remove( fname.c_str() );
166
167 {
169 }
170
171 mx::error_t errc;
172 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
173
174 REQUIRE( errc == mx::error_t::noerror );
175
176 REQUIRE( ex == true );
177 }
178
179 // clang-format off
180 #ifdef HASQUAD // clang-format on
181
182 SECTION( "quad" )
183 {
184 // first remove any existing file
186 REQUIRE( fname == "./.fftw_wisdom.quad" );
187 remove( fname.c_str() );
188
189 {
191 }
192
193 mx::error_t errc;
194 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
195
196 REQUIRE( errc == mx::error_t::noerror );
197
198 REQUIRE( ex == true );
199 }
200
201 // clang-format off
202 #endif // clang-format on
203}
204
205/// Create and destroy fftwEnvironment, with threads, environment set
206/**
207 * \ingroup fftwEnvironment_unit_tests
208 */
209TEST_CASE( "Create and destroy fftwEnvironment, with threads, environment set", "[math::ft]" )
210{
211 int rv = setenv( "MXFFTW_WISDOM", "/tmp/.fftw", 1 );
212
213 REQUIRE( rv == 0 );
214
215 SECTION( "float" )
216 {
217 // first remove any existing file
218 std::string fname = mx::math::ft::fftw_wisdom_filename<float>();
219 REQUIRE( fname == "/tmp/.fftw/fftw_wisdom.float" );
220 remove( fname.c_str() );
221 mx::ioutils::createDirectories( "/tmp/.fftw" );
222
223 {
225 }
226
227 mx::error_t errc;
228 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
229
230 REQUIRE( errc == mx::error_t::noerror );
231
232 REQUIRE( ex == true );
233 }
234
235 SECTION( "double" )
236 {
237 // first remove any existing file
238 std::string fname = mx::math::ft::fftw_wisdom_filename<double>();
239 REQUIRE( fname == "/tmp/.fftw/fftw_wisdom.double" );
240 remove( fname.c_str() );
241 mx::ioutils::createDirectories( "/tmp/.fftw" );
242
243 {
245 }
246
247 mx::error_t errc;
248 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
249
250 REQUIRE( errc == mx::error_t::noerror );
251
252 REQUIRE( ex == true );
253 }
254
255 SECTION( "long double" )
256 {
257 // first remove any existing file
259 REQUIRE( fname == "/tmp/.fftw/fftw_wisdom.long_double" );
260 remove( fname.c_str() );
261 mx::ioutils::createDirectories( "/tmp/.fftw" );
262
263 {
265 }
266
267 mx::error_t errc;
268 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
269
270 REQUIRE( errc == mx::error_t::noerror );
271
272 REQUIRE( ex == true );
273 }
274
275 // clang-format off
276 #ifdef HASQUAD // clang-format on
277
278 SECTION( "quad" )
279 {
280 // first remove any existing file
282 REQUIRE( fname == "/tmp/.fftw/fftw_wisdom.quad" );
283 remove( fname.c_str() );
284 mx::ioutils::createDirectories( "/tmp/.fftw" );
285
286 {
288 }
289
290 mx::error_t errc;
291 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
292
293 REQUIRE( errc == mx::error_t::noerror );
294
295 REQUIRE( ex == true );
296 }
297
298 // clang-format off
299 #endif // clang-format on
300}
301
302/// Create and destroy fftwEnvironment, with threads, environment not set
303/**
304 * \ingroup fftwEnvironment_unit_tests
305 */
306TEST_CASE( "Create and destroy fftwEnvironment, with threads, environment not set", "[math::ft]" )
307{
308 int rv = setenv( "MXFFTW_WISDOM", "", 1 );
309
310 REQUIRE( rv == 0 );
311
312 SECTION( "float" )
313 {
314 // first remove any existing file
315 std::string fname = mx::math::ft::fftw_wisdom_filename<float>();
316 REQUIRE( fname == "./.fftw_wisdom.float" );
317 remove( fname.c_str() );
318
319 {
321 }
322
323 mx::error_t errc;
324 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
325
326 REQUIRE( errc == mx::error_t::noerror );
327
328 REQUIRE( ex == true );
329 }
330
331 SECTION( "double" )
332 {
333 // first remove any existing file
334 std::string fname = mx::math::ft::fftw_wisdom_filename<double>();
335 REQUIRE( fname == "./.fftw_wisdom.double" );
336 remove( fname.c_str() );
337
338 {
340 }
341
342 mx::error_t errc;
343 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
344
345 REQUIRE( errc == mx::error_t::noerror );
346
347 REQUIRE( ex == true );
348 }
349
350 SECTION( "long double" )
351 {
352 // first remove any existing file
354 REQUIRE( fname == "./.fftw_wisdom.long_double" );
355 remove( fname.c_str() );
356
357 {
359 }
360
361 mx::error_t errc;
362 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
363
364 REQUIRE( errc == mx::error_t::noerror );
365
366 REQUIRE( ex == true );
367 }
368
369 // clang-format off
370 #ifdef HASQUAD // clang-format on
371
372 SECTION( "quad" )
373 {
374 // first remove any existing file
376 REQUIRE( fname == "./.fftw_wisdom.quad" );
377 remove( fname.c_str() );
378
379 {
381 }
382
383 mx::error_t errc;
384 bool ex = mx::ioutils::exists<mx::verbose::d>( fname, errc );
385
386 REQUIRE( errc == mx::error_t::noerror );
387
388 REQUIRE( ex == true );
389 }
390
391 // clang-format off
392 #endif // clang-format on
393}
Declares and defines the fftwEnvironment manager.
Declares and defines templatized wrappers for the fftw library.
Declarations of utilities for working with files.
error_t
The mxlib error codes.
Definition error_t.hpp:26
@ noerror
No error has occurred.
Definition error_t.hpp:27
TEST_CASE("Create and destroy fftwEnvironment, no threads, environment set", "[math::ft]")
Create and destroy fftwEnvironment, no threads, environment set.
std::string fftw_wisdom_filename()
Create the mxlib standard wisdom filename for the type.
bool exists(const std::string &path, mx::error_t &errc)
Check if a path exists.
error_t createDirectories(const std::string &path)
Create a directory or directories.
Definition fileUtils.cpp:83
Manage the FFTW environment and wisdom using RAII.