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`.
This commit is contained in:
Tobias Brunner
2021-11-29 15:29:22 +01:00
parent 43927e60a7
commit 66fd0c4db7
4 changed files with 27 additions and 14 deletions
+7 -6
View File
@@ -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)
+1 -1
View File
@@ -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));
+16 -4
View File
@@ -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);
+3 -3
View File
@@ -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)