1 /*****************************************************************************
2 
3         test.cpp
4         By Laurent de Soras
5 
6 --- Legal stuff ---
7 
8 This program is free software. It comes without any warranty, to
9 the extent permitted by applicable law. You can redistribute it
10 and/or modify it under the terms of the Do What The Fuck You Want
11 To Public License, Version 2, as published by Sam Hocevar. See
12 http://sam.zoy.org/wtfpl/COPYING for more details.
13 
14 *Tab=3***********************************************************************/
15 
16 
17 
18 #if defined (_MSC_VER)
19 	#pragma warning (4 : 4786) // "identifier was truncated to '255' characters in the debug information"
20 	#pragma warning (4 : 4800) // "forcing value to bool 'true' or 'false' (performance warning)"
21 #endif
22 
23 
24 
25 /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
26 
27 #include	"ffft/test/conf.h"
28 #include	"ffft/test/TestHelperFixLen.h"
29 #include	"ffft/test/TestHelperNormal.h"
30 
31 #if defined (_MSC_VER)
32 #include	<crtdbg.h>
33 #include	<new.h>
34 #endif	// _MSC_VER
35 
36 #include	<new>
37 
38 #include	<cassert>
39 #include	<cstdio>
40 
41 
42 
43 /*\\\ FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
44 
45 
46 
47 static int	TEST_perform_test_accuracy_all ();
48 static int	TEST_perform_test_speed_all ();
49 
50 static void	TEST_prog_init ();
51 static void	TEST_prog_end ();
52 
53 
54 
main(int argc,char * argv[])55 int main (int argc, char *argv [])
56 {
57 	using namespace std;
58 
59 	int				ret_val = 0;
60 
61 	TEST_prog_init ();
62 
63 	try
64 	{
65 		if (ret_val == 0)
66 		{
67 			ret_val = TEST_perform_test_accuracy_all ();
68 		}
69 
70 		if (ret_val == 0)
71 		{
72 			ret_val = TEST_perform_test_speed_all ();
73 		}
74 	}
75 
76 	catch (std::exception &e)
77 	{
78 		printf ("\n*** main(): Exception (std::exception) : %s\n", e.what ());
79 		ret_val = -1;
80 	}
81 
82 	catch (...)
83 	{
84 		printf ("\n*** main(): Undefined exception\n");
85 		ret_val = -1;
86 	}
87 
88 	TEST_prog_end ();
89 
90 	return (ret_val);
91 }
92 
93 
94 
TEST_perform_test_accuracy_all()95 int	TEST_perform_test_accuracy_all ()
96 {
97    int            ret_val = 0;
98 
99 	ffft::test::TestHelperNormal <float >::perform_test_accuracy (ret_val);
100 	ffft::test::TestHelperNormal <double>::perform_test_accuracy (ret_val);
101 
102    ffft::test::TestHelperFixLen < 1>::perform_test_accuracy (ret_val);
103    ffft::test::TestHelperFixLen < 2>::perform_test_accuracy (ret_val);
104    ffft::test::TestHelperFixLen < 3>::perform_test_accuracy (ret_val);
105    ffft::test::TestHelperFixLen < 4>::perform_test_accuracy (ret_val);
106    ffft::test::TestHelperFixLen < 7>::perform_test_accuracy (ret_val);
107    ffft::test::TestHelperFixLen < 8>::perform_test_accuracy (ret_val);
108    ffft::test::TestHelperFixLen <10>::perform_test_accuracy (ret_val);
109    ffft::test::TestHelperFixLen <12>::perform_test_accuracy (ret_val);
110    ffft::test::TestHelperFixLen <13>::perform_test_accuracy (ret_val);
111 
112 	return (ret_val);
113 }
114 
115 
116 
TEST_perform_test_speed_all()117 int	TEST_perform_test_speed_all ()
118 {
119    int            ret_val = 0;
120 
121 #if defined (ffft_test_SPEED_TEST_ENABLED)
122 
123 	ffft::test::TestHelperNormal <float >::perform_test_speed (ret_val);
124 	ffft::test::TestHelperNormal <double>::perform_test_speed (ret_val);
125 
126    ffft::test::TestHelperFixLen < 1>::perform_test_speed (ret_val);
127    ffft::test::TestHelperFixLen < 2>::perform_test_speed (ret_val);
128    ffft::test::TestHelperFixLen < 3>::perform_test_speed (ret_val);
129    ffft::test::TestHelperFixLen < 4>::perform_test_speed (ret_val);
130    ffft::test::TestHelperFixLen < 7>::perform_test_speed (ret_val);
131    ffft::test::TestHelperFixLen < 8>::perform_test_speed (ret_val);
132    ffft::test::TestHelperFixLen <10>::perform_test_speed (ret_val);
133    ffft::test::TestHelperFixLen <12>::perform_test_speed (ret_val);
134    ffft::test::TestHelperFixLen <14>::perform_test_speed (ret_val);
135    ffft::test::TestHelperFixLen <16>::perform_test_speed (ret_val);
136    ffft::test::TestHelperFixLen <20>::perform_test_speed (ret_val);
137 
138 #endif
139 
140    return (ret_val);
141 }
142 
143 
144 
145 #if defined (_MSC_VER)
TEST_new_handler_cb(size_t dummy)146 static int __cdecl	TEST_new_handler_cb (size_t dummy)
147 {
148 	throw std::bad_alloc ();
149 	return (0);
150 }
151 #endif	// _MSC_VER
152 
153 
154 
155 #if defined (_MSC_VER) && ! defined (NDEBUG)
TEST_debug_alloc_hook_cb(int alloc_type,void * user_data_ptr,size_t size,int block_type,long request_nbr,const unsigned char * filename_0,int line_nbr)156 static int	__cdecl	TEST_debug_alloc_hook_cb (int alloc_type, void *user_data_ptr, size_t size, int block_type, long request_nbr, const unsigned char *filename_0, int line_nbr)
157 {
158 	if (block_type != _CRT_BLOCK)	// Ignore CRT blocks to prevent infinite recursion
159 	{
160 		switch (alloc_type)
161 		{
162 		case	_HOOK_ALLOC:
163 		case	_HOOK_REALLOC:
164 		case	_HOOK_FREE:
165 
166 			// Put some debug code here
167 
168 			break;
169 
170 		default:
171 			assert (false);	// Undefined allocation type
172 			break;
173 		}
174 	}
175 
176 	return (1);
177 }
178 #endif
179 
180 
181 
182 #if defined (_MSC_VER) && ! defined (NDEBUG)
TEST_debug_report_hook_cb(int report_type,char * user_msg_0,int * ret_val_ptr)183 static int	__cdecl	TEST_debug_report_hook_cb (int report_type, char *user_msg_0, int *ret_val_ptr)
184 {
185 	*ret_val_ptr = 0;	// 1 to override the CRT default reporting mode
186 
187 	switch (report_type)
188 	{
189 	case	_CRT_WARN:
190 	case	_CRT_ERROR:
191 	case	_CRT_ASSERT:
192 
193 // Put some debug code here
194 
195 		break;
196 	}
197 
198 	return (*ret_val_ptr);
199 }
200 #endif
201 
202 
203 
TEST_prog_init()204 static void	TEST_prog_init ()
205 {
206 #if defined (_MSC_VER)
207 	::_set_new_handler (::TEST_new_handler_cb);
208 #endif	// _MSC_VER
209 
210 #if defined (_MSC_VER) && ! defined (NDEBUG)
211 	{
212 		const int	mode =   (1 * _CRTDBG_MODE_DEBUG)
213 						       | (1 * _CRTDBG_MODE_WNDW);
214 		::_CrtSetReportMode (_CRT_WARN, mode);
215 		::_CrtSetReportMode (_CRT_ERROR, mode);
216 		::_CrtSetReportMode (_CRT_ASSERT, mode);
217 
218 		const int	old_flags = ::_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG);
219 		::_CrtSetDbgFlag (  old_flags
220 		                  | (1 * _CRTDBG_LEAK_CHECK_DF)
221 		                  | (1 * _CRTDBG_CHECK_ALWAYS_DF));
222 		::_CrtSetBreakAlloc (-1);	// Specify here a memory bloc number
223 		::_CrtSetAllocHook (TEST_debug_alloc_hook_cb);
224 		::_CrtSetReportHook (TEST_debug_report_hook_cb);
225 
226 		// Speed up I/O but breaks C stdio compatibility
227 //		std::cout.sync_with_stdio (false);
228 //		std::cin.sync_with_stdio (false);
229 //		std::cerr.sync_with_stdio (false);
230 //		std::clog.sync_with_stdio (false);
231 	}
232 #endif	// _MSC_VER, NDEBUG
233 }
234 
235 
236 
TEST_prog_end()237 static void	TEST_prog_end ()
238 {
239 #if defined (_MSC_VER) && ! defined (NDEBUG)
240 	{
241 		const int	mode =   (1 * _CRTDBG_MODE_DEBUG)
242 						       | (0 * _CRTDBG_MODE_WNDW);
243 		::_CrtSetReportMode (_CRT_WARN, mode);
244 		::_CrtSetReportMode (_CRT_ERROR, mode);
245 		::_CrtSetReportMode (_CRT_ASSERT, mode);
246 
247 		::_CrtMemState	mem_state;
248 		::_CrtMemCheckpoint (&mem_state);
249 		::_CrtMemDumpStatistics (&mem_state);
250 	}
251 #endif	// _MSC_VER, NDEBUG
252 }
253 
254 
255 
256 /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
257