poulpy/poulpy-backend/src/cpu_spqlios/spqlios-arithmetic/test/CMakeLists.txt
poulpy-backend/src/cpu_spqlios/spqlios-arithmetic/test/CMakeLists.txtRaw
1set(CMAKE_CXX_STANDARD 17)
2
3set(test_incs ..)
4set(gtest_libs)
5set(benchmark_libs)
6# searching for libgtest
7find_path(gtest_inc NAMES gtest/gtest.h)
8find_library(gtest NAMES gtest)
9find_library(gtest_main REQUIRED NAMES gtest_main)
10if (gtest_inc AND gtest AND gtest_main)
11 message(STATUS "Found gtest: I=${gtest_inc} L=${gtest},${gtest_main}")
12 set(test_incs ${test_incs} ${gtest_inc})
13 set(gtest_libs ${gtest_libs} ${gtest} ${gtest_main} pthread)
14else()
15 message(FATAL_ERROR "Libgtest not found (required if ENABLE_TESTING is on): I=${gtest_inc} L=${gtest},${gtest_main}")
16endif()
17# searching for libbenchmark
18find_path(benchmark_inc NAMES benchmark/benchmark.h)
19find_library(benchmark NAMES benchmark)
20if (benchmark_inc AND benchmark)
21 message(STATUS "Found benchmark: I=${benchmark_inc} L=${benchmark}")
22 set(test_incs ${test_incs} ${benchmark_inc})
23 set(benchmark_libs ${benchmark_libs} ${benchmark})
24else()
25 message(FATAL_ERROR "Libbenchmark not found (required if ENABLE_TESTING is on): I=${benchmark_inc} L=${benchmark}")
26endif()
27find_path(VALGRIND_DIR NAMES valgrind/valgrind.h)
28if (VALGRIND_DIR)
29 message(STATUS "Found valgrind header ${VALGRIND_DIR}")
30else ()
31 # for now, we will fail if we don't find valgrind for tests
32 message(STATUS "CANNOT FIND valgrind header: ${VALGRIND_DIR}")
33endif ()
34
35add_library(spqlios-testlib SHARED
36 testlib/random.cpp
37 testlib/test_commons.h
38 testlib/test_commons.cpp
39 testlib/mod_q120.h
40 testlib/mod_q120.cpp
41 testlib/negacyclic_polynomial.cpp
42 testlib/negacyclic_polynomial.h
43 testlib/negacyclic_polynomial_impl.h
44 testlib/reim4_elem.cpp
45 testlib/reim4_elem.h
46 testlib/fft64_dft.cpp
47 testlib/fft64_dft.h
48 testlib/fft64_layouts.h
49 testlib/fft64_layouts.cpp
50 testlib/ntt120_layouts.cpp
51 testlib/ntt120_layouts.h
52 testlib/ntt120_dft.cpp
53 testlib/ntt120_dft.h
54 testlib/test_hash.cpp
55 testlib/sha3.h
56 testlib/sha3.c
57 testlib/polynomial_vector.h
58 testlib/polynomial_vector.cpp
59 testlib/vec_rnx_layout.h
60 testlib/vec_rnx_layout.cpp
61 testlib/zn_layouts.h
62 testlib/zn_layouts.cpp
63)
64if (VALGRIND_DIR)
65 target_include_directories(spqlios-testlib PRIVATE ${VALGRIND_DIR})
66 target_compile_definitions(spqlios-testlib PRIVATE VALGRIND_MEM_TESTS)
67endif ()
68target_link_libraries(spqlios-testlib libspqlios)
69
70
71
72# main unittest file
73message(STATUS "${gtest_libs}")
74set(UNITTEST_FILES
75 spqlios_test.cpp
76 spqlios_reim_conversions_test.cpp
77 spqlios_reim_test.cpp
78 spqlios_reim4_arithmetic_test.cpp
79 spqlios_cplx_test.cpp
80 spqlios_cplx_conversions_test.cpp
81 spqlios_q120_ntt_test.cpp
82 spqlios_q120_arithmetic_test.cpp
83 spqlios_coeffs_arithmetic_test.cpp
84 spqlios_vec_znx_big_test.cpp
85 spqlios_znx_small_test.cpp
86 spqlios_vmp_product_test.cpp
87 spqlios_vec_znx_dft_test.cpp
88 spqlios_svp_apply_test.cpp
89 spqlios_svp_prepare_test.cpp
90 spqlios_vec_znx_test.cpp
91 spqlios_vec_rnx_test.cpp
92 spqlios_vec_rnx_vmp_test.cpp
93 spqlios_vec_rnx_conversions_test.cpp
94 spqlios_vec_rnx_ppol_test.cpp
95 spqlios_vec_rnx_approxdecomp_tnxdbl_test.cpp
96 spqlios_zn_approxdecomp_test.cpp
97 spqlios_zn_conversions_test.cpp
98 spqlios_zn_vmp_test.cpp
99
100
101)
102
103add_executable(spqlios-test ${UNITTEST_FILES})
104target_link_libraries(spqlios-test spqlios-testlib libspqlios ${gtest_libs})
105target_include_directories(spqlios-test PRIVATE ${test_incs})
106add_test(NAME spqlios-test COMMAND spqlios-test)
107if (WIN32)
108 # copy the dlls to the test directory
109 cmake_minimum_required(VERSION 3.26)
110 add_custom_command(
111 POST_BUILD
112 TARGET spqlios-test
113 COMMAND ${CMAKE_COMMAND} -E copy
114 -t $<TARGET_FILE_DIR:spqlios-test> $<TARGET_RUNTIME_DLLS:spqlios-testlib> $<TARGET_RUNTIME_DLLS:libspqlios>
115 COMMAND_EXPAND_LISTS
116 )
117endif()
118
119# benchmarks
120add_executable(spqlios-cplx-fft-bench spqlios_cplx_fft_bench.cpp)
121target_link_libraries(spqlios-cplx-fft-bench libspqlios ${benchmark_libs} pthread)
122target_include_directories(spqlios-cplx-fft-bench PRIVATE ${test_incs})
123
124if (X86 OR X86_WIN32)
125 add_executable(spqlios-q120-ntt-bench spqlios_q120_ntt_bench.cpp)
126 target_link_libraries(spqlios-q120-ntt-bench libspqlios ${benchmark_libs} pthread)
127 target_include_directories(spqlios-q120-ntt-bench PRIVATE ${test_incs})
128
129 add_executable(spqlios-q120-arithmetic-bench spqlios_q120_arithmetic_bench.cpp)
130 target_link_libraries(spqlios-q120-arithmetic-bench libspqlios ${benchmark_libs} pthread)
131 target_include_directories(spqlios-q120-arithmetic-bench PRIVATE ${test_incs})
132endif ()
133
134if (X86 OR X86_WIN32)
135 add_executable(spqlios_reim4_arithmetic_bench spqlios_reim4_arithmetic_bench.cpp)
136 target_link_libraries(spqlios_reim4_arithmetic_bench ${benchmark_libs} libspqlios pthread)
137 target_include_directories(spqlios_reim4_arithmetic_bench PRIVATE ${test_incs})
138endif ()
139
140if (DEVMODE_INSTALL)
141 install(TARGETS spqlios-testlib)
142endif()