CMakeLists.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. # Load CMake Packages
  2. find_package(Check REQUIRED)
  3. set(LIBS ${CHECK_LIBRARIES} ${open62541_LIBRARIES})
  4. include_directories(${CHECK_INCLUDE_DIRS})
  5. #find_package(Threads REQUIRED)
  6. if(NOT MSVC AND UA_ENABLE_UNIT_TESTS_MEMCHECK)
  7. find_package(Valgrind REQUIRED)
  8. endif()
  9. if(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD")
  10. link_directories(/usr/local/lib)
  11. add_definitions(-Wno-gnu-zero-variadic-macro-arguments)
  12. endif()
  13. include_directories(${PROJECT_SOURCE_DIR}/include)
  14. include_directories(${PROJECT_SOURCE_DIR}/deps)
  15. include_directories(${PROJECT_SOURCE_DIR}/src)
  16. include_directories(${PROJECT_SOURCE_DIR}/src/server)
  17. include_directories(${PROJECT_SOURCE_DIR}/src/pubsub)
  18. include_directories(${PROJECT_SOURCE_DIR}/plugins)
  19. include_directories(${PROJECT_SOURCE_DIR}/plugins/historydata)
  20. include_directories(${PROJECT_BINARY_DIR}/src_generated)
  21. include_directories(${PROJECT_SOURCE_DIR}/tests/testing-plugins)
  22. add_definitions(-DUA_sleep_ms=UA_comboSleep)
  23. #############################
  24. # Compiled binaries folders #
  25. #############################
  26. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests)
  27. if (MSVC)
  28. set(TESTS_BINARY_DIR ${CMAKE_BINARY_DIR}/bin/tests/${CMAKE_BUILD_TYPE})
  29. else()
  30. set(TESTS_BINARY_DIR ${CMAKE_BINARY_DIR}/bin/tests)
  31. endif()
  32. # Use different plugins for testing
  33. set(test_plugin_sources ${PROJECT_SOURCE_DIR}/arch/ua_network_tcp.c
  34. ${PROJECT_SOURCE_DIR}/tests/testing-plugins/testing_clock.c
  35. ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
  36. ${PROJECT_SOURCE_DIR}/plugins/ua_config_default.c
  37. ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
  38. ${PROJECT_SOURCE_DIR}/plugins/ua_pki_certificate.c
  39. ${PROJECT_SOURCE_DIR}/plugins/ua_nodestore_default.c
  40. ${PROJECT_SOURCE_DIR}/plugins/historydata/ua_historydatabackend_memory.c
  41. ${PROJECT_SOURCE_DIR}/plugins/historydata/ua_historydatagathering_default.c
  42. ${PROJECT_SOURCE_DIR}/plugins/historydata/ua_historydatabase_default.c
  43. ${PROJECT_SOURCE_DIR}/plugins/securityPolicies/ua_securitypolicy_none.c
  44. ${PROJECT_SOURCE_DIR}/tests/testing-plugins/testing_policy.c
  45. ${PROJECT_SOURCE_DIR}/tests/testing-plugins/testing_networklayers.c
  46. )
  47. if(UA_ENABLE_ENCRYPTION)
  48. set(test_plugin_sources ${test_plugin_sources}
  49. ${PROJECT_SOURCE_DIR}/plugins/securityPolicies/ua_securitypolicy_basic128rsa15.c)
  50. set(test_plugin_sources ${test_plugin_sources}
  51. ${PROJECT_SOURCE_DIR}/plugins/securityPolicies/ua_securitypolicy_basic256sha256.c)
  52. endif()
  53. add_library(open62541-testplugins OBJECT ${test_plugin_sources} ${PROJECT_SOURCE_DIR}/arch/${UA_ARCHITECTURE}/ua_architecture_functions.c)
  54. add_dependencies(open62541-testplugins open62541)
  55. target_compile_definitions(open62541-testplugins PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
  56. if(NOT MSVC)
  57. add_definitions(-Wno-deprecated-declarations)
  58. endif()
  59. # Workaround some clang warnings in the uni tests
  60. if((NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND (CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang"))
  61. add_definitions(-Wno-sign-conversion)
  62. endif()
  63. # Unit Test Definition Macro
  64. # For now we need to disable the libc freeres. See https://github.com/open62541/open62541/pull/1003#issuecomment-315045143
  65. # This also requires to disable the phtread cache with no-nptl-pthread-stackcache
  66. set(VALGRIND_FLAGS --quiet --trace-children=yes --leak-check=full --run-libc-freeres=no --sim-hints=no-nptl-pthread-stackcache --track-fds=yes)
  67. macro(add_test_valgrind TEST_NAME)
  68. if(UA_ENABLE_UNIT_TESTS_MEMCHECK)
  69. if(MSVC)
  70. add_test(${TEST_NAME} drmemory -batch -exit_code_if_errors 1 -results_to_stderr -summary -- ${ARGN})
  71. else()
  72. set(VALGRIND_LOG ${TESTS_BINARY_DIR}/${TEST_NAME}.log)
  73. set(VALGRIND_CMD valgrind --error-exitcode=1 --suppressions=${PROJECT_SOURCE_DIR}/tools/valgrind_suppressions.supp ${VALGRIND_FLAGS} --log-file=${VALGRIND_LOG} ${ARGN})
  74. add_test(${TEST_NAME} ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/valgrind_check_error.py ${VALGRIND_LOG} ${VALGRIND_CMD})
  75. endif()
  76. else()
  77. add_test(${TEST_NAME} ${ARGN})
  78. endif()
  79. if (UA_BUILD_FUZZING_CORPUS)
  80. target_sources(check_${TEST_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/tests/fuzz/ua_debug_dump_pkgs_file.c)
  81. file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/corpus/${TEST_NAME})
  82. target_compile_definitions(check_${TEST_NAME} PRIVATE UA_CORPUS_OUTPUT_DIR="${PROJECT_BINARY_DIR}/corpus/${TEST_NAME}")
  83. endif()
  84. endmacro()
  85. add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
  86. # the unit test are built directly on the open62541 object files. so they can
  87. # access symbols that are hidden/not exported to the shared library
  88. add_executable(check_types_builtin check_types_builtin.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  89. target_link_libraries(check_types_builtin ${LIBS})
  90. add_test_valgrind(types_builtin ${TESTS_BINARY_DIR}/check_types_builtin)
  91. if(UA_ENABLE_JSON_ENCODING)
  92. add_executable(check_types_builtin_json check_types_builtin_json.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  93. target_link_libraries(check_types_builtin_json ${LIBS})
  94. add_test_valgrind(types_builtin_json ${TESTS_BINARY_DIR}/check_types_builtin_json)
  95. if(UA_ENABLE_PUBSUB)
  96. #later batch
  97. #add_executable(check_pubsub_encoding_json pubsub/check_pubsub_encoding_json.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  98. #target_link_libraries(check_pubsub_encoding_json ${LIBS})
  99. #add_test_valgrind(pubsub_encoding_json ${TESTS_BINARY_DIR}/check_pubsub_encoding_json)
  100. endif()
  101. endif()
  102. add_executable(check_types_memory check_types_memory.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  103. target_link_libraries(check_types_memory ${LIBS})
  104. add_test_valgrind(types_memory ${TESTS_BINARY_DIR}/check_types_memory)
  105. add_executable(check_types_range check_types_range.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  106. target_link_libraries(check_types_range ${LIBS})
  107. add_test_valgrind(types_range ${TESTS_BINARY_DIR}/check_types_range)
  108. add_executable(check_types_custom check_types_custom.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  109. target_link_libraries(check_types_custom ${LIBS})
  110. add_test_valgrind(types_custom ${TESTS_BINARY_DIR}/check_types_custom)
  111. add_executable(check_chunking check_chunking.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  112. target_link_libraries(check_chunking ${LIBS})
  113. add_test_valgrind(chunking ${TESTS_BINARY_DIR}/check_chunking)
  114. add_executable(check_utils check_utils.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  115. target_link_libraries(check_utils ${LIBS})
  116. add_test_valgrind(utils ${TESTS_BINARY_DIR}/check_utils)
  117. add_executable(check_securechannel check_securechannel.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  118. target_link_libraries(check_securechannel ${LIBS})
  119. add_test_valgrind(securechannel ${TESTS_BINARY_DIR}/check_securechannel)
  120. add_executable(check_timer check_timer.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  121. target_link_libraries(check_timer ${LIBS})
  122. add_test_valgrind(timer ${TESTS_BINARY_DIR}/check_timer)
  123. # Test Server
  124. add_executable(check_accesscontrol server/check_accesscontrol.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  125. target_link_libraries(check_accesscontrol ${LIBS})
  126. add_test_valgrind(accesscontrol ${TESTS_BINARY_DIR}/check_accesscontrol)
  127. add_executable(check_services_view server/check_services_view.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  128. target_link_libraries(check_services_view ${LIBS})
  129. add_test_valgrind(services_view ${TESTS_BINARY_DIR}/check_services_view)
  130. add_executable(check_services_attributes server/check_services_attributes.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  131. target_link_libraries(check_services_attributes ${LIBS})
  132. add_test_valgrind(services_attributes ${TESTS_BINARY_DIR}/check_services_attributes)
  133. add_executable(check_services_nodemanagement server/check_services_nodemanagement.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  134. target_link_libraries(check_services_nodemanagement ${LIBS})
  135. add_test_valgrind(services_nodemanagement ${TESTS_BINARY_DIR}/check_services_nodemanagement)
  136. add_executable(check_services_subscriptions server/check_services_subscriptions.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  137. target_link_libraries(check_services_subscriptions ${LIBS})
  138. add_test_valgrind(services_subscriptions ${TESTS_BINARY_DIR}/check_services_subscriptions)
  139. add_executable(check_monitoreditem_filter server/check_monitoreditem_filter.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  140. target_link_libraries(check_monitoreditem_filter ${LIBS})
  141. add_test_valgrind(monitoreditem_filter ${TESTS_BINARY_DIR}/check_monitoreditem_filter)
  142. add_executable(check_subscription_events server/check_subscription_events.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  143. target_link_libraries(check_subscription_events ${LIBS})
  144. add_test_valgrind(subscription_events ${TESTS_BINARY_DIR}/check_subscription_events)
  145. add_executable(check_nodestore server/check_nodestore.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  146. target_link_libraries(check_nodestore ${LIBS})
  147. add_test_valgrind(nodestore ${TESTS_BINARY_DIR}/check_nodestore)
  148. add_executable(check_historical_data server/check_historical_data.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  149. target_link_libraries(check_historical_data ${LIBS})
  150. add_test_valgrind(historical_data ${TESTS_BINARY_DIR}/check_historical_data)
  151. add_executable(check_session server/check_session.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  152. target_link_libraries(check_session ${LIBS})
  153. add_test_valgrind(session ${TESTS_BINARY_DIR}/check_session)
  154. add_executable(check_server_jobs server/check_server_jobs.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  155. target_link_libraries(check_server_jobs ${LIBS})
  156. add_test_valgrind(server_jobs ${TESTS_BINARY_DIR}/check_server_jobs)
  157. add_executable(check_server_userspace server/check_server_userspace.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  158. target_link_libraries(check_server_userspace ${LIBS})
  159. add_test_valgrind(server_userspace ${TESTS_BINARY_DIR}/check_server_userspace)
  160. add_executable(check_node_inheritance server/check_node_inheritance.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  161. target_link_libraries(check_node_inheritance ${LIBS})
  162. add_test_valgrind(node_inheritance ${TESTS_BINARY_DIR}/check_node_inheritance)
  163. add_executable(check_local_monitored_item server/check_local_monitored_item.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  164. target_link_libraries(check_local_monitored_item ${LIBS})
  165. add_test_valgrind(local_monitored_item ${TESTS_BINARY_DIR}/check_local_monitored_item)
  166. if(UA_ENABLE_DISCOVERY)
  167. add_executable(check_discovery server/check_discovery.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  168. target_link_libraries(check_discovery ${LIBS})
  169. add_test_valgrind(discovery ${TESTS_BINARY_DIR}/check_discovery)
  170. endif()
  171. if(UA_ENABLE_PUBSUB)
  172. add_executable(check_pubsub_encoding pubsub/check_pubsub_encoding.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  173. target_link_libraries(check_pubsub_encoding ${LIBS})
  174. add_test_valgrind(pubsub_encoding ${TESTS_BINARY_DIR}/check_pubsub_encoding)
  175. add_executable(check_pubsub_pds pubsub/check_pubsub_pds.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
  176. target_link_libraries(check_pubsub_pds ${LIBS})
  177. add_test_valgrind(check_pubsub_pds ${TESTS_BINARY_DIR}/check_pubsub_pds)
  178. add_executable(check_pubsub_connection_udp pubsub/check_pubsub_connection_udp.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
  179. target_link_libraries(check_pubsub_connection_udp ${LIBS})
  180. add_test_valgrind(check_pubsub_connection_udp ${TESTS_BINARY_DIR}/check_pubsub_connection_udp)
  181. add_executable(check_pubsub_publish pubsub/check_pubsub_publish.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
  182. target_link_libraries(check_pubsub_publish ${LIBS})
  183. add_test_valgrind(check_pubsub_publish ${TESTS_BINARY_DIR}/check_pubsub_publish)
  184. add_executable(check_pubsub_publishspeed pubsub/check_pubsub_publishspeed.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
  185. target_link_libraries(check_pubsub_publishspeed ${LIBS})
  186. add_test_valgrind(check_pubsub_publishspeed ${TESTS_BINARY_DIR}/check_pubsub_publish)
  187. add_executable(check_pubsub_multiple_layer pubsub/check_pubsub_multiple_layer.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
  188. target_link_libraries(check_pubsub_multiple_layer ${LIBS})
  189. add_test_valgrind(check_pubsub_multiple_layer ${TESTS_BINARY_DIR}/check_pubsub_multiple_layer)
  190. if(UA_ENABLE_PUBSUB_INFORMATIONMODEL)
  191. add_executable(check_pubsub_informationmodel pubsub/check_pubsub_informationmodel.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
  192. target_link_libraries(check_pubsub_informationmodel ${LIBS})
  193. add_test(check_pubsub_informationmodel ${TESTS_BINARY_DIR}/check_pubsub_informationmodel)
  194. if(UA_ENABLE_PUBSUB_INFORMATIONMODEL_METHODS)
  195. add_executable(check_pubsub_informationmodel_methods pubsub/check_pubsub_informationmodel_methods.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
  196. target_link_libraries(check_pubsub_informationmodel_methods ${LIBS})
  197. add_test(check_pubsub_informationmodel_methods ${TESTS_BINARY_DIR}/check_pubsub_informationmodel_methods)
  198. endif()
  199. endif()
  200. endif()
  201. add_executable(check_server_readspeed server/check_server_readspeed.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  202. target_link_libraries(check_server_readspeed ${LIBS})
  203. add_test_valgrind(server_readspeed ${TESTS_BINARY_DIR}/check_server_readspeed)
  204. if(UA_ENABLE_SUBSCRIPTIONS)
  205. add_executable(check_server_monitoringspeed server/check_server_monitoringspeed.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  206. target_link_libraries(check_server_monitoringspeed ${LIBS})
  207. add_test_valgrind(server_monitoringspeed ${TESTS_BINARY_DIR}/check_server_monitoringspeed)
  208. endif()
  209. # Test Client
  210. add_executable(check_client client/check_client.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  211. target_link_libraries(check_client ${LIBS})
  212. add_test_valgrind(client ${TESTS_BINARY_DIR}/check_client)
  213. add_executable(check_client_securechannel client/check_client_securechannel.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  214. target_link_libraries(check_client_securechannel ${LIBS})
  215. add_test_valgrind(client_securechannel ${TESTS_BINARY_DIR}/check_client_securechannel)
  216. add_executable(check_client_async client/check_client_async.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  217. target_link_libraries(check_client_async ${LIBS})
  218. add_test_valgrind(client_async ${TESTS_BINARY_DIR}/check_client_async)
  219. add_executable(check_client_async_connect client/check_client_async_connect.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  220. target_link_libraries(check_client_async_connect ${LIBS})
  221. add_test_valgrind(client_async_connect ${TESTS_BINARY_DIR}/check_client_async_connect)
  222. add_executable(check_client_subscriptions client/check_client_subscriptions.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  223. target_link_libraries(check_client_subscriptions ${LIBS})
  224. add_test_valgrind(client_subscriptions ${TESTS_BINARY_DIR}/check_client_subscriptions)
  225. add_executable(check_client_highlevel client/check_client_highlevel.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  226. target_link_libraries(check_client_highlevel ${LIBS})
  227. add_test_valgrind(client_highlevel ${TESTS_BINARY_DIR}/check_client_highlevel)
  228. # Test Encryption
  229. if(UA_ENABLE_ENCRYPTION)
  230. add_executable(check_encryption_basic128rsa15 encryption/check_encryption_basic128rsa15.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  231. target_link_libraries(check_encryption_basic128rsa15 ${LIBS})
  232. add_test_valgrind(encryption_basic128rsa15 ${TESTS_BINARY_DIR}/check_encryption_basic128rsa15)
  233. add_executable(check_encryption_basic256sha256 encryption/check_encryption_basic256sha256.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  234. target_link_libraries(check_encryption_basic256sha256 ${LIBS})
  235. add_test_valgrind(encryption_basic256sha256 ${TESTS_BINARY_DIR}/check_encryption_basic256sha256)
  236. endif()
  237. # Tests for Nodeset Compiler
  238. add_subdirectory(nodeset-compiler)