From: Tobias Brunner Date: Mon, 22 Nov 2021 14:06:19 +0000 (+0100) Subject: charon-tkm: Make only tests requiring TKM optional X-Git-Tag: 5.9.5dr3~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66fd0c4db7bee00a2af6db2cc76f3cefac7d8ad5;p=thirdparty%2Fstrongswan.git charon-tkm: Make only tests requiring TKM optional This way we can run many unit tests without having to run the TKM in the background and as regular user. To run the other tests, TESTS_TKM can optionally be defined when running `make check`. --- diff --git a/src/charon-tkm/Makefile.am b/src/charon-tkm/Makefile.am index 4939c074a1..03694e3f78 100644 --- a/src/charon-tkm/Makefile.am +++ b/src/charon-tkm/Makefile.am @@ -39,14 +39,15 @@ build_charon: build_charon.gpr src/charon-tkm.c build_tests: build_tests.gpr @$(GPRBUILD) -p $< $(BUILD_OPTS) $(TEST_OPTS) -check-tkm: build_tests +check: build_tests + if test -z "${TESTS_TKM}"; then \ + echo -e >&2 \ + "\nSome TKM tests are not enabled, by deafult, because they have" \ + "\nto be run as root and require a running TKM daemon. They may" \ + "\nbe enabled by defining the TESTS_TKM environment variable.\n"; \ + fi @LD_LIBRARY_PATH=$(LIBPT) obj/tests -check: - @echo "TKM tests are not run automatically because they have to be run as root" >&2 - @echo "and require a properly configured TKM daemon to be running." >&2 - @echo "They can be run from '$(abs_builddir)' with 'make check-tkm'" >&2 - install: build_charon $(INSTALL) -m 755 obj/charon-tkm $(DESTDIR)$(ipsecdir) diff --git a/src/charon-tkm/tests/keymat_tests.c b/src/charon-tkm/tests/keymat_tests.c index eea589c091..ff6a6c8c73 100644 --- a/src/charon-tkm/tests/keymat_tests.c +++ b/src/charon-tkm/tests/keymat_tests.c @@ -62,7 +62,7 @@ START_TEST(test_derive_ike_keys) aead_t * const aead = keymat->keymat_v2.keymat.get_aead(&keymat->keymat_v2.keymat, TRUE); fail_if(!aead, "AEAD is NULL"); - fail_if(aead->get_key_size(aead) != 96, "Key size mismatch %d", + fail_if(aead->get_key_size(aead) != 1, "Key size mismatch %d", aead->get_key_size(aead)); fail_if(aead->get_block_size(aead) != 16, "Block size mismatch %d", aead->get_block_size(aead)); diff --git a/src/charon-tkm/tests/tests.c b/src/charon-tkm/tests/tests.c index 150a6d4372..c09936a37a 100644 --- a/src/charon-tkm/tests/tests.c +++ b/src/charon-tkm/tests/tests.c @@ -41,21 +41,31 @@ static test_configuration_t tests[] = { { .suite = NULL, } }; -static bool tkm_initialized = false; +static bool tkm_initialized, use_tkm; static bool test_runner_init(bool init) { bool result = TRUE; - if (init) + if (init && use_tkm) { + int level = LEVEL_SILENT; + char *verbosity; + libcharon_init(); - lib->settings->set_int(lib->settings, - "test-runner.filelog.stdout.default", 0); + verbosity = getenv("TESTS_VERBOSITY"); + if (verbosity) + { + level = atoi(verbosity); + } + lib->settings->set_int(lib->settings, "%s.filelog.stderr.default", + lib->settings->get_int(lib->settings, "%s.filelog.stderr.default", + level, lib->ns), lib->ns); charon->load_loggers(charon); /* Register TKM specific plugins */ static plugin_feature_t features[] = { + PLUGIN_PROVIDE(CUSTOM, "tkm"), PLUGIN_REGISTER(NONCE_GEN, tkm_nonceg_create), PLUGIN_PROVIDE(NONCE_GEN), PLUGIN_CALLBACK(kernel_ipsec_register, tkm_kernel_ipsec_create), @@ -98,6 +108,8 @@ int main(int argc, char *argv[]) { bool result; + use_tkm = getenv("TESTS_TKM") != NULL; + /* disable leak detective because of how tkm_init/deinit is called, which * does not work otherwise due to limitations of the external libraries */ setenv("LEAK_DETECTIVE_DISABLE", "1", 1); diff --git a/src/charon-tkm/tests/tests.h b/src/charon-tkm/tests/tests.h index 0214a413e5..a93837c7cc 100644 --- a/src/charon-tkm/tests/tests.h +++ b/src/charon-tkm/tests/tests.h @@ -17,7 +17,7 @@ TEST_SUITE(make_id_manager_tests) TEST_SUITE(make_chunk_map_tests) TEST_SUITE(make_utility_tests) -TEST_SUITE(make_nonceg_tests) -TEST_SUITE(make_diffie_hellman_tests) -TEST_SUITE(make_keymat_tests) +TEST_SUITE_DEPEND(make_nonceg_tests, CUSTOM, "tkm") +TEST_SUITE_DEPEND(make_diffie_hellman_tests, CUSTOM, "tkm") +TEST_SUITE_DEPEND(make_keymat_tests, CUSTOM, "tkm") TEST_SUITE(make_kernel_sad_tests)