Kaynağa Gözat

Merge pull request #1090 from jpfr/merge_02_timing

Merge 0.2
Julius Pfrommer 7 yıl önce
ebeveyn
işleme
62e22811a5

+ 65 - 35
CMakeLists.txt

@@ -43,9 +43,9 @@ if(NOT ${OPEN62541_VER_COMMIT} OR ${OPEN62541_VER_COMMIT} STREQUAL "")
     set(OPEN62541_VER_COMMIT "undefined")
 endif()
 
-############
-# Settings #
-############
+#################
+# Build Options #
+#################
 
 # Set default build type.
 if(NOT CMAKE_BUILD_TYPE)
@@ -136,7 +136,28 @@ mark_as_advanced(UA_COMPILE_AS_CXX)
 # Compiler Settings #
 #####################
 
-list(APPEND open62541_LIBRARIES "") # Collect libraries
+# Collect libraries
+list(APPEND open62541_LIBRARIES "")
+if(NOT WIN32)
+  if(QNXNTO)
+    list(APPEND open62541_LIBRARIES socket)
+    list(APPEND open62541_LIBRARIES c)
+    list(APPEND open62541_LIBRARIES stdc++)
+  else()
+    list(APPEND open62541_LIBRARIES pthread m)
+    if(NOT APPLE)
+      list(APPEND open62541_LIBRARIES rt)
+    endif()
+  endif()
+else()
+  list(APPEND open62541_LIBRARIES ws2_32)
+    if(UA_ENABLE_DISCOVERY_MULTICAST)
+        list(APPEND open62541_LIBRARIES iphlpapi)
+    endif()
+endif()
+if(UA_ENABLE_MULTITHREADING)
+  list(APPEND open62541_LIBRARIES urcu-cds urcu urcu-common)
+endif(UA_ENABLE_MULTITHREADING)
 
 if(NOT UA_COMPILE_AS_CXX AND (CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang"))
     # Compiler
@@ -203,6 +224,7 @@ if (UA_ENABLE_DISCOVERY_MULTICAST)
 endif()
 include_directories(${PROJECT_BINARY_DIR}/src_generated
                     ${PROJECT_SOURCE_DIR}/include
+                    ${PROJECT_SOURCE_DIR}/plugins # TODO: discovery depends on the standard config
                     ${PROJECT_SOURCE_DIR}/deps)
 
 set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
@@ -221,8 +243,8 @@ set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
                      ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.h
                      ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.h
                      ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.h
-                     ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.h
-)
+                     ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.h)
+
 set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
                      ${PROJECT_SOURCE_DIR}/deps/pcg_basic.h
                      ${PROJECT_SOURCE_DIR}/deps/libc_time.h
@@ -243,8 +265,9 @@ set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
                      ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
                      ${PROJECT_SOURCE_DIR}/src/server/ua_server_internal.h
                      ${PROJECT_SOURCE_DIR}/src/server/ua_services.h
-                     ${PROJECT_SOURCE_DIR}/src/client/ua_client_internal.h
-)
+                     ${PROJECT_SOURCE_DIR}/src/client/ua_client_internal.h)
+
+# TODO: make client optional
 set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
                 ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_binary.c
                 ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
@@ -284,17 +307,15 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
                 ${PROJECT_SOURCE_DIR}/src/client/ua_client_discovery.c
                 ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c
                 ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c
-                # plugins and dependencies
-                ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
-                ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
-                ${PROJECT_SOURCE_DIR}/plugins/ua_clock.c
-                ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
-                ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c
+                # dependencies
                 ${PROJECT_SOURCE_DIR}/deps/libc_time.c
-                ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c
-)
-                ##TODO: make client stuff optional
+                ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)
 
+set(default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
+                           ${PROJECT_SOURCE_DIR}/plugins/ua_clock.c
+                           ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
+                           ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
+                           ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c)
 if(UA_ENABLE_EMBEDDED_LIBC)
   list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/libc_string.c)
 endif()
@@ -394,17 +415,17 @@ add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.h
                    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
                            ${OPEN62541_VER_COMMIT} ${CMAKE_CURRENT_BINARY_DIR}/open62541.h ${exported_headers}
                    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
