From patchwork Thu Jan 15 08:28:12 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4708 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:9186:b0:80a:3855:ce6a with SMTP id j6csp821595maf; Thu, 15 Jan 2026 00:28:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXsHGYqzlqeffQnmyrfria9h5W15r0USwH/i2UK+HQANG3wJAlqX0gs0k3sL0l3BzXeF3+bjUxB/N4=@openvpn.net X-Received: by 2002:a05:6808:23ce:b0:450:794a:6d05 with SMTP id 5614622812f47-45c73e63897mr3143925b6e.66.1768465712637; Thu, 15 Jan 2026 00:28:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1768465712; cv=none; d=google.com; s=arc-20240605; b=UxZIwR0ZttFOdRRGWAMnH9MrxVa2qJ2wJEKMM8cicefQxE5Oj1EFGo1lGGGaCs1r3Y 6C29rLLmbZ22uj8QWXg6DywUPG++MK1UTqf0L3eZox0LhbkqntVFIxv2kgog3T+/gTba 403Zzu4qw7UZ3PMcV5L3PDBaGMJ3Unv0QPkeYOjwpvn2YqYAp8C1BrgEeqd8jvjMgj8D 6SKrBzQ5jTd5/8e8rsivCH8TDAtu9QPF5jbE53oL7zxzP+FbVCr1bI+znE6dfpaqiKWa Q1RFC37BK/ZCyGtddzOBJi2G7UQ3b85IQzG26qBiLfHPNFS3v16DN3YfC2sAboINkcWd Ic1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=mrPhDJL4F3vhSj6OSkjrNl2PpwWV4DR2Y2EJZg2pBS0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=eWrdajwjGYZDBcDldHVhzqR9uUOUpcssAkDhBQS2AFUQZfl+3yMeztLBBVvChtit8G COg+8ipRJMd1BndSBQOCttUGbK4JakXFBUdgAC+0GAxqXAlwup9YpylyVFI707y/r6On Kg0SPmF8b+ZhJwlyrKSCY2r5i4jWmk+vEmhJVEMqZocbVvQTYrcns45zqhwP1MCkQTkY PoW0q2QrxqJCpUc12VWbYDZUpxzvNmWiTi4qcpOS10BEOCJzVMqaKAGYKH2WwZ3R4QLu sYYb35OzLMUMbJNj2PD1uSM4Gk5pLFVRLJVv7alImZGthU9ZGpcYG+brN2rag9waFd1r eh/g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=XnIdNGv2; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=V6G45c8M; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="E/3FMN4S"; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-4043ae5590csi415313fac.33.2026.01.15.00.28.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jan 2026 00:28:32 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=XnIdNGv2; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=V6G45c8M; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="E/3FMN4S"; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mrPhDJL4F3vhSj6OSkjrNl2PpwWV4DR2Y2EJZg2pBS0=; b=XnIdNGv20DuEncVBDZ/3tCNWsH JYHXwGNwI77KwrNLeJmyNlqNjV8zTPUhGCSltQLoTUUhkO5oAJ0dLq7TLn271kH2EI3vBJTKRa8Gd Ny3KrnXvRkK0RBg6h4PjItxEpbijgy1iOCxwfmWw9uYWV8HfP84Zg0HvZNz4dXfI6u3g=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vgIiU-0005Cq-3q; Thu, 15 Jan 2026 08:28:30 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vgIiR-0005Cg-Jd for openvpn-devel@lists.sourceforge.net; Thu, 15 Jan 2026 08:28:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=yXvmuhF2c5wJFEyHNrvW64At51J3DrCmNr6MsvbZnpQ=; b=V6G45c8MNNAezq2vFP6Rip+YZS SPT3sSB8unrRoNS7Bf5fbYE85k4yf/Z0gL/dM+5xfY/poqZSzFwgpTsbiN1stJjaAHjBDHJ2LBm43 VTIc47Pi//s5esEX9GSmvp96UEimT/Yji7XfQ9UxJjdFsF6L4ZvRvpotNUoyjadba4Vg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=yXvmuhF2c5wJFEyHNrvW64At51J3DrCmNr6MsvbZnpQ=; b=E/3FMN4SJkiwkwjTJV/shSZ+4+ lCX4GsXCxOH4BcK4ipPwCYpKkReS/PKFXU2pHFJQtlmEnAl8aV0Yyoqu8DOO1CzhM8QZAt6r5pz7+ SpNWWxnsnb5jkVV50MJdCnbmKPUi+oKl/qQmug9BA4yzQfU1Kqe2TNX88BeHWvhtMsio=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1vgIiO-0007FK-FD for openvpn-devel@lists.sourceforge.net; Thu, 15 Jan 2026 08:28:25 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 60F8SHB2018644 for ; Thu, 15 Jan 2026 09:28:18 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 60F8SHlV018643 for openvpn-devel@lists.sourceforge.net; Thu, 15 Jan 2026 09:28:17 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 15 Jan 2026 09:28:12 +0100 Message-ID: <20260115082817.18618-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld But add compat layer so that we can still build against older versions of cmocka. Mostly this is trivial but the custom check function changed its prototype, so that requires some more work. Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1vgIiO-0007FK-FD Subject: [Openvpn-devel] [PATCH v1] tests/unit_tests: Port to cmocka 2.0.0 API X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1854370702683522713?= X-GMAIL-MSGID: =?utf-8?q?1854370702683522713?= From: Frank Lichtenheld But add compat layer so that we can still build against older versions of cmocka. Mostly this is trivial but the custom check function changed its prototype, so that requires some more work. This backport commit additionally includes the fix for test_tls_crypt from commit 6246f2113f6e1fda13bca8de863dd5cc396ab6ef since the other test fixes from the original commit are not relevant to release/2.6. Change-Id: Ifb6594700db71d219643a29c581099c778bcbbc6 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1449 Message-Id: <20251218104042.5961-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35144.html Signed-off-by: Gert Doering Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1462 (cherry picked from commit 6db186e0b1d9783ea96e8a945a47fd23b45e4778) --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to release/2.6. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1462 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/CMakeLists.txt b/CMakeLists.txt index f7cb5a7..6983d111 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,6 +291,18 @@ ) set(HAVE_CONFIG_VERSION_H YES) +if (BUILD_TESTING) + find_package(cmocka CONFIG) + if (TARGET cmocka::cmocka) + set(CMOCKA_LIBRARIES cmocka::cmocka) + else () + pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) + set(CMOCKA_LIBRARIES PkgConfig::cmocka) + endif () + set(CMAKE_REQUIRED_LIBRARIES ${CMOCKA_LIBRARIES}) + check_include_files(cmocka_version.h HAVE_CMOCKA_VERSION_H) +endif () + configure_file(config.h.cmake.in config.h) configure_file(include/openvpn-plugin.h.in openvpn-plugin.h) # TODO we should remove the need for this, and always include config.h @@ -541,14 +553,6 @@ if (BUILD_TESTING) - find_package(cmocka CONFIG) - if (TARGET cmocka::cmocka) - set(CMOCKA_LIBRARIES cmocka::cmocka) - else () - pkg_search_module(cmocka cmocka REQUIRED IMPORTED_TARGET) - set(CMOCKA_LIBRARIES PkgConfig::cmocka) - endif () - set(unit_tests "test_auth_token" "test_buffer" diff --git a/config.h.cmake.in b/config.h.cmake.in index cedc5be..bf60d39 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -86,6 +86,9 @@ /* git version information in config-version.h */ #cmakedefine HAVE_CONFIG_VERSION_H +/* cmocka version information available in cmocka_version.h (>= 2.0.0) */ +#cmakedefine HAVE_CMOCKA_VERSION_H + /* Define to 1 if you have the `daemon' function. */ #cmakedefine HAVE_DAEMON diff --git a/configure.ac b/configure.ac index e77fd47..fb8d530 100644 --- a/configure.ac +++ b/configure.ac @@ -1525,7 +1525,16 @@ [have_cmocka="yes"], [AC_MSG_WARN([cmocka.pc not found on the system using pkg-config ${pkg_config_found}. Unit tests disabled])] ) -AM_CONDITIONAL([ENABLE_UNITTESTS], [test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes" ]) +AM_CONDITIONAL([ENABLE_UNITTESTS], [false]) +if test "${enable_unit_tests}" = "yes" -a "${have_cmocka}" = "yes"; then + AM_CONDITIONAL([ENABLE_UNITTESTS], [true]) + + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} ${CMOCKA_CFLAGS}" + # detect cmocka < 2.0.0 that had no cmocka_version.h + AC_CHECK_HEADERS([cmocka_version.h]) + CFLAGS="${saved_CFLAGS}" +fi AC_SUBST([ENABLE_UNITTESTS]) TEST_LDFLAGS="${OPTIONAL_CRYPTO_LIBS} ${OPTIONAL_PKCS11_HELPER_LIBS}" diff --git a/tests/unit_tests/openvpn/test_common.h b/tests/unit_tests/openvpn/test_common.h index 50e16d6..e5e4420 100644 --- a/tests/unit_tests/openvpn/test_common.h +++ b/tests/unit_tests/openvpn/test_common.h @@ -25,6 +25,27 @@ #include #include +/* 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 + * versions use uintmax_t. But LargestIntegralType + * is not guaranteed to be equal to uintmax_t, so + * we can't use that unconditionally. So we only use + * it if cmocka.h does not define LargestIntegralType. + */ +#ifndef LargestIntegralType +#define LargestIntegralType uintmax_t +#endif +/* redefine 2.x API in terms of 1.x API */ +#define CMockaValueData LargestIntegralType +#define check_expected_uint check_expected +#define expect_uint_value expect_value +#define expect_check_data expect_check +#define cast_ptr_to_cmocka_value(x) (x) +#endif + /** * Sets up the environment for unit tests like making both stderr and stdout * non-buffered to avoid messages getting lost if the program exits early. diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c index 5eb864e..bf5a8ce 100644 --- a/tests/unit_tests/openvpn/test_tls_crypt.c +++ b/tests/unit_tests/openvpn/test_tls_crypt.c @@ -112,8 +112,8 @@ __wrap_buffer_write_file(const char *filename, const struct buffer *buf) { const char *pem = BSTR(buf); - check_expected(filename); - check_expected(pem); + check_expected_ptr(filename); + check_expected_ptr(pem); return mock_type(bool); } @@ -121,7 +121,7 @@ struct buffer __wrap_buffer_read_from_file(const char *filename, struct gc_arena *gc) { - check_expected(filename); + check_expected_ptr(filename); const char *pem_str = mock_ptr_type(const char *); struct buffer ret = alloc_buf_gc(strlen(pem_str) + 1, gc);