[Openvpn-devel,v4] unit_tests: Fix build with CMocka 2.0.3

Message ID 20261203142017.602-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v4] unit_tests: Fix build with CMocka 2.0.3 |

Commit Message

Gert Doering Dec. 3, 2026, 2:20 p.m. UTC
  From: Frank Lichtenheld <frank@lichtenheld.com>

As seen in Fedora Rawhide builds.

- mock_assert type for line argument changed, make sure
  we avoid sign conversion errors.
- fail_msg doesn't seem to work without and VA_ARGS anymore.
  This might or might not be a bug (the documentation hasn't
  changed, but work around it either way).

Change-Id: Ifaebb8f5e7245c505a29c87f917f92bf16fa8027
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2394
---

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/+/2394
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
  

Patch

diff --git a/dev-tools/openvpn-cppcheck-library.cfg b/dev-tools/openvpn-cppcheck-library.cfg
index 37195d8..9ea9b80 100644
--- a/dev-tools/openvpn-cppcheck-library.cfg
+++ b/dev-tools/openvpn-cppcheck-library.cfg
@@ -32,6 +32,7 @@ 
   <!-- work around macro confusion -->
   <define name="CMSG_FIRSTHDR" value="cmsg_firsthdr" />
   <define name="CMSG_NXTHDR" value="cmsg_nxthdr" />
+  <define name="CM_VERSION_INT(a, b, c)" value="((a) &lt;&lt; 16 | (b) &lt;&lt; 8 | (c))" />
   <!-- otherwise a lot of unused variables are shown for enable-small builds -->
   <define name="DMSG_ALWAYS_AVAILABLE" value="1" />
   <!-- cppcheck understands it directly in format string, but not
diff --git a/tests/unit_tests/openvpn/mock_msg.c b/tests/unit_tests/openvpn/mock_msg.c
index 3e73d19..456b859 100644
--- a/tests/unit_tests/openvpn/mock_msg.c
+++ b/tests/unit_tests/openvpn/mock_msg.c
@@ -25,19 +25,22 @@ 
 #endif
 
 #include <stdarg.h>
-#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <setjmp.h>
-#include <stdint.h>
-#ifndef NO_CMOCKA
-#include <cmocka.h>
-#endif
 
 #include "errlevel.h"
 #include "error.h"
 #include "mock_msg.h"
 
+#ifndef NO_CMOCKA
+#include <stddef.h>
+#include <setjmp.h>
+#include <stdint.h>
+#include <cmocka.h>
+
+#include "test_common.h"
+#endif
+
 msglvl_t x_debug_level = 0; /* Default to (almost) no debugging output */
 msglvl_t print_x_debug_level = 0;
 
@@ -115,7 +118,7 @@ 
 void
 assert_failed(const char *filename, int line, const char *condition)
 {
-    mock_assert(false, condition ? condition : "", filename, line);
+    mock_assert(false, condition ? condition : "", filename, (ovpn_cmocka_line_t)line);
     /* Keep compiler happy.  Should not happen, mock_assert() does not return */
     exit(1);
 }
diff --git a/tests/unit_tests/openvpn/test_common.h b/tests/unit_tests/openvpn/test_common.h
index 85e099f..e8bdf88 100644
--- a/tests/unit_tests/openvpn/test_common.h
+++ b/tests/unit_tests/openvpn/test_common.h
@@ -20,6 +20,9 @@ 
  *  with this program; if not, see <https://www.gnu.org/licenses/>.
  */
 
+#ifndef TEST_COMMON_H
+#define TEST_COMMON_H
+
 #include <setjmp.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -31,6 +34,7 @@ 
 
 /* Do we use cmocka < 2.0.0? */
 #ifndef HAVE_CMOCKA_VERSION_H
+
 #define HAVE_OLD_CMOCKA_API 1
 /* compat with various versions of cmocka.h
  * Older versions have LargestIntegralType. Newer
@@ -50,6 +54,20 @@ 
 #define cast_ptr_to_cmocka_value(x)           (x)
 #define assert_int_in_range(value, min, max)  assert_in_range((value), (min), (max))
 #define assert_uint_in_range(value, min, max) assert_in_range((value), (min), (max))
+
+typedef int ovpn_cmocka_line_t;
+
+#else
+
+#include <cmocka_version.h>
+
+/* handle differences in different 2.x versions */
+#if CMOCKA_VERSION_INT >= CM_VERSION_INT(2, 0, 3)
+typedef size_t ovpn_cmocka_line_t;
+#else
+typedef int ovpn_cmocka_line_t;
+#endif
+
 #endif
 
 /**
@@ -97,3 +115,5 @@ 
 
     snprintf(buf, bufsize, "%s/%s", srcdir, filename);
 }
+
+#endif
diff --git a/tests/unit_tests/openvpn/test_provider.c b/tests/unit_tests/openvpn/test_provider.c
index 5d31da3..c2c0a41 100644
--- a/tests/unit_tests/openvpn/test_provider.c
+++ b/tests/unit_tests/openvpn/test_provider.c
@@ -256,7 +256,7 @@ 
 
     if (!mctx || EVP_DigestSignInit_ex(mctx, &pctx, mdname, NULL, NULL, pkey, params) <= 0)
     {
-        fail_msg("Failed to initialize EVP_DigestSignInit_ex()");
+        fail_msg("%s", "Failed to initialize EVP_DigestSignInit_ex()");
         goto done;
     }
 
@@ -266,7 +266,7 @@ 
 
     if ((sig = test_calloc(1, siglen)) == NULL)
     {
-        fail_msg("Out of memory");
+        fail_msg("%s", "Out of memory");
     }
     assert_int_equal(EVP_DigestSign(mctx, sig, &siglen, (uint8_t *)test_msg, strlen(test_msg)), 1);