-                           ${exported_headers}
-                           ${internal_headers})
+                           ${exported_headers} ${internal_headers})
 
 add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/open62541.c
                    PRE_BUILD
                    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py
-                           ${OPEN62541_VER_COMMIT} ${CMAKE_CURRENT_BINARY_DIR}/open62541.c ${internal_headers} ${lib_sources}
+                           ${OPEN62541_VER_COMMIT} ${CMAKE_CURRENT_BINARY_DIR}/open62541.c
+                           ${internal_headers} ${lib_sources} ${default_plugin_sources}
                    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/amalgamate.py ${internal_headers} ${lib_sources})
 
 ADD_CUSTOM_TARGET(open62541_amalgamation DEPENDS ${PROJECT_BINARY_DIR}/open62541.h
-                                                  ${PROJECT_BINARY_DIR}/open62541.c)
+                                                 ${PROJECT_BINARY_DIR}/open62541.c)
 
 # example information model from nodeset xml
 add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
@@ -433,46 +454,52 @@ assign_source_group(${exported_headers})
 
 if(UA_ENABLE_AMALGAMATION)
     add_library(open62541-object OBJECT ${PROJECT_BINARY_DIR}/open62541.c ${PROJECT_BINARY_DIR}/open62541.h)
+    target_include_directories(open62541-object PRIVATE ${PROJECT_BINARY_DIR})
 
     # make sure the open62541_amalgamation target builds before so that amalgamation is finished and it is not executed again for open62541-object 
     # and thus may overwrite the amalgamation result during multiprocessor compilation
     add_dependencies(open62541-object open62541_amalgamation)
 
-    target_include_directories(open62541-object PRIVATE ${PROJECT_BINARY_DIR})
+    add_library(open62541 $<TARGET_OBJECTS:open62541-object>)
+
     if(UA_COMPILE_AS_CXX)
         set_source_files_properties(${PROJECT_BINARY_DIR}/open62541.c PROPERTIES LANGUAGE CXX)
     endif()
 else()
     add_definitions(-DUA_NO_AMALGAMATION)
     add_library(open62541-object OBJECT ${lib_sources} ${internal_headers} ${exported_headers})
