From patchwork Tue Nov 4 08:16:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4564 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:9ac3:b0:72f:f16c:e055 with SMTP id m3csp212227maw; Tue, 4 Nov 2025 00:17:10 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWBYTkjlI206PEQV7Bh7hgYD8QJeL63SXS4oqTrgsjLMZVkocX+ABG3kjAgIjuA0lHy+L7uHmKUi+A=@openvpn.net X-Google-Smtp-Source: AGHT+IFbMV2CDhz/12sFCOW4GlCMED3o2h0J1EYX1s5RaFWF6CdfUekANMbbAcVGGdjdfG+niZaq X-Received: by 2002:a05:6871:a206:b0:3d1:cea9:7dca with SMTP id 586e51a60fabf-3dacab331a4mr5351890fac.22.1762244229685; Tue, 04 Nov 2025 00:17:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1762244229; cv=none; d=google.com; s=arc-20240605; b=EUZpmViewlikJIQEecR4tVy1GwvWXfcp5mEH1XPD9hnqnNXNF38gjbj8EjhhY7lLP9 EH93d/bagFnrrBNCqKAcgdXQH1X/5a3MtekPv8udepqGLu0fsQWjbzyp91kLc528H75R NCbqNyhow0m3b1jTa7bkpSJgJbUkmPkyX/tssMaDUAvjatfRdj68itYYOXctpPoXs35A PTi9VQMZZj57iqGlWaZJ53dNadQNo+ks7BjQmcL65WRIXy16ODIaKg5lggO33LbwYiiv wfiQjPY6yZFmPGCgkcB58fMAv/Yhg3R1qiT8aOgeVGr93dujQfnMKgQn6qY7KZeE7mxO 2hdA== 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=KK2QEZiz6XePA4AcVSx9/vi9QsV90cucYepE8T4xuDQ=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=C926aSqBwG9sQXFufgk97vQcpJuxkWsoay79goB9zs2TOZxAgenGz+bu21xn6lakZg 5xPcG8iaqdobHO/JJ8dXguQzh0QB4spAGFaLyfCFWvnktmep3pMmvybKsqNE/eQDY424 9HrMa2S95cl/Sqm63gEyHruCrusIM6SO6e8j/QnaRsC4Luh5/01ukWi5Rddliuoj26ta heoEpWw9R4VaNE/FGegF7MOvvZ2Y6dCDzYFYf4EJiU7iugUjXhQ8yixmjF8yUDTWloVu XlOXcRR8XW4wbmpdAAC9iE9hAssRaWZFqeHLplFOqApNsMDSe+9fjEApEbOjjLeZeHGt eHvQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=coU+0HS1; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=TEUZRCui; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=VOx+h0le; 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 46e09a7af769-7c699bba447si3604757a34.78.2025.11.04.00.17.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Nov 2025 00:17:09 -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=coU+0HS1; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=TEUZRCui; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=VOx+h0le; 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=KK2QEZiz6XePA4AcVSx9/vi9QsV90cucYepE8T4xuDQ=; b=coU+0HS10AjO1SAesX1gPnjAFk 90rv2koDxT8FosQb4I4b3aMV5Dgo1RI0lPcVlLTxhHBx34GuDQ1ZFOG6TT+EJof2G7ykiEnBLRzb0 /rA93+O3HhT4345NcfcrFSzq+BLpiAZ0kpsgum/PeYVxAV5ZM7XZOHj30tSfk6jt3LK8=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vGCDy-0006pB-Oa; Tue, 04 Nov 2025 08:17:06 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vGCDy-0006ov-Bz for openvpn-devel@lists.sourceforge.net; Tue, 04 Nov 2025 08:17:06 +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=ISS5xu1tKJrvDzr61JbWJ0scDp9g7DHFL2m/upCd2Ok=; b=TEUZRCuiBP4x6kF3nsKClzoXFG 5WV8DiyGebt+B/rz6BDH/tbo/J4jeKlQ2Lalrr1oI8t06P/DzSZPqInpRDm+Nyy9dIrAeWbxQHasx dykCQeMGuw9hkSNiAwTzQCfk5P+jf+TqZHWwosJ/JsLjTOskNfhq0t51C+BxItqwx4rE=; 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=ISS5xu1tKJrvDzr61JbWJ0scDp9g7DHFL2m/upCd2Ok=; b=VOx+h0lenYFuYYmEgy504YPwbS vyakBCMQeVA3Q1q5a2pDLQEQsNXXtb8ICIifcsJIGKZjtj3s7cFnfu2r7CNozezxyvEKpkNM5W20F jyfv1mGpNad/L+UtIg+jcvzIKtONzf4j4hn1BcsebYJ/ZZHTybq1K6pTl9AKs+j72lko=; 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 1vGCDx-0004Wd-E4 for openvpn-devel@lists.sourceforge.net; Tue, 04 Nov 2025 08:17:06 +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 5A48Gr2f003389 for ; Tue, 4 Nov 2025 09:16:53 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 5A48GrTD003388 for openvpn-devel@lists.sourceforge.net; Tue, 4 Nov 2025 09:16:53 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Tue, 4 Nov 2025 09:16:47 +0100 Message-ID: <20251104081653.3368-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 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: Antonio Quartulli We have agreed to never use the plain assert() anywhere in the code. Unit tests are almost there as they always use cmocka provided assert helpers, except for two cases. Convert those two to cmocka assert calls too. 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: 1vGCDx-0004Wd-E4 Subject: [Openvpn-devel] [PATCH v1] unit_tests: prefer proper cmocka assert helpers 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?1847847005497582692?= X-GMAIL-MSGID: =?utf-8?q?1847847005497582692?= From: Antonio Quartulli We have agreed to never use the plain assert() anywhere in the code. Unit tests are almost there as they always use cmocka provided assert helpers, except for two cases. Convert those two to cmocka assert calls too. While at it also ensure that the proper bool helpers are used rather than checking _int_equal against true/false. Drop assert.h in cryptoapi.c as well as it's not needed anymore. GitHub: Closes OpenVPN/openvpn#894 Change-Id: I61e4968f2e83d12d4d3fc3ccba92a06eb5ed5866 Signed-off-by: Antonio Quartulli Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1345 --- 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/+/1345 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/cryptoapi.c b/src/openvpn/cryptoapi.c index bba6ed2..b18b9d4 100644 --- a/src/openvpn/cryptoapi.c +++ b/src/openvpn/cryptoapi.c @@ -45,7 +45,6 @@ #include #include #include -#include #include "buffer.h" #include "openssl_compat.h" diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index 92c4c65..25a8def 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -463,38 +463,38 @@ const char test1[] = A_TIMES_256 "EOL\n" A_TIMES_256 "EOF"; /* line buffer bigger than actual line */ - assert_int_equal(buf_write(&buf, test1, sizeof(test1)), true); + assert_true(buf_write(&buf, test1, sizeof(test1))); status = buf_parse(&buf, '\n', line, sizeof(line)); - assert_int_equal(status, true); + assert_true(status); assert_string_equal(line, A_TIMES_256 "EOL"); status = buf_parse(&buf, '\n', line, sizeof(line)); - assert_int_equal(status, true); + assert_true(status); assert_string_equal(line, A_TIMES_256 "EOF"); /* line buffer exactly same size as actual line + terminating \0 */ buf_reset_len(&buf); - assert_int_equal(buf_write(&buf, test1, sizeof(test1)), true); + assert_true(buf_write(&buf, test1, sizeof(test1))); status = buf_parse(&buf, '\n', line, 260); - assert_int_equal(status, true); + assert_true(status); assert_string_equal(line, A_TIMES_256 "EOL"); status = buf_parse(&buf, '\n', line, 260); - assert_int_equal(status, true); + assert_true(status); assert_string_equal(line, A_TIMES_256 "EOF"); /* line buffer smaller than actual line */ buf_reset_len(&buf); - assert_int_equal(buf_write(&buf, test1, sizeof(test1)), true); + assert_true(buf_write(&buf, test1, sizeof(test1))); status = buf_parse(&buf, '\n', line, 257); - assert_int_equal(status, true); + assert_true(status); assert_string_equal(line, A_TIMES_256); status = buf_parse(&buf, '\n', line, 257); - assert_int_equal(status, true); + assert_true(status); assert_string_equal(line, "EOL"); status = buf_parse(&buf, '\n', line, 257); - assert_int_equal(status, true); + assert_true(status); assert_string_equal(line, A_TIMES_256); status = buf_parse(&buf, '\n', line, 257); - assert_int_equal(status, true); + assert_true(status); assert_string_equal(line, "EOF"); gc_free(&gc); diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c b/tests/unit_tests/openvpn/test_cryptoapi.c index 6e83465..2edfba9b 100644 --- a/tests/unit_tests/openvpn/test_cryptoapi.c +++ b/tests/unit_tests/openvpn/test_cryptoapi.c @@ -121,7 +121,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", hash4, 0 }, { 0 } }; - assert(sizeof(certs_local) == sizeof(certs)); + assert_int_equal(sizeof(certs_local), sizeof(certs)); memcpy(certs, certs_local, sizeof(certs_local)); } diff --git a/tests/unit_tests/openvpn/test_misc.c b/tests/unit_tests/openvpn/test_misc.c index 10bed1d..954794e 100644 --- a/tests/unit_tests/openvpn/test_misc.c +++ b/tests/unit_tests/openvpn/test_misc.c @@ -101,7 +101,7 @@ const char *msg = parse_auth_failed_temp(&o, teststr); assert_string_equal(msg, ""); assert_int_equal(o.server_backoff_time, 42); - assert_int_equal(o.no_advance, true); + assert_true(o.no_advance); } static void diff --git a/tests/unit_tests/openvpn/test_pkcs11.c b/tests/unit_tests/openvpn/test_pkcs11.c index 01cbf96..81d2280 100644 --- a/tests/unit_tests/openvpn/test_pkcs11.c +++ b/tests/unit_tests/openvpn/test_pkcs11.c @@ -148,7 +148,7 @@ { cert4, key4, cname4, "OVPN TEST CA2", "OVPN Test Cert 4", { 0 }, NULL }, { 0 } }; - assert(sizeof(certs_local) == sizeof(certs)); + assert_int_equal(sizeof(certs_local), sizeof(certs)); memcpy(certs, certs_local, sizeof(certs_local)); }