summaryrefslogtreecommitdiff
path: root/src/charon-tkm/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/charon-tkm/tests')
-rw-r--r--src/charon-tkm/tests/chunk_map_tests.c17
-rw-r--r--src/charon-tkm/tests/diffie_hellman_tests.c18
-rw-r--r--src/charon-tkm/tests/id_manager_tests.c20
-rw-r--r--src/charon-tkm/tests/kernel_sad_tests.c23
-rw-r--r--src/charon-tkm/tests/keymat_tests.c18
-rw-r--r--src/charon-tkm/tests/nonceg_tests.c21
-rw-r--r--src/charon-tkm/tests/test_runner.c84
-rw-r--r--src/charon-tkm/tests/tests.c114
-rw-r--r--src/charon-tkm/tests/tests.h (renamed from src/charon-tkm/tests/test_runner.h)21
-rw-r--r--src/charon-tkm/tests/utils_tests.c15
10 files changed, 225 insertions, 126 deletions
diff --git a/src/charon-tkm/tests/chunk_map_tests.c b/src/charon-tkm/tests/chunk_map_tests.c
index 6deef9a80..1283a787c 100644
--- a/src/charon-tkm/tests/chunk_map_tests.c
+++ b/src/charon-tkm/tests/chunk_map_tests.c
@@ -14,7 +14,7 @@
* for more details.
*/
-#include <check.h>
+#include <tests/test_suite.h>
#include "tkm_chunk_map.h"
@@ -48,11 +48,20 @@ START_TEST(test_chunk_map_handling)
}
END_TEST
-TCase *make_chunk_map_tests(void)
+Suite *make_chunk_map_tests()
{
- TCase *tc = tcase_create("Chunk map tests");
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("chunk map");
+
+ tc = tcase_create("creating");
tcase_add_test(tc, test_chunk_map_creation);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("handling");
tcase_add_test(tc, test_chunk_map_handling);
+ suite_add_tcase(s, tc);
- return tc;
+ return s;
}
diff --git a/src/charon-tkm/tests/diffie_hellman_tests.c b/src/charon-tkm/tests/diffie_hellman_tests.c
index ffe99614d..89658a770 100644
--- a/src/charon-tkm/tests/diffie_hellman_tests.c
+++ b/src/charon-tkm/tests/diffie_hellman_tests.c
@@ -14,7 +14,8 @@
* for more details.
*/
-#include <check.h>
+#include <daemon.h>
+#include <tests/test_suite.h>
#include "tkm_diffie_hellman.h"
@@ -49,11 +50,20 @@ START_TEST(test_dh_get_my_pubvalue)
}
END_TEST
-TCase *make_diffie_hellman_tests(void)
+Suite *make_diffie_hellman_tests()
{
- TCase *tc = tcase_create("Diffie-Hellman tests");
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("Diffie-Hellman");
+
+ tc = tcase_create("creation");
tcase_add_test(tc, test_dh_creation);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("get_my_pubvalue");
tcase_add_test(tc, test_dh_get_my_pubvalue);
+ suite_add_tcase(s, tc);
- return tc;
+ return s;
}
diff --git a/src/charon-tkm/tests/id_manager_tests.c b/src/charon-tkm/tests/id_manager_tests.c
index 15522f118..8157496ca 100644
--- a/src/charon-tkm/tests/id_manager_tests.c
+++ b/src/charon-tkm/tests/id_manager_tests.c
@@ -14,7 +14,7 @@
* for more details.
*/
-#include <check.h>
+#include <tests/test_suite.h>
#include "tkm_id_manager.h"
@@ -135,16 +135,28 @@ START_TEST(test_release_id_nonexistent)
}
END_TEST
-TCase *make_id_manager_tests(void)
+Suite *make_id_manager_tests()
{
- TCase *tc = tcase_create("Context id manager tests");
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("context id manager");
+
+ tc = tcase_create("creation");
tcase_add_test(tc, test_id_mgr_creation);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("acquire");
tcase_add_test(tc, test_acquire_id);
tcase_add_test(tc, test_acquire_id_invalid_kind);
tcase_add_test(tc, test_acquire_id_same);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("release");
tcase_add_test(tc, test_release_id);
tcase_add_test(tc, test_release_id_invalid_kind);
tcase_add_test(tc, test_release_id_nonexistent);
+ suite_add_tcase(s, tc);
- return tc;
+ return s;
}
diff --git a/src/charon-tkm/tests/kernel_sad_tests.c b/src/charon-tkm/tests/kernel_sad_tests.c
index 11785602d..6f0b396d3 100644
--- a/src/charon-tkm/tests/kernel_sad_tests.c
+++ b/src/charon-tkm/tests/kernel_sad_tests.c
@@ -14,7 +14,7 @@
* for more details.
*/
-#include <check.h>
+#include <tests/test_suite.h>
#include "tkm_kernel_sad.h"
@@ -107,16 +107,31 @@ START_TEST(test_remove_nonexistent)
}
END_TEST
-TCase *make_kernel_sad_tests(void)
+Suite *make_kernel_sad_tests()
{
- TCase *tc = tcase_create("Kernel SAD tests");
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("kernel SAD tests");
+
+ tc = tcase_create("creation");
tcase_add_test(tc, test_sad_creation);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("insert");
tcase_add_test(tc, test_insert);
tcase_add_test(tc, test_insert_duplicate);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("get_esa_id");
tcase_add_test(tc, test_get_esa_id);
tcase_add_test(tc, test_get_esa_id_nonexistent);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("remove");
tcase_add_test(tc, test_remove);
tcase_add_test(tc, test_remove_nonexistent);
+ suite_add_tcase(s, tc);
- return tc;
+ return s;
}
diff --git a/src/charon-tkm/tests/keymat_tests.c b/src/charon-tkm/tests/keymat_tests.c
index 2a7525d4e..1982671d3 100644
--- a/src/charon-tkm/tests/keymat_tests.c
+++ b/src/charon-tkm/tests/keymat_tests.c
@@ -14,7 +14,8 @@
* for more details.
*/
-#include <check.h>
+#include <tests/test_suite.h>
+
#include <daemon.h>
#include <hydra.h>
#include <config/proposal.h>
@@ -139,11 +140,20 @@ START_TEST(test_derive_child_keys)
}
END_TEST
-TCase *make_keymat_tests(void)
+Suite *make_keymat_tests()
{
- TCase *tc = tcase_create("Keymat tests");
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("keymat");
+
+ tc = tcase_create("derive IKE keys");
tcase_add_test(tc, test_derive_ike_keys);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("derive CHILD keys");
tcase_add_test(tc, test_derive_child_keys);
+ suite_add_tcase(s, tc);
- return tc;
+ return s;
}
diff --git a/src/charon-tkm/tests/nonceg_tests.c b/src/charon-tkm/tests/nonceg_tests.c
index 3a1effab8..6f524cb22 100644
--- a/src/charon-tkm/tests/nonceg_tests.c
+++ b/src/charon-tkm/tests/nonceg_tests.c
@@ -14,7 +14,8 @@
* for more details.
*/
-#include <check.h>
+#include <tests/test_suite.h>
+
#include <tkm/client.h>
#include "tkm.h"
@@ -82,12 +83,24 @@ START_TEST(test_nonceg_get_nonce)
}
END_TEST
-TCase *make_nonceg_tests(void)
+Suite *make_nonceg_tests()
{
- TCase *tc = tcase_create("Nonce generator tests");
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("nonce generator");
+
+ tc = tcase_create("creation");
tcase_add_test(tc, test_nonceg_creation);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("allocate");
tcase_add_test(tc, test_nonceg_allocate_nonce);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("get");
tcase_add_test(tc, test_nonceg_get_nonce);
+ suite_add_tcase(s, tc);
- return tc;
+ return s;
}
diff --git a/src/charon-tkm/tests/test_runner.c b/src/charon-tkm/tests/test_runner.c
deleted file mode 100644
index 5ae032935..000000000
--- a/src/charon-tkm/tests/test_runner.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2012 Reto Buerki
- * Copyright (C) 2012 Adrian-Ken Rueegsegger
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include <library.h>
-#include <hydra.h>
-#include <daemon.h>
-
-#include "tkm.h"
-#include "tkm_nonceg.h"
-#include "tkm_diffie_hellman.h"
-#include "tkm_kernel_ipsec.h"
-#include "test_runner.h"
-
-int main(void)
-{
- library_init(NULL);
- libhydra_init("test_runner");
- libcharon_init("test_runner");
-
- lib->settings->set_int(lib->settings, "test_runner.filelog.stdout.default",
- 1);
- charon->load_loggers(charon, NULL, FALSE);
-
- /* Register TKM specific plugins */
- static plugin_feature_t features[] = {
- PLUGIN_REGISTER(NONCE_GEN, tkm_nonceg_create),
- PLUGIN_PROVIDE(NONCE_GEN),
- PLUGIN_REGISTER(DH, tkm_diffie_hellman_create),
- PLUGIN_PROVIDE(DH, MODP_3072_BIT),
- PLUGIN_PROVIDE(DH, MODP_4096_BIT),
- PLUGIN_CALLBACK(kernel_ipsec_register, tkm_kernel_ipsec_create),
- PLUGIN_PROVIDE(CUSTOM, "kernel-ipsec"),
- };
- lib->plugins->add_static_features(lib->plugins, "tkm-tests", features,
- countof(features), TRUE);
-
- if (!charon->initialize(charon, PLUGINS))
- {
- fprintf(stderr, "Unable to init charon");
- return EXIT_FAILURE;
- }
-
- if (!tkm_init())
- {
- fprintf(stderr, "Could not connect to TKM, aborting tests\n");
- return EXIT_FAILURE;
- }
-
- int number_failed;
- Suite *s = suite_create("TKM tests");
- suite_add_tcase(s, make_id_manager_tests());
- suite_add_tcase(s, make_chunk_map_tests());
- suite_add_tcase(s, make_utility_tests());
- suite_add_tcase(s, make_nonceg_tests());
- suite_add_tcase(s, make_diffie_hellman_tests());
- suite_add_tcase(s, make_keymat_tests());
- suite_add_tcase(s, make_kernel_sad_tests());
-
- SRunner *sr = srunner_create(s);
-
- srunner_run_all(sr, CK_NORMAL);
- number_failed = srunner_ntests_failed(sr);
-
- tkm_deinit();
- libcharon_deinit();
- libhydra_deinit();
- library_deinit();
- srunner_free(sr);
-
- return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
diff --git a/src/charon-tkm/tests/tests.c b/src/charon-tkm/tests/tests.c
new file mode 100644
index 000000000..18754c717
--- /dev/null
+++ b/src/charon-tkm/tests/tests.c
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Copyright (C) 2012 Reto Buerki
+ * Copyright (C) 2012 Adrian-Ken Rueegsegger
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <tests/test_runner.h>
+
+#include <library.h>
+#include <hydra.h>
+#include <daemon.h>
+
+#include "tkm.h"
+#include "tkm_nonceg.h"
+#include "tkm_diffie_hellman.h"
+#include "tkm_kernel_ipsec.h"
+
+/* declare test suite constructors */
+#define TEST_SUITE(x) test_suite_t* x();
+#define TEST_SUITE_DEPEND(x, ...) TEST_SUITE(x)
+#include "tests.h"
+#undef TEST_SUITE
+#undef TEST_SUITE_DEPEND
+
+static test_configuration_t tests[] = {
+#define TEST_SUITE(x) \
+ { .suite = x, },
+#define TEST_SUITE_DEPEND(x, type, args) \
+ { .suite = x, .feature = PLUGIN_DEPENDS(type, args) },
+#include "tests.h"
+ { .suite = NULL, }
+};
+
+static bool tkm_initialized = false;
+
+static bool test_runner_init(bool init)
+{
+ bool result = TRUE;
+
+ if (init)
+ {
+ libhydra_init();
+ libcharon_init();
+ lib->settings->set_int(lib->settings,
+ "test_runner.filelog.stdout.default", 0);
+ charon->load_loggers(charon, NULL, FALSE);
+
+ /* Register TKM specific plugins */
+ static plugin_feature_t features[] = {
+ PLUGIN_REGISTER(NONCE_GEN, tkm_nonceg_create),
+ PLUGIN_PROVIDE(NONCE_GEN),
+ PLUGIN_CALLBACK(kernel_ipsec_register, tkm_kernel_ipsec_create),
+ PLUGIN_PROVIDE(CUSTOM, "kernel-ipsec"),
+ };
+ lib->plugins->add_static_features(lib->plugins, "tkm-tests", features,
+ countof(features), TRUE);
+
+ lib->settings->set_int(lib->settings, "%s.dh_mapping.%d", 1,
+ lib->ns, MODP_3072_BIT);
+ lib->settings->set_int(lib->settings, "%s.dh_mapping.%d", 2,
+ lib->ns, MODP_4096_BIT);
+ register_dh_mapping();
+
+ plugin_loader_add_plugindirs(BUILDDIR "/src/libstrongswan/plugins",
+ PLUGINS);
+ plugin_loader_add_plugindirs(BUILDDIR "/src/libhydra/plugins",
+ PLUGINS);
+ plugin_loader_add_plugindirs(BUILDDIR "/src/libcharon/plugins",
+ PLUGINS);
+ if (charon->initialize(charon, PLUGINS))
+ {
+ if (!tkm_initialized)
+ {
+ if (!tkm_init())
+ {
+ return FALSE;
+ }
+ tkm_initialized = true;
+ }
+ return TRUE;
+ }
+ result = FALSE;
+ }
+
+ destroy_dh_mapping();
+ libcharon_deinit();
+ libhydra_deinit();
+ return result;
+}
+
+int main(int argc, char *argv[])
+{
+ bool result;
+
+ /* 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);
+
+ result = test_runner_run("tkm", tests, test_runner_init);
+ tkm_deinit();
+
+ return result;
+}
diff --git a/src/charon-tkm/tests/test_runner.h b/src/charon-tkm/tests/tests.h
index 236a7f2a6..fb5e96a9c 100644
--- a/src/charon-tkm/tests/test_runner.h
+++ b/src/charon-tkm/tests/tests.h
@@ -14,17 +14,10 @@
* for more details.
*/
-#ifndef TEST_RUNNER_H_
-#define TEST_RUNNER_H_
-
-#include <check.h>
-
-TCase *make_id_manager_tests(void);
-TCase *make_chunk_map_tests(void);
-TCase *make_utility_tests(void);
-TCase *make_nonceg_tests(void);
-TCase *make_diffie_hellman_tests(void);
-TCase *make_keymat_tests(void);
-TCase *make_kernel_sad_tests(void);
-
-#endif /** TEST_RUNNER_H_ */
+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(make_kernel_sad_tests)
diff --git a/src/charon-tkm/tests/utils_tests.c b/src/charon-tkm/tests/utils_tests.c
index b3ead7633..0a4d6fbd2 100644
--- a/src/charon-tkm/tests/utils_tests.c
+++ b/src/charon-tkm/tests/utils_tests.c
@@ -14,7 +14,8 @@
* for more details.
*/
-#include <check.h>
+#include <tests/test_suite.h>
+
#include <tkm/types.h>
#include "tkm_utils.h"
@@ -53,11 +54,17 @@ START_TEST(test_chunk_to_sequence)
}
END_TEST
-TCase *make_utility_tests(void)
+Suite *make_utility_tests()
{
- TCase *tc = tcase_create("Utility tests");
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("utility tests");
+
+ tc = tcase_create("chunk<->sequence");
tcase_add_test(tc, test_sequence_to_chunk);
tcase_add_test(tc, test_chunk_to_sequence);
+ suite_add_tcase(s, tc);
- return tc;
+ return s;
}