-    target_include_directories(open62541-object PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/plugins)
+    target_include_directories(open62541-object PRIVATE ${PROJECT_SOURCE_DIR}/src)
+
+    add_library(open62541-plugins OBJECT ${default_plugin_sources} ${exported_headers})
+    target_include_directories(open62541-plugins PRIVATE ${PROJECT_SOURCE_DIR}/plugins)
+    target_include_directories(open62541-plugins PRIVATE ${PROJECT_BINARY_DIR}/src_generated)
+    target_compile_definitions(open62541-plugins PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
+
+    add_library(open62541 $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-plugins>)
 
     if(UA_COMPILE_AS_CXX)
         set_source_files_properties(${lib_sources} PROPERTIES LANGUAGE CXX)
+        set_source_files_properties(${default_plugin_sources} PROPERTIES LANGUAGE CXX)
     endif()
 endif()
-add_library(open62541 $<TARGET_OBJECTS:open62541-object>)
-target_link_libraries(open62541 ${open62541_LIBRARIES})
 
+# Export Symbols
 target_compile_definitions(open62541-object PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
 target_compile_definitions(open62541 PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
-
 if (UA_ENABLE_DISCOVERY_MULTICAST)
     target_compile_definitions(open62541-object PRIVATE -DMDNSD_DYNAMIC_LINKING_EXPORT)
     target_compile_definitions(open62541 PRIVATE -DMDNSD_DYNAMIC_LINKING_EXPORT)
 endif()
 
+# DLL requires linking to dependencies
+target_link_libraries(open62541 ${open62541_LIBRARIES})
+
+# Always generate the amalgamated header
+add_dependencies(open62541 open62541_amalgamation)
+
 # Generate properly versioned shared library links on Linux
 SET_TARGET_PROPERTIES(open62541 PROPERTIES SOVERSION 0 VERSION "${OPEN62541_VER_MAJOR}.${OPEN62541_VER_MINOR}.${OPEN62541_VER_PATCH}")
 
-if(WIN32)
-    target_link_libraries(open62541 ws2_32)
-    if (UA_ENABLE_DISCOVERY_MULTICAST)
-        target_link_libraries(open62541 iphlpapi) # for GetAdaptersAddresses
-        list(APPEND open62541_LIBRARIES iphlpapi)
-    endif()
-endif()
-
 ##########################
 # Build Selected Targets #
 ##########################
@@ -485,7 +512,10 @@ if(UA_BUILD_EXAMPLES)
 endif()
 
 if(UA_BUILD_UNIT_TESTS)
-    target_compile_definitions(open62541-object PRIVATE UA_BUILD_UNIT_TESTS) # Export some internal functions
+    if(UA_ENABLE_AMALGAMATION)
+        # Cannot compile tests with amalgamation. Amalgamation uses the default plugins, not the testing plugins
+        message(FATAL_ERROR "Unit tests cannot be generated with source amalgamation enabled")
+    endif()
     enable_testing()
     add_subdirectory(tests)
 endif()

+ 1 - 36
examples/CMakeLists.txt

@@ -7,38 +7,10 @@ include_directories(${PROJECT_BINARY_DIR})
 #############################
 
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)
-
-list(APPEND LIBS ${open62541_LIBRARIES})
-if(NOT WIN32)
-  if(QNXNTO)
-    list(APPEND LIBS socket)
-    list(APPEND LIBS c)
-    list(APPEND LIBS stdc++)
-  else()
-    list(APPEND LIBS pthread)
-    if (NOT APPLE)
-      list(APPEND LIBS rt)
-    endif()
-  endif()
-else()
-  list(APPEND LIBS ws2_32)
-endif()
-if(UA_ENABLE_MULTITHREADING)
-  list(APPEND LIBS urcu-cds urcu urcu-common)
-endif(UA_ENABLE_MULTITHREADING)
-
-set(STATIC_OBJECTS $<TARGET_OBJECTS:open62541-object>)
-if(WIN32 AND BUILD_SHARED_LIBS)
-    # on windows the .dll.a file has to be used for the linker
-    list(APPEND LIBS open62541)
-    set(STATIC_OBJECTS "")
-endif()
 
 macro(add_example EXAMPLE_NAME EXAMPLE_SOURCE)
   add_executable(${EXAMPLE_NAME} ${STATIC_OBJECTS} ${EXAMPLE_SOURCE})
-  target_link_libraries(${EXAMPLE_NAME} ${LIBS})
+  target_link_libraries(${EXAMPLE_NAME} open62541 ${open62541_LIBRARIES})
   assign_source_group(${EXAMPLE_SOURCE})
   add_dependencies(${EXAMPLE_NAME} open62541_amalgamation)
   set_target_properties(${EXAMPLE_NAME} PROPERTIES FOLDER "open62541/examples")
@@ -91,13 +63,6 @@ add_example(server_instantiation server_instantiation.c)
 
 add_example(server_repeated_job server_repeated_job.c)
 
-
-if(NOT BUILD_SHARED_LIBS)
-    # needs internal methods which are not exported in the dynamic lib
-    add_example(server_readspeed server_readspeed.c)
-    target_include_directories(server_readspeed PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/deps) # needs an internal header
-endif()
-
 add_example(server_inheritance server_inheritance.c)
 
 if(NOT BUILD_SHARED_LIBS AND UA_BUILD_EXAMPLES_NODESET_COMPILER)

+ 38 - 34
tests/CMakeLists.txt

@@ -11,30 +11,29 @@ include_directories(${CHECK_INCLUDE_DIRS})
 #############################
 
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests)
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests)
-
 set(TESTS_BINARY_DIR ${CMAKE_BINARY_DIR}/bin/tests)
 
+# Load CMake Packages
 find_package(Check REQUIRED)
 find_package(Threads REQUIRED)
 if(UA_ENABLE_VALGRIND_UNIT_TESTS)
     find_package(Valgrind REQUIRED)
 endif()
 
