CMakeLists.txt 8.7 KB

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