(no commit message)
[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 <queues/job_queue.h>
27 #include <queues/event_queue.h>
28 #include <queues/send_queue.h>
29 #include <config/configuration_manager.h>
30 #include <sa/ike_sa_manager.h>
31 #include <network/socket.h>
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>
51 #include <testcases/hasher_test.h>
52 #include <testcases/hmac_test.h>
53 #include <testcases/prf_plus_test.h>
54 #include <testcases/aes_cbc_crypter_test.h>
55 #include <testcases/hmac_signer_test.h>
56
57 /* output for test messages */
58 extern FILE * stderr;
59
60 test_t linked_list_test = {test_linked_list,"Linked List"};
61 test_t iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
62 test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"};
63 test_t event_queue_test = {test_event_queue,"Event-Queue"};
64 test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
65 test_t send_queue_test = {test_send_queue,"Send-Queue"};
66 test_t socket_test = {test_socket,"Socket"};
67 test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
68 test_t sender_test = {test_sender,"Sender"};
69 test_t scheduler_test = {test_scheduler,"Scheduler"};
70 test_t receiver_test = {test_receiver,"Receiver"};
71 test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"};
72 test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
73 test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"};
74 test_t generator_test1 = {test_generator_with_header_payload,"Generator: header payload"};
75 test_t generator_test2 = {test_generator_with_transform_attribute,"Generator: transform attribute"};
76 test_t generator_test3 = {test_generator_with_transform_substructure,"Generator: transform substructure"};
77 test_t generator_test4 = {test_generator_with_proposal_substructure,"Generator: proposal substructure"};
78 test_t generator_test5 = {test_generator_with_sa_payload,"Generator: Message with SA Payload"};
79 test_t generator_test6 = {test_generator_with_ke_payload,"Generator: KE Payload"};
80 test_t generator_test7 = {test_generator_with_notify_payload,"Generator: Notify Payload"};
81 test_t generator_test8 = {test_generator_with_nonce_payload,"Generator: Nonce Payload"};
82 test_t generator_test9 = {test_generator_with_id_payload,"Generator: ID Payload"};
83 test_t parser_test1 = {test_parser_with_header_payload, "Parser: header payload"};
84 test_t parser_test2 = {test_parser_with_sa_payload, "Parser: sa payload"};
85 test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"};
86 test_t parser_test4 = {test_parser_with_ke_payload, "Parser: key exchange payload"};
87 test_t parser_test5 = {test_parser_with_notify_payload, "Parser: notify payload"};
88 test_t parser_test6 = {test_parser_with_id_payload, "Parser: ID payload"};
89 test_t packet_test = {test_packet,"Packet"};
90 test_t diffie_hellman_test = {test_diffie_hellman,"Diffie Hellman"};
91 test_t sha1_hasher_test = {test_sha1_hasher,"SHA1 hasher"};
92 test_t md5_hasher_test = {test_md5_hasher,"MD5 hasher"};
93 test_t hmac_test1 = {test_hmac_sha1, "HMAC using SHA1"};
94 test_t hmac_test2 = {test_hmac_md5, "HMAC using MD5"};
95 test_t prf_plus_test = {test_prf_plus, "prf+"};
96 test_t aes_cbc_crypter_test = {test_aes_cbc_crypter, "AES CBC"};
97 test_t hmac_signer_test1 = {test_hmac_md5_signer, "HMAC MD5 signer test"};
98 test_t hmac_signer_test2 = {test_hmac_sha1_signer, "HMAC SHA1 signer test"};
99
100
101 /**
102 * Global job-queue
103 */
104 job_queue_t *global_job_queue;
105
106 /**
107 * Global event-queue
108 */
109 event_queue_t *global_event_queue;
110
111 /**
112 * Global send-queue
113 */
114 send_queue_t *global_send_queue;
115
116 /**
117 * Global configuration_manager
118 */
119 configuration_manager_t *global_configuration_manager;
120
121 /**
122 * Global configuration_manager
123 */
124 ike_sa_manager_t *global_ike_sa_manager;
125
126 /**
127 * Global socket
128 */
129 socket_t *global_socket;
130
131
132 /**
133 * Global logger
134 */
135 logger_manager_t *global_logger_manager;
136
137 int main()
138 {
139 FILE * test_output = stderr;
140
141 test_t *all_tests[] ={
142 &linked_list_test,
143 &iterator_test,
144 &linked_list_insert_and_remove_test,
145 &thread_pool_test,
146 &job_queue_test1,
147 &event_queue_test,
148 &send_queue_test,
149 &scheduler_test,
150 &socket_test,
151 &sender_test,
152 &receiver_test,
153 &ike_sa_id_test,
154 &ike_sa_test,
155 &generator_test1,
156 &generator_test2,
157 &parser_test1,
158 &parser_test2,
159 &parser_test3,
160 &parser_test4,
161 &parser_test5,
162 &parser_test6,
163 &generator_test3,
164 &generator_test4,
165 &generator_test5,
166 &generator_test6,
167 &generator_test7,
168 &generator_test8,
169 &generator_test9,
170 &ike_sa_manager_test,
171 &packet_test,
172 &diffie_hellman_test,
173 &sha1_hasher_test,
174 &md5_hasher_test,
175 &hmac_test1,
176 &hmac_test2,
177 &prf_plus_test,
178 &aes_cbc_crypter_test,
179 &hmac_signer_test1,
180 &hmac_signer_test2,
181 NULL
182 };
183 global_logger_manager = logger_manager_create(0);
184
185 global_socket = socket_create(4600);
186
187 global_job_queue = job_queue_create();
188 global_event_queue = event_queue_create();
189 global_send_queue = send_queue_create();
190 global_configuration_manager = configuration_manager_create();
191 global_ike_sa_manager = ike_sa_manager_create();
192
193 global_logger_manager->disable_logger_level(global_logger_manager,TESTER,FULL);
194 //global_logger_manager->enable_logger_level(global_logger_manager,TESTER,RAW);
195
196 tester_t *tester = tester_create(test_output, FALSE);
197
198
199 tester->perform_tests(tester,all_tests);
200 //tester->perform_test(tester,&generator_test9);
201
202
203
204 tester->destroy(tester);
205
206
207 /* Destroy objects*/
208 global_configuration_manager->destroy(global_configuration_manager);
209 global_ike_sa_manager->destroy(global_ike_sa_manager);
210
211 /* Destroy all queues */
212 global_job_queue->destroy(global_job_queue);
213 global_event_queue->destroy(global_event_queue);
214 global_send_queue->destroy(global_send_queue);
215
216 global_socket->destroy(global_socket);
217
218 global_logger_manager->destroy(global_logger_manager);
219
220 #ifdef LEAK_DETECTIVE
221 /* Leaks are reported on stderr */
222 report_memory_leaks(void);
223 #endif
224
225 return 0;
226 }