From patchwork Tue Jan 23 10:43:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3589 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7301:3b94:b0:101:b91e:57cc with SMTP id kh20csp295933dyb; Tue, 23 Jan 2024 02:44:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFf2cJqcPo2LCKbIHlE7hQN6kBJ3uf3+pHhuYJ6EBBslgdQ/GLQc7VWJchgGDDND307lm9N X-Received: by 2002:a05:6a21:9216:b0:19a:511c:9361 with SMTP id tl22-20020a056a21921600b0019a511c9361mr12424007pzb.1.1706006677286; Tue, 23 Jan 2024 02:44:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706006677; cv=none; d=google.com; s=arc-20160816; b=ifVfNCiU03OwyCmGw3W6uAHLK3s1oOOj0lXbunecNfbaW894HC0xLpFENjPuzW+YEC KhzLmwr0upGPOIoKi67Kpu7jTxF4Zrv8o7ucu+YviT0GfPyF38yE8AAPh+fzrtsMwndR naWK4c4mmJ8IApRWFH2mA89otR/zypzmrDGcl6Hdz0HA0aMmDvwXRJLN2wZ6H1DyNqQ+ 0Hys/fkLCvwQa0TwJbbdkmntoTixZ0nrDqFodC0UM1BeaByePJ9e1n7dmfp4I1BJV7cd 4BhFRiaWbsj25Gml1QGcUj8EDC83DFtf59mVYKIuzyPBl3EbUBKqSIH8NnE3xcLqk9N9 BROw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=GSdIKrJDn0GvghiJ98cRu9mLlspFynks64BXNOJoTc0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=0Sjne+UyVUqpGuQjRh/rLOuQ3dKA4dWmqRdnXcsujLlxBzebl3PvjhVZ0QdQShOeJ3 /+uYd5Bx2H8eS5UZE2Psqiq2W8noUURZoYtqbO9yoE2+OPBnEyJ/nMtUNxtRkjsZKGFE 9OlvxiW1SbhFXBgSeW53hNMN57/BDExvPcLdnjct/fNUHWlfpZEsswYaxaJlLWaiS5eI xb1UpdSdbaHxAeB6ELUpPkdCCS5eW13QtQr/kYsMkA1BZml6cS+QUDnRGTK0E2Hs6I5F yZmia4+6Lb8+OalgUMTk1ZwIHnL4ke+VAwuTKxIbeJPWM1naq0XtsrWCW0Vm+eDRiRFz QuyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=LRV7L5FM; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=hlyZA4MZ; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=teDn4CMr; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id d5-20020a17090ad3c500b0028e88453568si9657615pjw.161.2024.01.23.02.44.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jan 2024 02:44:37 -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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=LRV7L5FM; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=hlyZA4MZ; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=teDn4CMr; 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 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 1rSEGM-0008Kg-Uh; Tue, 23 Jan 2024 10:44:15 +0000 Received: from [172.30.20.202] (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 1rSEGJ-0008KG-PZ for openvpn-devel@lists.sourceforge.net; Tue, 23 Jan 2024 10:44:13 +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:Cc:To:From:Sender:Reply-To: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=nu3NAxwgMBQ2pbYFBBfYHInz9jgYjWoxsfvg6Gugo3c=; b=LRV7L5FMs18KJHGmaSRoWJLVBt JBCK9L/gMgqZGMFNWHbQx1DDe+0LHxJaD29cP9Ut+/7O5ZAyIVO8vEPcNllwJJVO9sBqYPJ1DVpAD yEKo/koLn3hkZSjqu7Yaorg6msgdc/NJQDxg8H9e6Hp1TEWhvETZWtVMfO2WXbbsdisQ=; 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:Cc:To:From:Sender:Reply-To: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=nu3NAxwgMBQ2pbYFBBfYHInz9jgYjWoxsfvg6Gugo3c=; b=hlyZA4MZBR1WnwEp1FyHD+jZ2Y QHyHQ5wLLM5fvFDIvXggUo7jZGOv4aceUAWRgj3oruvd5H+UWiW9x0tfiX9wAj/ekem3DgPBAPw90 pnSWFFAuwVzb2dAXirCJn9mbHgfiy2Dbm63rlSaWvCz4Iy05gFFR4b3++acLqqOkflFM=; Received: from mout-p-101.mailbox.org ([80.241.56.151]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rSEGF-00030N-WB for openvpn-devel@lists.sourceforge.net; Tue, 23 Jan 2024 10:44:12 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4TK3c018jQz9sqq; Tue, 23 Jan 2024 11:44:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1706006640; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nu3NAxwgMBQ2pbYFBBfYHInz9jgYjWoxsfvg6Gugo3c=; b=teDn4CMrOKio1sgLGFsxlP0I3aZt+2cw23Kh4+04gMMMbjNzjnNw2ha9d28lXp2X94LRGB CO2NjRKdJyMw5xp4pL0kQB/tDhBYXtwWK0xMZ+gyM0gDaEkPFHD0NFfSjr1R1cmXWZmNYz k+my4dijLH7RgkX5dTBbd6L1paCEil4Bx4HUX326ktT4aJQJwLMn6mMglgcA9MPr1/SgT7 FmnHMMYFIDRiHBc4pHEqD9aNjYNfh3KTMVmfBWNbf26HfujBiK9MHz/bBHn1W4qjOTAX6y pVMZUz7NeEqYLitRmnzNQcBhCsIImgybxZ5ZXpgelcdAu2WRe26OdIxtenwG9Q== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Tue, 23 Jan 2024 11:43:58 +0100 Message-Id: <20240123104358.495517-1-frank@lichtenheld.com> In-Reply-To: <20240122132748.22541-1-gert@greenie.muc.de> References: <20240122132748.22541-1-gert@greenie.muc.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4TK3c018jQz9sqq X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", 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: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.151 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1rSEGF-00030N-WB Subject: [Openvpn-devel] [PATCH v4] 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?1788797369366146813?= X-GMAIL-MSGID: =?utf-8?q?1788877657453532274?= 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 --- 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/+/504 This mail reflects revision 4 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld 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 ee84c1f..52ffb54 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) @@ -356,6 +357,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test(test_buffer_strprefix), cmocka_unit_test(test_buffer_printf_catrunc), 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 08c9c44..01c16c9 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"; @@ -445,6 +446,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 d90bfc3..e0479a8 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 */ @@ -486,6 +487,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 43ae96b..193f131 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 72a1c3b..ecf1e39 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_pkcs11.c b/tests/unit_tests/openvpn/test_pkcs11.c index b6c130e..81cdf88 100644 --- a/tests/unit_tests/openvpn/test_pkcs11.c +++ b/tests/unit_tests/openvpn/test_pkcs11.c @@ -37,11 +37,13 @@ #include #include +#include "test_common.h" #define token_name "Test Token" #define PIN "12345" #define HASHSIZE 20 + struct management *management; /* global */ /* replacement for crypto_print_openssl_errors() */ @@ -459,6 +461,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(test_pkcs11_ids, setup_pkcs11, teardown_pkcs11), diff --git a/tests/unit_tests/openvpn/test_pkt.c b/tests/unit_tests/openvpn/test_pkt.c index 7f05184..1084d66 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" @@ -628,6 +629,7 @@ int main(void) { + openvpn_unit_test_setup(); const struct CMUnitTest tests[] = { cmocka_unit_test(test_tls_decrypt_lite_none), cmocka_unit_test(test_tls_decrypt_lite_auth), diff --git a/tests/unit_tests/openvpn/test_provider.c b/tests/unit_tests/openvpn/test_provider.c index 335fca2..94deab6 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_ssl.c b/tests/unit_tests/openvpn/test_ssl.c index d0c3df7..18b9ec8 100644 --- a/tests/unit_tests/openvpn/test_ssl.c +++ b/tests/unit_tests/openvpn/test_ssl.c @@ -43,6 +43,7 @@ #include "mss.h" #include "ssl_verify_backend.h" #include "win32.h" +#include "test_common.h" /* Mock function to be allowed to include win32.c which is required for * getting the temp directory */ @@ -122,6 +123,8 @@ int main(void) { + openvpn_unit_test_setup(); + const struct CMUnitTest tests[] = { cmocka_unit_test(crypto_pem_encode_certificate) }; diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c index 465543a..a01fbe5 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,