CMakeLists.txt 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. # CMake build script for ZeroMQ tests
  2. cmake_minimum_required(VERSION "2.8.1")
  3. # On Windows: solution file will be called tests.sln
  4. project(tests)
  5. set(tests
  6. test_ancillaries
  7. test_system
  8. test_pair_inproc
  9. test_pair_tcp
  10. test_reqrep_inproc
  11. test_reqrep_tcp
  12. test_hwm
  13. test_hwm_pubsub
  14. test_reqrep_device
  15. test_sub_forward
  16. test_invalid_rep
  17. test_msg_flags
  18. test_msg_ffn
  19. test_connect_resolve
  20. test_immediate
  21. test_last_endpoint
  22. test_term_endpoint
  23. test_router_mandatory
  24. test_probe_router
  25. test_stream
  26. test_stream_empty
  27. test_stream_disconnect
  28. test_disconnect_inproc
  29. test_unbind_wildcard
  30. test_ctx_options
  31. test_ctx_destroy
  32. test_security_no_zap_handler
  33. test_security_null
  34. test_security_plain
  35. test_security_zap
  36. test_iov
  37. test_spec_req
  38. test_spec_rep
  39. test_spec_dealer
  40. test_spec_router
  41. test_spec_pushpull
  42. test_req_correlate
  43. test_req_relaxed
  44. test_conflate
  45. test_inproc_connect
  46. test_issue_566
  47. test_shutdown_stress
  48. test_timeo
  49. test_many_sockets
  50. test_diffserv
  51. test_connect_rid
  52. test_xpub_nodrop
  53. test_pub_invert_matching
  54. test_setsockopt
  55. test_sockopt_hwm
  56. test_heartbeats
  57. test_atomics
  58. test_bind_src_address
  59. test_capabilities
  60. test_metadata
  61. test_router_handover
  62. test_srcfd
  63. test_stream_timeout
  64. test_xpub_manual
  65. test_xpub_welcome_msg
  66. test_xpub_verbose
  67. test_base85
  68. test_bind_after_connect_tcp
  69. test_sodium
  70. test_monitor
  71. test_socket_null
  72. test_reconnect_ivl
  73. test_reconnect_options
  74. test_mock_pub_sub)
  75. if(NOT WIN32)
  76. list(APPEND tests test_security_gssapi test_socks test_connect_null_fuzzer test_bind_null_fuzzer test_connect_fuzzer test_bind_fuzzer)
  77. endif()
  78. if(ZMQ_HAVE_CURVE)
  79. list(APPEND tests test_security_curve)
  80. if(NOT WIN32)
  81. list(APPEND tests test_connect_curve_fuzzer test_bind_curve_fuzzer test_z85_decode_fuzzer)
  82. endif()
  83. endif()
  84. option(ENABLE_CAPSH "Run tests that require sudo and capsh (for cap_net_admin)" OFF)
  85. if(ENABLE_CAPSH)
  86. find_program(CAPSH_PROGRAM NAMES capsh)
  87. if(CAPSH_PROGRAM)
  88. list(APPEND tests test_pair_tcp_cap_net_admin)
  89. else()
  90. message(STATUS "capsh not found, skipping tests that require CAP_NET_ADMIN")
  91. endif()
  92. endif()
  93. if(ZMQ_HAVE_IPC)
  94. list(APPEND tests test_ipc_wildcard test_pair_ipc test_reqrep_ipc test_rebind_ipc)
  95. endif()
  96. if(NOT WIN32)
  97. list(
  98. APPEND
  99. tests
  100. test_proxy
  101. test_proxy_hwm
  102. test_proxy_single_socket
  103. test_proxy_terminate
  104. test_getsockopt_memset
  105. test_filter_ipc
  106. test_stream_exceeds_buffer
  107. test_router_mandatory_hwm
  108. test_use_fd
  109. test_zmq_poll_fd)
  110. if(HAVE_FORK)
  111. list(APPEND tests test_fork)
  112. endif()
  113. if(CMAKE_SYSTEM_NAME MATCHES "Linux")
  114. list(APPEND tests test_abstract_ipc)
  115. if(ZMQ_HAVE_TIPC)
  116. list(
  117. APPEND
  118. tests
  119. test_address_tipc
  120. test_pair_tipc
  121. test_reqrep_device_tipc
  122. test_reqrep_tipc
  123. test_router_mandatory_tipc
  124. test_sub_forward_tipc
  125. test_connect_delay_tipc
  126. test_shutdown_stress_tipc
  127. test_term_endpoint_tipc)
  128. endif()
  129. endif()
  130. endif()
  131. if(WITH_VMCI)
  132. list(APPEND tests test_pair_vmci test_reqrep_vmci)
  133. endif()
  134. if(ENABLE_DRAFTS)
  135. list(
  136. APPEND
  137. tests
  138. test_poller
  139. test_thread_safe
  140. test_client_server
  141. test_timers
  142. test_radio_dish
  143. test_scatter_gather
  144. test_dgram
  145. test_app_meta
  146. test_router_notify
  147. test_xpub_manual_last_value
  148. test_peer
  149. test_msg_init
  150. test_channel
  151. test_hello_msg
  152. test_disconnect_msg
  153. )
  154. endif()
  155. if(ZMQ_HAVE_WS)
  156. list(APPEND tests test_ws_transport)
  157. if(ZMQ_HAVE_WSS)
  158. list(APPEND tests test_wss_transport)
  159. endif()
  160. endif()
  161. # add location of platform.hpp for Windows builds
  162. if(WIN32)
  163. add_definitions(-DZMQ_CUSTOM_PLATFORM_HPP)
  164. add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
  165. # Same name on 64bit systems
  166. link_libraries(ws2_32.lib)
  167. endif()
  168. add_library(
  169. unity STATIC
  170. "${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity.c" "${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity.h"
  171. "${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity_internals.h")
  172. set_target_properties(unity PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity.h")
  173. target_compile_definitions(unity PUBLIC "UNITY_USE_COMMAND_LINE_ARGS" "UNITY_EXCLUDE_FLOAT")
  174. target_include_directories(unity PUBLIC "${CMAKE_CURRENT_LIST_DIR}/../external/unity")
  175. set(TESTUTIL_SOURCES
  176. testutil.cpp
  177. testutil.hpp
  178. testutil_monitoring.cpp
  179. testutil_monitoring.hpp
  180. testutil_security.cpp
  181. testutil_security.hpp
  182. testutil_unity.cpp
  183. testutil_unity.hpp)
  184. if(BUILD_STATIC)
  185. add_library(testutil-static STATIC ${TESTUTIL_SOURCES})
  186. target_link_libraries(testutil-static libzmq-static ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} unity)
  187. endif()
  188. if(BUILD_SHARED)
  189. add_library(testutil STATIC ${TESTUTIL_SOURCES})
  190. target_link_libraries(testutil libzmq ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} unity)
  191. endif()
  192. if(BUILD_STATIC AND NOT BUILD_SHARED)
  193. # use testutil-static for both tests and unit tests
  194. set(TESTUTIL_LIB testutil-static)
  195. else()
  196. # use testutil for tests and testutil-static for unit tests
  197. set(TESTUTIL_LIB testutil)
  198. endif()
  199. if(MSVC_VERSION LESS 1700)
  200. set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/../external/unity/unity.c" PROPERTIES LANGUAGE CXX)
  201. endif()
  202. if(MSVC_VERSION LESS 1600)
  203. target_compile_definitions(unity PUBLIC "UNITY_EXCLUDE_STDINT_H")
  204. endif()
  205. # add include dirs for all targets
  206. include_directories("${ZeroMQ_SOURCE_DIR}/../include" "${ZeroMQ_BINARY_DIR}")
  207. if(WIN32)
  208. add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
  209. endif()
  210. # Does not work, times out every time
  211. if(WIN32)
  212. list(REMOVE_ITEM tests test_many_sockets)
  213. endif()
  214. foreach(test ${tests})
  215. # target_sources not supported before CMake 3.1
  216. if(ZMQ_HAVE_CURVE AND ${test} MATCHES test_security_curve)
  217. add_executable(${test} ${test}.cpp "../src/tweetnacl.c" "../src/err.cpp" "../src/random.cpp" "../src/clock.cpp")
  218. else()
  219. add_executable(${test} ${test}.cpp)
  220. endif()
  221. target_link_libraries(${test} ${TESTUTIL_LIB})
  222. if(WIN32)
  223. # This is the output for Debug dynamic builds on Visual Studio 6.0 You should provide the correct directory, don't
  224. # know how to do it automatically
  225. find_path(LIBZMQ_PATH "libzmq.lib" PATHS "../bin/Win32/Debug/v120/dynamic")
  226. if(NOT ${LIBZMQ_PATH} STREQUAL "LIBZMQ_PATH-NOTFOUND")
  227. set_target_properties(${test} PROPERTIES LINK_FLAGS "/LIBPATH:${LIBZMQ_PATH}")
  228. endif()
  229. else()
  230. # per-test directories not generated on OS X / Darwin
  231. if(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang.*")
  232. link_directories(${test} PRIVATE "${ZeroMQ_SOURCE_DIR}/../lib")
  233. endif()
  234. endif()
  235. if(RT_LIBRARY)
  236. target_link_libraries(${test} ${RT_LIBRARY})
  237. endif()
  238. if(CMAKE_SYSTEM_NAME MATCHES "QNX")
  239. target_link_libraries(${test} socket)
  240. target_link_libraries(${test} m)
  241. endif()
  242. if(WIN32)
  243. add_test(
  244. NAME ${test}
  245. WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH}
  246. COMMAND ${test})
  247. else()
  248. if(${test} MATCHES "_cap_net_admin")
  249. add_test(NAME ${test} COMMAND sh -c "sudo ${CAPSH_PROGRAM} --caps=cap_net_admin+eip -- -c $<TARGET_FILE:${test}>")
  250. else()
  251. add_test(NAME ${test} COMMAND ${test})
  252. endif()
  253. endif()
  254. set_tests_properties(${test} PROPERTIES TIMEOUT 10)
  255. set_tests_properties(${test} PROPERTIES SKIP_RETURN_CODE 77)
  256. endforeach()
  257. # override timeout for these tests
  258. if(ZMQ_HAVE_CURVE)
  259. set_tests_properties(test_security_curve PROPERTIES TIMEOUT 60)
  260. endif()
  261. set_tests_properties(test_heartbeats PROPERTIES TIMEOUT 60)
  262. if(WIN32 AND ENABLE_DRAFTS)
  263. set_tests_properties(test_radio_dish PROPERTIES TIMEOUT 30)
  264. endif()
  265. # add additional required flags ZMQ_USE_TWEETNACL will already be defined when not using sodium
  266. if(ZMQ_HAVE_CURVE AND NOT ZMQ_USE_TWEETNACL)
  267. target_compile_definitions(test_security_curve PRIVATE "-DZMQ_USE_TWEETNACL")
  268. endif()
  269. set_tests_properties(test_security_zap PROPERTIES TIMEOUT 60)
  270. set_tests_properties(test_reconnect_ivl PROPERTIES TIMEOUT 15)
  271. # Check whether all tests in the current folder are present
  272. file(READ "${CMAKE_CURRENT_LIST_FILE}" CURRENT_LIST_FILE_CONTENT)
  273. file(GLOB ALL_TEST_SOURCES "test_*.cpp")
  274. foreach(TEST_SOURCE ${ALL_TEST_SOURCES})
  275. get_filename_component(TESTNAME "${TEST_SOURCE}" NAME_WE)
  276. string(REGEX MATCH "${TESTNAME}" MATCH_TESTNAME "${CURRENT_LIST_FILE_CONTENT}")
  277. if(NOT MATCH_TESTNAME)
  278. message(AUTHOR_WARNING "Test '${TESTNAME}' is not known to CTest.")
  279. endif()
  280. endforeach()