create a_linalg_mul
[liba.git] / test / CMakeLists.txt
blobb6a44372f5a217f6e8ddb890e1c91ae7816d863a
1 get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
3 function(set_executable_options)
4   list(FIND ENABLED_LANGUAGES CXX HAS_CXX)
5   set_target_properties(${ARGN} PROPERTIES
6     INTERPROCEDURAL_OPTIMIZATION ${LIBA_IPO}
7     POSITION_INDEPENDENT_CODE ${LIBA_PIE}
8   )
10   if(${HAS_CXX} GREATER -1)
11     set_property(TARGET ${ARGN} APPEND PROPERTY COMPILE_DEFINITIONS HAS_CXX)
12   endif()
14   if(LIBA_IWYU AND IWYU_FOUND)
15     add_include_what_you_use(TARGETS ${ARGN})
16   endif()
18   if(LIBA_CLANG_TIDY AND CLANG_TIDY_FOUND)
19     add_clang_tidy(TARGETS ${ARGN} OPTIONS --fix)
20   endif()
22   if(LIBA_CPPCHECK AND CPPCHECK_FOUND)
23     add_cppcheck(TARGETS ${ARGN} OPTIONS --enable=warning,performance)
24   endif()
26   if(LIBA_WARNINGS)
27     target_compile_warnings(${ARGN})
28   endif()
30   if(LIBA_ANALYZER)
31     target_compile_analyzer(${ARGN})
32   endif()
34   if(LIBA_SANITIZE)
35     target_compile_sanitize(${ARGN})
36     target_link_sanitize(${ARGN})
37   endif()
39   if(LIBA_STATIC)
40     target_link_static(${ARGN})
41   endif()
42 endfunction()
44 set(TARGET_PREFIX test.)
46 function(building target)
47   set(TARGET "${TARGET_PREFIX}${target}")
48   list(FIND ENABLED_LANGUAGES CXX HAS_CXX)
50   if(${HAS_CXX} EQUAL -1)
51     file_filter(ARGN ${ARGN} EXT c h)
52   endif()
54   if(LIBA_SANITIZE AND CMAKE_VERSION VERSION_LESS 3.12)
55     list(APPEND ARGN $<TARGET_OBJECTS:asan>)
56   endif()
58   if(NOT TARGET_SUPPORTS_EXECUTABLES)
59     add_library(${TARGET} STATIC ${ARGN})
60   else()
61     add_executable(${TARGET} ${ARGN})
62   endif()
64   if(LIBA_SANITIZE AND CMAKE_VERSION VERSION_LESS 3.12)
65     add_library_properties(${TARGET} PRIVATE asan)
66   elseif(LIBA_SANITIZE)
67     target_link_libraries(${TARGET} PRIVATE asan)
68   elseif(BUILD_SHARED_LIBS)
69     target_link_libraries(${TARGET} PRIVATE liba)
70   else()
71     target_link_libraries(${TARGET} PRIVATE alib)
72   endif()
74   set_executable_options(${TARGET})
75 endfunction()
77 function(unittest target)
78   set(TARGET "${TARGET_PREFIX}${target}")
79   cmake_parse_arguments(TEST "" "NAME" "ARGS" ${ARGN})
80   set(ARGS)
82   if(NOT TEST_NAME)
83     set(TEST_NAME ${target})
84   endif()
86   if(IS_MULTI_CONFIG)
87     set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
88   else()
89     set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
90   endif()
92   if(IS_MULTI_CONFIG AND BUILD_SHARED_LIBS)
93     set(WORKING_DIRECTORY $<TARGET_FILE_DIR:alib>)
94   else()
95     set(WORKING_DIRECTORY ${BINARY_DIRECTORY})
96   endif()
98   foreach(arg ${TEST_ARGS} ${TEST_UNPARSED_ARGUMENTS})
99     get_filename_component(ext ${arg} EXT)
101     if(NOT ext OR IS_ABSOLUTE ${arg})
102       list(APPEND ARGS ${arg})
103     elseif(NOT EMSCRIPTEN)
104       list(APPEND ARGS ${BINARY_DIRECTORY}/${arg})
105     endif()
106   endforeach()
108   if(NOT TARGET_SUPPORTS_EXECUTABLES AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
109     return()
110   endif()
112   add_test(NAME ${TEST_NAME} WORKING_DIRECTORY ${WORKING_DIRECTORY}
113     COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${TARGET}> ${ARGS}
114   )
115   set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 30
116     FAIL_REGULAR_EXPRESSION "ERROR;error;:[0-9]+:"
117   )
118 endfunction()
120 option(LIBA_GNUPLOT "Enable/Disable gnuplot" 0)
122 if(LIBA_GNUPLOT)
123   find_package(Gnuplot)
124 endif()
126 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
127   function(unitplot target script output)
128     set(TARGET "${TARGET_PREFIX}${target}")
129     set(SOURCE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
131     if(IS_MULTI_CONFIG)
132       set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
133     else()
134       set(BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
135     endif()
137     if(IS_MULTI_CONFIG AND BUILD_SHARED_LIBS)
138       set(WORKING_DIRECTORY $<TARGET_FILE_DIR:alib>)
139     else()
140       set(WORKING_DIRECTORY ${BINARY_DIRECTORY})
141     endif()
143     if(NOT IS_ABSOLUTE ${script})
144       file(TO_CMAKE_PATH ${SOURCE_DIRECTORY}/${script} script)
145     endif()
147     if(NOT IS_ABSOLUTE ${output})
148       file(TO_CMAKE_PATH ${BINARY_DIRECTORY}/${output} output)
149     endif()
151     if(NOT TARGET_SUPPORTS_EXECUTABLES AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
152       return()
153     endif()
155     add_custom_command(TARGET ${TARGET} POST_BUILD WORKING_DIRECTORY ${WORKING_DIRECTORY}
156       COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${TARGET}> ${output} ${ARGN}
157       COMMAND ${GNUPLOT_EXECUTABLE} -c ${script} ${output}
158     )
159   endfunction()
160 endif()
162 building(a a.c a.cc)
163 unittest(a NAME a_for ARGS for 10)
164 unittest(a NAME a_hash_bkdr ARGS hash_bkdr hash_bkdr)
165 unittest(a NAME a_hash_sdbm ARGS hash_sdbm hash_sdbm)
166 unittest(a)
168 building(avl avl.c avl.cc)
169 unittest(avl)
171 building(buf buf.c buf.cc)
172 unittest(buf)
174 building(complex complex.c complex.cc)
175 unittest(complex ARGS -4,3 -2,1)
177 building(crc crc.c crc.cc)
178 unittest(crc ARGS crc.c)
180 building(hash hash.c hash.cc)
181 unittest(hash)
183 building(hpf hpf.c hpf.cc)
184 unittest(hpf)
186 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
187   unitplot(hpf 2.gp hpf.csv)
188 endif()
190 building(linalg linalg.c linalg.cc)
191 unittest(linalg)
193 building(linalg_plu linalg_plu.c linalg_plu.cc)
194 unittest(linalg_plu)
196 building(list list.c list.cc)
197 unittest(list)
199 building(lpf lpf.c lpf.cc)
200 unittest(lpf)
202 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
203   unitplot(lpf 3.gp lpf.csv)
204 endif()
206 building(math math.c math.cc)
207 unittest(math)
209 building(mf mf.c mf.cc)
210 unittest(mf)
212 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
213   unitplot(mf mf.gp mf_gauss.csv -4 4 1 0)
214   unitplot(mf mf.gp mf_gauss2.csv -4 4 1 -1 1 1)
215   unitplot(mf mf.gp mf_gbell.csv -4 4 2 4 0)
216   unitplot(mf mf.gp mf_sig.csv -4 4 2 0)
217   unitplot(mf mf.gp mf_dsig.csv -4 4 5 -2 5 2)
218   unitplot(mf mf.gp mf_psig.csv -4 4 5 -2 -5 2)
219   unitplot(mf mf.gp mf_trap.csv -3 3 -2 -1 1 2)
220   unitplot(mf mf.gp mf_tri.csv -2 2 -1 0 1)
221   unitplot(mf mf.gp mf_lins.csv -2 2 -1 1)
222   unitplot(mf mf.gp mf_linz.csv -2 2 -1 1)
223   unitplot(mf mf.gp mf_s.csv -2 2 -1 1)
224   unitplot(mf mf.gp mf_z.csv -2 2 -1 1)
225   unitplot(mf mf.gp mf_pi.csv -3 3 -2 -1 1 2)
226 endif()
228 building(notefreqs notefreqs.c notefreqs.cc)
229 unittest(notefreqs)
231 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
232   unitplot(notefreqs notefreqs.gp notefreqs.csv)
233 endif()
235 building(pid pid.c pid.cc)
236 unittest(pid)
238 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
239   unitplot(pid 3.gp pid.csv)
240 endif()
242 building(pid_expert pid_expert.c pid_expert.cc)
243 unittest(pid_expert)
245 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
246   unitplot(pid_expert 3.gp pid_expert.csv)
247 endif()
249 building(pid_fuzzy pid_fuzzy.c pid_fuzzy.cc)
250 unittest(pid_fuzzy)
252 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
253   unitplot(pid_fuzzy 3.gp pid_fuzzy.csv)
254 endif()
256 building(pid_neuro pid_neuro.c pid_neuro.cc)
257 unittest(pid_neuro)
259 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
260   unitplot(pid_neuro 3.gp pid_neuro.csv)
261 endif()
263 building(poly poly.c poly.cc)
264 unittest(poly)
266 building(que que.c que.cc)
267 unittest(que)
269 building(rbt rbt.c rbt.cc)
270 unittest(rbt)
272 building(regress regress.c regress.cc)
273 unittest(regress)
275 building(regress_linear regress_linear.c regress_linear.cc)
276 unittest(regress_linear)
278 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
279   unitplot(regress_linear regress1.gp regress_linear_1sgd.csv)
280   unitplot(regress_linear regress1.gp regress_linear_1bgd.csv)
281   unitplot(regress_linear regress1.gp regress_linear_1mgd.csv)
282   unitplot(regress_linear regress2.gp regress_linear_2sgd.csv)
283   unitplot(regress_linear regress2.gp regress_linear_2bgd.csv)
284   unitplot(regress_linear regress2.gp regress_linear_2mgd.csv)
285 endif()
287 building(regress_simple regress_simple.c regress_simple.cc)
288 unittest(regress_simple)
290 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
291   unitplot(regress_simple regress1.gp regress_simple.csv)
292 endif()
294 building(slist slist.c slist.cc)
295 unittest(slist)
297 building(str str.c str.cc)
298 unittest(str)
300 building(test test.c test.cc)
301 unittest(test)
303 building(tf tf.c tf.cc)
304 unittest(tf)
306 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
307   unitplot(tf 2.gp tf.csv)
308 endif()
310 building(trajbell trajbell.c trajbell.cc)
311 unittest(trajbell ARGS trajbell.csv 3 2 3 0 10)
313 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
314   unitplot(trajbell traj4.gp trajbell.csv 3 2 3 0 10)
315 endif()
317 building(trajpoly3 trajpoly3.c trajpoly3.cc)
318 unittest(trajpoly3 ARGS trajpoly3.csv 0 10 0 10)
320 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
321   unitplot(trajpoly3 traj3.gp trajpoly3.csv 0 10 0 10)
322 endif()
324 building(trajpoly5 trajpoly5.c trajpoly5.cc)
325 unittest(trajpoly5 ARGS trajpoly5.csv 0 10 0 10)
327 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
328   unitplot(trajpoly5 traj3.gp trajpoly5.csv 0 10 0 10)
329 endif()
331 building(trajpoly7 trajpoly7.c trajpoly7.cc)
332 unittest(trajpoly7 ARGS trajpoly7.csv 0 10 0 10)
334 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
335   unitplot(trajpoly7 traj4.gp trajpoly7.csv 0 10 0 10)
336 endif()
338 building(trajtrap trajtrap.c trajtrap.cc)
339 unittest(trajtrap ARGS trajtrap.csv 2 2 -2 0 4)
341 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
342   unitplot(trajtrap traj3.gp trajtrap.csv 2 2 -2 0 4)
343 endif()
345 building(utf utf.c utf.cc)
346 unittest(utf)
348 building(vec vec.c vec.cc)
349 unittest(vec)
351 building(version version.c version.cc)
352 unittest(version)