-set(LIBS ${CHECK_LIBRARIES} ${open62541_LIBRARIES} open62541)
-if(NOT WIN32)
-  list(APPEND LIBS pthread m)
-  if(NOT APPLE)
-    list(APPEND LIBS rt subunit)
-  endif()
-else()
-    list(APPEND LIBS ws2_32)
-endif()
-if(UA_ENABLE_MULTITHREADING)
-    list(APPEND LIBS urcu-cds urcu urcu-common)
-endif()
+set(LIBS subunit ${CHECK_LIBRARIES} ${open62541_LIBRARIES})
 
+# Use different plugins for testing
+set(test_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
+                        ${PROJECT_SOURCE_DIR}/tests/testing_clock.c
+                        ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
+                        ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c
+                        ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
+                        ${PROJECT_SOURCE_DIR}/tests/testing_clock.c)
+
+add_library(open62541-testplugins OBJECT ${test_plugin_sources})
+add_dependencies(open62541-testplugins open62541)
+
+# Workaround some clang warnings in the uni tests
 if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
     add_definitions(-Wno-sign-conversion)
 endif()
@@ -52,70 +51,75 @@ endmacro()
 # the unit test are built directly on the open62541 object files. so they can
 # access symbols that are hidden/not exported to the shared library
 
-add_executable(check_types_builtin check_types_builtin.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_types_builtin check_types_builtin.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_types_builtin ${LIBS})
 add_test_valgrind(types_builtin ${TESTS_BINARY_DIR}/check_types_builtin)
 
-add_executable(check_types_memory check_types_memory.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_types_memory check_types_memory.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_types_memory ${LIBS})
 add_test_valgrind(types_memory ${TESTS_BINARY_DIR}/check_types_memory)
 
-add_executable(check_types_range check_types_range.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_types_range check_types_range.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_types_range ${LIBS})
 add_test_valgrind(types_range ${TESTS_BINARY_DIR}/check_types_range)
 
-add_executable(check_types_custom check_types_custom.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_types_custom check_types_custom.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_types_custom ${LIBS})
 add_test_valgrind(types_custom ${TESTS_BINARY_DIR}/check_types_custom)
 
-add_executable(check_chunking check_chunking.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_chunking check_chunking.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_chunking ${LIBS})
 add_test_valgrind(chunking ${TESTS_BINARY_DIR}/check_chunking)
 
-add_executable(check_utils check_utils.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_utils check_utils.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_utils ${LIBS})
 add_test_valgrind(check_utils ${TESTS_BINARY_DIR}/check_utils)
 
 # Test Server
 
-add_executable(check_services_view check_services_view.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_services_view check_services_view.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_services_view ${LIBS})
 add_test_valgrind(services_view ${TESTS_BINARY_DIR}/check_services_view)
 
-add_executable(check_services_attributes check_services_attributes.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_services_attributes check_services_attributes.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_services_attributes ${LIBS})
 add_test_valgrind(services_attributes ${TESTS_BINARY_DIR}/check_services_attributes)
 
-add_executable(check_services_nodemanagement check_services_nodemanagement.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_services_nodemanagement check_services_nodemanagement.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_services_nodemanagement ${LIBS})
 add_test_valgrind(services_nodemanagement ${TESTS_BINARY_DIR}/check_services_nodemanagement)
 
-add_executable(check_services_subscriptions check_services_subscriptions.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_services_subscriptions check_services_subscriptions.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_services_subscriptions ${LIBS})
 add_test_valgrind(check_services_subscriptions ${TESTS_BINARY_DIR}/check_services_subscriptions)
 
-add_executable(check_nodestore check_nodestore.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_nodestore check_nodestore.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_nodestore ${LIBS})
 add_test_valgrind(nodestore ${TESTS_BINARY_DIR}/check_nodestore)
 
-add_executable(check_session check_session.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_session check_session.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_session ${LIBS})
 add_test_valgrind(session ${TESTS_BINARY_DIR}/check_session)
 
-add_executable(check_server_jobs check_server_jobs.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_server_jobs check_server_jobs.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_server_jobs ${LIBS})
 add_test_valgrind(check_server_jobs ${TESTS_BINARY_DIR}/check_server_jobs)
 
