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