CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. include_directories(${PROJECT_SOURCE_DIR}/include)
  2. include_directories(${PROJECT_SOURCE_DIR}/deps)
  3. include_directories(${PROJECT_SOURCE_DIR}/src)
  4. include_directories(${PROJECT_SOURCE_DIR}/src/server)
  5. include_directories(${PROJECT_SOURCE_DIR}/plugins)
  6. include_directories(${PROJECT_BINARY_DIR}/src_generated)
  7. include_directories(${CHECK_INCLUDE_DIRS})
  8. #############################
  9. # Compiled binaries folders #
  10. #############################
  11. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests)
  12. set(TESTS_BINARY_DIR ${CMAKE_BINARY_DIR}/bin/tests)
  13. # Load CMake Packages
  14. find_package(Check REQUIRED)
  15. find_package(Threads REQUIRED)
  16. if(UA_ENABLE_VALGRIND_UNIT_TESTS)
  17. find_package(Valgrind REQUIRED)
  18. endif()
  19. set(LIBS subunit ${CHECK_LIBRARIES} ${open62541_LIBRARIES})
  20. # Use different plugins for testing
  21. set(test_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
  22. ${PROJECT_SOURCE_DIR}/tests/testing_clock.c
  23. ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
  24. ${PROJECT_SOURCE_DIR}/plugins/ua_config_default.c
  25. ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
  26. ${PROJECT_SOURCE_DIR}/plugins/ua_nodestore_default.c
  27. ${PROJECT_SOURCE_DIR}/tests/testing_clock.c)
  28. add_library(open62541-testplugins OBJECT ${test_plugin_sources})
  29. add_dependencies(open62541-testplugins open62541)
  30. # Workaround some clang warnings in the unit tests
  31. if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
  32. add_definitions(-Wno-sign-conversion)
  33. endif()
  34. # Unit Test Definition Macro
  35. set(VALGRIND_FLAGS --quiet --trace-children=yes --leak-check=full)
  36. macro(add_test_valgrind TEST_NAME)
  37. if(UA_ENABLE_VALGRIND_UNIT_TESTS)
  38. add_test(${TEST_NAME} valgrind --error-exitcode=1 --suppressions=${PROJECT_SOURCE_DIR}/tools/valgrind_suppressions.supp ${VALGRIND_FLAGS} ${ARGN})
  39. else()
  40. add_test(${TEST_NAME} ${ARGN})
  41. endif()
  42. endmacro()
  43. # the unit test are built directly on the open62541 object files. so they can
  44. # access symbols that are hidden/not exported to the shared library
  45. add_executable(check_types_builtin check_types_builtin.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  46. target_link_libraries(check_types_builtin ${LIBS})
  47. add_test_valgrind(types_builtin ${TESTS_BINARY_DIR}/check_types_builtin)
  48. add_executable(check_types_memory check_types_memory.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  49. target_link_libraries(check_types_memory ${LIBS})
  50. add_test_valgrind(types_memory ${TESTS_BINARY_DIR}/check_types_memory)
  51. add_executable(check_types_range check_types_range.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  52. target_link_libraries(check_types_range ${LIBS})
  53. add_test_valgrind(types_range ${TESTS_BINARY_DIR}/check_types_range)
  54. add_executable(check_types_custom check_types_custom.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  55. target_link_libraries(check_types_custom ${LIBS})
  56. add_test_valgrind(types_custom ${TESTS_BINARY_DIR}/check_types_custom)
  57. add_executable(check_chunking check_chunking.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  58. target_link_libraries(check_chunking ${LIBS})
  59. add_test_valgrind(chunking ${TESTS_BINARY_DIR}/check_chunking)
  60. add_executable(check_utils check_utils.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  61. target_link_libraries(check_utils ${LIBS})
  62. add_test_valgrind(check_utils ${TESTS_BINARY_DIR}/check_utils)
  63. # Test Server
  64. add_executable(check_accesscontrol check_accesscontrol.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  65. target_link_libraries(check_accesscontrol ${LIBS})
  66. add_test_valgrind(check_accesscontrol ${TESTS_BINARY_DIR}/check_accesscontrol)
  67. add_executable(check_services_view check_services_view.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  68. target_link_libraries(check_services_view ${LIBS})
  69. add_test_valgrind(services_view ${TESTS_BINARY_DIR}/check_services_view)
  70. add_executable(check_services_attributes check_services_attributes.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  71. target_link_libraries(check_services_attributes ${LIBS})
  72. add_test_valgrind(services_attributes ${TESTS_BINARY_DIR}/check_services_attributes)
  73. add_executable(check_services_nodemanagement check_services_nodemanagement.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  74. target_link_libraries(check_services_nodemanagement ${LIBS})
  75. add_test_valgrind(services_nodemanagement ${TESTS_BINARY_DIR}/check_services_nodemanagement)
  76. add_executable(check_services_subscriptions check_services_subscriptions.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  77. target_link_libraries(check_services_subscriptions ${LIBS})
  78. add_test_valgrind(check_services_subscriptions ${TESTS_BINARY_DIR}/check_services_subscriptions)
  79. add_executable(check_nodestore check_nodestore.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  80. target_link_libraries(check_nodestore ${LIBS})
  81. add_test_valgrind(nodestore ${TESTS_BINARY_DIR}/check_nodestore)
  82. add_executable(check_session check_session.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  83. target_link_libraries(check_session ${LIBS})
  84. add_test_valgrind(session ${TESTS_BINARY_DIR}/check_session)
  85. add_executable(check_server_jobs check_server_jobs.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  86. target_link_libraries(check_server_jobs ${LIBS})
  87. add_test_valgrind(check_server_jobs ${TESTS_BINARY_DIR}/check_server_jobs)
  88. add_executable(check_server_userspace check_server_userspace.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  89. target_link_libraries(check_server_userspace ${LIBS})
  90. add_test_valgrind(check_server_userspace ${TESTS_BINARY_DIR}/check_server_userspace)
  91. if(UA_ENABLE_DISCOVERY)
  92. add_executable(check_discovery check_discovery.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  93. target_link_libraries(check_discovery ${LIBS})
  94. add_test_valgrind(discovery ${TESTS_BINARY_DIR}/check_discovery)
  95. endif()
  96. # Readspeed server
  97. add_executable(check_server_readspeed check_server_readspeed.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  98. target_link_libraries(check_server_readspeed ${LIBS})
  99. add_test_valgrind(check_server_readspeed ${TESTS_BINARY_DIR}/check_server_readspeed)
  100. # Test server with network dumps from files
  101. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
  102. ${CMAKE_CURRENT_BINARY_DIR}/client_CLO.bin
  103. ${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin
  104. ${CMAKE_CURRENT_BINARY_DIR}/client_Browse.bin
  105. ${CMAKE_CURRENT_BINARY_DIR}/client_Read.bin
  106. ${CMAKE_CURRENT_BINARY_DIR}/client_Write.bin
  107. PRE_BUILD
  108. COMMAND python ${PROJECT_SOURCE_DIR}/tools/hex2bin.py
  109. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_HELOPN.hex
  110. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_CLO.hex
  111. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_CreateActivateSession.hex
  112. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Browse.hex
  113. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Read.hex
  114. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Write.hex
  115. DEPENDS ${PROJECT_SOURCE_DIR}/tools/hex2bin.py
  116. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_HELOPN.hex
  117. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_CLO.hex
  118. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_CreateActivateSession.hex
  119. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Browse.hex
  120. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Read.hex
  121. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Write.hex)
  122. add_custom_target(client_HELOPN.bin DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin")
  123. add_custom_target(client_CreateActivateSession.bin DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin")
  124. add_executable(check_server_binary_messages check_server_binary_messages.c testing_networklayers.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  125. target_include_directories(check_server_binary_messages PRIVATE ${PROJECT_SOURCE_DIR}/src/server)
  126. target_link_libraries(check_server_binary_messages ${LIBS})
  127. add_dependencies(check_server_binary_messages client_HELOPN.bin)
  128. add_test_valgrind(check_server_binary_messages_browse ${TESTS_BINARY_DIR}/check_server_binary_messages
  129. ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
  130. ${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin
  131. ${CMAKE_CURRENT_BINARY_DIR}/client_Browse.bin
  132. ${CMAKE_CURRENT_BINARY_DIR}/client_CLO.bin)
  133. add_test_valgrind(check_server_binary_messages_read ${TESTS_BINARY_DIR}/check_server_binary_messages
  134. ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
  135. ${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin
  136. ${CMAKE_CURRENT_BINARY_DIR}/client_Read.bin
  137. ${CMAKE_CURRENT_BINARY_DIR}/client_CLO.bin)
  138. add_test_valgrind(check_server_binary_messages_write ${TESTS_BINARY_DIR}/check_server_binary_messages
  139. ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
  140. ${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin
  141. ${CMAKE_CURRENT_BINARY_DIR}/client_Write.bin
  142. ${CMAKE_CURRENT_BINARY_DIR}/client_CLO.bin)
  143. # Test Client
  144. add_executable(check_client check_client.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  145. target_link_libraries(check_client ${LIBS})
  146. add_test_valgrind(check_client ${TESTS_BINARY_DIR}/check_client)
  147. add_executable(check_client_async check_client_async.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  148. target_link_libraries(check_client_async ${LIBS})
  149. add_test_valgrind(check_client_async ${TESTS_BINARY_DIR}/check_client_async)
  150. add_executable(check_client_subscriptions check_client_subscriptions.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  151. target_link_libraries(check_client_subscriptions ${LIBS})
  152. add_test_valgrind(check_client_subscriptions ${TESTS_BINARY_DIR}/check_client_subscriptions)
  153. add_executable(check_client_highlevel check_client_highlevel.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
  154. target_link_libraries(check_client_highlevel ${LIBS})
  155. add_test_valgrind(check_client_highlevel ${TESTS_BINARY_DIR}/check_client_highlevel)