aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-29 11:24:08 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-29 11:24:08 +0000
commitaf106ded69593d7f4676f32da6e0058cf1577ce2 (patch)
treee09e73d77cb1b137346defe393a86882b779712d /src/testbed
parentcc7efcc843411a956524a00c91425b9d626b03c3 (diff)
downloadgnunet-af106ded69593d7f4676f32da6e0058cf1577ce2.tar.gz
gnunet-af106ded69593d7f4676f32da6e0058cf1577ce2.zip
testbed operations
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am10
-rw-r--r--src/testbed/test_testbed_api.c2
-rw-r--r--src/testbed/test_testbed_api_operations.c232
-rw-r--r--src/testbed/testbed_api_operations.c55
-rw-r--r--src/testbed/testbed_api_operations.h50
5 files changed, 337 insertions, 12 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index d3ca76c17..29e5270c6 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -69,12 +69,14 @@ check_PROGRAMS = \
69 test_testbed_api_hosts \ 69 test_testbed_api_hosts \
70 test_testbed_api_2peers \ 70 test_testbed_api_2peers \
71 test_testbed_api \ 71 test_testbed_api \
72 test_testbed_api_operations \
72 test_gnunet_testbed_helper 73 test_gnunet_testbed_helper
73 74
74if ENABLE_TEST_RUN 75if ENABLE_TEST_RUN
75 TESTS = \ 76 TESTS = \
76 test_testbed_api \ 77 test_testbed_api \
77 test_testbed_api_hosts \ 78 test_testbed_api_hosts \
79 test_testbed_api_operations \
78 test_gnunet_testbed_helper 80 test_gnunet_testbed_helper
79endif 81endif
80 82
@@ -98,9 +100,15 @@ test_testbed_api_2peers_LDADD = \
98 $(top_builddir)/src/testing/libgnunettesting.la \ 100 $(top_builddir)/src/testing/libgnunettesting.la \
99 libgnunettestbed.la 101 libgnunettestbed.la
100 102
103test_testbed_api_operations_SOURCES = \
104 test_testbed_api_operations.c
105test_testbed_api_operations_LDADD = \
106 $(top_builddir)/src/util/libgnunetutil.la \
107 libgnunettestbed.la
108
101test_gnunet_testbed_helper_SOURCES = \ 109test_gnunet_testbed_helper_SOURCES = \
102 test_gnunet_testbed_helper.c 110 test_gnunet_testbed_helper.c
103test_gnunet_testbed_helper_LDADD = \ 111test_gnunet_testbed_helper_LDADD = \
104 $(top_builddir)/src/util/libgnunetutil.la \ 112 $(top_builddir)/src/util/libgnunetutil.la \
105 libgnunettestbed.la \ 113 libgnunettestbed.la \
106 -lz 114 -lz \ No newline at end of file
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c
index 0d2a9d677..2544ae464 100644
--- a/src/testbed/test_testbed_api.c
+++ b/src/testbed/test_testbed_api.c
@@ -322,7 +322,6 @@ run (void *cls, char *const *args, const char *cfgfile,
322int main (int argc, char **argv) 322int main (int argc, char **argv)
323{ 323{
324 int ret; 324 int ret;
325
326 char *const argv2[] = { "test_testbed_api", 325 char *const argv2[] = { "test_testbed_api",
327 "-c", "test_testbed_api.conf", 326 "-c", "test_testbed_api.conf",
328 NULL 327 NULL
@@ -330,6 +329,7 @@ int main (int argc, char **argv)
330 struct GNUNET_GETOPT_CommandLineOption options[] = { 329 struct GNUNET_GETOPT_CommandLineOption options[] = {
331 GNUNET_GETOPT_OPTION_END 330 GNUNET_GETOPT_OPTION_END
332 }; 331 };
332
333 result = GNUNET_SYSERR; 333 result = GNUNET_SYSERR;
334 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 334 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
335 "test_testbed_api", "nohelp", options, &run, 335 "test_testbed_api", "nohelp", options, &run,
diff --git a/src/testbed/test_testbed_api_operations.c b/src/testbed/test_testbed_api_operations.c
new file mode 100644
index 000000000..312c49c84
--- /dev/null
+++ b/src/testbed/test_testbed_api_operations.c
@@ -0,0 +1,232 @@
1/*
2 This file is part of GNUnet
3 (C) 2008--2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file testbed/test_testbed_api_operations.c
23 * @brief tests cases for testbed_api_operations.c
24 * @author Sree Harsha Totakura
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "testbed_api_operations.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind,...) \
35 GNUNET_log (kind, __VA_ARGS__)
36
37/**
38 * Queue A
39 */
40struct OperationQueue *q1;
41
42/**
43 * Queue B
44 */
45struct OperationQueue *q2;
46
47/**
48 * This operation should go into both queues and block op2 until it is done
49 */
50struct GNUNET_TESTBED_Operation *op1;
51
52/**
53 * This operation should go into q1 and q2
54 */
55struct GNUNET_TESTBED_Operation *op2;
56
57
58/**
59 * Enumeration of test stages
60 */
61enum Test
62 {
63 /**
64 * Initial stage
65 */
66 TEST_INIT,
67
68 /**
69 * op1 has been started
70 */
71 TEST_OP1_STARTED,
72
73 /**
74 * op1 has been released
75 */
76 TEST_OP1_RELEASED,
77
78 /**
79 * op2 has started
80 */
81 TEST_OP2_STARTED,
82
83 /**
84 * op2 released
85 */
86 TEST_OP2_RELEASED
87
88 };
89
90/**
91 * The test result
92 */
93enum Test result;
94
95
96/**
97 * Task to simulate artificial delay and change the test stage
98 *
99 * @param cls NULL
100 * @param tc the task context
101 */
102static void
103step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
104{
105 switch (result)
106 {
107 case TEST_OP1_STARTED:
108 GNUNET_TESTBED_operation_release_ (op1);
109 break;
110 case TEST_OP2_STARTED:
111 GNUNET_TESTBED_operation_release_ (op2);
112 break;
113 default:
114 GNUNET_assert (0);
115 }
116}
117
118
119/**
120 * Function to call to start an operation once all
121 * queues the operation is part of declare that the
122 * operation can be activated.
123 */
124static void
125start_cb (void *cls)
126{
127 switch (result)
128 {
129 case TEST_INIT:
130 GNUNET_assert (&op1 == cls);
131 result = TEST_OP1_STARTED;
132 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &step, NULL);
133 break;
134 case TEST_OP1_RELEASED:
135 GNUNET_assert (&op2 == cls);
136 result = TEST_OP2_STARTED;
137 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &step, NULL);
138 break;
139 default:
140 GNUNET_assert (0);
141 }
142}
143
144
145/**
146 * Function to call to cancel an operation (release all associated
147 * resources). This can be because of a call to
148 * "GNUNET_TESTBED_operation_cancel" (before the operation generated
149 * an event) or AFTER the operation generated an event due to a call
150 * to "GNUNET_TESTBED_operation_done". Thus it is not guaranteed that
151 * a callback to the 'OperationStart' preceeds the call to
152 * 'OperationRelease'. Implementations of this function are expected
153 * to clean up whatever state is in 'cls' and release all resources
154 * associated with the operation.
155 */
156static void
157release_cb (void *cls)
158{
159 switch (result)
160 {
161 case TEST_OP1_STARTED:
162 GNUNET_assert (&op1 == cls);
163 result = TEST_OP1_RELEASED;
164 break;
165 case TEST_OP2_STARTED:
166 GNUNET_assert (&op2 == cls);
167 result = TEST_OP2_RELEASED;
168 GNUNET_TESTBED_operation_queue_destroy_ (q1);
169 GNUNET_TESTBED_operation_queue_destroy_ (q2);
170 break;
171 default:
172 GNUNET_assert (0);
173 }
174}
175
176
177/**
178 * Main run function.
179 *
180 * @param cls NULL
181 * @param args arguments passed to GNUNET_PROGRAM_run
182 * @param cfgfile the path to configuration file
183 * @param cfg the configuration file handle
184 */
185static void
186run (void *cls, char *const *args, const char *cfgfile,
187 const struct GNUNET_CONFIGURATION_Handle *config)
188{
189 q1 = GNUNET_TESTBED_operation_queue_create_ (1);
190 GNUNET_assert (NULL != q1);
191 q2 = GNUNET_TESTBED_operation_queue_create_ (2);
192 GNUNET_assert (NULL != q2);
193 op1 = GNUNET_TESTBED_operation_create_ (&op1,
194 start_cb,
195 release_cb,
196 OP_PEER_CREATE, /* irrelavant here */
197 NULL);
198 GNUNET_assert (NULL != op1);
199 op2 = GNUNET_TESTBED_operation_create_ (&op2,
200 start_cb,
201 release_cb,
202 OP_PEER_CREATE, /* irrelavant here */
203 NULL);
204 GNUNET_TESTBED_operation_queue_insert_ (q1, op1);
205 GNUNET_TESTBED_operation_queue_insert_ (q2, op1);
206 GNUNET_TESTBED_operation_queue_insert_ (q1, op2);
207 GNUNET_TESTBED_operation_queue_insert_ (q2, op2);
208 result = TEST_INIT;
209}
210
211/**
212 * Main function
213 */
214int main (int argc, char **argv)
215{
216 int ret;
217 char *const argv2[] =
218 {"test_testbed_api_operations", "-c", "test_testbed_api.conf", NULL};
219 struct GNUNET_GETOPT_CommandLineOption options[] =
220 {GNUNET_GETOPT_OPTION_END};
221
222 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
223 "test_testbed_api_operations", "nohelp", options,
224 &run, NULL);
225 if ((GNUNET_OK != ret) || (TEST_OP2_RELEASED != result))
226 return 1;
227 op1 = NULL;
228 op2 = NULL;
229 q1 = NULL;
230 q2 = NULL;
231 return 0;
232}
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index 10e9071c6..1692171e3 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -116,6 +116,11 @@ struct GNUNET_TESTBED_Operation
116 struct OperationQueue **queues; 116 struct OperationQueue **queues;
117 117
118 /** 118 /**
119 * Pointer to operation's data
120 */
121 void *data;
122
123 /**
119 * The Operation ID 124 * The Operation ID
120 */ 125 */
121 uint64_t id; 126 uint64_t id;
@@ -135,6 +140,11 @@ struct GNUNET_TESTBED_Operation
135 */ 140 */
136 enum OperationState state; 141 enum OperationState state;
137 142
143 /**
144 * The type of the operation
145 */
146 enum OperationType type;
147
138}; 148};
139 149
140 150
@@ -149,12 +159,12 @@ call_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
149{ 159{
150 struct GNUNET_TESTBED_Operation *op = cls; 160 struct GNUNET_TESTBED_Operation *op = cls;
151 161
152 op->start_task_id = GNUNET_SCHEDULER_NO_TASK; 162 op->start_task_id = GNUNET_SCHEDULER_NO_TASK;
163 op->state = OP_STATE_STARTED;
153 if (NULL != op->start) 164 if (NULL != op->start)
154 { 165 {
155 op->start (op->cb_cls); 166 op->start (op->cb_cls);
156 } 167 }
157 op->state = OP_STATE_STARTED;
158} 168}
159 169
160 170
@@ -183,6 +193,35 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
183 193
184 194
185/** 195/**
196 * Create an 'operation' to be performed.
197 *
198 * @param cls closure for the callbacks
199 * @param start function to call to start the operation
200 * @param release function to call to close down the operation
201 * @param type the type of the operation
202 * @param data operation's relavant data
203 * @return handle to the operation
204 */
205struct GNUNET_TESTBED_Operation *
206GNUNET_TESTBED_operation_create_ (void *cls,
207 OperationStart start,
208 OperationRelease release,
209 enum OperationType type,
210 void *data)
211{
212 struct GNUNET_TESTBED_Operation *op;
213
214 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
215 op->start = start;
216 op->release = release;
217 op->cb_cls = cls;
218 op->type = type;
219 op->data = data;
220 return op;
221}
222
223
224/**
186 * Create an operation queue. 225 * Create an operation queue.
187 * 226 *
188 * @param max_active maximum number of operations in this 227 * @param max_active maximum number of operations in this
@@ -210,7 +249,7 @@ void
210GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) 249GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
211{ 250{
212 GNUNET_assert (NULL == queue->head); 251 GNUNET_assert (NULL == queue->head);
213 GNUNET_assert (NULL == queue->tail); 252 GNUNET_assert (NULL == queue->tail);
214 GNUNET_free (queue); 253 GNUNET_free (queue);
215} 254}
216 255
@@ -266,8 +305,8 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
266 GNUNET_assert (NULL != entry); 305 GNUNET_assert (NULL != entry);
267 if (OP_STATE_STARTED == operation->state) 306 if (OP_STATE_STARTED == operation->state)
268 queue->active++; 307 queue->active++;
269 GNUNET_CONTAINER_DLL_remove (queue->head, queue->tail, entry);
270 entry2 = entry->next; 308 entry2 = entry->next;
309 GNUNET_CONTAINER_DLL_remove (queue->head, queue->tail, entry);
271 GNUNET_free (entry); 310 GNUNET_free (entry);
272 for (; NULL != entry2; entry2 = entry2->next) 311 for (; NULL != entry2; entry2 = entry2->next)
273 if (OP_STATE_STARTED != entry2->op->state) 312 if (OP_STATE_STARTED != entry2->op->state)
@@ -294,10 +333,12 @@ GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *operation)
294 GNUNET_SCHEDULER_cancel (operation->start_task_id); 333 GNUNET_SCHEDULER_cancel (operation->start_task_id);
295 operation->start_task_id = GNUNET_SCHEDULER_NO_TASK; 334 operation->start_task_id = GNUNET_SCHEDULER_NO_TASK;
296 } 335 }
297 if (NULL != operation->release)
298 operation->release (operation->cb_cls);
299 for (i = 0; i < operation->nqueues; i++) 336 for (i = 0; i < operation->nqueues; i++)
300 GNUNET_TESTBED_operation_queue_remove_ (operation->queues[i], operation); 337 GNUNET_TESTBED_operation_queue_remove_ (operation->queues[i], operation);
338 GNUNET_free (operation->queues);
339 if (NULL != operation->release)
340 operation->release (operation->cb_cls);
341 GNUNET_free (operation);
301} 342}
302 343
303 344
diff --git a/src/testbed/testbed_api_operations.h b/src/testbed/testbed_api_operations.h
index 245e9a60e..a02f397ac 100644
--- a/src/testbed/testbed_api_operations.h
+++ b/src/testbed/testbed_api_operations.h
@@ -38,6 +38,44 @@ struct OperationQueue;
38 38
39 39
40/** 40/**
41 * Enumeration of operation types
42 */
43enum OperationType
44 {
45 /**
46 * Peer create operation
47 */
48 OP_PEER_CREATE,
49
50 /**
51 * Peer start operation
52 */
53 OP_PEER_START,
54
55 /**
56 * Peer stop operation
57 */
58 OP_PEER_STOP,
59
60 /**
61 * Peer destroy operation
62 */
63 OP_PEER_DESTROY,
64
65 /**
66 * Get peer information operation
67 */
68 OP_PEER_INFO,
69
70 /**
71 * Overlay connection operation
72 */
73 OP_OVERLAY_CONNECT,
74
75 };
76
77
78/**
41 * Create an operation queue. 79 * Create an operation queue.
42 * 80 *
43 * @param max_active maximum number of operations in this 81 * @param max_active maximum number of operations in this
@@ -94,6 +132,8 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
94 * Function to call to start an operation once all 132 * Function to call to start an operation once all
95 * queues the operation is part of declare that the 133 * queues the operation is part of declare that the
96 * operation can be activated. 134 * operation can be activated.
135 *
136 * @param cls the closure from GNUNET_TESTBED_operation_create_()
97 */ 137 */
98typedef void (*OperationStart)(void *cls); 138typedef void (*OperationStart)(void *cls);
99 139
@@ -107,7 +147,9 @@ typedef void (*OperationStart)(void *cls);
107 * a callback to the 'OperationStart' preceeds the call to 147 * a callback to the 'OperationStart' preceeds the call to
108 * 'OperationRelease'. Implementations of this function are expected 148 * 'OperationRelease'. Implementations of this function are expected
109 * to clean up whatever state is in 'cls' and release all resources 149 * to clean up whatever state is in 'cls' and release all resources
110 * associated with the operation. 150 * associated with the operation.
151 *
152 * @param cls the closure from GNUNET_TESTBED_operation_create_()
111 */ 153 */
112typedef void (*OperationRelease)(void *cls); 154typedef void (*OperationRelease)(void *cls);
113 155
@@ -118,14 +160,16 @@ typedef void (*OperationRelease)(void *cls);
118 * @param cls closure for the callbacks 160 * @param cls closure for the callbacks
119 * @param start function to call to start the operation 161 * @param start function to call to start the operation
120 * @param release function to call to close down the operation 162 * @param release function to call to close down the operation
121 * @param ... FIXME 163 * @param type the type of the operation
164 * @param data operation's relavant data
122 * @return handle to the operation 165 * @return handle to the operation
123 */ 166 */
124struct GNUNET_TESTBED_Operation * 167struct GNUNET_TESTBED_Operation *
125GNUNET_TESTBED_operation_create_ (void *cls, 168GNUNET_TESTBED_operation_create_ (void *cls,
126 OperationStart start, 169 OperationStart start,
127 OperationRelease release, 170 OperationRelease release,
128 ...); 171 enum OperationType type,
172 void *data);
129 173
130 174
131/** 175/**