]>
Commit | Line | Data |
---|---|---|
fd9cabd4 JH |
1 | /** |
2 | * @file tests.c | |
3 | * | |
ed37dee6 | 4 | * @brief Main for all testcases. |
fd9cabd4 JH |
5 | * |
6 | */ | |
7 | ||
8 | /* | |
9 | * Copyright (C) 2005 Jan Hutter, Martin Willi | |
10 | * Hochschule fuer Technik Rapperswil | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify it | |
13 | * under the terms of the GNU General Public License as published by the | |
14 | * Free Software Foundation; either version 2 of the License, or (at your | |
15 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, but | |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
20 | * for more details. | |
21 | */ | |
22 | ||
23 | ||
24 | #include <stdio.h> | |
7d995669 | 25 | |
0e96f7d8 MW |
26 | #include <daemon.h> |
27 | ||
94852e75 JH |
28 | #include <queues/job_queue.h> |
29 | #include <queues/event_queue.h> | |
30 | #include <queues/send_queue.h> | |
8a491129 | 31 | #include <config/configuration.h> |
face0be4 MW |
32 | #include <sa/ike_sa_manager.h> |
33 | #include <network/socket.h> | |
94852e75 JH |
34 | #include <utils/logger_manager.h> |
35 | #include <utils/allocator.h> | |
36 | #include <utils/tester.h> | |
68621281 MW |
37 | #include "linked_list_test.h" |
38 | #include "thread_pool_test.h" | |
39 | #include "job_queue_test.h" | |
40 | #include "event_queue_test.h" | |
41 | #include "send_queue_test.h" | |
42 | #include "socket_test.h" | |
43 | #include "sender_test.h" | |
44 | #include "scheduler_test.h" | |
45 | #include "receiver_test.h" | |
46 | #include "ike_sa_id_test.h" | |
47 | #include "ike_sa_test.h" | |
48 | #include "ike_sa_manager_test.h" | |
49 | #include "generator_test.h" | |
50 | #include "parser_test.h" | |
51 | #include "packet_test.h" | |
52 | #include "diffie_hellman_test.h" | |
53 | #include "hasher_test.h" | |
54 | #include "hmac_test.h" | |
55 | #include "prf_plus_test.h" | |
56 | #include "aes_cbc_crypter_test.h" | |
57 | #include "hmac_signer_test.h" | |
58 | #include "encryption_payload_test.h" | |
59 | #include "connection_test.h" | |
60 | #include "policy_test.h" | |
61 | #include "proposal_test.h" | |
62 | #include "rsa_test.h" | |
63 | #include "kernel_interface_test.h" | |
64 | #include "child_sa_test.h" | |
65 | #include "der_decoder_test.h" | |
66 | #include "certificate_test.h" | |
fd9cabd4 JH |
67 | |
68 | /* output for test messages */ | |
69 | extern FILE * stderr; | |
70 | ||
fd9cabd4 | 71 | test_t linked_list_test = {test_linked_list,"Linked List"}; |
bdb141cb | 72 | test_t iterator_test = {test_linked_list_iterator,"Linked List Iterator"}; |
fd9cabd4 | 73 | test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"}; |
6962f6c9 | 74 | test_t event_queue_test = {test_event_queue,"Event-Queue"}; |
6962f6c9 | 75 | test_t job_queue_test1 = {test_job_queue,"Job-Queue"}; |
6962f6c9 | 76 | test_t send_queue_test = {test_send_queue,"Send-Queue"}; |
fd9cabd4 | 77 | test_t socket_test = {test_socket,"Socket"}; |
fd9cabd4 | 78 | test_t thread_pool_test = {test_thread_pool,"Thread Pool"}; |
6962f6c9 | 79 | test_t sender_test = {test_sender,"Sender"}; |
6d4f09bc | 80 | test_t scheduler_test = {test_scheduler,"Scheduler"}; |
50fffcc4 | 81 | test_t receiver_test = {test_receiver,"Receiver"}; |
c9473633 | 82 | test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"}; |
4acf505a | 83 | test_t ike_sa_test = {test_ike_sa,"IKE_SA"}; |
d4425c1b | 84 | test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"}; |
f3c01a28 | 85 | test_t generator_test1 = {test_generator_with_header_payload,"Generator: header payload"}; |
f3c01a28 | 86 | test_t generator_test2 = {test_generator_with_transform_attribute,"Generator: transform attribute"}; |
f3c01a28 | 87 | test_t generator_test3 = {test_generator_with_transform_substructure,"Generator: transform substructure"}; |
2b9dd467 | 88 | test_t generator_test4 = {test_generator_with_proposal_substructure,"Generator: proposal substructure"}; |
7f613a4b | 89 | test_t generator_test5 = {test_generator_with_sa_payload,"Generator: Message with SA Payload"}; |
113f461e | 90 | test_t generator_test6 = {test_generator_with_ke_payload,"Generator: KE Payload"}; |
8166bcec | 91 | test_t generator_test7 = {test_generator_with_notify_payload,"Generator: Notify Payload"}; |
2a489f33 | 92 | test_t generator_test8 = {test_generator_with_nonce_payload,"Generator: Nonce Payload"}; |
db6e7645 | 93 | test_t generator_test9 = {test_generator_with_id_payload,"Generator: ID Payload"}; |
23266335 | 94 | test_t generator_test10 = {test_generator_with_auth_payload,"Generator: AUTH Payload"}; |
7da522ba | 95 | test_t generator_test11 = {test_generator_with_ts_payload,"Generator: TS Payload"}; |
f6ba78c3 | 96 | test_t generator_test12 = {test_generator_with_cert_payload,"Generator: CERT Payload"}; |
7cc2ee5a | 97 | test_t generator_test13 = {test_generator_with_certreq_payload,"Generator: CERTREQ Payload"}; |
9bdd74ea | 98 | test_t generator_test14 = {test_generator_with_delete_payload,"Generator: DELETE Payload"}; |
e70c7feb | 99 | test_t generator_test15 = {test_generator_with_vendor_id_payload,"Generator: VENDOR ID Payload"}; |
7ba3f707 | 100 | test_t generator_test16 = {test_generator_with_cp_payload,"Generator: CP Payload"}; |
c81eb6e7 | 101 | test_t generator_test17 = {test_generator_with_eap_payload,"Generator: EAP Payload"}; |
260f3338 | 102 | test_t parser_test1 = {test_parser_with_header_payload, "Parser: header payload"}; |
260f3338 | 103 | test_t parser_test2 = {test_parser_with_sa_payload, "Parser: sa payload"}; |
260f3338 | 104 | test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"}; |
22a5e2b8 | 105 | test_t parser_test4 = {test_parser_with_ke_payload, "Parser: key exchange payload"}; |
cb4f26c5 | 106 | test_t parser_test5 = {test_parser_with_notify_payload, "Parser: notify payload"}; |
db6e7645 | 107 | test_t parser_test6 = {test_parser_with_id_payload, "Parser: ID payload"}; |
23266335 | 108 | test_t parser_test7 = {test_parser_with_auth_payload, "Parser: AUTH payload"}; |
7da522ba | 109 | test_t parser_test8 = {test_parser_with_ts_payload, "Parser: TS payload"}; |
f6ba78c3 | 110 | test_t parser_test9 = {test_parser_with_cert_payload, "Parser: CERT payload"}; |
7cc2ee5a | 111 | test_t parser_test10 = {test_parser_with_certreq_payload, "Parser: CERTREQ payload"}; |
9bdd74ea | 112 | test_t parser_test11 = {test_parser_with_delete_payload, "Parser: DELETE payload"}; |
e70c7feb | 113 | test_t parser_test12 = {test_parser_with_vendor_id_payload, "Parser: VENDOR ID payload"}; |
7ba3f707 | 114 | test_t parser_test13 = {test_parser_with_cp_payload, "Parser: CP payload"}; |
c81eb6e7 | 115 | test_t parser_test14 = {test_parser_with_eap_payload, "Parser: EAP payload"}; |
110dc83a | 116 | test_t packet_test = {test_packet,"Packet"}; |
4750f6c6 | 117 | test_t diffie_hellman_test = {test_diffie_hellman,"Diffie Hellman"}; |
b2410480 | 118 | test_t sha1_hasher_test = {test_sha1_hasher,"SHA1 hasher"}; |
b2410480 | 119 | test_t md5_hasher_test = {test_md5_hasher,"MD5 hasher"}; |
bfa4b218 | 120 | test_t hmac_test1 = {test_hmac_sha1, "HMAC using SHA1"}; |
2018a40a | 121 | test_t hmac_test2 = {test_hmac_md5, "HMAC using MD5"}; |
5e280720 | 122 | test_t prf_plus_test = {test_prf_plus, "prf+"}; |
7b0dafeb | 123 | test_t aes_cbc_crypter_test = {test_aes_cbc_crypter, "AES CBC"}; |
42e69fbd | 124 | test_t hmac_signer_test1 = {test_hmac_md5_signer, "HMAC MD5 signer test"}; |
42e69fbd | 125 | test_t hmac_signer_test2 = {test_hmac_sha1_signer, "HMAC SHA1 signer test"}; |
0f803b47 | 126 | test_t encryption_payload_test = {test_encryption_payload, "encryption payload test"}; |
16b9a73c MW |
127 | test_t connection_test = {test_connection, "connection_t test"}; |
128 | test_t policy_test = {test_policy, "policy_t test"}; | |
ce461bbd | 129 | test_t proposal_test = {test_proposal, "proposal_t test"}; |
8ff8c33d | 130 | test_t rsa_test = {test_rsa, "RSA private/public key test"}; |
ba425b87 | 131 | test_t kernel_interface_test = {test_kernel_interface, "Kernel Interface"}; |
30b5b412 | 132 | test_t child_sa_test = {test_child_sa, "Child SA"}; |
9c781c15 | 133 | test_t der_decoder_test = {test_der_decoder, "DER decoder"}; |
efadbf79 | 134 | test_t certificate_test = {test_certificate, "X509 Certificate"}; |
5e280720 | 135 | |
4750f6c6 | 136 | |
0e96f7d8 | 137 | daemon_t* charon; |
da6f7756 | 138 | |
e85220af | 139 | static void daemon_kill(daemon_t *this, char* none) |
0e96f7d8 MW |
140 | { |
141 | this->logger_manager->destroy(this->logger_manager); | |
9c781c15 | 142 | //this->socket->destroy(this->socket); |
0e96f7d8 MW |
143 | this->ike_sa_manager->destroy(this->ike_sa_manager); |
144 | this->job_queue->destroy(this->job_queue); | |
145 | this->event_queue->destroy(this->event_queue); | |
146 | this->send_queue->destroy(this->send_queue); | |
30b5b412 | 147 | this->kernel_interface->destroy(this->kernel_interface); |
8a491129 | 148 | //this->configuration->destroy(this->configuration); |
0e96f7d8 MW |
149 | allocator_free(charon); |
150 | } | |
9b4f5ef8 MW |
151 | |
152 | /** | |
0e96f7d8 MW |
153 | * @brief Create the dummy daemon for testing. |
154 | * | |
155 | * @return created daemon_t | |
9b4f5ef8 | 156 | */ |
0e96f7d8 | 157 | daemon_t *daemon_create() |
8ff8c33d | 158 | { |
0e96f7d8 MW |
159 | charon = allocator_alloc_thing(daemon_t); |
160 | ||
161 | /* assign methods */ | |
e85220af | 162 | charon->kill = daemon_kill; |
0e96f7d8 MW |
163 | |
164 | charon->logger_manager = logger_manager_create(0); | |
9c781c15 | 165 | //charon->socket = socket_create(4510); |
0e96f7d8 MW |
166 | charon->ike_sa_manager = ike_sa_manager_create(); |
167 | charon->job_queue = job_queue_create(); | |
168 | charon->event_queue = event_queue_create(); | |
169 | charon->send_queue = send_queue_create(); | |
30b5b412 | 170 | charon->kernel_interface = kernel_interface_create(); |
8a491129 | 171 | //charon->configuration = configuration_create(RETRANSMIT_TIMEOUT,MAX_RETRANSMIT_COUNT,HALF_OPEN_IKE_SA_TIMEOUT); |
0e96f7d8 MW |
172 | charon->sender = NULL; |
173 | charon->receiver = NULL; | |
174 | charon->scheduler = NULL; | |
175 | charon->thread_pool = NULL; | |
176 | ||
177 | return charon; | |
178 | } | |
7d995669 JH |
179 | |
180 | ||
0e96f7d8 | 181 | int main() |
fd9cabd4 | 182 | { |
0e96f7d8 MW |
183 | FILE * test_output = stderr; |
184 | ||
185 | test_t *all_tests[] ={ | |
bfa4b218 | 186 | &linked_list_test, |
bdb141cb | 187 | &iterator_test, |
bfa4b218 MW |
188 | &linked_list_insert_and_remove_test, |
189 | &thread_pool_test, | |
190 | &job_queue_test1, | |
191 | &event_queue_test, | |
192 | &send_queue_test, | |
193 | &scheduler_test, | |
194 | &socket_test, | |
195 | &sender_test, | |
196 | &receiver_test, | |
197 | &ike_sa_id_test, | |
2018a40a | 198 | &ike_sa_test, |
bfa4b218 MW |
199 | &generator_test1, |
200 | &generator_test2, | |
201 | &parser_test1, | |
202 | &parser_test2, | |
203 | &parser_test3, | |
204 | &parser_test4, | |
205 | &parser_test5, | |
db6e7645 | 206 | &parser_test6, |
23266335 | 207 | &parser_test7, |
7da522ba | 208 | &parser_test8, |
f6ba78c3 | 209 | &parser_test9, |
7cc2ee5a | 210 | &parser_test10, |
9bdd74ea | 211 | &parser_test11, |
e70c7feb | 212 | &parser_test12, |
7ba3f707 | 213 | &parser_test13, |
c81eb6e7 | 214 | &parser_test14, |
bfa4b218 MW |
215 | &generator_test3, |
216 | &generator_test4, | |
217 | &generator_test5, | |
218 | &generator_test6, | |
219 | &generator_test7, | |
220 | &generator_test8, | |
db6e7645 | 221 | &generator_test9, |
23266335 | 222 | &generator_test10, |
7da522ba | 223 | &generator_test11, |
f6ba78c3 | 224 | &generator_test12, |
7cc2ee5a | 225 | &generator_test13, |
9bdd74ea | 226 | &generator_test14, |
e70c7feb | 227 | &generator_test15, |
7ba3f707 | 228 | &generator_test16, |
c81eb6e7 | 229 | &generator_test17, |
2018a40a | 230 | &ike_sa_manager_test, |
bfa4b218 MW |
231 | &packet_test, |
232 | &diffie_hellman_test, | |
b2410480 MW |
233 | &sha1_hasher_test, |
234 | &md5_hasher_test, | |
bfa4b218 | 235 | &hmac_test1, |
2018a40a | 236 | &hmac_test2, |
bfa4b218 | 237 | &prf_plus_test, |
7b0dafeb | 238 | &aes_cbc_crypter_test, |
42e69fbd JH |
239 | &hmac_signer_test1, |
240 | &hmac_signer_test2, | |
0f803b47 | 241 | &encryption_payload_test, |
16b9a73c MW |
242 | &connection_test, |
243 | &policy_test, | |
ce461bbd | 244 | &proposal_test, |
8ff8c33d | 245 | &rsa_test, |
bfa4b218 | 246 | NULL |
fd9cabd4 | 247 | }; |
30b5b412 MW |
248 | /* get rid of compiler warning ;-) */ |
249 | *all_tests = *all_tests; | |
8ff8c33d MW |
250 | |
251 | /* allocator needs initialization */ | |
252 | allocator_init(); | |
0e96f7d8 MW |
253 | |
254 | daemon_create(); | |
255 | ||
efadbf79 MW |
256 | //charon->logger_manager->enable_log_level(charon->logger_manager, ALL_LOGGERS, FULL); |
257 | charon->logger_manager->set_output(charon->logger_manager, ALL_LOGGERS, stdout); | |
0e96f7d8 MW |
258 | |
259 | tester_t *tester = tester_create(test_output, FALSE); | |
260 | ||
30b5b412 | 261 | //tester->perform_tests(tester,all_tests); |
9c781c15 | 262 | tester->perform_test(tester,&rsa_test); |
0e96f7d8 | 263 | |
1f9c9180 | 264 | |
0e96f7d8 | 265 | tester->destroy(tester); |
fd9cabd4 | 266 | |
e85220af | 267 | charon->kill(charon, NULL); |
7d995669 | 268 | |
fd9cabd4 | 269 | #ifdef LEAK_DETECTIVE |
6c4b815f | 270 | /* Leaks are reported on stderr */ |
283ac6ef | 271 | report_memory_leaks(void); |
fd9cabd4 JH |
272 | #endif |
273 | ||
274 | return 0; | |
275 | } |