CMakeLists.txt 9.8 KB

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