]>
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 | |
94852e75 JH |
26 | #include <queues/job_queue.h> |
27 | #include <queues/event_queue.h> | |
28 | #include <queues/send_queue.h> | |
face0be4 MW |
29 | #include <config/configuration_manager.h> |
30 | #include <sa/ike_sa_manager.h> | |
31 | #include <network/socket.h> | |
94852e75 JH |
32 | #include <utils/logger_manager.h> |
33 | #include <utils/allocator.h> | |
34 | #include <utils/tester.h> | |
35 | #include <testcases/linked_list_test.h> | |
36 | #include <testcases/thread_pool_test.h> | |
37 | #include <testcases/job_queue_test.h> | |
38 | #include <testcases/event_queue_test.h> | |
39 | #include <testcases/send_queue_test.h> | |
40 | #include <testcases/socket_test.h> | |
41 | #include <testcases/sender_test.h> | |
42 | #include <testcases/scheduler_test.h> | |
43 | #include <testcases/receiver_test.h> | |
44 | #include <testcases/ike_sa_id_test.h> | |
45 | #include <testcases/ike_sa_test.h> | |
46 | #include <testcases/ike_sa_manager_test.h> | |
47 | #include <testcases/generator_test.h> | |
48 | #include <testcases/parser_test.h> | |
49 | #include <testcases/packet_test.h> | |
50 | #include <testcases/diffie_hellman_test.h> | |
b2410480 | 51 | #include <testcases/hasher_test.h> |
94852e75 JH |
52 | #include <testcases/hmac_test.h> |
53 | #include <testcases/prf_plus_test.h> | |
7b0dafeb | 54 | #include <testcases/aes_cbc_crypter_test.h> |
42e69fbd | 55 | #include <testcases/hmac_signer_test.h> |
fd9cabd4 JH |
56 | |
57 | /* output for test messages */ | |
58 | extern FILE * stderr; | |
59 | ||
fd9cabd4 JH |
60 | /** |
61 | * Test for linked_list_t | |
62 | */ | |
63 | test_t linked_list_test = {test_linked_list,"Linked List"}; | |
64 | ||
65 | /** | |
66 | * Test for linked_list_t with iterator | |
67 | */ | |
bdb141cb | 68 | test_t iterator_test = {test_linked_list_iterator,"Linked List Iterator"}; |
fd9cabd4 JH |
69 | |
70 | /** | |
71 | * Test for linked_list_t insert and remove | |
72 | */ | |
73 | test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"}; | |
74 | ||
75 | /** | |
76 | * Test for event_queue_t | |
77 | */ | |
6962f6c9 | 78 | test_t event_queue_test = {test_event_queue,"Event-Queue"}; |
fd9cabd4 JH |
79 | |
80 | /** | |
81 | * Test 1 for job_queue_t | |
82 | */ | |
6962f6c9 | 83 | test_t job_queue_test1 = {test_job_queue,"Job-Queue"}; |
fd9cabd4 JH |
84 | |
85 | /** | |
86 | * Test 1 for linked_list_t | |
87 | */ | |
6962f6c9 | 88 | test_t send_queue_test = {test_send_queue,"Send-Queue"}; |
fd9cabd4 JH |
89 | |
90 | /** | |
91 | * Test for socket_t | |
92 | */ | |
93 | test_t socket_test = {test_socket,"Socket"}; | |
94 | ||
95 | /** | |
96 | * Test for thread_pool_t | |
97 | */ | |
98 | test_t thread_pool_test = {test_thread_pool,"Thread Pool"}; | |
99 | ||
6962f6c9 JH |
100 | /** |
101 | * Test for sender_t | |
102 | */ | |
103 | test_t sender_test = {test_sender,"Sender"}; | |
104 | ||
6d4f09bc MW |
105 | /** |
106 | * Test for scheduler_t | |
107 | */ | |
108 | test_t scheduler_test = {test_scheduler,"Scheduler"}; | |
c9473633 | 109 | |
50fffcc4 JH |
110 | /** |
111 | * Test for receiver_t | |
112 | */ | |
113 | test_t receiver_test = {test_receiver,"Receiver"}; | |
da6f7756 | 114 | |
c9473633 JH |
115 | /** |
116 | * Test for ike_sa_id_t | |
117 | */ | |
118 | test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"}; | |
6d4f09bc | 119 | |
4acf505a JH |
120 | /** |
121 | * Test for ike_sa_t | |
122 | */ | |
123 | test_t ike_sa_test = {test_ike_sa,"IKE_SA"}; | |
124 | ||
2426b58d | 125 | |
d4425c1b MW |
126 | /** |
127 | * Test for ike_sa_manager_t | |
128 | */ | |
129 | test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"}; | |
130 | ||
f3c01a28 | 131 | test_t generator_test1 = {test_generator_with_header_payload,"Generator: header payload"}; |
f3c01a28 | 132 | test_t generator_test2 = {test_generator_with_transform_attribute,"Generator: transform attribute"}; |
f3c01a28 | 133 | test_t generator_test3 = {test_generator_with_transform_substructure,"Generator: transform substructure"}; |
2b9dd467 | 134 | test_t generator_test4 = {test_generator_with_proposal_substructure,"Generator: proposal substructure"}; |
7f613a4b | 135 | test_t generator_test5 = {test_generator_with_sa_payload,"Generator: Message with SA Payload"}; |
113f461e | 136 | test_t generator_test6 = {test_generator_with_ke_payload,"Generator: KE Payload"}; |
8166bcec | 137 | test_t generator_test7 = {test_generator_with_notify_payload,"Generator: Notify Payload"}; |
2a489f33 | 138 | test_t generator_test8 = {test_generator_with_nonce_payload,"Generator: Nonce Payload"}; |
7f613a4b | 139 | |
2426b58d | 140 | |
283ac6ef | 141 | /** |
260f3338 | 142 | * Parser test for ike header |
283ac6ef | 143 | */ |
260f3338 | 144 | test_t parser_test1 = {test_parser_with_header_payload, "Parser: header payload"}; |
6c55be34 MW |
145 | |
146 | ||
147 | /** | |
148 | * Parser test for ike security association | |
149 | */ | |
260f3338 MW |
150 | test_t parser_test2 = {test_parser_with_sa_payload, "Parser: sa payload"}; |
151 | ||
152 | /** | |
153 | * Parser test for ike nonce payload | |
154 | */ | |
155 | test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"}; | |
283ac6ef | 156 | |
22a5e2b8 MW |
157 | /** |
158 | * Parser test for ike nonce payload | |
159 | */ | |
160 | test_t parser_test4 = {test_parser_with_ke_payload, "Parser: key exchange payload"}; | |
161 | ||
cb4f26c5 MW |
162 | /** |
163 | * Parser test for ike notify payload | |
164 | */ | |
165 | test_t parser_test5 = {test_parser_with_notify_payload, "Parser: notify payload"}; | |
166 | ||
283ac6ef | 167 | |
110dc83a JH |
168 | /** |
169 | * Test for packet_t | |
170 | */ | |
171 | test_t packet_test = {test_packet,"Packet"}; | |
172 | ||
173 | ||
4750f6c6 JH |
174 | /** |
175 | * Test for packet_t | |
176 | */ | |
177 | test_t diffie_hellman_test = {test_diffie_hellman,"Diffie Hellman"}; | |
178 | ||
3e075ba1 | 179 | /** |
72200048 | 180 | * Test for sha1 hasher |
3e075ba1 | 181 | */ |
b2410480 | 182 | test_t sha1_hasher_test = {test_sha1_hasher,"SHA1 hasher"}; |
3e075ba1 | 183 | |
bfa4b218 MW |
184 | /** |
185 | * Test for md5 hasher | |
186 | */ | |
b2410480 | 187 | test_t md5_hasher_test = {test_md5_hasher,"MD5 hasher"}; |
bfa4b218 | 188 | |
72200048 MW |
189 | /** |
190 | * Test for hmac | |
191 | */ | |
bfa4b218 | 192 | test_t hmac_test1 = {test_hmac_sha1, "HMAC using SHA1"}; |
2018a40a | 193 | test_t hmac_test2 = {test_hmac_md5, "HMAC using MD5"}; |
72200048 | 194 | |
5e280720 MW |
195 | /** |
196 | * Test for prf_plus | |
197 | */ | |
198 | test_t prf_plus_test = {test_prf_plus, "prf+"}; | |
199 | ||
7b0dafeb JH |
200 | /** |
201 | * Test for AES CBC crypter | |
202 | */ | |
203 | test_t aes_cbc_crypter_test = {test_aes_cbc_crypter, "AES CBC"}; | |
5e280720 | 204 | |
42e69fbd JH |
205 | /** |
206 | * Test for hmac signer with MD5 | |
207 | */ | |
208 | test_t hmac_signer_test1 = {test_hmac_md5_signer, "HMAC MD5 signer test"}; | |
5e280720 | 209 | |
42e69fbd JH |
210 | /** |
211 | * Test for hmac signer with SHA1 | |
212 | */ | |
213 | test_t hmac_signer_test2 = {test_hmac_sha1_signer, "HMAC SHA1 signer test"}; | |
5e280720 | 214 | |
4750f6c6 | 215 | |
da6f7756 JH |
216 | /** |
217 | * Global job-queue | |
218 | */ | |
219 | job_queue_t *global_job_queue; | |
220 | ||
221 | /** | |
222 | * Global event-queue | |
223 | */ | |
224 | event_queue_t *global_event_queue; | |
fd9cabd4 | 225 | |
9b4f5ef8 MW |
226 | /** |
227 | * Global send-queue | |
228 | */ | |
da6f7756 JH |
229 | send_queue_t *global_send_queue; |
230 | ||
9b4f5ef8 MW |
231 | /** |
232 | * Global configuration_manager | |
233 | */ | |
234 | configuration_manager_t *global_configuration_manager; | |
235 | ||
236 | /** | |
237 | * Global configuration_manager | |
238 | */ | |
239 | ike_sa_manager_t *global_ike_sa_manager; | |
240 | ||
da6f7756 JH |
241 | /** |
242 | * Global socket | |
243 | */ | |
244 | socket_t *global_socket; | |
7d995669 JH |
245 | |
246 | ||
247 | /** | |
248 | * Global logger | |
249 | */ | |
ffd555f5 | 250 | logger_manager_t *global_logger_manager; |
da6f7756 | 251 | |
fd9cabd4 JH |
252 | int main() |
253 | { | |
254 | FILE * test_output = stderr; | |
255 | ||
256 | test_t *all_tests[] ={ | |
bfa4b218 | 257 | &linked_list_test, |
bdb141cb | 258 | &iterator_test, |
bfa4b218 MW |
259 | &linked_list_insert_and_remove_test, |
260 | &thread_pool_test, | |
261 | &job_queue_test1, | |
262 | &event_queue_test, | |
263 | &send_queue_test, | |
264 | &scheduler_test, | |
265 | &socket_test, | |
266 | &sender_test, | |
267 | &receiver_test, | |
268 | &ike_sa_id_test, | |
2018a40a | 269 | &ike_sa_test, |
bfa4b218 MW |
270 | &generator_test1, |
271 | &generator_test2, | |
272 | &parser_test1, | |
273 | &parser_test2, | |
274 | &parser_test3, | |
275 | &parser_test4, | |
276 | &parser_test5, | |
277 | &generator_test3, | |
278 | &generator_test4, | |
279 | &generator_test5, | |
280 | &generator_test6, | |
281 | &generator_test7, | |
282 | &generator_test8, | |
2018a40a | 283 | &ike_sa_manager_test, |
bfa4b218 MW |
284 | &packet_test, |
285 | &diffie_hellman_test, | |
b2410480 MW |
286 | &sha1_hasher_test, |
287 | &md5_hasher_test, | |
bfa4b218 | 288 | &hmac_test1, |
2018a40a | 289 | &hmac_test2, |
bfa4b218 | 290 | &prf_plus_test, |
7b0dafeb | 291 | &aes_cbc_crypter_test, |
42e69fbd JH |
292 | &hmac_signer_test1, |
293 | &hmac_signer_test2, | |
bfa4b218 | 294 | NULL |
fd9cabd4 | 295 | }; |
42e69fbd | 296 | global_logger_manager = logger_manager_create(0); |
d5fc0f73 | 297 | |
da6f7756 | 298 | global_socket = socket_create(4600); |
fd9cabd4 | 299 | |
da6f7756 JH |
300 | global_job_queue = job_queue_create(); |
301 | global_event_queue = event_queue_create(); | |
302 | global_send_queue = send_queue_create(); | |
9b4f5ef8 MW |
303 | global_configuration_manager = configuration_manager_create(); |
304 | global_ike_sa_manager = ike_sa_manager_create(); | |
7d995669 | 305 | |
6906d8fe | 306 | global_logger_manager->disable_logger_level(global_logger_manager,TESTER,FULL); |
42e69fbd | 307 | //global_logger_manager->enable_logger_level(global_logger_manager,TESTER,RAW); |
da6f7756 | 308 | |
6dfc0b79 | 309 | tester_t *tester = tester_create(test_output, FALSE); |
fd9cabd4 | 310 | |
66e379a2 | 311 | |
42e69fbd JH |
312 | tester->perform_tests(tester,all_tests); |
313 | // tester->perform_test(tester,&hmac_signer_test2); | |
66e379a2 | 314 | |
2b9dd467 | 315 | |
fd9cabd4 JH |
316 | |
317 | tester->destroy(tester); | |
da6f7756 | 318 | |
7d995669 | 319 | |
1f9c9180 JH |
320 | /* Destroy objects*/ |
321 | global_configuration_manager->destroy(global_configuration_manager); | |
322 | global_ike_sa_manager->destroy(global_ike_sa_manager); | |
323 | ||
da6f7756 JH |
324 | /* Destroy all queues */ |
325 | global_job_queue->destroy(global_job_queue); | |
326 | global_event_queue->destroy(global_event_queue); | |
327 | global_send_queue->destroy(global_send_queue); | |
fd9cabd4 | 328 | |
da6f7756 | 329 | global_socket->destroy(global_socket); |
fd9cabd4 | 330 | |
ffd555f5 | 331 | global_logger_manager->destroy(global_logger_manager); |
7d995669 | 332 | |
fd9cabd4 | 333 | #ifdef LEAK_DETECTIVE |
6c4b815f | 334 | /* Leaks are reported on stderr */ |
283ac6ef | 335 | report_memory_leaks(void); |
fd9cabd4 JH |
336 | #endif |
337 | ||
338 | return 0; | |
339 | } |