Change in openvpn[master]: Ensure that all unit tests use unbuffered stdout and stderr
A message that is not in the archive (sent off-list or not yet received): gerrit.1705927509000.I5c06dc13e9d8ab73997f79b13c30ee8949e5e993@...2715...
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
to review the following change.
Change subject: Ensure that all unit tests use unbuffered stdout and stderr
......................................................................
Ensure that all unit tests use unbuffered stdout and stderr
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
---
M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_auth_token.c M tests/unit_tests/openvpn/test_buffer.c
A tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_cryptoapi.c M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_ncp.c
M tests/unit_tests/openvpn/test_networking.c M tests/unit_tests/openvpn/test_packet_id.c M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_provider.c
M tests/unit_tests/openvpn/test_ssl.c
M tests/unit_tests/openvpn/test_tls_crypt.c
15 files changed, 70 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/04/504/1
tests/unit_tests/openvpn/test_argv.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_auth_token.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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),
tests/unit_tests/openvpn/test_buffer.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_common.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* 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. <[email protected]...> +* +* 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 <stdio.h> +#include <cmocka.h> + +/** +* 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 ); +}
tests/unit_tests/openvpn/test_crypto.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_cryptoapi.c +2 -0
@@ -31,6 +31,7 @@#include "integer.h" #include "xkey_common.h" #include "cert_data.h" +#include "test_common.h" #if defined(HAVE_XKEY_PROVIDER ) && defined (ENABLE_CRYPTOAPI )#include <setjmp.h>
@@ -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),
tests/unit_tests/openvpn/test_misc.c +2 -0
@@ -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 ); }
tests/unit_tests/openvpn/test_ncp.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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
tests/unit_tests/openvpn/test_networking.c +2 -0
@@ -1,6 +1,7 @@#include "config.h" #include "syshead.h" #include "networking.h" +#include "test_common.h" #include <assert.h>
@@ -223,6 +224,7 @@int main (int argc,char *argv[]) { +openvpn_unit_test_setup ();int test;if (argc <2 )
tests/unit_tests/openvpn/test_packet_id.c +2 -0
@@ -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,
tests/unit_tests/openvpn/test_pkcs11.c +3 -0
@@ -37,11 +37,13 @@#include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_pkt.c +2 -0
@@ -33,6 +33,7 @@#include <string.h> #include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_provider.c +3 -0
@@ -40,6 +40,8 @@#include <openssl/core_names.h> #include <openssl/evp.h> +#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);
tests/unit_tests/openvpn/test_ssl.c +3 -0
@@ -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) };
tests/unit_tests/openvpn/test_tls_crypt.c +2 -0
@@ -34,6 +34,7 @@#include <setjmp.h> #include <cmocka.h> +#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,
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993
Gerrit-Change-Number: 504
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
to look at the new patch set (#2).
Change subject: Ensure that all unit tests use unbuffered stdout and stderr
......................................................................
Ensure that all unit tests use unbuffered stdout and stderr
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
---
M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_auth_token.c M tests/unit_tests/openvpn/test_buffer.c
A tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_cryptoapi.c M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_ncp.c
M tests/unit_tests/openvpn/test_packet_id.c M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_provider.c
M tests/unit_tests/openvpn/test_ssl.c
M tests/unit_tests/openvpn/test_tls_crypt.c
14 files changed, 69 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/04/504/2
tests/unit_tests/openvpn/test_argv.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_auth_token.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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),
tests/unit_tests/openvpn/test_buffer.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_common.h new file +40 -0
@@ -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. <[email protected]...> +* +* 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 <stdio.h> +#include <cmocka.h> +#include <setjmp.h> + +/** +* 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 ); +}
tests/unit_tests/openvpn/test_crypto.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_cryptoapi.c +2 -0
@@ -31,6 +31,7 @@#include "integer.h" #include "xkey_common.h" #include "cert_data.h" +#include "test_common.h" #if defined(HAVE_XKEY_PROVIDER ) && defined (ENABLE_CRYPTOAPI )#include <setjmp.h>
@@ -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),
tests/unit_tests/openvpn/test_misc.c +2 -0
@@ -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 ); }
tests/unit_tests/openvpn/test_ncp.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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
tests/unit_tests/openvpn/test_packet_id.c +2 -0
@@ -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,
tests/unit_tests/openvpn/test_pkcs11.c +3 -0
@@ -37,11 +37,13 @@#include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_pkt.c +2 -0
@@ -33,6 +33,7 @@#include <string.h> #include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_provider.c +3 -0
@@ -40,6 +40,8 @@#include <openssl/core_names.h> #include <openssl/evp.h> +#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);
tests/unit_tests/openvpn/test_ssl.c +3 -0
@@ -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) };
tests/unit_tests/openvpn/test_tls_crypt.c +2 -0
@@ -34,6 +34,7 @@#include <setjmp.h> #include <cmocka.h> +#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,
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993
Gerrit-Change-Number: 504
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
to look at the new patch set (#3).
Change subject: Ensure that all unit tests use unbuffered stdout and stderr
......................................................................
Ensure that all unit tests use unbuffered stdout and stderr
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
---
M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_auth_token.c M tests/unit_tests/openvpn/test_buffer.c
A tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_cryptoapi.c M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_ncp.c
M tests/unit_tests/openvpn/test_packet_id.c M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_provider.c
M tests/unit_tests/openvpn/test_ssl.c
M tests/unit_tests/openvpn/test_tls_crypt.c
14 files changed, 69 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/04/504/3
tests/unit_tests/openvpn/test_argv.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_auth_token.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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),
tests/unit_tests/openvpn/test_buffer.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_common.h new file +40 -0
@@ -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. <[email protected]...> +* +* 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 <stdio.h> +#include <cmocka.h> +#include <setjmp.h> + +/** +* 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 ); +}
tests/unit_tests/openvpn/test_crypto.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_cryptoapi.c +2 -0
@@ -40,6 +40,7 @@#include <openssl/core_names.h> #include <openssl/evp.h> #include <openssl/pkcs12.h> +#include "test_common.h" #include <cryptoapi.h> #include <cryptoapi.c> /* 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),
tests/unit_tests/openvpn/test_misc.c +2 -0
@@ -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 ); }
tests/unit_tests/openvpn/test_ncp.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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
tests/unit_tests/openvpn/test_packet_id.c +2 -0
@@ -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,
tests/unit_tests/openvpn/test_pkcs11.c +3 -0
@@ -37,11 +37,13 @@#include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_pkt.c +2 -0
@@ -33,6 +33,7 @@#include <string.h> #include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_provider.c +3 -0
@@ -40,6 +40,8 @@#include <openssl/core_names.h> #include <openssl/evp.h> +#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);
tests/unit_tests/openvpn/test_ssl.c +3 -0
@@ -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) };
tests/unit_tests/openvpn/test_tls_crypt.c +2 -0
@@ -34,6 +34,7 @@#include <setjmp.h> #include <cmocka.h> +#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,
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993
Gerrit-Change-Number: 504
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/504?usp=email )
Change subject: Ensure that all unit tests use unbuffered stdout and stderr
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993
Gerrit-Change-Number: 504
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Mon, 22 Jan 2024 13:21:43 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v3 1/1 Ensure that all unit tests use unbuffered stdout and stderr
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
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.
---
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 3 of this Change. Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>
tests/unit_tests/openvpn/test_argv.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_auth_token.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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),
tests/unit_tests/openvpn/test_buffer.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_common.h new file +40 -0
@@ -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. <[email protected]...> +* +* 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 <stdio.h> +#include <cmocka.h> +#include <setjmp.h> + +/** +* 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 ); +}
tests/unit_tests/openvpn/test_crypto.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_cryptoapi.c +2 -0
@@ -40,6 +40,7 @@#include <openssl/core_names.h> #include <openssl/evp.h> #include <openssl/pkcs12.h> +#include "test_common.h" #include <cryptoapi.h> #include <cryptoapi.c> /* 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),
tests/unit_tests/openvpn/test_misc.c +2 -0
@@ -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 ); }
tests/unit_tests/openvpn/test_ncp.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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
tests/unit_tests/openvpn/test_packet_id.c +2 -0
@@ -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,
tests/unit_tests/openvpn/test_pkcs11.c +3 -0
@@ -37,11 +37,13 @@#include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_pkt.c +2 -0
@@ -33,6 +33,7 @@#include <string.h> #include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_provider.c +3 -0
@@ -40,6 +40,8 @@#include <openssl/core_names.h> #include <openssl/evp.h> +#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);
tests/unit_tests/openvpn/test_ssl.c +3 -0
@@ -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) };
tests/unit_tests/openvpn/test_tls_crypt.c +2 -0
@@ -34,6 +34,7 @@#include <setjmp.h> #include <cmocka.h> +#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,
PATCH v4 1/1 Ensure that all unit tests use unbuffered stdout and stderr
From: Arne Schwabe <[email protected]...>
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.
---
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 <[email protected]...>
tests/unit_tests/openvpn/test_argv.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_auth_token.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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),
tests/unit_tests/openvpn/test_buffer.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_common.h new file +40 -0
@@ -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. <[email protected]...> +* +* 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 <stdio.h> +#include <setjmp.h> +#include <cmocka.h> + +/** +* 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 ); +}
tests/unit_tests/openvpn/test_crypto.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_cryptoapi.c +2 -0
@@ -40,6 +40,7 @@#include <openssl/core_names.h> #include <openssl/evp.h> #include <openssl/pkcs12.h> +#include "test_common.h" #include <cryptoapi.h> #include <cryptoapi.c> /* 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),
tests/unit_tests/openvpn/test_misc.c +2 -0
@@ -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 ); }
tests/unit_tests/openvpn/test_ncp.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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
tests/unit_tests/openvpn/test_packet_id.c +2 -0
@@ -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,
tests/unit_tests/openvpn/test_pkcs11.c +3 -0
@@ -37,11 +37,13 @@#include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_pkt.c +2 -0
@@ -33,6 +33,7 @@#include <string.h> #include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_provider.c +3 -0
@@ -40,6 +40,8 @@#include <openssl/core_names.h> #include <openssl/evp.h> +#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);
tests/unit_tests/openvpn/test_ssl.c +3 -0
@@ -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) };
tests/unit_tests/openvpn/test_tls_crypt.c +2 -0
@@ -34,6 +34,7 @@#include <setjmp.h> #include <cmocka.h> +#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,
[Openvpn-devel] [PATCH applied] Re: Ensure that all unit tests use unbuffered stdout and stderr
Tested on a local "make check" run and on GHA (another option might have been to change our mock x_msg() to use stderr instead, but this way we can also see "if anything else" wants to say something on stdout).
Your patch has been applied to the master branch.
commit 7869617a0f85089fb5e6fbe2db6f03542a8f33f4
Author: Arne Schwabe Date: Tue Jan 23 11:43:58 2024 +0100
Ensure that all unit tests use unbuffered stdout and stderr
Acked-by: Frank Lichtenheld <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg28122.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Attention is currently required from: flichtenheld, plaisthos.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
to look at the new patch set (#4).
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
Change subject: Ensure that all unit tests use unbuffered stdout and stderr
......................................................................
Ensure that all unit tests use unbuffered stdout and stderr
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
---
M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_auth_token.c M tests/unit_tests/openvpn/test_buffer.c
A tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_cryptoapi.c M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_ncp.c
M tests/unit_tests/openvpn/test_packet_id.c M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_provider.c
M tests/unit_tests/openvpn/test_ssl.c
M tests/unit_tests/openvpn/test_tls_crypt.c
14 files changed, 69 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/04/504/4
tests/unit_tests/openvpn/test_argv.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_auth_token.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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),
tests/unit_tests/openvpn/test_buffer.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_common.h new file +40 -0
@@ -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. <[email protected]...> +* +* 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 <stdio.h> +#include <setjmp.h> +#include <cmocka.h> + +/** +* 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 ); +}
tests/unit_tests/openvpn/test_crypto.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_cryptoapi.c +2 -0
@@ -40,6 +40,7 @@#include <openssl/core_names.h> #include <openssl/evp.h> #include <openssl/pkcs12.h> +#include "test_common.h" #include <cryptoapi.h> #include <cryptoapi.c> /* 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),
tests/unit_tests/openvpn/test_misc.c +2 -0
@@ -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 ); }
tests/unit_tests/openvpn/test_ncp.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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
tests/unit_tests/openvpn/test_packet_id.c +2 -0
@@ -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,
tests/unit_tests/openvpn/test_pkcs11.c +3 -0
@@ -37,11 +37,13 @@#include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_pkt.c +2 -0
@@ -33,6 +33,7 @@#include <string.h> #include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_provider.c +3 -0
@@ -40,6 +40,8 @@#include <openssl/core_names.h> #include <openssl/evp.h> +#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);
tests/unit_tests/openvpn/test_ssl.c +3 -0
@@ -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) };
tests/unit_tests/openvpn/test_tls_crypt.c +2 -0
@@ -34,6 +34,7 @@#include <setjmp.h> #include <cmocka.h> +#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,
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993
Gerrit-Change-Number: 504
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/504?usp=email )
Change subject: Ensure that all unit tests use unbuffered stdout and stderr
......................................................................
Patch Set 4: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993
Gerrit-Change-Number: 504
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Tue, 23 Jan 2024 10:39:42 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
cron2 has uploaded a new patch set (#5) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/504?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
Change subject: Ensure that all unit tests use unbuffered stdout and stderr
......................................................................
Ensure that all unit tests use unbuffered stdout and stderr
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.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg28122.html
---
M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_auth_token.c
M tests/unit_tests/openvpn/test_buffer.c
A tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_ncp.c
M tests/unit_tests/openvpn/test_packet_id.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_provider.c
M tests/unit_tests/openvpn/test_ssl.c
M tests/unit_tests/openvpn/test_tls_crypt.c
14 files changed, 69 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/04/504/5
tests/unit_tests/openvpn/test_argv.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_auth_token.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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),
tests/unit_tests/openvpn/test_buffer.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_common.h new file +40 -0
@@ -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. <[email protected]...> +* +* 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 <stdio.h> +#include <setjmp.h> +#include <cmocka.h> + +/** +* 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 ); +}
tests/unit_tests/openvpn/test_crypto.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_cryptoapi.c +2 -0
@@ -40,6 +40,7 @@#include <openssl/core_names.h> #include <openssl/evp.h> #include <openssl/pkcs12.h> +#include "test_common.h" #include <cryptoapi.h> #include <cryptoapi.c> /* 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),
tests/unit_tests/openvpn/test_misc.c +2 -0
@@ -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 ); }
tests/unit_tests/openvpn/test_ncp.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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
tests/unit_tests/openvpn/test_packet_id.c +2 -0
@@ -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,
tests/unit_tests/openvpn/test_pkcs11.c +3 -0
@@ -37,11 +37,13 @@#include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_pkt.c +2 -0
@@ -33,6 +33,7 @@#include <string.h> #include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_provider.c +3 -0
@@ -40,6 +40,8 @@#include <openssl/core_names.h> #include <openssl/evp.h> +#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);
tests/unit_tests/openvpn/test_ssl.c +3 -0
@@ -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) };
tests/unit_tests/openvpn/test_tls_crypt.c +2 -0
@@ -34,6 +34,7 @@#include <setjmp.h> #include <cmocka.h> +#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,
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993
Gerrit-Change-Number: 504
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/504?usp=email )
Change subject: Ensure that all unit tests use unbuffered stdout and stderr
......................................................................
Ensure that all unit tests use unbuffered stdout and stderr
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.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg28122.html
---
M tests/unit_tests/openvpn/test_argv.c
M tests/unit_tests/openvpn/test_auth_token.c
M tests/unit_tests/openvpn/test_buffer.c
A tests/unit_tests/openvpn/test_common.h
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_misc.c
M tests/unit_tests/openvpn/test_ncp.c
M tests/unit_tests/openvpn/test_packet_id.c
M tests/unit_tests/openvpn/test_pkcs11.c
M tests/unit_tests/openvpn/test_pkt.c
M tests/unit_tests/openvpn/test_provider.c
M tests/unit_tests/openvpn/test_ssl.c
M tests/unit_tests/openvpn/test_tls_crypt.c
14 files changed, 69 insertions(+), 0 deletions(-)
tests/unit_tests/openvpn/test_argv.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_auth_token.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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),
tests/unit_tests/openvpn/test_buffer.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_common.h new file +40 -0
@@ -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. <[email protected]...> +* +* 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 <stdio.h> +#include <setjmp.h> +#include <cmocka.h> + +/** +* 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 ); +}
tests/unit_tests/openvpn/test_crypto.c +2 -0
@@ -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),
tests/unit_tests/openvpn/test_cryptoapi.c +2 -0
@@ -40,6 +40,7 @@#include <openssl/core_names.h> #include <openssl/evp.h> #include <openssl/pkcs12.h> +#include "test_common.h" #include <cryptoapi.h> #include <cryptoapi.c> /* 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),
tests/unit_tests/openvpn/test_misc.c +2 -0
@@ -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 ); }
tests/unit_tests/openvpn/test_ncp.c +2 -0
@@ -35,6 +35,7 @@#include <cmocka.h> #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
tests/unit_tests/openvpn/test_packet_id.c +2 -0
@@ -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,
tests/unit_tests/openvpn/test_pkcs11.c +3 -0
@@ -37,11 +37,13 @@#include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_pkt.c +2 -0
@@ -33,6 +33,7 @@#include <string.h> #include <setjmp.h> #include <cmocka.h> +#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),
tests/unit_tests/openvpn/test_provider.c +3 -0
@@ -40,6 +40,8 @@#include <openssl/core_names.h> #include <openssl/evp.h> +#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);
tests/unit_tests/openvpn/test_ssl.c +3 -0
@@ -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) };
tests/unit_tests/openvpn/test_tls_crypt.c +2 -0
@@ -34,6 +34,7 @@#include <setjmp.h> #include <cmocka.h> +#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,
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/504?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I5c06dc13e9d8ab73997f79b13c30ee8949e5e993
Gerrit-Change-Number: 504
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged