aboutsummaryrefslogtreecommitdiff
path: root/src/lockmanager
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-05-15 13:09:51 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-05-15 13:09:51 +0000
commit896f08906416a09cceab7447265fbe54dc883156 (patch)
treeaa14a7e510a048d03255127f4e0f5d764b125d4d /src/lockmanager
parent61ce2675585cee27c115addff49540fc9e6fb617 (diff)
downloadgnunet-896f08906416a09cceab7447265fbe54dc883156.tar.gz
gnunet-896f08906416a09cceab7447265fbe54dc883156.zip
server crash test case
Diffstat (limited to 'src/lockmanager')
-rw-r--r--src/lockmanager/Makefile.am9
-rw-r--r--src/lockmanager/lockmanager_api.c53
-rw-r--r--src/lockmanager/test_lockmanager_api_servercrash.c327
3 files changed, 385 insertions, 4 deletions
diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am
index ee6f816f1..0fbc20b0f 100644
--- a/src/lockmanager/Makefile.am
+++ b/src/lockmanager/Makefile.am
@@ -39,7 +39,8 @@ libgnunetlockmanager_la_LDFLAGS = \
39 39
40check_PROGRAMS = \ 40check_PROGRAMS = \
41 test-lockmanager-api \ 41 test-lockmanager-api \
42 test-lockmanager-api-lockrelease 42 test-lockmanager-api-lockrelease \
43 test-lockmanager-api-servercrash
43 44
44EXTRA_DIST = \ 45EXTRA_DIST = \
45 test_lockmanager_api.conf 46 test_lockmanager_api.conf
@@ -58,4 +59,10 @@ test_lockmanager_api_lockrelease_SOURCES = \
58 test_lockmanager_api_lockrelease.c 59 test_lockmanager_api_lockrelease.c
59test_lockmanager_api_lockrelease_LDADD = \ 60test_lockmanager_api_lockrelease_LDADD = \
60 $(top_builddir)/src/util/libgnunetutil.la \ 61 $(top_builddir)/src/util/libgnunetutil.la \
62 libgnunetlockmanager.la
63
64test_lockmanager_api_servercrash_SOURCES = \
65 test_lockmanager_api_servercrash.c
66test_lockmanager_api_servercrash_LDADD = \
67 $(top_builddir)/src/util/libgnunetutil.la \
61 libgnunetlockmanager.la \ No newline at end of file 68 libgnunetlockmanager.la \ No newline at end of file
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c
index 53f5365e4..b25904d7b 100644
--- a/src/lockmanager/lockmanager_api.c
+++ b/src/lockmanager/lockmanager_api.c
@@ -214,7 +214,7 @@ call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
214 if (NULL != r->status_cb) 214 if (NULL != r->status_cb)
215 { 215 {
216 LOG (GNUNET_ERROR_TYPE_DEBUG, 216 LOG (GNUNET_ERROR_TYPE_DEBUG,
217 "Calling status change callback for lock: %d in domain: %s\n", 217 "Calling status change for SUCCESS on lock num: %d, domain: %s\n",
218 r->lock, r->domain); 218 r->lock, r->domain);
219 r->status_cb (r->status_cb_cls, 219 r->status_cb (r->status_cb_cls,
220 r->domain, 220 r->domain,
@@ -225,6 +225,44 @@ call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
225 225
226 226
227/** 227/**
228 * Iterator to call relase and free all LockingRequest entries
229 *
230 * @param cls the lockmanager handle
231 * @param key current key code
232 * @param value the Locking request
233 * @return GNUNET_YES if we should continue to
234 * iterate,
235 * GNUNET_NO if not.
236 */
237static int
238release_iterator(void *cls,
239 const GNUNET_HashCode * key,
240 void *value)
241{
242 struct GNUNET_LOCKMANAGER_Handle *h = cls;
243 struct GNUNET_LOCKMANAGER_LockingRequest *r = value;
244
245 if (NULL != r->status_cb)
246 {
247 LOG (GNUNET_ERROR_TYPE_DEBUG,
248 "Calling status change for RELEASE on lock num: %d, domain: %s\n",
249 r->lock, r->domain);
250 r->status_cb (r->status_cb_cls,
251 r->domain,
252 r->lock,
253 GNUNET_LOCKMANAGER_RELEASE);
254 }
255 GNUNET_assert (GNUNET_YES ==
256 GNUNET_CONTAINER_multihashmap_remove (h->hashmap,
257 key,
258 value));
259 GNUNET_free (r->domain);
260 GNUNET_free (r);
261 return GNUNET_YES;
262}
263
264
265/**
228 * Handler for server replies 266 * Handler for server replies
229 * 267 *
230 * @param cls the LOCKMANAGER_Handle 268 * @param cls the LOCKMANAGER_Handle
@@ -246,6 +284,10 @@ handle_replies (void *cls,
246 { 284 {
247 LOG (GNUNET_ERROR_TYPE_DEBUG, 285 LOG (GNUNET_ERROR_TYPE_DEBUG,
248 "Lockmanager service not available or went down\n"); 286 "Lockmanager service not available or went down\n");
287 /* Should release all locks and free its locking requests */
288 GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap,
289 &release_iterator,
290 handle);
249 return; 291 return;
250 } 292 }
251 if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type)) 293 if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type))
@@ -327,7 +369,7 @@ transmit_notify (void *cls, size_t size, void *buf)
327/** 369/**
328 * Iterator to free hash map entries. 370 * Iterator to free hash map entries.
329 * 371 *
330 * @param cls NULL 372 * @param cls the lockmanger handle
331 * @param key current key code 373 * @param key current key code
332 * @param value the Locking request 374 * @param value the Locking request
333 * @return GNUNET_YES if we should continue to 375 * @return GNUNET_YES if we should continue to
@@ -339,10 +381,15 @@ free_iterator(void *cls,
339 const GNUNET_HashCode * key, 381 const GNUNET_HashCode * key,
340 void *value) 382 void *value)
341{ 383{
384 struct GNUNET_LOCKMANAGER_Handle *h = cls;
342 struct GNUNET_LOCKMANAGER_LockingRequest *r = value; 385 struct GNUNET_LOCKMANAGER_LockingRequest *r = value;
343 386
344 LOG (GNUNET_ERROR_TYPE_DEBUG, 387 LOG (GNUNET_ERROR_TYPE_DEBUG,
345 "Clearing locking request\n"); 388 "Clearing locking request\n");
389 GNUNET_assert (GNUNET_YES ==
390 GNUNET_CONTAINER_multihashmap_remove (h->hashmap,
391 key,
392 value));
346 GNUNET_free (r->domain); 393 GNUNET_free (r->domain);
347 GNUNET_free (r); 394 GNUNET_free (r);
348 return GNUNET_YES; 395 return GNUNET_YES;
@@ -404,7 +451,7 @@ GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle)
404 "calling %s\n", __func__); 451 "calling %s\n", __func__);
405 GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, 452 GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap,
406 &free_iterator, 453 &free_iterator,
407 NULL); 454 handle);
408 } 455 }
409 GNUNET_CONTAINER_multihashmap_destroy (handle->hashmap); 456 GNUNET_CONTAINER_multihashmap_destroy (handle->hashmap);
410 GNUNET_free (handle); 457 GNUNET_free (handle);
diff --git a/src/lockmanager/test_lockmanager_api_servercrash.c b/src/lockmanager/test_lockmanager_api_servercrash.c
new file mode 100644
index 000000000..769e044e0
--- /dev/null
+++ b/src/lockmanager/test_lockmanager_api_servercrash.c
@@ -0,0 +1,327 @@
1/*
2 This file is part of GNUnet.
3 (C) 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 2, 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 lockmanager/test_lockmanager_api_lockrelease.c
23 * @brief Test cases for lockmanager_api where client disconnects abruptly
24 * @author Sree Harsha Totakura
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_lockmanager_service.h"
30
31#define VERBOSE GNUNET_YES
32
33#define VERBOSE_ARM 1
34
35#define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
37
38#define TIME_REL_SECONDS(min) \
39 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min)
40
41/**
42 * Various steps of the test
43 */
44enum Test
45 {
46 /**
47 * Signal test failure
48 */
49 TEST_FAIL,
50
51 /**
52 * Testing just began
53 */
54 TEST_INIT,
55
56 /**
57 * Client 1 has got the lock successfully; Client 2 should try to acquire
58 * the lock now; after some time client 1 has to release the lock
59 */
60 TEST_CLIENT1_LOCK_SUCCESS,
61
62 /**
63 * Client 2 has got the lock; Server should crash now;
64 */
65 TEST_CLIENT2_LOCK_SUCCESS,
66
67 /**
68 * Client 2 should get lock release due to server crash; Should call
69 * shutdown now
70 */
71 TEST_CLIENT2_SERVER_CRASH_SUCCESS
72 };
73
74/**
75 * The testing result
76 */
77static enum Test result;
78
79/**
80 * The process id of the GNUNET ARM process
81 */
82static struct GNUNET_OS_Process *arm_pid = NULL;
83
84/**
85 * Configuration Handle
86 */
87static struct GNUNET_CONFIGURATION_Handle *config;
88
89/**
90 * The handle to the lockmanager service
91 */
92static struct GNUNET_LOCKMANAGER_Handle *handle;
93
94/**
95 * A second client handle to the lockmanager service
96 */
97static struct GNUNET_LOCKMANAGER_Handle *handle2;
98
99/**
100 * The locking request
101 */
102static struct GNUNET_LOCKMANAGER_LockingRequest *request;
103
104/**
105 * The locking request of second client
106 */
107static struct GNUNET_LOCKMANAGER_LockingRequest *request2;
108
109/**
110 * Abort task identifier
111 */
112static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
113
114
115/**
116 * Shutdown nicely
117 *
118 * @param cls
119 * @param tc the task context
120 */
121static void
122do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
123{
124 if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
125 {
126 GNUNET_SCHEDULER_cancel (abort_task_id);
127 abort_task_id = GNUNET_SCHEDULER_NO_TASK;
128 }
129 if (NULL != handle)
130 GNUNET_LOCKMANAGER_disconnect (handle);
131 if (NULL != handle2)
132 GNUNET_LOCKMANAGER_disconnect (handle2);
133 if (NULL != arm_pid)
134 {
135 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
136 {
137 LOG (GNUNET_ERROR_TYPE_DEBUG,
138 "Kill gnunet-service-arm manually\n");
139 }
140 GNUNET_OS_process_wait (arm_pid);
141 GNUNET_OS_process_destroy (arm_pid);
142 }
143 if (NULL != config)
144 GNUNET_CONFIGURATION_destroy (config);
145}
146
147
148/**
149 * Abort
150 *
151 * @param cls
152 * @param tc the task context
153 */
154static void
155do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
156{
157 LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n");
158 abort_task_id = GNUNET_SCHEDULER_NO_TASK;
159 result = TEST_FAIL;
160 do_shutdown (cls, tc);
161}
162
163
164/**
165 * Callback for lock status changes
166 *
167 * @param cls the handle
168 *
169 * @param domain_name the locking domain of the lock
170 *
171 * @param lock the lock for which this status is relevant
172 *
173 * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
174 * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost
175 */
176static void
177status_cb (void *cls,
178 const char *domain_name,
179 uint32_t lock,
180 enum GNUNET_LOCKMANAGER_Status status)
181{
182 LOG (GNUNET_ERROR_TYPE_DEBUG,
183 "Status change callback called on lock: %d of domain: %s\n",
184 lock, domain_name);
185 GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
186 switch (result)
187 {
188 case TEST_INIT:
189 GNUNET_assert (handle == cls);
190 GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
191 result = TEST_CLIENT1_LOCK_SUCCESS;
192 request2 = GNUNET_LOCKMANAGER_acquire_lock (handle2,
193 "GNUNET_LOCKMANAGER_TESTING",
194 99,
195 &status_cb,
196 handle2);
197 GNUNET_assert (NULL != request2);
198 GNUNET_LOCKMANAGER_cancel_request (request);
199 request = NULL;
200 break;
201 case TEST_CLIENT1_LOCK_SUCCESS:
202 GNUNET_assert (handle2 == cls);
203 GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
204 result = TEST_CLIENT2_LOCK_SUCCESS;
205 /* We should kill the lockmanager process */
206 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
207 {
208 LOG (GNUNET_ERROR_TYPE_DEBUG,
209 "Kill gnunet-service-arm manually\n");
210 }
211 GNUNET_OS_process_wait (arm_pid);
212 GNUNET_OS_process_destroy (arm_pid);
213 arm_pid =NULL;
214 break;
215 case TEST_CLIENT2_LOCK_SUCCESS:
216 GNUNET_assert (handle2 == cls);
217 GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status);
218 GNUNET_assert (99 == lock);
219 GNUNET_assert (0 == strcmp (domain_name, "GNUNET_LOCKMANAGER_TESTING"));
220 result = TEST_CLIENT2_SERVER_CRASH_SUCCESS;
221 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1),
222 &do_shutdown,
223 NULL);
224 break;
225 default:
226 GNUNET_assert (0); /* We should never reach here */
227 }
228
229}
230
231
232/**
233 * Testing function
234 *
235 * @param cls NULL
236 * @param tc the task context
237 */
238static void
239test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
240{
241 result = TEST_INIT;
242 handle = GNUNET_LOCKMANAGER_connect (config);
243 GNUNET_assert (NULL != handle);
244 handle2 = GNUNET_LOCKMANAGER_connect (config);
245
246 request = GNUNET_LOCKMANAGER_acquire_lock (handle,
247 "GNUNET_LOCKMANAGER_TESTING",
248 99,
249 &status_cb,
250 handle);
251 GNUNET_assert (NULL != request);
252 abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (60),
253 &do_abort,
254 NULL);
255}
256
257
258/**
259 * Main point of test execution
260 */
261static void
262run (void *cls, char *const *args, const char *cfgfile,
263 const struct GNUNET_CONFIGURATION_Handle *cfg)
264{
265 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
266 config = GNUNET_CONFIGURATION_dup (cfg);
267 arm_pid =
268 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
269 "gnunet-service-arm",
270#if VERBOSE_ARM
271 "-L", "DEBUG",
272#endif
273 "-c", "test_lockmanager_api.conf", NULL);
274
275 GNUNET_assert (NULL != arm_pid);
276 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1),
277 &test,
278 NULL);
279}
280
281
282/**
283 * Main function
284 */
285int main (int argc, char **argv)
286{
287 int ret;
288
289 char *const argv2[] = { "test-lockmanager-api-servercrash",
290 "-c", "test_lockmanager_api.conf",
291#if VERBOSE
292 "-L", "DEBUG",
293#endif
294 NULL
295 };
296
297 struct GNUNET_GETOPT_CommandLineOption options[] = {
298 GNUNET_GETOPT_OPTION_END
299 };
300
301 GNUNET_log_setup ("test-lockmanager-api-servercrash",
302#if VERBOSE
303 "DEBUG",
304#else
305 "WARNING",
306#endif
307 NULL);
308
309 ret =
310 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
311 "test-lockmanager-api-servercrash",
312 "nohelp", options, &run, NULL);
313
314 if (GNUNET_OK != ret)
315 {
316 LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
317 ret);
318 return 1;
319 }
320 if (TEST_CLIENT2_LOCK_SUCCESS != result)
321 {
322 LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
323 return 1;
324 }
325 LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n");
326 return 0;
327}