3e3c850a360da3a444f0e6d352d91431e9052631
[strongswan.git] / Source / charon / testcases / testcases.c
1 /**
2 * @file tests.c
3 *
4 * @brief Main for all testcases.
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>
25
26 #include <daemon.h>
27
28 #include <queues/job_queue.h>
29 #include <queues/event_queue.h>
30 #include <queues/send_queue.h>
31 #include <config/configuration_manager.h>
32 #include <sa/ike_sa_manager.h>
33 #include <network/socket.h>
34 #include <utils/logger_manager.h>
35 #include <utils/allocator.h>
36 #include <utils/tester.h>
37 #include <testcases/linked_list_test.h>
38 #include <testcases/thread_pool_test.h>
39 #include <testcases/job_queue_test.h>
40 #include <testcases/event_queue_test.h>
41 #include <testcases/send_queue_test.h>
42 #include <testcases/socket_test.h>
43 #include <testcases/sender_test.h>
44 #include <testcases/scheduler_test.h>
45 #include <testcases/receiver_test.h>
46 #include <testcases/ike_sa_id_test.h>
47 #include <testcases/ike_sa_test.h>
48 #include <testcases/ike_sa_manager_test.h>
49 #include <testcases/generator_test.h>
50 #include <testcases/parser_test.h>
51 #include <testcases/packet_test.h>
52 #include <testcases/diffie_hellman_test.h>
53 #include <testcases/hasher_test.h>
54 #include <testcases/hmac_test.h>
55 #include <testcases/prf_plus_test.h>
56 #include <testcases/aes_cbc_crypter_test.h>
57 #include <testcases/hmac_signer_test.h>
58 #include <testcases/encryption_payload_test.h>
59 #include <testcases/init_config_test.h>
60 #include <testcases/sa_config_test.h>
61 #include <testcases/rsa_test.h>
62 #include <testcases/prime_pool_test.h>
63
64 /* output for test messages */
65 extern FILE * stderr;
66
67 test_t linked_list_test = {test_linked_list,"Linked List"};
68 test_t iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
69 test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"};
70 test_t event_queue_test = {test_event_queue,"Event-Queue"};
71 test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
72 test_t send_queue_test = {test_send_queue,"Send-Queue"};
73 test_t socket_test = {test_socket,"Socket"};
74 test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
75 test_t sender_test = {test_sender,"Sender"};
76 test_t scheduler_test = {test_scheduler,"Scheduler"};
77 test_t receiver_test = {test_receiver,"Receiver"};
78 test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"};
79 test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
80 test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"};
81 test_t generator_test1 = {test_generator_with_header_payload,"Generator: header payload"};
82 test_t generator_test2 = {test_generator_with_transform_attribute,"Generator: transform attribute"};
83 test_t generator_test3 = {test_generator_with_transform_substructure,"Generator: transform substructure"};
84 test_t generator_test4 = {test_generator_with_proposal_substructure,"Generator: proposal substructure"};
85 test_t generator_test5 = {test_generator_with_sa_payload,"Generator: Message with SA Payload"};
86 test_t generator_test6 = {test_generator_with_ke_payload,"Generator: KE Payload"};
87 test_t generator_test7 = {test_generator_with_notify_payload,"Generator: Notify Payload"};
88 test_t generator_test8 = {test_generator_with_nonce_payload,"Generator: Nonce Payload"};
89 test_t generator_test9 = {test_generator_with_id_payload,"Generator: ID Payload"};
90 test_t generator_test10 = {test_generator_with_auth_payload,"Generator: AUTH Payload"};
91 test_t generator_test11 = {test_generator_with_ts_payload,"Generator: TS Payload"};
92 test_t generator_test12 = {test_generator_with_cert_payload,"Generator: CERT Payload"};
93 test_t generator_test13 = {test_generator_with_certreq_payload,"Generator: CERTREQ Payload"};
94 test_t generator_test14 = {test_generator_with_delete_payload,"Generator: DELETE Payload"};
95 test_t generator_test15 = {test_generator_with_vendor_id_payload,"Generator: VENDOR ID Payload"};
96 test_t parser_test1 = {test_parser_with_header_payload, "Parser: header payload"};
97 test_t parser_test2 = {test_parser_with_sa_payload, "Parser: sa payload"};
98 test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"};
99 test_t parser_test4 = {test_parser_with_ke_payload, "Parser: key exchange payload"};
100 test_t parser_test5 = {test_parser_with_notify_payload, "Parser: notify payload"};
101 test_t parser_test6 = {test_parser_with_id_payload, "Parser: ID payload"};
102 test_t parser_test7 = {test_parser_with_auth_payload, "Parser: AUTH payload"};
103 test_t parser_test8 = {test_parser_with_ts_payload, "Parser: TS payload"};
104 test_t parser_test9 = {test_parser_with_cert_payload, "Parser: CERT payload"};
105 test_t parser_test10 = {test_parser_with_certreq_payload, "Parser: CERTREQ payload"};
106 test_t parser_test11 = {test_parser_with_delete_payload, "Parser: DELETE payload"};
107 test_t parser_test12 = {test_parser_with_vendor_id_payload, "Parser: VENDOR ID payload"};
108 test_t packet_test = {test_packet,"Packet"};
109 test_t diffie_hellman_test = {test_diffie_hellman,"Diffie Hellman"};
110 test_t sha1_hasher_test = {test_sha1_hasher,"SHA1 hasher"};
111 test_t md5_hasher_test = {test_md5_hasher,"MD5 hasher"};
112 test_t hmac_test1 = {test_hmac_sha1, "HMAC using SHA1"};
113 test_t hmac_test2 = {test_hmac_md5, "HMAC using MD5"};
114 test_t prf_plus_test = {test_prf_plus, "prf+"};
115 test_t aes_cbc_crypter_test = {test_aes_cbc_crypter, "AES CBC"};
116 test_t hmac_signer_test1 = {test_hmac_md5_signer, "HMAC MD5 signer test"};
117 test_t hmac_signer_test2 = {test_hmac_sha1_signer, "HMAC SHA1 signer test"};
118 test_t encryption_payload_test = {test_encryption_payload, "encryption payload test"};
119 test_t init_config_test = {test_init_config, "init_config_t test"};
120 test_t sa_config_test = {test_sa_config, "sa_config_t test"};
121 test_t rsa_test = {test_rsa, "RSA private/public key test"};
122 test_t prime_pool_test = {test_prime_pool, "Prime pool"};
123
124
125 daemon_t* charon;
126
127 static void daemon_kill(daemon_t *this, char* none)
128 {
129 this->logger_manager->destroy(this->logger_manager);
130 this->socket->destroy(this->socket);
131 this->ike_sa_manager->destroy(this->ike_sa_manager);
132 this->job_queue->destroy(this->job_queue);
133 this->prime_pool->destroy(this->prime_pool);
134 this->event_queue->destroy(this->event_queue);
135 this->send_queue->destroy(this->send_queue);
136 this->configuration_manager->destroy(this->configuration_manager);
137 allocator_free(charon);
138 }
139
140 /**
141 * @brief Create the dummy daemon for testing.
142 *
143 * @return created daemon_t
144 */
145 daemon_t *daemon_create()
146 {
147 charon = allocator_alloc_thing(daemon_t);
148
149 /* assign methods */
150 charon->kill = daemon_kill;
151
152 charon->logger_manager = logger_manager_create(0);
153 charon->socket = socket_create(4600);
154 charon->ike_sa_manager = ike_sa_manager_create();
155 charon->job_queue = job_queue_create();
156 charon->event_queue = event_queue_create();
157 charon->send_queue = send_queue_create();
158 charon->prime_pool = prime_pool_create(0);
159 charon->configuration_manager = configuration_manager_create(RETRANSMIT_TIMEOUT,MAX_RETRANSMIT_COUNT);
160 charon->sender = NULL;
161 charon->receiver = NULL;
162 charon->scheduler = NULL;
163 charon->thread_pool = NULL;
164
165 return charon;
166 }
167
168
169 int main()
170 {
171 FILE * test_output = stderr;
172
173 test_t *all_tests[] ={
174 &linked_list_test,
175 &iterator_test,
176 &linked_list_insert_and_remove_test,
177 &thread_pool_test,
178 &job_queue_test1,
179 &event_queue_test,
180 &send_queue_test,
181 &scheduler_test,
182 &socket_test,
183 &sender_test,
184 &receiver_test,
185 &ike_sa_id_test,
186 &ike_sa_test,
187 &generator_test1,
188 &generator_test2,
189 &parser_test1,
190 &parser_test2,
191 &parser_test3,
192 &parser_test4,
193 &parser_test5,
194 &parser_test6,
195 &parser_test7,
196 &parser_test8,
197 &parser_test9,
198 &parser_test10,
199 &parser_test11,
200 &parser_test12,
201 &generator_test3,
202 &generator_test4,
203 &generator_test5,
204 &generator_test6,
205 &generator_test7,
206 &generator_test8,
207 &generator_test9,
208 &generator_test10,
209 &generator_test11,
210 &generator_test12,
211 &generator_test13,
212 &generator_test14,
213 &generator_test15,
214 &ike_sa_manager_test,
215 &packet_test,
216 &diffie_hellman_test,
217 &sha1_hasher_test,
218 &md5_hasher_test,
219 &hmac_test1,
220 &hmac_test2,
221 &prf_plus_test,
222 &aes_cbc_crypter_test,
223 &hmac_signer_test1,
224 &hmac_signer_test2,
225 &encryption_payload_test,
226 &init_config_test,
227 &sa_config_test,
228 &rsa_test,
229 &prime_pool_test,
230 NULL
231 };
232
233 /* allocator needs initialization */
234 allocator_init();
235
236 daemon_create();
237
238 charon->logger_manager->disable_logger_level(charon->logger_manager,TESTER,FULL);
239 // charon->logger_manager->enable_logger_level(charon->logger_manager,TESTER,RAW);
240
241 tester_t *tester = tester_create(test_output, FALSE);
242
243
244 tester->perform_tests(tester,all_tests);
245 // tester->perform_test(tester,&parser_test12);
246
247
248 tester->destroy(tester);
249
250 charon->kill(charon, NULL);
251
252 #ifdef LEAK_DETECTIVE
253 /* Leaks are reported on stderr */
254 report_memory_leaks(void);
255 #endif
256
257 return 0;
258 }