[Openvpn-devel,v2] Remove local get_random in test_misc.c

Message ID 20260806090951.20900-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] Remove local get_random in test_misc.c |

Commit Message

Gert Doering Aug. 6, 2026, 9:09 a.m. UTC
  From: Arne Schwabe <arne@rfc2549.org>

The get_random in test_misc.c conflicts
with the get_random function that OpenVPN defines in crypto.h
Also adjust the implementation in mock_get_random.c to match the
prototype in crypto.h

Change-Id: I3db70001be7f39cf84d562517647f1a305962b42
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Antonio Quartulli <antonio@mandelbit.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1834
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1834
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
Antonio Quartulli <antonio@mandelbit.com>
  

Comments

Gert Doering Aug. 6, 2026, 10:11 a.m. UTC | #1
Straightforward removal of conflicting functions.  Tested that it works
if I apply this on top of master and 2.7 right now, without any of the
other patches in gerrit that might be needed.

Your patch has been applied to the master and release/2.7 branch
(keep test code "in sync").

commit 5978a46e3db1013f327bb315d283d5816c3a4526 (master)
commit 3402f9aa03776a6055f690b9b63cea933c56ab6e (release/2.7)
Author: Arne Schwabe
Date:   Thu Aug 6 11:09:45 2026 +0200

     Remove local get_random in test_misc.c

     Signed-off-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Antonio Quartulli <antonio@mandelbit.com>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1834
     Message-Id: <20260806090951.20900-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg38155.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
  

Patch

diff --git a/tests/unit_tests/openvpn/mock_get_random.c b/tests/unit_tests/openvpn/mock_get_random.c
index 0840e31..5cb768b 100644
--- a/tests/unit_tests/openvpn/mock_get_random.c
+++ b/tests/unit_tests/openvpn/mock_get_random.c
@@ -28,7 +28,7 @@ 
 #include <stdint.h>
 #include <cmocka.h>
 
-unsigned long
+int64_t
 get_random(void)
 {
     /* rand() is not very random, but it's C99 and this is just for testing */
diff --git a/tests/unit_tests/openvpn/test_misc.c b/tests/unit_tests/openvpn/test_misc.c
index 501286c..8da7abe 100644
--- a/tests/unit_tests/openvpn/test_misc.c
+++ b/tests/unit_tests/openvpn/test_misc.c
@@ -38,6 +38,7 @@ 
 #include "test_common.h"
 #include "list.h"
 #include "mock_msg.h"
+#include "crypto.h"
 #ifdef _WIN32
 #include "win32-util.h"
 #endif
@@ -141,13 +142,6 @@ 
     return strcmp((const char *)key1, (const char *)key2) == 0;
 }
 
-static uint32_t
-get_random(void)
-{
-    /* rand() is not very random, but it's C99 and this is just for testing */
-    return (uint32_t)rand();
-}
-
 static struct hash_element *
 hash_lookup_by_value(struct hash *hash, void *value)
 {
@@ -263,7 +257,7 @@ 
         {
             struct hash_iterator hi;
             struct hash_element *he;
-            inc = (get_random() % 3) + 1;
+            inc = ((uint32_t)get_random() % 3) + 1;
             hash_iterator_init_range(hash, &hi, base, base + inc);
 
             while ((he = hash_iterator_next(&hi)))