CMakeLists.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests)
  13. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests)
  14. set(TESTS_BINARY_DIR ${CMAKE_BINARY_DIR}/bin/tests)
  15. find_package(Check REQUIRED)
  16. find_package(Threads REQUIRED)
  17. if(UA_ENABLE_VALGRIND_UNIT_TESTS)
  18. find_package(Valgrind REQUIRED)
  19. endif()
  20. set(LIBS ${CHECK_LIBRARIES} ${open62541_LIBRARIES} open62541)
  21. if(NOT WIN32)
  22. list(APPEND LIBS pthread m)
  23. if(NOT APPLE)
  24. list(APPEND LIBS rt subunit)
  25. endif()
  26. else()
  27. list(APPEND LIBS ws2_32)
  28. endif()
  29. if(UA_ENABLE_MULTITHREADING)
  30. list(APPEND LIBS urcu-cds urcu urcu-common)
  31. endif()
  32. if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
  33. add_definitions(-Wno-sign-conversion)
  34. endif()
  35. # Unit Test Definition Macro
  36. set(VALGRIND_FLAGS --quiet --trace-children=yes --leak-check=full)
  37. macro(add_test_valgrind TEST_NAME)
  38. if(UA_ENABLE_VALGRIND_UNIT_TESTS)
  39. add_test(${TEST_NAME} valgrind --error-exitcode=1 ${VALGRIND_FLAGS} ${ARGN})
  40. else()
  41. add_test(${TEST_NAME} ${ARGN})
  42. endif()
  43. endmacro()
  44. # the unit test are built directly on the open62541 object files. so they can
  45. # access symbols that are hidden/not exported to the shared library
  46. add_executable(check_types_builtin check_types_builtin.c $<TARGET_OBJECTS:open62541-object>)
  47. target_link_libraries(check_types_builtin ${LIBS})
  48. add_test_valgrind(types_builtin ${TESTS_BINARY_DIR}/check_types_builtin)
  49. add_executable(check_types_memory check_types_memory.c $<TARGET_OBJECTS:open62541-object>)
  50. target_link_libraries(check_types_memory ${LIBS})
  51. add_test_valgrind(types_memory ${TESTS_BINARY_DIR}/check_types_memory)
  52. add_executable(check_types_range check_types_range.c $<TARGET_OBJECTS:open62541-object>)
  53. target_link_libraries(check_types_range ${LIBS})
  54. add_test_valgrind(types_range ${TESTS_BINARY_DIR}/check_types_range)
  55. add_executable(check_types_custom check_types_custom.c $<TARGET_OBJECTS:open62541-object>)
  56. target_link_libraries(check_types_custom ${LIBS})
  57. add_test_valgrind(types_custom ${TESTS_BINARY_DIR}/check_types_custom)
  58. add_executable(check_chunking check_chunking.c $<TARGET_OBJECTS:open62541-object>)
  59. target_link_libraries(check_chunking ${LIBS})
  60. add_test_valgrind(chunking ${TESTS_BINARY_DIR}/check_chunking)
  61. add_executable(check_utils check_utils.c $<TARGET_OBJECTS:open62541-object>)
  62. target_link_libraries(check_utils ${LIBS})
  63. add_test_valgrind(check_utils ${TESTS_BINARY_DIR}/check_utils)
  64. # Test Server
  65. add_executable(check_services_view check_services_view.c $<TARGET_OBJECTS:open62541-object>)
  66. target_link_libraries(check_services_view ${LIBS})
  67. add_test_valgrind(services_view ${TESTS_BINARY_DIR}/check_services_view)
  68. add_executable(check_services_attributes check_services_attributes.c $<TARGET_OBJECTS:open62541-object>)
  69. target_link_libraries(check_services_attributes ${LIBS})
  70. add_test_valgrind(services_attributes ${TESTS_BINARY_DIR}/check_services_attributes)
  71. add_executable(check_services_nodemanagement check_services_nodemanagement.c $<TARGET_OBJECTS:open62541-object>)
  72. target_link_libraries(check_services_nodemanagement ${LIBS})
  73. add_test_valgrind(services_nodemanagement ${TESTS_BINARY_DIR}/check_services_nodemanagement)
  74. add_executable(check_services_subscriptions check_services_subscriptions.c $<TARGET_OBJECTS:open62541-object>)
  75. target_link_libraries(check_services_subscriptions ${LIBS})
  76. add_test_valgrind(check_services_subscriptions ${TESTS_BINARY_DIR}/check_services_subscriptions)
  77. add_executable(check_nodestore check_nodestore.c $<TARGET_OBJECTS:open62541-object>)
  78. target_link_libraries(check_nodestore ${LIBS})
  79. add_test_valgrind(nodestore ${TESTS_BINARY_DIR}/check_nodestore)
  80. add_executable(check_session check_session.c $<TARGET_OBJECTS:open62541-object>)
  81. target_link_libraries(check_session ${LIBS})
  82. add_test_valgrind(session ${TESTS_BINARY_DIR}/check_session)
  83. add_executable(check_server_jobs check_server_jobs.c $<TARGET_OBJECTS:open62541-object>)
  84. target_link_libraries(check_server_jobs ${LIBS})
  85. add_test_valgrind(check_server_jobs ${TESTS_BINARY_DIR}/check_server_jobs)
  86. add_executable(check_server_userspace check_server_userspace.c $<TARGET_OBJECTS:open62541-object>)
  87. target_link_libraries(check_server_userspace ${LIBS})
  88. add_test_valgrind(check_server_userspace ${TESTS_BINARY_DIR}/check_server_userspace)
  89. add_executable(check_discovery check_discovery.c $<TARGET_OBJECTS:open62541-object>)
  90. target_link_libraries(check_discovery ${LIBS})
  91. add_test_valgrind(discovery ${TESTS_BINARY_DIR}/check_discovery)
  92. # Test server with network dumps from files
  93. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
  94. ${CMAKE_CURRENT_BINARY_DIR}/client_CLO.bin
  95. ${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin
  96. ${CMAKE_CURRENT_BINARY_DIR}/client_Browse.bin
  97. ${CMAKE_CURRENT_BINARY_DIR}/client_Read.bin
  98. ${CMAKE_CURRENT_BINARY_DIR}/client_Write.bin
  99. PRE_BUILD
  100. COMMAND python ${PROJECT_SOURCE_DIR}/tools/hex2bin.py
  101. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_HELOPN.hex
  102. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_CLO.hex
  103. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_CreateActivateSession.hex
  104. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Browse.hex
  105. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Read.hex
  106. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Write.hex
  107. DEPENDS ${PROJECT_SOURCE_DIR}/tools/hex2bin.py
  108. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_HELOPN.hex
  109. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_CLO.hex
  110. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_CreateActivateSession.hex
  111. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Browse.hex
  112. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Read.hex
  113. ${CMAKE_CURRENT_SOURCE_DIR}/dumps/client_Write.hex)
  114. add_custom_target(client_HELOPN.bin DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin")
  115. add_custom_target(client_CreateActivateSession.bin DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin")
  116. add_executable(check_server_binary_messages check_server_binary_messages.c testing_networklayers.c $<TARGET_OBJECTS:open62541-object>)
  117. target_include_directories(check_server_binary_messages PRIVATE ${PROJECT_SOURCE_DIR}/src/server)
  118. target_link_libraries(check_server_binary_messages ${LIBS})
  119. add_dependencies(check_server_binary_messages client_HELOPN.bin)
  120. add_test_valgrind(check_server_binary_messages_browse ${TESTS_BINARY_DIR}/check_server_binary_messages
  121. ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
  122. ${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin
  123. ${CMAKE_CURRENT_BINARY_DIR}/client_Browse.bin
  124. ${CMAKE_CURRENT_BINARY_DIR}/client_CLO.bin)
  125. add_test_valgrind(check_server_binary_messages_read ${TESTS_BINARY_DIR}/check_server_binary_messages
  126. ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
  127. ${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin
  128. ${CMAKE_CURRENT_BINARY_DIR}/client_Read.bin
  129. ${CMAKE_CURRENT_BINARY_DIR}/client_CLO.bin)
  130. add_test_valgrind(check_server_binary_messages_write ${TESTS_BINARY_DIR}/check_server_binary_messages
  131. ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
  132. ${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin
  133. ${CMAKE_CURRENT_BINARY_DIR}/client_Write.bin
  134. ${CMAKE_CURRENT_BINARY_DIR}/client_CLO.bin)
  135. # Test Client
  136. add_executable(check_client check_client.c $<TARGET_OBJECTS:open62541-object>)
  137. target_link_libraries(check_client ${LIBS})
  138. add_test_valgrind(check_client ${TESTS_BINARY_DIR}/check_client)
  139. add_executable(check_client_subscriptions check_client_subscriptions.c $<TARGET_OBJECTS:open62541-object>)
  140. target_link_libraries(check_client_subscriptions ${LIBS})
  141. add_test_valgrind(check_client_subscriptions ${TESTS_BINARY_DIR}/check_client_subscriptions)
  142. add_executable(check_client_highlevel check_client_highlevel.c $<TARGET_OBJECTS:open62541-object>)
  143. target_link_libraries(check_client_highlevel ${LIBS})
  144. add_test_valgrind(check_client_highlevel ${TESTS_BINARY_DIR}/check_client_highlevel)