0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 04:02:15 +02:00
openvpn3/test/unittests
Mark Deric 1a5e4a7558 Add a unit test for checking header dependencies
Signed-off-by: Mark Deric <jmark@openvpn.net>
2022-07-21 11:08:42 -07:00
..
comp-testdata Move compression unit test from common to core repository 2019-04-15 17:05:09 +02:00
input [test/misc] Convert hashstr to unit test 2022-07-01 15:57:30 +02:00
output test_path: add missing output file for windows build 2022-07-06 11:17:18 +02:00
pki [test/misc] Convert OpenSSL PKI test to unittest 2022-07-01 15:57:30 +02:00
.gitignore Added fast IP address formatting via BufferFormat::ipv4/ipv6 2022-01-13 09:40:13 -06:00
CMakeLists.txt Add a unit test for checking header dependencies 2022-07-21 11:08:42 -07:00
core_tests.cpp Refactor InitProcess to use refcounting 2020-09-02 20:37:01 +02:00
README-comp.txt Fix some typos in unittest README files 2021-02-11 02:14:19 +01:00
README.md Fix some typos in unittest README files 2021-02-11 02:14:19 +01:00
test_b64.cpp always free allocated memory in base64 test 2021-05-18 06:13:12 +02:00
test_buffer_ip.cpp Added fast IP address formatting via BufferFormat::ipv4/ipv6 2022-01-13 09:40:13 -06:00
test_capture.cpp [test/misc] unittest: Update capture test to use new IPv6 block API 2022-07-01 15:57:30 +02:00
test_cleanup.cpp [test/misc] Convert misc/cleanup.cpp to unittest 2022-07-01 15:57:30 +02:00
test_common.h unittests: test_common.h should include <openvpn/io/io.hpp> rather than <asio.hpp> directly 2020-08-19 18:52:56 +02:00
test_comp.cpp fix potential division by zero in compression test 2021-05-18 06:13:31 +02:00
test_continuation.cpp Change continuation_test1 to always only use 100 iteration 2020-09-30 17:58:12 +02:00
test_cpu_time.cpp test_cpu_time: fix unused variable 2022-04-14 10:35:56 +02:00
test_crypto_hashstr.cpp [test/misc] Convert hashstr to unit test 2022-07-01 15:57:30 +02:00
test_crypto.cpp [OSSL 3.0] Use new EVP_MAC API for HMAC implementation 2021-11-12 14:27:12 +01:00
test_csum.cpp [test/misc] Fix multiple instances of comparison of signed with unsigned 2022-07-01 15:57:30 +02:00
test_dns.cpp add support for --dns option 2022-02-10 18:35:02 +01:00
test_format.cpp [test/misc] Convert format.cpp to unittest 2022-07-01 15:57:30 +02:00
test_header_deps.cpp Add a unit test for checking header dependencies 2022-07-21 11:08:42 -07:00
test_headredact.cpp [test/misc] Convert http header redact test to Google unit test 2022-07-01 15:57:30 +02:00
test_helper.hpp unittests: added SaveCurrentLogObject 2021-08-17 13:07:40 -06:00
test_hostport.cpp [test/misc] unittests: added new test for HostPort::split_host_port() 2022-07-01 15:57:30 +02:00
test_http_proxy.cpp add unit test for HTTP proxy options 2021-04-14 22:40:07 +02:00
test_ip.cpp [test/misc] Fix compiler warnings with -Wall and clang and gcc 2022-07-01 15:57:30 +02:00
test_iphelper.cpp win: add ipv4 routes via IP Helper API 2020-09-09 18:25:38 +03:00
test_log.cpp Update copyrights 2020-03-18 19:37:32 +01:00
test_mbedtls_x509certinfo.cpp Update copyrights 2020-03-18 19:37:32 +01:00
test_misc_unix.cpp [test/misc] Disable unix only unit tests on windows 2022-07-01 15:57:30 +02:00
test_openssl_x509certinfo.cpp add support for the --peer-fingerprint option 2021-04-28 23:56:22 +02:00
test_opensslpki.cpp [test/misc] Adjust unit test to Allow loading private keys with legacy algorithm change 2022-07-01 15:57:30 +02:00
test_optfilt.cpp add support for --dns option 2022-02-10 18:35:02 +01:00
test_parseargv.cpp [test/misc] unit tests: Option::render() no longer emits lines with a trailing space 2022-07-01 15:57:30 +02:00
test_path.cpp [test/misc] Convert misc/path to unit test 2022-07-01 15:57:30 +02:00
test_peer_fingerprint.cpp don't limit peer-fingerprint option size 2021-09-07 14:41:01 +02:00
test_pipe.cpp [test/misc] Updated system_cmd() calls to reflect newly added sigset_t* parameter 2022-07-01 15:57:30 +02:00
test_pktid.cpp test_pktid: add explicit cast for PIDRecv::REPLAY_WINDOW_SIZE 2022-07-06 11:21:28 +02:00
test_pktstream.cpp PacketStream: change message size validation logic to support growable buffers for DNS-over-TCP 2021-08-03 10:42:35 +02:00
test_prefixlen.cpp [test/misc] Fix multiple instances of comparison of signed with unsigned 2022-07-01 15:57:30 +02:00
test_rc.cpp [test/misc] Convert misc/rc to unittest 2022-07-01 15:57:30 +02:00
test_remotelist.cpp RemoteList unittest: extend BulkResolve test 2021-09-28 15:29:03 +02:00
test_route_emulation.cpp Update copyrights 2020-03-18 19:37:32 +01:00
test_route.cpp [test/misc] Convert misc/route to unittest 2022-07-01 15:57:30 +02:00
test_safestr.cpp SafeString: use timing-attack-resistant crypto::str_neq for comparisons 2021-08-17 13:07:40 -06:00
test_session_id.cpp [test/misc] Convert session/token related tests to unit tests 2022-07-01 15:57:30 +02:00
test_sitnl.cpp unittests: fix test_sitnl 2022-01-11 15:00:44 +01:00
test_ssl.cpp test_ssl: fix ssl.enablelegacyProvider 2022-04-07 12:14:23 +02:00
test_statickey.cpp [test/misc] Covert skmove into unit test 2022-07-01 15:57:30 +02:00
test_streq.cpp [test/misc] Convert streq test to unittest 2022-07-01 15:57:30 +02:00
test_time.cpp [test/misc] test_time: fix range error to show correct interval 2022-07-01 15:57:30 +02:00
test_typeindex.cpp [test/misc] unittests: added test_typeindex.cpp that's a POC for using std::typeindex as a faster replacement for dynamic_cast 2022-07-01 15:57:30 +02:00
test_validatecreds.cpp [test/misc] Convert validate_creds test to unittests 2022-07-01 15:57:30 +02:00
test_verify_x509_name.cpp Update copyrights 2020-03-18 19:37:32 +01:00
test_weak.cpp [test/misc] unittests: added test_weak for testing weak references 2022-07-01 15:57:30 +02:00

