libhydra: Remove unused hydra->daemon
[strongswan.git] / src / charon-tkm / tests / tests.c
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Copyright (C) 2012 Reto Buerki
4 * Copyright (C) 2012 Adrian-Ken Rueegsegger
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 #include <tests/test_runner.h>
19
20 #include <library.h>
21 #include <hydra.h>
22 #include <daemon.h>
23
24 #include "tkm.h"
25 #include "tkm_nonceg.h"
26 #include "tkm_diffie_hellman.h"
27 #include "tkm_kernel_ipsec.h"
28
29 /* declare test suite constructors */
30 #define TEST_SUITE(x) test_suite_t* x();
31 #define TEST_SUITE_DEPEND(x, ...) TEST_SUITE(x)
32 #include "tests.h"
33 #undef TEST_SUITE
34 #undef TEST_SUITE_DEPEND
35
36 static test_configuration_t tests[] = {
37 #define TEST_SUITE(x) \
38 { .suite = x, },
39 #define TEST_SUITE_DEPEND(x, type, args) \
40 { .suite = x, .feature = PLUGIN_DEPENDS(type, args) },
41 #include "tests.h"
42 { .suite = NULL, }
43 };
44
45 static bool tkm_initialized = false;
46
47 static bool test_runner_init(bool init)
48 {
49 bool result = TRUE;
50
51 if (init)
52 {
53 libhydra_init();
54 libcharon_init("test_runner");
55 lib->settings->set_int(lib->settings,
56 "test_runner.filelog.stdout.default", 0);
57 charon->load_loggers(charon, NULL, FALSE);
58
59 /* Register TKM specific plugins */
60 static plugin_feature_t features[] = {
61 PLUGIN_REGISTER(NONCE_GEN, tkm_nonceg_create),
62 PLUGIN_PROVIDE(NONCE_GEN),
63 PLUGIN_CALLBACK(kernel_ipsec_register, tkm_kernel_ipsec_create),
64 PLUGIN_PROVIDE(CUSTOM, "kernel-ipsec"),
65 };
66 lib->plugins->add_static_features(lib->plugins, "tkm-tests", features,
67 countof(features), TRUE);
68
69 lib->settings->set_int(lib->settings, "%s.dh_mapping.%d", 1,
70 charon->name, MODP_3072_BIT);
71 lib->settings->set_int(lib->settings, "%s.dh_mapping.%d", 2,
72 charon->name, MODP_4096_BIT);
73 register_dh_mapping();
74
75 plugin_loader_add_plugindirs(BUILDDIR "/src/libstrongswan/plugins",
76 PLUGINS);
77 plugin_loader_add_plugindirs(BUILDDIR "/src/libhydra/plugins",
78 PLUGINS);
79 plugin_loader_add_plugindirs(BUILDDIR "/src/libcharon/plugins",
80 PLUGINS);
81 if (charon->initialize(charon, PLUGINS))
82 {
83 if (!tkm_initialized)
84 {
85 if (!tkm_init())
86 {
87 return FALSE;
88 }
89 tkm_initialized = true;
90 }
91 return TRUE;
92 }
93 result = FALSE;
94 }
95
96 destroy_dh_mapping();
97 libcharon_deinit();
98 libhydra_deinit();
99 return result;
100 }
101
102 int main(int argc, char *argv[])
103 {
104 bool result;
105
106 /* disable leak detective because of how tkm_init/deinit is called, which
107 * does not work otherwise due to limitations of the external libraries */
108 setenv("LEAK_DETECTIVE_DISABLE", "1", 1);
109
110 result = test_runner_run("tkm", tests, test_runner_init);
111 tkm_deinit();
112
113 return result;
114 }