Give the unit tests a big overhaul [v9.18]
The unit tests contain a lot of duplicated code and here's an attempt to reduce code duplication.
This commit does several things:
-
Remove #ifdef HAVE_CMOCKA - we already solve this with automake conditionals.
-
Create a set of ISC_TEST_* and ISC_*TEST macros to wrap the test implementations, test lists, and the main test routine, so we don't have to repeat this all over again. The macros were modeled after libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START ISC_TEST_ENTRY(test1) ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown functions, and per-test setup and teardown functions.
-
The macros prefix the test functions and cmocka entries, so the name of the test can now match the tested function name, and we don't have to append
_test
becauserun_test_
is automatically prepended to the main test function, andsetup_test_
andteardown_test_
is prepended to setup and teardown function. -
Update all the unit tests to use the new syntax and fix a few bits here and there.
-
In the future, we can separate the test declarations and test implementations which are going to greatly help with uncluttering the bigger unit tests like doh_test and netmgr_test, because the test implementations are not declared static (see
ISC_RUN_TEST_DECLARE
andISC_RUN_TEST_IMPL
for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly outweighs all the negatives of using the macros. There's less duplicated code, the tests are more uniform and the implementation can be more flexible.
(cherry picked from commit 63fe9312)
Backport of !6243 (merged)