소스 검색

seed rng if not disabled by flag, fix #632

Julius Pfrommer 8 년 전
부모
커밋
3b50718415
3개의 변경된 파일7개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 0
      CMakeLists.txt
  2. 1 0
      include/ua_config.h.in
  3. 3 2
      src/server/ua_server.c

+ 3 - 0
CMakeLists.txt

@@ -66,6 +66,9 @@ mark_as_advanced(UA_ENABLE_TYPENAMES)
 option(UA_ENABLE_EMBEDDED_LIBC "Use a custom implementation of some libc functions that might be missing on embedded targets (e.g. string handling)." OFF)
 mark_as_advanced(UA_ENABLE_EMBEDDED_LIBC)
 
+option(UA_ENABLE_DETERMINISTIC_RNG "Do not seed the random number generator (e.g. for unit tests)." OFF)
+mark_as_advanced(UA_ENABLE_DETERMINISTIC_RNG)
+
 option(UA_ENABLE_GENERATE_NAMESPACE0 "Generate and load UA XML Namespace 0 definition (experimental)" OFF)
 mark_as_advanced(UA_ENABLE_GENERATE_NAMESPACE0)
 

+ 1 - 0
include/ua_config.h.in

@@ -44,6 +44,7 @@ extern "C" {
 #cmakedefine UA_ENABLE_STATUSCODE_DESCRIPTIONS
 #cmakedefine UA_ENABLE_TYPENAMES
 #cmakedefine UA_ENABLE_EMBEDDED_LIBC
+#cmakedefine UA_ENABLE_DETERMINISTIC_RNG
 #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
 #cmakedefine UA_ENABLE_EXTERNAL_NAMESPACES
 #cmakedefine UA_ENABLE_NONSTANDARD_STATELESS

+ 3 - 2
src/server/ua_server.c

@@ -451,8 +451,9 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     SLIST_INIT(&server->delayedCallbacks);
 #endif
 
-    /* uncomment for non-reproducible server runs */
-    //UA_random_seed(UA_DateTime_now());
+#ifndef UA_ENABLE_DETERMINISTIC_RNG
+    UA_random_seed((UA_UInt64)UA_DateTime_now());
+#endif
 
     /* ns0 and ns1 */
     server->namespaces = UA_Array_new(2, &UA_TYPES[UA_TYPES_STRING]);