remove inttypes.h
[liba.git] / test / CMakeLists.txt
bloba86eeed20fd1145bc1f321c47320f8e08d8974b3
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(list list.c list.cc)
191 unittest(list)
193 building(lpf lpf.c lpf.cc)
194 unittest(lpf)
196 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
197   unitplot(lpf 3.gp lpf.csv)
198 endif()
200 building(math math.c math.cc)
201 unittest(math)
203 building(mf mf.c mf.cc)
204 unittest(mf)
206 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
207   unitplot(mf mf.gp mf_gauss.csv -4 4 1 0)
208   unitplot(mf mf.gp mf_gauss2.csv -4 4 1 -1 1 1)
209   unitplot(mf mf.gp mf_gbell.csv -4 4 2 4 0)
210   unitplot(mf mf.gp mf_sig.csv -4 4 2 0)
211   unitplot(mf mf.gp mf_dsig.csv -4 4 5 -2 5 2)
212   unitplot(mf mf.gp mf_psig.csv -4 4 5 -2 -5 2)
213   unitplot(mf mf.gp mf_trap.csv -3 3 -2 -1 1 2)
214   unitplot(mf mf.gp mf_tri.csv -2 2 -1 0 1)
215   unitplot(mf mf.gp mf_lins.csv -2 2 -1 1)
216   unitplot(mf mf.gp mf_linz.csv -2 2 -1 1)
217   unitplot(mf mf.gp mf_s.csv -2 2 -1 1)
218   unitplot(mf mf.gp mf_z.csv -2 2 -1 1)
219   unitplot(mf mf.gp mf_pi.csv -3 3 -2 -1 1 2)
220 endif()
222 building(notefreqs notefreqs.c notefreqs.cc)
223 unittest(notefreqs)
225 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
226   unitplot(notefreqs notefreqs.gp notefreqs.csv)
227 endif()
229 building(pid pid.c pid.cc)
230 unittest(pid)
232 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
233   unitplot(pid 3.gp pid.csv)
234 endif()
236 building(pid_expert pid_expert.c pid_expert.cc)
237 unittest(pid_expert)
239 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
240   unitplot(pid_expert 3.gp pid_expert.csv)
241 endif()
243 building(pid_fuzzy pid_fuzzy.c pid_fuzzy.cc)
244 unittest(pid_fuzzy)
246 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
247   unitplot(pid_fuzzy 3.gp pid_fuzzy.csv)
248 endif()
250 building(pid_neuro pid_neuro.c pid_neuro.cc)
251 unittest(pid_neuro)
253 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
254   unitplot(pid_neuro 3.gp pid_neuro.csv)
255 endif()
257 building(poly poly.c poly.cc)
258 unittest(poly)
260 building(que que.c que.cc)
261 unittest(que)
263 building(rbt rbt.c rbt.cc)
264 unittest(rbt)
266 building(regress regress.c regress.cc)
267 unittest(regress)
269 building(regress_linear regress_linear.c regress_linear.cc)
270 unittest(regress_linear)
272 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
273   unitplot(regress_linear regress1.gp regress_linear_1sgd.csv)
274   unitplot(regress_linear regress1.gp regress_linear_1bgd.csv)
275   unitplot(regress_linear regress1.gp regress_linear_1mgd.csv)
276   unitplot(regress_linear regress2.gp regress_linear_2sgd.csv)
277   unitplot(regress_linear regress2.gp regress_linear_2bgd.csv)
278   unitplot(regress_linear regress2.gp regress_linear_2mgd.csv)
279 endif()
281 building(regress_simple regress_simple.c regress_simple.cc)
282 unittest(regress_simple)
284 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
285   unitplot(regress_simple regress1.gp regress_simple.csv)
286 endif()
288 building(slist slist.c slist.cc)
289 unittest(slist)
291 building(str str.c str.cc)
292 unittest(str)
294 building(test test.c test.cc)
295 unittest(test)
297 building(tf tf.c tf.cc)
298 unittest(tf)
300 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
301   unitplot(tf 2.gp tf.csv)
302 endif()
304 building(trajbell trajbell.c trajbell.cc)
305 unittest(trajbell ARGS trajbell.csv 3 2 3 0 10)
307 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
308   unitplot(trajbell traj4.gp trajbell.csv 3 2 3 0 10)
309 endif()
311 building(trajpoly3 trajpoly3.c trajpoly3.cc)
312 unittest(trajpoly3 ARGS trajpoly3.csv 0 10 0 10)
314 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
315   unitplot(trajpoly3 traj3.gp trajpoly3.csv 0 10 0 10)
316 endif()
318 building(trajpoly5 trajpoly5.c trajpoly5.cc)
319 unittest(trajpoly5 ARGS trajpoly5.csv 0 10 0 10)
321 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
322   unitplot(trajpoly5 traj3.gp trajpoly5.csv 0 10 0 10)
323 endif()
325 building(trajpoly7 trajpoly7.c trajpoly7.cc)
326 unittest(trajpoly7 ARGS trajpoly7.csv 0 10 0 10)
328 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
329   unitplot(trajpoly7 traj4.gp trajpoly7.csv 0 10 0 10)
330 endif()
332 building(trajtrap trajtrap.c trajtrap.cc)
333 unittest(trajtrap ARGS trajtrap.csv 2 2 -2 0 4)
335 if(LIBA_GNUPLOT AND GNUPLOT_FOUND)
336   unitplot(trajtrap traj3.gp trajtrap.csv 2 2 -2 0 4)
337 endif()
339 building(utf utf.c utf.cc)
340 unittest(utf)
342 building(vec vec.c vec.cc)
343 unittest(vec)
345 building(version version.c version.cc)
346 unittest(version)