- uncompletet test for ike_sa_manager
authorMartin Willi <martin@strongswan.org>
Tue, 8 Nov 2005 16:24:35 +0000 (16:24 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 8 Nov 2005 16:24:35 +0000 (16:24 -0000)
Source/charon/tests/ike_sa_manager_test.c [new file with mode: 0644]
Source/charon/tests/ike_sa_manager_test.h [new file with mode: 0644]

diff --git a/Source/charon/tests/ike_sa_manager_test.c b/Source/charon/tests/ike_sa_manager_test.c
new file mode 100644 (file)
index 0000000..9d812a6
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * @file ike_sa_manager_test.c
+ * 
+ * @brief Tests to test the IKE_SA-Manager type ike_sa_manager_t
+ * 
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include <string.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include "ike_sa_manager_test.h"
+#include "../types.h"
+#include "../tester.h"
+#include "../ike_sa_manager.h"
+
+
+static struct ike_sa_manager_test_struct_s {
+       tester_t *tester;
+       ike_sa_manager_t *isam;
+} globals;
+
+static void sa_blocker_thread(ike_sa_id_t *ike_sa_id)
+{
+       ike_sa_t *ike_sa;
+       ike_sa_manager_t *isam;
+       tester_t *tester;
+       status_t status;
+       
+       isam = globals.isam;
+       tester = globals.tester;
+       status = isam->checkout_ike_sa(isam, ike_sa_id, &ike_sa);
+       tester->assert_true(tester, (status == SUCCESS), "checkout_ike_sa as blocker");
+       sleep(1);
+       status = isam->checkin_ike_sa(isam, ike_sa);
+       
+       
+}
+
+void test_ike_sa_manager(tester_t *tester)
+{
+       status_t status;
+       spi_t initiator, responder;
+       ike_sa_id_t *ike_sa_id;
+       ike_sa_t *ike_sa;
+       ike_sa_manager_t *isam;
+       pthread_t threads[3];
+       
+       isam = ike_sa_manager_create();
+       
+       /* we play initiator for IKE_SA_INIT first */
+       memset(&initiator, 0, sizeof(initiator));
+       memset(&responder, 0, sizeof(responder));
+       
+       ike_sa_id = ike_sa_id_create(initiator, responder, INITIATOR);
+
+       status = isam->checkout_ike_sa(isam, ike_sa_id, &ike_sa);
+       
+       tester->assert_true(tester, (status == SUCCESS), "checkout_ike_sa as initiator");
+       pthread_create(&threads[0], NULL, (void*(*)(void*))sa_blocker_thread, (void*)ike_sa_id);
+       
+       
+       status = isam->checkin_ike_sa(isam, ike_sa);
+       
+       pthread_join(threads[0], NULL);
+       
+       
+       ike_sa_id->destroy(ike_sa_id);
+       isam->destroy(isam);
+}
diff --git a/Source/charon/tests/ike_sa_manager_test.h b/Source/charon/tests/ike_sa_manager_test.h
new file mode 100644 (file)
index 0000000..e61107e
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * @file ike_sa_manager_test.c
+ * 
+ * @brief Tests to test the IKE_SA-Manager type ike_sa_manager_t
+ * 
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef IKE_SA_MANAGER_TEST_H_
+#define IKE_SA_MANAGER_TEST_H_
+
+#include "../tester.h"
+
+/**
+ * @brief Test function used to test the ike_sa_manager_t functionality
+ * 
+ *
+ * @param tester associated tester_t-object
+ */
+void test_ike_sa_manager(tester_t *tester);
+
+
+
+#endif /*IKE_SA_MANAGER_TEST_H_*/