]> git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/test/CMakeLists.txt
buildsys: switch source download to quincy
[ceph.git] / ceph / src / civetweb / test / CMakeLists.txt
1 # Determine if we should print to the output
2 if (CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT)
3 set(THIRD_PARTY_LOGGING 0)
4 else()
5 set(THIRD_PARTY_LOGGING 1)
6 endif()
7
8 # We use the check unit testing framework for our C unit tests
9 include(ExternalProject)
10 #if(NOT WIN32)
11 # # Apply the patch to check to fix CMake building on OS X
12 # set(CHECK_PATCH_COMMAND patch
13 # ${CIVETWEB_THIRD_PARTY_DIR}/src/check-unit-test-framework/CMakeLists.txt
14 # ${CMAKE_SOURCE_DIR}/cmake/check/c82fe8888aacfe784476112edd3878256d2e30bc.patch
15 # )
16 #else()
17 # set(CHECK_PATCH_COMMAND "")
18 #endif()
19 ExternalProject_Add(check-unit-test-framework
20 DEPENDS c-library
21
22 ## Use an official, released check version:
23 # URL "https://codeload.github.com/libcheck/check/zip/${CIVETWEB_CHECK_VERSION}"
24 # DOWNLOAD_NAME "${CIVETWEB_CHECK_VERSION}.zip"
25 # URL_MD5 ${CIVETWEB_CHECK_MD5_HASH}
26
27 ## Use a civetweb specific patched version
28 URL "https://github.com/civetweb/check/archive/master.zip"
29 DOWNLOAD_NAME "master.zip"
30 # <Edit this file to flush AppVeyor build cache and force reloading check>
31
32 PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
33 BUILD_IN_SOURCE 1
34 PATCH_COMMAND ${CHECK_PATCH_COMMAND}
35 CMAKE_ARGS
36 "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
37 "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
38 "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
39 LOG_DOWNLOAD ${THIRD_PARTY_LOGGING}
40 LOG_UPDATE ${THIRD_PARTY_LOGGING}
41 LOG_CONFIGURE ${THIRD_PARTY_LOGGING}
42 LOG_BUILD ${THIRD_PARTY_LOGGING}
43 LOG_TEST ${THIRD_PARTY_LOGGING}
44 LOG_INSTALL ${THIRD_PARTY_LOGGING})
45
46 ExternalProject_Get_Property(check-unit-test-framework INSTALL_DIR)
47 set(CHECK_INSTALL_DIR ${INSTALL_DIR})
48 unset(INSTALL_DIR)
49 link_directories("${CHECK_INSTALL_DIR}/lib")
50 include_directories("${CHECK_INSTALL_DIR}/include")
51 if ((WIN32 AND MINGW) OR APPLE)
52 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/libcheck.a")
53 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/libcompat.a")
54 elseif (WIN32)
55 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/check.lib")
56 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/compat.lib")
57 else()
58 set(CHECK_LIBRARIES "${CHECK_INSTALL_DIR}/lib/libcheck.a")
59 endif()
60 find_package(LibM)
61 if (LIBM_FOUND)
62 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBM::LIBM")
63 endif()
64 find_package(LibRt)
65 if (LIBRT_FOUND)
66 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBRT::LIBRT")
67 endif()
68 find_package(LibSubunit)
69 if (LIBSUBUNIT_FOUND)
70 set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBSUBUNIT::LIBSUBUNIT")
71 endif()
72
73 # Build the C unit tests
74 add_library(shared-c-unit-tests STATIC shared.c)
75 target_include_directories(
76 shared-c-unit-tests PUBLIC
77 ${PROJECT_SOURCE_DIR}/include)
78
79 add_library(public-func-c-unit-tests STATIC public_func.c)
80 if (BUILD_SHARED_LIBS)
81 target_compile_definitions(public-func-c-unit-tests PRIVATE CIVETWEB_DLL_IMPORTS)
82 endif()
83 target_include_directories(
84 public-func-c-unit-tests PUBLIC
85 ${PROJECT_SOURCE_DIR}/include)
86 target_link_libraries(public-func-c-unit-tests c-library ${CHECK_LIBRARIES})
87 add_dependencies(public-func-c-unit-tests check-unit-test-framework)
88
89 add_library(public-server-c-unit-tests STATIC public_server.c)
90 if (BUILD_SHARED_LIBS)
91 target_compile_definitions(public-server-c-unit-tests PRIVATE CIVETWEB_DLL_IMPORTS)
92 endif()
93 target_include_directories(
94 public-server-c-unit-tests PUBLIC
95 ${PROJECT_SOURCE_DIR}/include)
96 target_link_libraries(public-server-c-unit-tests c-library ${CHECK_LIBRARIES})
97 add_dependencies(public-server-c-unit-tests check-unit-test-framework)
98
99 add_library(private-c-unit-tests STATIC private.c)
100 target_include_directories(
101 private-c-unit-tests PUBLIC
102 ${PROJECT_SOURCE_DIR}/include)
103 target_link_libraries(private-c-unit-tests ${CHECK_LIBRARIES})
104 add_dependencies(private-c-unit-tests check-unit-test-framework)
105
106 add_library(timer-c-unit-tests STATIC timertest.c)
107 target_include_directories(
108 timer-c-unit-tests PUBLIC
109 ${PROJECT_SOURCE_DIR}/include)
110 target_link_libraries(timer-c-unit-tests ${CHECK_LIBRARIES})
111 add_dependencies(timer-c-unit-tests check-unit-test-framework)
112
113 add_library(exe-c-unit-tests STATIC private_exe.c)
114 if (BUILD_SHARED_LIBS)
115 target_compile_definitions(exe-c-unit-tests PRIVATE)
116 endif()
117 target_include_directories(
118 exe-c-unit-tests PUBLIC
119 ${PROJECT_SOURCE_DIR}/include)
120 target_link_libraries(exe-c-unit-tests c-library ${CHECK_LIBRARIES})
121 add_dependencies(exe-c-unit-tests check-unit-test-framework)
122
123 add_executable(main-c-unit-test main.c)
124 target_link_libraries(main-c-unit-test
125 shared-c-unit-tests
126 public-func-c-unit-tests
127 public-server-c-unit-tests
128 private-c-unit-tests
129 timer-c-unit-tests
130 exe-c-unit-tests
131 ${CHECK_LIBRARIES})
132 add_dependencies(main-c-unit-test check-unit-test-framework)
133
134 # Add a check command that builds the dependent test program
135 add_custom_target(check
136 COMMAND ${CMAKE_CTEST_COMMAND}
137 DEPENDS main-c-unit-test)
138
139 # A macro for adding tests
140 macro(civetweb_add_test suite test_case)
141 set(test "test-${suite}-${test_case}")
142 string(TOLOWER "${test}" test)
143 string(REGEX REPLACE "[^-A-Za-z0-9]" "-" test "${test}")
144 add_test(
145 NAME ${test}
146 COMMAND main-c-unit-test "--test-dir=${CMAKE_CURRENT_SOURCE_DIR}" "--suite=${suite}" "--test-case=${test_case}")
147 if (WIN32)
148 string(REPLACE ";" "\\;" test_path "$ENV{PATH}")
149 set_tests_properties(${test} PROPERTIES
150 ENVIRONMENT "PATH=${test_path}\\;$<TARGET_FILE_DIR:c-library>")
151 endif()
152 endmacro(civetweb_add_test)
153
154
155 # Tests of private functions
156 civetweb_add_test(Private "HTTP Message")
157 civetweb_add_test(Private "HTTP Keep Alive")
158 civetweb_add_test(Private "URL Parsing 1")
159 civetweb_add_test(Private "URL Parsing 2")
160 civetweb_add_test(Private "URL Parsing 3")
161 civetweb_add_test(Private "Internal Parsing 1")
162 civetweb_add_test(Private "Internal Parsing 2")
163 civetweb_add_test(Private "Internal Parsing 3")
164 civetweb_add_test(Private "Internal Parsing 4")
165 civetweb_add_test(Private "Internal Parsing 5")
166 civetweb_add_test(Private "Internal Parsing 6")
167 civetweb_add_test(Private "Encode Decode")
168 civetweb_add_test(Private "Mask Data")
169 civetweb_add_test(Private "Date Parsing")
170 civetweb_add_test(Private "SHA1")
171
172 # Public API function tests
173 civetweb_add_test(PublicFunc "Version")
174 civetweb_add_test(PublicFunc "Options")
175 civetweb_add_test(PublicFunc "MIME types")
176 civetweb_add_test(PublicFunc "strcasecmp")
177 civetweb_add_test(PublicFunc "URL encoding decoding")
178 civetweb_add_test(PublicFunc "Cookies and variables")
179 civetweb_add_test(PublicFunc "MD5")
180 civetweb_add_test(PublicFunc "Aux functions")
181
182 # Public API server tests
183 civetweb_add_test(PublicServer "Check test environment")
184 civetweb_add_test(PublicServer "Init library")
185 civetweb_add_test(PublicServer "Start threads")
186 civetweb_add_test(PublicServer "Minimal Server")
187 civetweb_add_test(PublicServer "Minimal Client")
188 civetweb_add_test(PublicServer "Start Stop HTTP Server")
189 civetweb_add_test(PublicServer "Start Stop HTTP Server IPv6")
190 civetweb_add_test(PublicServer "Start Stop HTTPS Server")
191 civetweb_add_test(PublicServer "TLS Server Client")
192 civetweb_add_test(PublicServer "Server Requests")
193 civetweb_add_test(PublicServer "Store Body")
194 civetweb_add_test(PublicServer "Handle Form")
195 civetweb_add_test(PublicServer "HTTP Authentication")
196 civetweb_add_test(PublicServer "HTTP Keep Alive")
197 civetweb_add_test(PublicServer "Error handling")
198 civetweb_add_test(PublicServer "Limit speed")
199 civetweb_add_test(PublicServer "Large file")
200 civetweb_add_test(PublicServer "File in memory")
201
202 # Timer tests
203 civetweb_add_test(Timer "Timer Single Shot")
204 civetweb_add_test(Timer "Timer Periodic")
205 civetweb_add_test(Timer "Timer Mixed")
206
207 # Tests with main.c
208 #civetweb_add_test(EXE "Helper funcs")
209
210
211 # Add the coverage command(s)
212 if (${CMAKE_BUILD_TYPE} MATCHES "[Cc]overage")
213 find_program(GCOV_EXECUTABLE gcov)
214 find_program(LCOV_EXECUTABLE lcov)
215 find_program(GENHTML_EXECUTABLE genhtml)
216 find_program(CTEST_EXECUTABLE ctest)
217 if (GCOV_EXECUTABLE AND LCOV_EXECUTABLE AND GENHTML_EXECUTABLE AND CTEST_EXECUTABLE AND HAVE_C_FLAG_COVERAGE)
218 add_custom_command(
219 OUTPUT ${CMAKE_BINARY_DIR}/lcov/index.html
220 COMMAND ${LCOV_EXECUTABLE} -q -z -d .
221 COMMAND ${LCOV_EXECUTABLE} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o before.lcov -i
222 COMMAND ${CTEST_EXECUTABLE} --force-new-ctest-process
223 COMMAND ${LCOV_EXECUTABLE} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o after.lcov
224 COMMAND ${LCOV_EXECUTABLE} -q -a before.lcov -a after.lcov --output-file final.lcov
225 COMMAND ${LCOV_EXECUTABLE} -q -r final.lcov "'${CMAKE_SOURCE_DIR}/test/*'" -o final.lcov
226 COMMAND ${GENHTML_EXECUTABLE} final.lcov -o lcov --demangle-cpp --sort -p "${CMAKE_SOURCE_DIR}" -t benchmark
227 DEPENDS main-c-unit-test
228 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
229 COMMENT "Running LCOV"
230 )
231 add_custom_target(coverage
232 DEPENDS ${CMAKE_BINARY_DIR}/lcov/index.html
233 COMMENT "LCOV report at lcov/index.html"
234 )
235 message(STATUS "Coverage command added")
236 else()
237 if (HAVE_C_FLAG_COVERAGE)
238 set(C_FLAG_COVERAGE_MESSAGE supported)
239 else()
240 set(C_FLAG_COVERAGE_MESSAGE unavailable)
241 endif()
242 message(WARNING
243 "Coverage command not available:\n"
244 " gcov: ${GCOV_EXECUTABLE}\n"
245 " lcov: ${LCOV_EXECUTABLE}\n"
246 " genhtml: ${GENHTML_EXECUTABLE}\n"
247 " ctest: ${CTEST_EXECUTABLE}\n"
248 " --coverage flag: ${C_FLAG_COVERAGE_MESSAGE}")
249 endif()
250 endif()