From patchwork Thu Jan 15 08:28:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4709 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:9186:b0:80a:3855:ce6a with SMTP id j6csp821585maf; Thu, 15 Jan 2026 00:28:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXTW33pnyGWemSjGk3/15OGyaYot3RSTG4VVmhxJF9DOpFlGrsKNoSI8COEPlDcXSuPOlVSl7iaAUk=@openvpn.net X-Received: by 2002:a05:6820:2817:b0:65d:1c:f3a5 with SMTP id 006d021491bc7-66102b32a68mr2310777eaf.20.1768465711961; Thu, 15 Jan 2026 00:28:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1768465711; cv=none; d=google.com; s=arc-20240605; b=gvJQxvI2TX3b7PTMAnsnHungFgMAdFj2+16vIqKsrw5vliLH9tNv7t0kFyFEOcA0EK o2sj/Y8+Bx8s4tWrNkLBH8+E6NP1YanaqyF1D6jGYcY/StCGetJLczX9KgORIDefxxMm cO4bRUMHipwXW4yezdpF50X6ro5LQR+dqiiFx3OOHwgY/2ZOHJaCWHW3RdW6z+IXGzCk 1JEbrjDas694P0sAcsLztkpqIXZ4xJerC8Zl/Q7kKj7Lw18WpoM5iYOzHhazSunPr625 U+7sE79jy85xoKBnPJK2JMM8R76UecaRzt4tvK8vSyGEFYu2vC5NvhdFp89DCKfyV/py zNcA== 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=nEXmyxc6ft5BA6zt8dGdvjhAmMQo8pXR8uP302WoaN0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=kA/wF+vYCWJBN5BFDX6zHrMuqE7luPSRk9k9U0HInqnqCeuajgDyJzlt+iGGT8k8lY fQ0ehWxJdN4TjODV4inlwU4wOHO++AXm6YKF04M225UCVAocP6zBZxnu710Tq1hV0UmA LwCyDvn0p9x4vaARExRLmX4+1lbT4lcreNEoohTYKcdW9AOjfKQR+WP3EvGBTImh0GV8 hhLhEoeXnuoVLXXsURsqcLHS/ZMOeaoHQCftVPNCQK3Dw/luYsNW4wSVjdOznMjj1zAX 0pW74t4159ihLoZ+9Jwnapb+xnmFHCNXohriOaihA/+vt6olJYPSYePAsnxTfsyEQdZM WLiQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="dZjj9Kh/"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=H9bhHDDU; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dAO7Ri4D; 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 006d021491bc7-65f48d3f297si14779737eaf.76.2026.01.15.00.28.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Jan 2026 00:28:31 -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="dZjj9Kh/"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=H9bhHDDU; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dAO7Ri4D; 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=nEXmyxc6ft5BA6zt8dGdvjhAmMQo8pXR8uP302WoaN0=; b=dZjj9Kh//i5eFwGhcE/O43x0E9 3RzYZCzxj5jUMUUof18kPwaPBRFM+09Pvnxs9e8/mhmMGpVjGQA1JyAv3Gf4xU5Dd9+qp/talCT9l Gyo48VkBhV+Gsoz7T+91mVbqx4S0Rp6YTI5CeMxxQG6f60vks/aHwFPmBvBeGheg6Uyw=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vgIiR-0007k0-Nm; Thu, 15 Jan 2026 08:28:28 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vgIiQ-0007j5-QT 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=ovTLyvGKthAp4vyuWtri09gH3O8DnZTzLnc/iuOn1NI=; b=H9bhHDDUwHFs/ezNr5y7UPk65T 43niA/VgBgkH/MSAIAwVlDDQXWq8mCFWKasWcJcUwZexwOemOeYHKmbTUBCPZaiFQmhlFa79TP8oY Ap015RkfGCuoca4SVMBYcEnUCQO8UyoksWxQKk5xuJ1O/K+Kku7JygqcS5OukI6u+YTg=; 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=ovTLyvGKthAp4vyuWtri09gH3O8DnZTzLnc/iuOn1NI=; b=dAO7Ri4DW4RSBX6MEpS9FVallP qiUGI4O9kby2QEOSxOF0ISjiytGu8zpJ8/MCwdL2bSvusjIS8dceot9gr9XK7UIsK2JpPM72AHYAO E085Z+a1AoNrIERWNo4aU6+e/LE6rrDWvPYCipZrDk23MTACjjeLCcMfzH+5VEWf0ha4=; 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 1vgIiJ-0007F6-JR for openvpn-devel@lists.sourceforge.net; Thu, 15 Jan 2026 08:28:20 +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 60F8S7H2018611 for ; Thu, 15 Jan 2026 09:28:07 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 60F8S7X8018610 for openvpn-devel@lists.sourceforge.net; Thu, 15 Jan 2026 09:28:07 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 15 Jan 2026 09:28:01 +0100 Message-ID: <20260115082807.18596-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: Arne Schwabe stderr is normally always unbuffered but stdout can be buffered. Especially, when stdout is redirected it will become buffered while it is normally unbuffered when connected to a terminal. This mean t [...] 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: 1vgIiJ-0007F6-JR Subject: [Openvpn-devel] [PATCH v1] Ensure that all unit tests use unbuffered stdout and stderr 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?1854370702336216767?= X-GMAIL-MSGID: =?utf-8?q?1854370702336216767?= From: Arne Schwabe stderr is normally always unbuffered but stdout can be buffered. Especially, when stdout is redirected it will become buffered while it is normally unbuffered when connected to a terminal. This mean that if the unit exits prematurely, the output in the buffered output will be lost. As the unit test x_msg mock implementation prints even fatal on stdout we ensure with this setup method that stdout is also unbuffered. Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993 Acked-by: Frank Lichtenheld Message-Id: <20240123104358.495517-1-frank@lichtenheld.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28122.html Signed-off-by: Gert Doering Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1461 (cherry picked from commit 7869617a0f85089fb5e6fbe2db6f03542a8f33f4) --- 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/+/1461 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/openvpn/test_argv.c index 1b18ac0..33b3dec 100644 --- a/tests/unit_tests/openvpn/test_argv.c +++ b/tests/unit_tests/openvpn/test_argv.c @@ -12,6 +12,7 @@ #include "argv.h" #include "buffer.h" +#include "test_common.h" /* Defines for use in the tests and the mock parse_line() */ #define PATH1 "/s p a c e" @@ -252,6 +253,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test(argv_printf__multiple_spaces_in_format__parsed_as_one), cmocka_unit_test(argv_printf_cat__multiple_spaces_in_format__parsed_as_one), diff --git a/tests/unit_tests/openvpn/test_auth_token.c b/tests/unit_tests/openvpn/test_auth_token.c index a027330..3a3cb69 100644 --- a/tests/unit_tests/openvpn/test_auth_token.c +++ b/tests/unit_tests/openvpn/test_auth_token.c @@ -35,6 +35,7 @@ #include #include "auth_token.c" +#include "test_common.h" struct test_context { struct tls_multi multi; @@ -407,6 +408,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(auth_token_basic_test, setup, teardown), cmocka_unit_test_setup_teardown(auth_token_fail_invalid_key, setup, teardown), diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index df1fdcb..c30ba42 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -32,6 +32,7 @@ #include "buffer.h" #include "buffer.c" +#include "test_common.h" static void test_buffer_strprefix(void **state) @@ -369,6 +370,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test(test_buffer_strprefix), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separator_empty, diff --git a/tests/unit_tests/openvpn/test_common.h b/tests/unit_tests/openvpn/test_common.h new file mode 100644 index 0000000..50e16d6 --- /dev/null +++ b/tests/unit_tests/openvpn/test_common.h @@ -0,0 +1,40 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2016-2021 Fox Crypto B.V. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include + +/** + * 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. + * + * This has a openvpn prefix to avoid confusion with cmocka's unit_test_setup_* + * methods + */ +void +openvpn_unit_test_setup() +{ + assert_int_equal(setvbuf(stdout, NULL, _IONBF, BUFSIZ), 0); + assert_int_equal(setvbuf(stderr, NULL, _IONBF, BUFSIZ), 0); +} diff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/openvpn/test_crypto.c index 4b1627a..ff639678 100644 --- a/tests/unit_tests/openvpn/test_crypto.c +++ b/tests/unit_tests/openvpn/test_crypto.c @@ -39,6 +39,7 @@ #include "ssl_backend.h" #include "mss.h" +#include "test_common.h" static const char testtext[] = "Dummy text to test PEM encoding"; @@ -479,6 +480,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test(crypto_pem_encode_decode_loopback), cmocka_unit_test(crypto_translate_cipher_names), diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c b/tests/unit_tests/openvpn/test_cryptoapi.c index 18e38d0..e5f6557 100644 --- a/tests/unit_tests/openvpn/test_cryptoapi.c +++ b/tests/unit_tests/openvpn/test_cryptoapi.c @@ -40,6 +40,7 @@ #include #include #include +#include "test_common.h" #include #include /* pull-in the whole file to test static functions */ @@ -582,6 +583,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test(test_parse_hexstring), cmocka_unit_test(import_certs), diff --git a/tests/unit_tests/openvpn/test_misc.c b/tests/unit_tests/openvpn/test_misc.c index eac3466..68ca9b6 100644 --- a/tests/unit_tests/openvpn/test_misc.c +++ b/tests/unit_tests/openvpn/test_misc.c @@ -36,6 +36,7 @@ #include "ssl_util.h" #include "options_util.h" +#include "test_common.h" static void test_compat_lzo_string(void **state) @@ -117,5 +118,6 @@ int main(void) { + openvpn_unit_test_setup(); return cmocka_run_group_tests(misc_tests, NULL, NULL); } diff --git a/tests/unit_tests/openvpn/test_ncp.c b/tests/unit_tests/openvpn/test_ncp.c index 9e26c74..a8e1021 100644 --- a/tests/unit_tests/openvpn/test_ncp.c +++ b/tests/unit_tests/openvpn/test_ncp.c @@ -35,6 +35,7 @@ #include #include "ssl_ncp.c" +#include "test_common.h" /* Defines for use in the tests and the mock parse_line() */ @@ -272,6 +273,7 @@ int main(void) { + openvpn_unit_test_setup(); #if defined(ENABLE_CRYPTO_OPENSSL) OpenSSL_add_all_algorithms(); #endif diff --git a/tests/unit_tests/openvpn/test_packet_id.c b/tests/unit_tests/openvpn/test_packet_id.c index 2a2a973..ff3f788 100644 --- a/tests/unit_tests/openvpn/test_packet_id.c +++ b/tests/unit_tests/openvpn/test_packet_id.c @@ -35,6 +35,7 @@ #include "packet_id.h" #include "reliable.h" +#include "test_common.h" struct test_packet_id_write_data { struct { @@ -273,6 +274,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(test_packet_id_write_short, test_packet_id_write_setup, diff --git a/tests/unit_tests/openvpn/test_pkt.c b/tests/unit_tests/openvpn/test_pkt.c index 62abafa..3a68c56 100644 --- a/tests/unit_tests/openvpn/test_pkt.c +++ b/tests/unit_tests/openvpn/test_pkt.c @@ -33,6 +33,7 @@ #include #include #include +#include "test_common.h" #include "crypto.h" #include "options.h" @@ -778,6 +779,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test(test_verify_hmac_none), cmocka_unit_test(test_tls_decrypt_lite_none), diff --git a/tests/unit_tests/openvpn/test_provider.c b/tests/unit_tests/openvpn/test_provider.c index 8a0b816..934b2d3b 100644 --- a/tests/unit_tests/openvpn/test_provider.c +++ b/tests/unit_tests/openvpn/test_provider.c @@ -40,6 +40,8 @@ #include #include +#include "test_common.h" + struct management *management; /* global */ static int mgmt_callback_called; @@ -119,6 +121,7 @@ static void init_test() { + openvpn_unit_test_setup(); prov[0] = OSSL_PROVIDER_load(NULL, "default"); OSSL_PROVIDER_add_builtin(NULL, prov_name, xkey_provider_init); prov[1] = OSSL_PROVIDER_load(NULL, prov_name); diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c index 3eac04c..5eb864e 100644 --- a/tests/unit_tests/openvpn/test_tls_crypt.c +++ b/tests/unit_tests/openvpn/test_tls_crypt.c @@ -34,6 +34,7 @@ #include #include +#include "test_common.h" #include "tls_crypt.c" /* Define this function here as dummy since including the ssl_*.c files @@ -673,6 +674,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(tls_crypt_loopback, test_tls_crypt_setup,