- uncompletet test for ike_sa_manager
[strongswan.git] / Source / charon / tests / ike_sa_manager_test.c
1 /**
2 * @file ike_sa_manager_test.c
3 *
4 * @brief Tests to test the IKE_SA-Manager type ike_sa_manager_t
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 #include <string.h>
24 #include <pthread.h>
25 #include <unistd.h>
26
27 #include "ike_sa_manager_test.h"
28 #include "../types.h"
29 #include "../tester.h"
30 #include "../ike_sa_manager.h"
31
32
33 static struct ike_sa_manager_test_struct_s {
34 tester_t *tester;
35 ike_sa_manager_t *isam;
36 } globals;
37
38 static void sa_blocker_thread(ike_sa_id_t *ike_sa_id)
39 {
40 ike_sa_t *ike_sa;
41 ike_sa_manager_t *isam;
42 tester_t *tester;
43 status_t status;
44
45 isam = globals.isam;
46 tester = globals.tester;
47 status = isam->checkout_ike_sa(isam, ike_sa_id, &ike_sa);
48 tester->assert_true(tester, (status == SUCCESS), "checkout_ike_sa as blocker");
49 sleep(1);
50 status = isam->checkin_ike_sa(isam, ike_sa);
51
52
53 }
54
55 void test_ike_sa_manager(tester_t *tester)
56 {
57 status_t status;
58 spi_t initiator, responder;
59 ike_sa_id_t *ike_sa_id;
60 ike_sa_t *ike_sa;
61 ike_sa_manager_t *isam;
62 pthread_t threads[3];
63
64 isam = ike_sa_manager_create();
65
66 /* we play initiator for IKE_SA_INIT first */
67 memset(&initiator, 0, sizeof(initiator));
68 memset(&responder, 0, sizeof(responder));
69
70 ike_sa_id = ike_sa_id_create(initiator, responder, INITIATOR);
71
72 status = isam->checkout_ike_sa(isam, ike_sa_id, &ike_sa);
73
74 tester->assert_true(tester, (status == SUCCESS), "checkout_ike_sa as initiator");
75 pthread_create(&threads[0], NULL, (void*(*)(void*))sa_blocker_thread, (void*)ike_sa_id);
76
77
78 status = isam->checkin_ike_sa(isam, ike_sa);
79
80 pthread_join(threads[0], NULL);
81
82
83 ike_sa_id->destroy(ike_sa_id);
84 isam->destroy(isam);
85 }