]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
charon-tkm: Make only tests requiring TKM optional
authorTobias Brunner <tobias@strongswan.org>
Mon, 22 Nov 2021 14:06:19 +0000 (15:06 +0100)
committerTobias Brunner <tobias@strongswan.org>
Mon, 29 Nov 2021 14:29:22 +0000 (15:29 +0100)
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`.

src/charon-tkm/Makefile.am
src/charon-tkm/tests/keymat_tests.c
src/charon-tkm/tests/tests.c
src/charon-tkm/tests/tests.h

index 4939c074a14eb09549a9aae28255ed03ec5880e7..03694e3f78baa49719c0ae4bc1c66a78844327eb 100644 (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)
 
index eea589c091e78b873cbc91982abc37c4d7f20f08..ff6a6c8c738e9dcfeb6132bbc0369a80635dfbfe 100644 (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));
index 150a6d43723fc9838d53465c0a95b9854b1c0b90..c09936a37a13a8413a52a694951f8c4281ddc756 100644 (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);
index 0214a413e52c73d41f9a1e4c57993e8dee583350..a93837c7cc3d0e21260bd362aa3d4dac28c34c6d 100644 (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)