0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00
openvpn3/test/unittests
Lev Stipakov d79536240e
unittests/CMakeLists.txt: fix tests execution
Commit 941104cf4 refactored the way how test files are added, but
broke (disabled) execution of sitnl and cputime tests. Fix that.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-09-09 12:35:25 +03:00
..
comp-testdata Move compression unit test from common to core repository 2019-04-15 17:05:09 +02:00
.gitignore unittests: added test_all to .gitignore 2020-08-19 18:53:07 +02:00
CMakeLists.txt unittests/CMakeLists.txt: fix tests execution 2020-09-09 12:35:25 +03:00
core_tests.cpp Refactor InitProcess to use refcounting 2020-09-02 20:37:01 +02:00
README-comp.txt Convert unit test to Googletest 2019-04-15 17:23:37 +02:00
README.md Expand Unittest documentation 2019-12-03 11:04:15 +01:00
test_b64.cpp Update copyrights 2020-03-18 19:37:32 +01: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 unittests/test_comp.cpp: added missing '/' in filename lookup 2020-04-24 13:22:53 +02:00
test_continuation.cpp push-continuation: added new server-side fragmentor 2020-08-19 18:53:00 +02:00
test_cpu_time.cpp Update copyrights 2020-03-18 19:37:32 +01:00
test_helper.hpp unittests: work around some limitations in googletest 2020-08-19 18:52:54 +02: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_openssl_x509certinfo.cpp Update copyrights 2020-03-18 19:37:32 +01:00
test_route_emulation.cpp Update copyrights 2020-03-18 19:37:32 +01:00
test_sitnl.cpp Update copyrights 2020-03-18 19:37:32 +01:00
test_ssl.cpp Unit tests: added new "fake-secure" random source that's guaranteed to be deterministic 2020-08-19 18:52:51 +02:00
test_verify_x509_name.cpp Update copyrights 2020-03-18 19:37:32 +01: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. Eah test includes an #include test_common.h at the top to setup common openvpn3 library parameter 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.