Unit test framework for OpenVPN3

The unit test framework is written in the Google Test framework.

Building/running the unit tests

Before building the unit tests themselves, you should build the dependencies as described in the README.rst.

The unit test cmake files assume here that the deps directory is on the same level as the openvpn3 directory unless overridden by the DEP_DIR variable.

The directory for cmake to build a project can be everywhere, but it is recommended to keep it outside of the source tree.

Building unit tests (assuming you are in the openvpn3 directory):

➜ mkdir ../unit_test_build
➜ cd ../unit_test_build
➜ cmake ../openvpn3
➜ cmake --build . --target coreUnitTests

Note: On Linux and Mac OS you can use make coreUnitTests instead of cmake --build

Run the unit tests:

➜  ./test/unittests/coreUnitTests --gtest_shuffle

On a Mac with OpenSSL from homebrew:

➜ cmake ../openvpn3 -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1

Using mbed TLS instead of OpenSSL

➜ cmake ../openvpn3 -DUSE_MBEDTLS

A full list of build options can shown together with short descriptions can be shown with

➜ cmake -LH .

Examplary commands for building and running on Windows:

➜ cmake -DDEP_DIR=C:\o3\deps -DUSE_MBEDTLS=true -DCMAKE_GENERATOR_PLATFORM=x64 C:\o3\openvpn3
➜ cmake --build . --target coreUnitTests
➜ test\unittests\Debug\coreUnitTests.exe --gtest_output="xml:test_core.xml" --gtest_shuffle

Frequently used command line options

Show the help for gtest command line options:

➜ ./test/unittests/coreUnitTests --help

Run only tests starting with Base64 or a sepcific Base64 test:

➜ ./test/unittests/coreUnitTests --gtest_filter='Base64.*'
➜ ./test/unittests/coreUnitTests --gtest_filter=Base64.tooshortdest

Run all test but the Base64 tests

➜ ./test/unittests/coreUnitTests --gtest_filter='-Base64.*'

Multiple pattern can be specified with a list separated by :

➜ ./test/unittests/coreUnitTests --gtest_filter='OpenSSL_X509_get_serial.*:Base64.*'

Shuffle order the order in which the tests are run:

➜ ./test/unittests/coreUnitTests --gtest_shuffle

If a certain order yields failures, repeat that order:

➜ ./test/unittests/coreUnitTests --gtest_shuffle --gtest_random_seed=23

Run also the tests that are normally disabled

➜ ./test/unittests/coreUnitTests --gtest_also_run_disabled_tests

Writing unit tetss

Each new test suite should be a new a file called test_suitename.cpp and added to the CMakeLists.txt file. Each test includes an #include test_common.h at the top to setup common openvpn3 library parameters and to set the OPENVPN_EXTERN define to extern. This is done so header files that define globals can be included multiple times. The only file that includes headers without the OPENVPN_EXTERN being set is the core_tests.cpp file. All global includes should be done in this file.

Currently all tests can fit in the same compilation unit coreUnitTests. If a unit test requires special compile/includes or other options that are not compatible with the rest of the unit tests, another compilation unit should be added to the CMAKELists.txt

The test_helper.cc file adds helper functions that can be used for unit tests. See the file for more information.