-add_executable(check_server_userspace check_server_userspace.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_server_userspace check_server_userspace.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_server_userspace ${LIBS})
 add_test_valgrind(check_server_userspace ${TESTS_BINARY_DIR}/check_server_userspace)
 
 if(UA_ENABLE_DISCOVERY)
-    add_executable(check_discovery check_discovery.c $<TARGET_OBJECTS:open62541-object>)
+    add_executable(check_discovery check_discovery.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
     target_link_libraries(check_discovery ${LIBS})
     add_test_valgrind(discovery ${TESTS_BINARY_DIR}/check_discovery)
 endif()
 
+# Readspeed server
+add_executable(check_server_readspeed check_server_readspeed.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
+target_link_libraries(check_server_readspeed ${LIBS})
+add_test_valgrind(check_server_readspeed ${TESTS_BINARY_DIR}/check_server_readspeed)
+
 # Test server with network dumps from files
 
 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
@@ -142,7 +146,7 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin
 add_custom_target(client_HELOPN.bin DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/client_HELOPN.bin")
 add_custom_target(client_CreateActivateSession.bin DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/client_CreateActivateSession.bin")
 
-add_executable(check_server_binary_messages check_server_binary_messages.c testing_networklayers.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_server_binary_messages check_server_binary_messages.c testing_networklayers.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_include_directories(check_server_binary_messages PRIVATE ${PROJECT_SOURCE_DIR}/src/server)
 target_link_libraries(check_server_binary_messages ${LIBS})
 add_dependencies(check_server_binary_messages client_HELOPN.bin)
@@ -167,14 +171,14 @@ add_test_valgrind(check_server_binary_messages_write ${TESTS_BINARY_DIR}/check_s
 
 # Test Client
 
-add_executable(check_client check_client.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_client check_client.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_client ${LIBS})
 add_test_valgrind(check_client ${TESTS_BINARY_DIR}/check_client)
 
-add_executable(check_client_subscriptions check_client_subscriptions.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_client_subscriptions check_client_subscriptions.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_client_subscriptions ${LIBS})
 add_test_valgrind(check_client_subscriptions ${TESTS_BINARY_DIR}/check_client_subscriptions)
 
-add_executable(check_client_highlevel check_client_highlevel.c $<TARGET_OBJECTS:open62541-object>)
+add_executable(check_client_highlevel check_client_highlevel.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_client_highlevel ${LIBS})
 add_test_valgrind(check_client_highlevel ${TESTS_BINARY_DIR}/check_client_highlevel)

+ 4 - 0
tests/check_client_subscriptions.c

@@ -12,7 +12,9 @@
 #include "ua_client_highlevel.h"
 #include "ua_config_standard.h"
 #include "ua_network_tcp.h"
+
 #include "check.h"
+#include "testing_clock.h"
 
 UA_Server *server;
 UA_Boolean *running;
@@ -67,6 +69,8 @@ START_TEST(Client_subscription) {
                                                       UA_ATTRIBUTEID_VALUE, monitoredItemHandler, NULL, &monId);
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
 
+    UA_sleep((UA_UInt32)UA_SubscriptionSettings_standard.requestedPublishingInterval + 1);
+
     notificationReceived = false;
     retval = UA_Client_Subscriptions_manuallySendPublishRequest(client);
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);

+ 10 - 3
tests/check_discovery.c

@@ -29,6 +29,7 @@
 #include "ua_config_standard.h"
 #include "ua_network_tcp.h"
 #include "check.h"
+#include "testing_clock.h"
 
 
 // set register timeout to 1 second so we are able to test it.
@@ -69,6 +70,7 @@ static void setup_lds(void) {
     UA_Server_run_startup(server_lds);
     pthread_create(&server_thread_lds, NULL, serverloop_lds, NULL);
     // wait until LDS started
+    UA_sleep(1000);
     sleep(1);
 }
 
@@ -148,7 +150,6 @@ START_TEST(Server_unregister) {
     }
 END_TEST
 
-
 START_TEST(Server_register_semaphore) {
         // create the semaphore
         int fd = open("/tmp/open62541-unit-test-semaphore", O_RDWR|O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
@@ -175,8 +176,11 @@ END_TEST
 
 START_TEST(Server_unregister_periodic) {
         // wait for first register delay
+        UA_sleep(1000);
         sleep(1);
         UA_Server_removeRepeatedJob(server_register, periodicRegisterJobId);
+        UA_sleep(1000);
+        sleep(1);
         UA_StatusCode retval = UA_Server_unregister_discovery(server_register, NULL);
         ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
     }
@@ -461,22 +465,26 @@ END_TEST
 
 START_TEST(Util_wait_timeout) {
         // wait until server is removed by timeout. Additionally wait a few seconds more to be sure.
-        sleep(checkWait);
+        UA_sleep(100000 * checkWait);
+        sleep(1);
     }
 END_TEST
 
 START_TEST(Util_wait_mdns) {
+        UA_sleep(1000);
         sleep(1);
     }
 END_TEST
 
 START_TEST(Util_wait_startup) {
+        UA_sleep(1000);
         sleep(1);
     }
 END_TEST
 
 START_TEST(Util_wait_retry) {
         // first retry is after 2 seconds, then 4, so it should be enough to wait 3 seconds
+        UA_sleep(3000);
         sleep(3);
     }
 END_TEST
@@ -528,7 +536,6 @@ static Suite* testSuite_Client(void) {
     suite_add_tcase(s,tc_register_find);
 #endif
 
-
     // register server again, then wait for timeout and auto unregister
     TCase *tc_register_timeout = tcase_create("RegisterServer timeout");
     tcase_add_unchecked_fixture(tc_register_timeout, setup_lds, teardown_lds);

+ 4 - 4
tests/check_server_jobs.c

@@ -7,7 +7,7 @@
 #include "ua_config_standard.h"
 
 #include "check.h"
-#include <unistd.h>
+#include "testing_clock.h"
 
 UA_Server *server = NULL;
 
@@ -40,11 +40,11 @@ START_TEST(Server_addRemoveRepeatedJob) {
     UA_Server_run_iterate(server, false);
 
     /* Wait until the job has surely timed out */
-    usleep(15*1000);
+    UA_sleep(15);
     UA_Server_run_iterate(server, false);
 
     /* Wait a bit longer until the workers have picked up the dispatched job */
-    usleep(15*1000);
+    UA_sleep(15);
     ck_assert_uint_eq(*executed, true);
 
     UA_Server_removeRepeatedJob(server, id);
@@ -67,7 +67,7 @@ START_TEST(Server_repeatedJobRemoveItself) {
     };
     UA_Server_addRepeatedJob(server, rj, 10, jobId);
 
-    usleep(15*1000);
+    UA_sleep(15);
     UA_Server_run_iterate(server, false);
 
     UA_Guid_delete(jobId);

+ 2 - 6
examples/server_readspeed.c

@@ -6,13 +6,9 @@
 
 #include <time.h>
 #include <stdio.h>
-#include "open62541.h"
 
-/* include guards to prevent double definitions with open62541.h */
-#define UA_TYPES_H_
-#define UA_SERVER_H_
-#define UA_CONNECTION_H_
-#define UA_TYPES_GENERATED_H_
+#include "ua_server.h"
+#include "ua_config_standard.h"
 #include "server/ua_services.h"
 #include "ua_types_encoding_binary.h"
 

+ 6 - 3
tests/check_services_subscriptions.c

@@ -9,7 +9,7 @@
 #include "ua_config_standard.h"
 
 #include "check.h"
-#include <unistd.h>
+#include "testing_clock.h"
 
 UA_Server *server = NULL;
 
@@ -161,6 +161,9 @@ START_TEST(Server_publishCallback) {
     ck_assert(publishingInterval > 0.0f);
     UA_CreateSubscriptionResponse_deleteMembers(&response);
 
+    /* Sleep until the publishing interval times out */
+    UA_sleep((UA_UInt32)publishingInterval + 1);
+
     /* Keepalive is set to max initially */
     UA_Subscription *sub;
     LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry)
@@ -168,9 +171,9 @@ START_TEST(Server_publishCallback) {
 
     /* Sleep until the publishing interval times out */
     UA_Server_run_iterate(server, false);
-    usleep((useconds_t)(publishingInterval * 1000) + 1000);
+    UA_sleep((UA_UInt32)publishingInterval + 1);
     UA_Server_run_iterate(server, false);
-    usleep((useconds_t)(publishingInterval * 1000) + 1000);
+    UA_sleep((UA_UInt32)publishingInterval + 1);
 
     LIST_FOREACH(sub, &adminSession.serverSubscriptions, listEntry)
         ck_assert_uint_eq(sub->currentKeepAliveCount, sub->maxKeepAliveCount+1);

+ 2 - 1
tests/check_session.c

@@ -41,7 +41,7 @@ START_TEST(Session_updateLifetime_ShallWork) {
     tmpDateTime = session.validTill;
     UA_Session_updateLifetime(&session);
 
-    UA_Int32 result = (session.validTill > tmpDateTime);
+    UA_Int32 result = (session.validTill >= tmpDateTime);
     ck_assert_int_gt(result,0);
 }
 END_TEST
@@ -64,6 +64,7 @@ int main(void) {
 
     s = testSuite_Session();
     sr = srunner_create(s);
+    srunner_set_fork_status(sr, CK_NOFORK);
     srunner_run_all(sr,CK_NORMAL);
     number_failed += srunner_ntests_failed(sr);
     srunner_free(sr);

+ 20 - 0
tests/testing_clock.c

@@ -0,0 +1,20 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "testing_clock.h"
+
+UA_DateTime testingClock = 0;
+
+UA_DateTime UA_DateTime_now(void) {
+    return testingClock;
+}
+
+UA_DateTime UA_DateTime_nowMonotonic(void) {
+    return testingClock;
+}
+
+void
+UA_sleep(UA_UInt32 duration) {
+    testingClock += duration * UA_MSEC_TO_DATETIME;
+}

+ 20 - 0
tests/testing_clock.h

@@ -0,0 +1,20 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef TESTING_CLOCK_H_
+#define TESTING_CLOCK_H_
+
+#include "ua_types.h"
+
+/* The testing clock is used for reproducible unit tests that require precise
+ * timings. It implements the following functions from ua_types.h. They return a
+ * deterministic time that can be advanced manually with UA_sleep.
+ *
+ * UA_DateTime UA_EXPORT UA_DateTime_now(void);
+ * UA_DateTime UA_EXPORT UA_DateTime_nowMonotonic(void); */
+
+/* Forwards the testing clock by the given duration in ms */
+void UA_sleep(UA_UInt32 duration);
+
+#endif /* TESTING_CLOCK_H_ */

+ 2 - 2
tools/travis/travis_osx_script.sh

@@ -40,14 +40,14 @@ else
 
     echo "Compile multithreaded version" && echo -en 'travis_fold:start:script.build.multithread\\r'
     mkdir -p build && cd build
-    cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLESERVER=ON -DUA_BUILD_EXAMPLES=ON ..
+    cmake -DUA_ENABLE_MULTITHREADING=ON -DUA_BUILD_EXAMPLES=ON ..
     make -j
     cd .. && rm -rf build
 	echo -en 'travis_fold:end:script.build.multithread\\r'
 
     echo "Debug build and unit tests with valgrind" && echo -en 'travis_fold:start:script.build.unit_test\\r'
     mkdir -p build && cd build
-    cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=OFF -DUA_ENABLE_VALGRIND_UNIT_TESTS=OFF ..
+    cmake -DCMAKE_BUILD_TYPE=Debug -DUA_BUILD_EXAMPLES=ON -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_UNIT_TESTS=ON -DUA_ENABLE_COVERAGE=ON -DUA_ENABLE_VALGRIND_UNIT_TESTS=ON ..
     make -j && make test ARGS="-V"
     cd .. && rm -rf build
 	echo -en 'travis_fold:end:script.build.unit_test\\r'