diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-20 10:04:01 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-20 10:04:01 +0000 |
commit | 8bd22bae6f169bf30b13c4565cfcf66e0ed45c1c (patch) | |
tree | e4a3e1112dfd05724c25dc93ee5ff881a5fd8160 /src/lockmanager | |
parent | eef168bdbf40609b944dada415fc536e15cac494 (diff) | |
download | gnunet-8bd22bae6f169bf30b13c4565cfcf66e0ed45c1c.tar.gz gnunet-8bd22bae6f169bf30b13c4565cfcf66e0ed45c1c.zip |
-changes required for acquire retry
Diffstat (limited to 'src/lockmanager')
-rw-r--r-- | src/lockmanager/Makefile.am | 6 | ||||
-rw-r--r-- | src/lockmanager/lockmanager_api.c | 112 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api.c | 6 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_acquireretry.c | 284 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_lockrelease.c | 6 | ||||
-rw-r--r-- | src/lockmanager/test_lockmanager_api_servercrash.c | 8 |
6 files changed, 380 insertions, 42 deletions
diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am index 056b8cc08..9a672cbef 100644 --- a/src/lockmanager/Makefile.am +++ b/src/lockmanager/Makefile.am | |||
@@ -39,9 +39,9 @@ libgnunetlockmanager_la_LDFLAGS = \ | |||
39 | -version-info 0:0:0 | 39 | -version-info 0:0:0 |
40 | 40 | ||
41 | check_PROGRAMS = \ | 41 | check_PROGRAMS = \ |
42 | test-lockmanager-api \ | 42 | test_lockmanager_api \ |
43 | test-lockmanager-api-lockrelease \ | 43 | test_lockmanager_api_lockrelease \ |
44 | test-lockmanager-api-servercrash | 44 | test_lockmanager_api_servercrash |
45 | 45 | ||
46 | EXTRA_DIST = \ | 46 | EXTRA_DIST = \ |
47 | test_lockmanager_api.conf | 47 | test_lockmanager_api.conf |
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c index bfc4d1c1a..07e0220dd 100644 --- a/src/lockmanager/lockmanager_api.c +++ b/src/lockmanager/lockmanager_api.c | |||
@@ -100,6 +100,11 @@ struct GNUNET_LOCKMANAGER_Handle | |||
100 | * Double linked list tail for message queue | 100 | * Double linked list tail for message queue |
101 | */ | 101 | */ |
102 | struct MessageQueue *mq_tail; | 102 | struct MessageQueue *mq_tail; |
103 | |||
104 | /** | ||
105 | * Are we currently handling replies? | ||
106 | */ | ||
107 | int in_replies; | ||
103 | }; | 108 | }; |
104 | 109 | ||
105 | 110 | ||
@@ -163,6 +168,17 @@ struct LockingRequestMatch | |||
163 | 168 | ||
164 | 169 | ||
165 | /** | 170 | /** |
171 | * Handler for server replies | ||
172 | * | ||
173 | * @param cls the LOCKMANAGER_Handle | ||
174 | * @param msg received message, NULL on timeout or fatal error | ||
175 | */ | ||
176 | static void | ||
177 | handle_replies (void *cls, | ||
178 | const struct GNUNET_MessageHeader *msg); | ||
179 | |||
180 | |||
181 | /** | ||
166 | * Transmit notify for sending message to server | 182 | * Transmit notify for sending message to server |
167 | * | 183 | * |
168 | * @param cls the lockmanager handle | 184 | * @param cls the lockmanager handle |
@@ -178,13 +194,20 @@ transmit_notify (void *cls, size_t size, void *buf) | |||
178 | uint16_t msg_size; | 194 | uint16_t msg_size; |
179 | 195 | ||
180 | handle->transmit_handle = NULL; | 196 | handle->transmit_handle = NULL; |
197 | queue_entity = handle->mq_head; | ||
198 | GNUNET_assert (NULL != queue_entity); | ||
181 | if ((0 == size) || (NULL == buf)) | 199 | if ((0 == size) || (NULL == buf)) |
182 | { | 200 | { |
183 | /* FIXME: Timed out -- requeue? */ | 201 | handle->transmit_handle = |
202 | GNUNET_CLIENT_notify_transmit_ready (handle->conn, | ||
203 | ntohs | ||
204 | (queue_entity->msg->header.size), | ||
205 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
206 | GNUNET_YES, | ||
207 | &transmit_notify, | ||
208 | handle); | ||
184 | return 0; | 209 | return 0; |
185 | } | 210 | } |
186 | queue_entity = handle->mq_head; | ||
187 | GNUNET_assert (NULL != queue_entity); | ||
188 | msg_size = ntohs (queue_entity->msg->header.size); | 211 | msg_size = ntohs (queue_entity->msg->header.size); |
189 | GNUNET_assert (size >= msg_size); | 212 | GNUNET_assert (size >= msg_size); |
190 | memcpy (buf, queue_entity->msg, msg_size); | 213 | memcpy (buf, queue_entity->msg, msg_size); |
@@ -207,6 +230,14 @@ transmit_notify (void *cls, size_t size, void *buf) | |||
207 | &transmit_notify, | 230 | &transmit_notify, |
208 | handle); | 231 | handle); |
209 | } | 232 | } |
233 | if (GNUNET_NO == handle->in_replies) | ||
234 | { | ||
235 | GNUNET_CLIENT_receive (handle->conn, | ||
236 | &handle_replies, | ||
237 | handle, | ||
238 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
239 | handle->in_replies = GNUNET_YES; | ||
240 | } | ||
210 | return msg_size; | 241 | return msg_size; |
211 | } | 242 | } |
212 | 243 | ||
@@ -344,7 +375,32 @@ call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
344 | 375 | ||
345 | 376 | ||
346 | /** | 377 | /** |
347 | * Iterator to call relase and free all LockingRequest entries | 378 | * Function to generate acquire message for a lock |
379 | * | ||
380 | * @param domain_name the domain name of the lock | ||
381 | * @param lock the lock number | ||
382 | * @return the generated GNUNET_LOCKMANAGER_Message | ||
383 | */ | ||
384 | static struct GNUNET_LOCKMANAGER_Message * | ||
385 | generate_acquire_msg (const char *domain_name, uint32_t lock) | ||
386 | { | ||
387 | struct GNUNET_LOCKMANAGER_Message *msg; | ||
388 | size_t domain_name_len; | ||
389 | uint16_t msg_size; | ||
390 | |||
391 | domain_name_len = strlen (domain_name) + 1; | ||
392 | msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_len; | ||
393 | msg = GNUNET_malloc (msg_size); | ||
394 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE); | ||
395 | msg->header.size = htons (msg_size); | ||
396 | msg->lock = htonl (lock); | ||
397 | memcpy (&msg[1], domain_name, domain_name_len); | ||
398 | return msg; | ||
399 | } | ||
400 | |||
401 | |||
402 | /** | ||
403 | * Iterator to call relase on locks | ||
348 | * | 404 | * |
349 | * @param cls the lockmanager handle | 405 | * @param cls the lockmanager handle |
350 | * @param key current key code | 406 | * @param key current key code |
@@ -354,29 +410,29 @@ call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
354 | * GNUNET_NO if not. | 410 | * GNUNET_NO if not. |
355 | */ | 411 | */ |
356 | static int | 412 | static int |
357 | release_iterator(void *cls, | 413 | release_n_retry_iterator (void *cls, |
358 | const struct GNUNET_HashCode * key, | 414 | const struct GNUNET_HashCode * key, |
359 | void *value) | 415 | void *value) |
360 | { | 416 | { |
361 | struct GNUNET_LOCKMANAGER_Handle *h = cls; | ||
362 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; | 417 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; |
418 | struct GNUNET_LOCKMANAGER_Handle *h = cls; | ||
419 | struct GNUNET_LOCKMANAGER_Message *msg; | ||
363 | 420 | ||
421 | if (GNUNET_LOCKMANAGER_RELEASE == r->status) | ||
422 | return GNUNET_YES; | ||
364 | if (NULL != r->status_cb) | 423 | if (NULL != r->status_cb) |
365 | { | 424 | { |
366 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 425 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
367 | "Calling status change for RELEASE on lock num: %d, domain: %s\n", | 426 | "Calling status change for RELEASE on lock num: %d, domain: %s\n", |
368 | r->lock, r->domain); | 427 | r->lock, r->domain); |
428 | r->status = GNUNET_LOCKMANAGER_RELEASE; | ||
369 | r->status_cb (r->status_cb_cls, | 429 | r->status_cb (r->status_cb_cls, |
370 | r->domain, | 430 | r->domain, |
371 | r->lock, | 431 | r->lock, |
372 | GNUNET_LOCKMANAGER_RELEASE); | 432 | GNUNET_LOCKMANAGER_RELEASE); |
373 | } | 433 | } |
374 | GNUNET_assert (GNUNET_YES == | 434 | msg = generate_acquire_msg (r->domain, r->lock); |
375 | GNUNET_CONTAINER_multihashmap_remove (h->hashmap, | 435 | queue_message (h, msg); |
376 | key, | ||
377 | value)); | ||
378 | GNUNET_free (r->domain); | ||
379 | GNUNET_free (r); | ||
380 | return GNUNET_YES; | 436 | return GNUNET_YES; |
381 | } | 437 | } |
382 | 438 | ||
@@ -398,14 +454,15 @@ handle_replies (void *cls, | |||
398 | struct GNUNET_HashCode hash; | 454 | struct GNUNET_HashCode hash; |
399 | uint32_t lock; | 455 | uint32_t lock; |
400 | uint16_t msize; | 456 | uint16_t msize; |
401 | 457 | ||
458 | handle->in_replies = GNUNET_NO; | ||
402 | if (NULL == msg) | 459 | if (NULL == msg) |
403 | { | 460 | { |
404 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 461 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
405 | "Lockmanager service not available or went down\n"); | 462 | "Lockmanager service not available or went down\n"); |
406 | /* Should release all locks and free its locking requests */ | 463 | /* Should release all locks and retry to acquire them */ |
407 | GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, | 464 | GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, |
408 | &release_iterator, | 465 | &release_n_retry_iterator, |
409 | handle); | 466 | handle); |
410 | return; | 467 | return; |
411 | } | 468 | } |
@@ -413,6 +470,7 @@ handle_replies (void *cls, | |||
413 | &handle_replies, | 470 | &handle_replies, |
414 | handle, | 471 | handle, |
415 | GNUNET_TIME_UNIT_FOREVER_REL); | 472 | GNUNET_TIME_UNIT_FOREVER_REL); |
473 | handle->in_replies = GNUNET_YES; | ||
416 | if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type)) | 474 | if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type)) |
417 | { | 475 | { |
418 | GNUNET_break (0); | 476 | GNUNET_break (0); |
@@ -522,7 +580,7 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
522 | &handle_replies, | 580 | &handle_replies, |
523 | h, | 581 | h, |
524 | GNUNET_TIME_UNIT_FOREVER_REL); | 582 | GNUNET_TIME_UNIT_FOREVER_REL); |
525 | 583 | h->in_replies = GNUNET_YES; | |
526 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); | 584 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__); |
527 | return h; | 585 | return h; |
528 | } | 586 | } |
@@ -604,7 +662,6 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | |||
604 | struct GNUNET_LOCKMANAGER_LockingRequest *r; | 662 | struct GNUNET_LOCKMANAGER_LockingRequest *r; |
605 | struct GNUNET_LOCKMANAGER_Message *msg; | 663 | struct GNUNET_LOCKMANAGER_Message *msg; |
606 | struct GNUNET_HashCode hash; | 664 | struct GNUNET_HashCode hash; |
607 | uint16_t msg_size; | ||
608 | size_t domain_name_length; | 665 | size_t domain_name_length; |
609 | 666 | ||
610 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); | 667 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__); |
@@ -617,12 +674,7 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | |||
617 | r->status_cb = status_cb; | 674 | r->status_cb = status_cb; |
618 | r->status_cb_cls = status_cb_cls; | 675 | r->status_cb_cls = status_cb_cls; |
619 | memcpy (r->domain, domain_name, domain_name_length); | 676 | memcpy (r->domain, domain_name, domain_name_length); |
620 | msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_length; | 677 | msg = generate_acquire_msg (r->domain, r->lock); |
621 | msg = GNUNET_malloc (msg_size); | ||
622 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE); | ||
623 | msg->header.size = htons (msg_size); | ||
624 | msg->lock = htonl (lock); | ||
625 | memcpy (&msg[1], r->domain, domain_name_length); | ||
626 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Queueing ACQUIRE message\n"); | 678 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Queueing ACQUIRE message\n"); |
627 | queue_message (handle, msg); | 679 | queue_message (handle, msg); |
628 | get_key (r->domain, r->lock, &hash); | 680 | get_key (r->domain, r->lock, &hash); |
@@ -638,8 +690,8 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | |||
638 | 690 | ||
639 | /** | 691 | /** |
640 | * Function to cancel the locking request generated by | 692 | * Function to cancel the locking request generated by |
641 | * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired us then the lock is | 693 | * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired by us then the lock |
642 | * released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any | 694 | * is released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any |
643 | * status changes resulting due to this call. | 695 | * status changes resulting due to this call. |
644 | * | 696 | * |
645 | * @param request the LockingRequest to cancel | 697 | * @param request the LockingRequest to cancel |
diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c index e8d04128f..f9f7aac0c 100644 --- a/src/lockmanager/test_lockmanager_api.c +++ b/src/lockmanager/test_lockmanager_api.c | |||
@@ -239,7 +239,7 @@ int main (int argc, char **argv) | |||
239 | { | 239 | { |
240 | int ret; | 240 | int ret; |
241 | 241 | ||
242 | char *const argv2[] = { "test-lockmanager-api", | 242 | char *const argv2[] = { "test_lockmanager_api", |
243 | "-c", "test_lockmanager_api.conf", | 243 | "-c", "test_lockmanager_api.conf", |
244 | #if VERBOSE | 244 | #if VERBOSE |
245 | "-L", "DEBUG", | 245 | "-L", "DEBUG", |
@@ -251,7 +251,7 @@ int main (int argc, char **argv) | |||
251 | GNUNET_GETOPT_OPTION_END | 251 | GNUNET_GETOPT_OPTION_END |
252 | }; | 252 | }; |
253 | 253 | ||
254 | GNUNET_log_setup ("test-lockmanager-api", | 254 | GNUNET_log_setup ("test_lockmanager_api", |
255 | #if VERBOSE | 255 | #if VERBOSE |
256 | "DEBUG", | 256 | "DEBUG", |
257 | #else | 257 | #else |
@@ -261,7 +261,7 @@ int main (int argc, char **argv) | |||
261 | 261 | ||
262 | ret = | 262 | ret = |
263 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 263 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, |
264 | "test-lockmanager-api", "nohelp", options, &run, NULL); | 264 | "test_lockmanager_api", "nohelp", options, &run, NULL); |
265 | 265 | ||
266 | if (GNUNET_OK != ret) | 266 | if (GNUNET_OK != ret) |
267 | { | 267 | { |
diff --git a/src/lockmanager/test_lockmanager_api_acquireretry.c b/src/lockmanager/test_lockmanager_api_acquireretry.c new file mode 100644 index 000000000..6f4f1379e --- /dev/null +++ b/src/lockmanager/test_lockmanager_api_acquireretry.c | |||
@@ -0,0 +1,284 @@ | |||
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_acquireretry.c | ||
23 | * @brief Test cases for lockmanager_api where the server crashes and comes | ||
24 | * back; the api should try to acqurie the lock again | ||
25 | * @author Sree Harsha Totakura | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_lockmanager_service.h" | ||
31 | |||
32 | /** | ||
33 | * Generic logging shortcut | ||
34 | */ | ||
35 | #define LOG(kind,...) \ | ||
36 | GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
38 | #define TIME_REL_SECS(sec) \ | ||
39 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | ||
40 | |||
41 | /** | ||
42 | * Various stages in test | ||
43 | */ | ||
44 | enum 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 has successfully acquired the lock | ||
58 | */ | ||
59 | TEST_CLIENT_LOCK_SUCESS, | ||
60 | |||
61 | /** | ||
62 | * Client has lost the lock | ||
63 | */ | ||
64 | TEST_CLIENT_LOCK_RELEASE, | ||
65 | |||
66 | /** | ||
67 | * Client has again acquired the lock | ||
68 | */ | ||
69 | TEST_CLIENT_LOCK_AGAIN_SUCCESS | ||
70 | }; | ||
71 | |||
72 | /** | ||
73 | * The process id of the GNUNET ARM process | ||
74 | */ | ||
75 | static struct GNUNET_OS_Process *arm_pid = NULL; | ||
76 | |||
77 | /** | ||
78 | * Configuration Handle | ||
79 | */ | ||
80 | static struct GNUNET_CONFIGURATION_Handle *config; | ||
81 | |||
82 | /** | ||
83 | * The handle to the lockmanager service | ||
84 | */ | ||
85 | static struct GNUNET_LOCKMANAGER_Handle *handle; | ||
86 | |||
87 | /** | ||
88 | * The locking request | ||
89 | */ | ||
90 | static struct GNUNET_LOCKMANAGER_LockingRequest *request; | ||
91 | |||
92 | /** | ||
93 | * Abort task identifier | ||
94 | */ | ||
95 | static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; | ||
96 | |||
97 | /** | ||
98 | * The test result | ||
99 | */ | ||
100 | enum Test result; | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Shutdown nicely | ||
105 | * | ||
106 | * @param cls | ||
107 | * @param tc the task context | ||
108 | */ | ||
109 | static void | ||
110 | do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
111 | { | ||
112 | if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) | ||
113 | { | ||
114 | GNUNET_SCHEDULER_cancel (abort_task_id); | ||
115 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
116 | } | ||
117 | if (NULL != handle) | ||
118 | GNUNET_LOCKMANAGER_disconnect (handle); | ||
119 | if (NULL != arm_pid) | ||
120 | { | ||
121 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | ||
122 | { | ||
123 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
124 | "Kill gnunet-service-arm manually\n"); | ||
125 | } | ||
126 | GNUNET_OS_process_wait (arm_pid); | ||
127 | GNUNET_OS_process_destroy (arm_pid); | ||
128 | } | ||
129 | if (NULL != config) | ||
130 | GNUNET_CONFIGURATION_destroy (config); | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * Abort | ||
135 | * | ||
136 | * @param cls | ||
137 | * @param tc the task context | ||
138 | */ | ||
139 | static void | ||
140 | do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
141 | { | ||
142 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n"); | ||
143 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
144 | result = TEST_FAIL; | ||
145 | do_shutdown (cls, tc); | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
150 | * Callback for lock status changes | ||
151 | * | ||
152 | * @param cls the handle | ||
153 | * | ||
154 | * @param domain_name the locking domain of the lock | ||
155 | * | ||
156 | * @param lock the lock for which this status is relevant | ||
157 | * | ||
158 | * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully | ||
159 | * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost | ||
160 | */ | ||
161 | static void | ||
162 | status_cb (void *cls, | ||
163 | const char *domain_name, | ||
164 | uint32_t lock, | ||
165 | enum GNUNET_LOCKMANAGER_Status status) | ||
166 | { | ||
167 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
168 | "Status change callback called on lock: %d of domain: %s\n", | ||
169 | lock, domain_name); | ||
170 | switch (result) | ||
171 | { | ||
172 | case TEST_INIT: | ||
173 | GNUNET_assert (handle == cls); | ||
174 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
175 | result = TEST_CLIENT_LOCK_SUCCESS; | ||
176 | /* We should kill the lockmanager process */ | ||
177 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) | ||
178 | { | ||
179 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
180 | "Kill gnunet-service-arm manually\n"); | ||
181 | } | ||
182 | GNUNET_OS_process_wait (arm_pid); | ||
183 | GNUNET_OS_process_destroy (arm_pid); | ||
184 | arm_pid =NULL; | ||
185 | break; | ||
186 | case TEST_CLIENT_LOCK_SUCCESS: | ||
187 | GNUNET_assert (handle == cls); | ||
188 | GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status); | ||
189 | result = TEST_CLIENT_LOCK_RELEASE; | ||
190 | /* Now we should start again the lockmanager process */ | ||
191 | arm_pid = | ||
192 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
193 | "gnunet-service-arm", | ||
194 | "-c", "test_lockmanager_api.conf", NULL); | ||
195 | GNUNET_assert (NULL != arm_pid); | ||
196 | break; | ||
197 | case TEST_CLIENT_LOCK_RELEASE: | ||
198 | GNUNET_asset (handle == cls); | ||
199 | GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status); | ||
200 | result = TEST_CLIENT_LOCK_AGAIN_SUCCESS; | ||
201 | GNUNET_LOCKMANAGER_cancel_request (request); | ||
202 | request = NULL; | ||
203 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(1), &do_shutdown, NULL); | ||
204 | break; | ||
205 | default: | ||
206 | GNUNET_assert (0); /* We should never reach here */ | ||
207 | } | ||
208 | } | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Testing function | ||
213 | * | ||
214 | * @param cls NULL | ||
215 | * @param tc the task context | ||
216 | */ | ||
217 | static void | ||
218 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
219 | { | ||
220 | result = TEST_INIT; | ||
221 | handle = GNUNET_LOCKMANAGER_connect (config); | ||
222 | GNUNET_assert (NULL != handle); | ||
223 | request = GNUNET_LOCKMANAGER_acquire_lock (handle, | ||
224 | "GNUNET_LOCKMANAGER_TESTING", | ||
225 | 99, | ||
226 | &status_cb, | ||
227 | handle); | ||
228 | GNUNET_assert (NULL != request); | ||
229 | abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (10), | ||
230 | &do_abort, | ||
231 | NULL); | ||
232 | } | ||
233 | |||
234 | |||
235 | /** | ||
236 | * Main point of test execution | ||
237 | */ | ||
238 | static void | ||
239 | run (void *cls, char *const *args, const char *cfgfile, | ||
240 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
241 | { | ||
242 | config = cfg; | ||
243 | arm_pid = | ||
244 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
245 | "gnunet-service-arm", | ||
246 | "-c", "test_lockmanager_api.conf", NULL); | ||
247 | GNUNET_assert (NULL != arm_pid); | ||
248 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(3), &test, NULL); | ||
249 | } | ||
250 | |||
251 | |||
252 | /** | ||
253 | * Main function | ||
254 | */ | ||
255 | int main (int argc, char **argv) | ||
256 | { | ||
257 | int ret; | ||
258 | |||
259 | char *const argv2[] = { "test_lockmanager_api_servercrash", | ||
260 | "-c", "test_lockmanager_api.conf", | ||
261 | NULL | ||
262 | }; | ||
263 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
264 | GNUNET_GETOPT_OPTION_END | ||
265 | }; | ||
266 | |||
267 | ret = | ||
268 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
269 | "test_lockmanager_api_servercrash", | ||
270 | "nohelp", options, &run, NULL); | ||
271 | if (GNUNET_OK != ret) | ||
272 | { | ||
273 | LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n", | ||
274 | ret); | ||
275 | return 1; | ||
276 | } | ||
277 | if (TEST_CLIENT_LOCK_AGAIN_SUCCESS != result) | ||
278 | { | ||
279 | LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); | ||
280 | return 1; | ||
281 | } | ||
282 | LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n"); | ||
283 | return 0; | ||
284 | } | ||
diff --git a/src/lockmanager/test_lockmanager_api_lockrelease.c b/src/lockmanager/test_lockmanager_api_lockrelease.c index 7e24d10ce..64e328ba0 100644 --- a/src/lockmanager/test_lockmanager_api_lockrelease.c +++ b/src/lockmanager/test_lockmanager_api_lockrelease.c | |||
@@ -260,7 +260,7 @@ int main (int argc, char **argv) | |||
260 | { | 260 | { |
261 | int ret; | 261 | int ret; |
262 | 262 | ||
263 | char *const argv2[] = { "test-lockmanager-api-lockrelease", | 263 | char *const argv2[] = { "test_lockmanager_api_lockrelease", |
264 | "-c", "test_lockmanager_api.conf", | 264 | "-c", "test_lockmanager_api.conf", |
265 | #if VERBOSE | 265 | #if VERBOSE |
266 | "-L", "DEBUG", | 266 | "-L", "DEBUG", |
@@ -272,7 +272,7 @@ int main (int argc, char **argv) | |||
272 | GNUNET_GETOPT_OPTION_END | 272 | GNUNET_GETOPT_OPTION_END |
273 | }; | 273 | }; |
274 | 274 | ||
275 | GNUNET_log_setup ("test-lockmanager-api-lockrelease", | 275 | GNUNET_log_setup ("test_lockmanager_api_lockrelease", |
276 | #if VERBOSE | 276 | #if VERBOSE |
277 | "DEBUG", | 277 | "DEBUG", |
278 | #else | 278 | #else |
@@ -282,7 +282,7 @@ int main (int argc, char **argv) | |||
282 | 282 | ||
283 | ret = | 283 | ret = |
284 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 284 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, |
285 | "test-lockmanager-api-lockrelease", | 285 | "test_lockmanager_api_lockrelease", |
286 | "nohelp", options, &run, NULL); | 286 | "nohelp", options, &run, NULL); |
287 | 287 | ||
288 | if (GNUNET_OK != ret) | 288 | if (GNUNET_OK != ret) |
diff --git a/src/lockmanager/test_lockmanager_api_servercrash.c b/src/lockmanager/test_lockmanager_api_servercrash.c index 3fa6418c8..974a31f7e 100644 --- a/src/lockmanager/test_lockmanager_api_servercrash.c +++ b/src/lockmanager/test_lockmanager_api_servercrash.c | |||
@@ -217,6 +217,8 @@ status_cb (void *cls, | |||
217 | GNUNET_assert (99 == lock); | 217 | GNUNET_assert (99 == lock); |
218 | GNUNET_assert (0 == strcmp (domain_name, "GNUNET_LOCKMANAGER_TESTING")); | 218 | GNUNET_assert (0 == strcmp (domain_name, "GNUNET_LOCKMANAGER_TESTING")); |
219 | result = TEST_CLIENT2_SERVER_CRASH_SUCCESS; | 219 | result = TEST_CLIENT2_SERVER_CRASH_SUCCESS; |
220 | GNUNET_LOCKMANAGER_cancel_request (request2); | ||
221 | request2 = NULL; | ||
220 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), | 222 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), |
221 | &do_shutdown, | 223 | &do_shutdown, |
222 | NULL); | 224 | NULL); |
@@ -285,7 +287,7 @@ int main (int argc, char **argv) | |||
285 | { | 287 | { |
286 | int ret; | 288 | int ret; |
287 | 289 | ||
288 | char *const argv2[] = { "test-lockmanager-api-servercrash", | 290 | char *const argv2[] = { "test_lockmanager_api_servercrash", |
289 | "-c", "test_lockmanager_api.conf", | 291 | "-c", "test_lockmanager_api.conf", |
290 | #if VERBOSE | 292 | #if VERBOSE |
291 | "-L", "DEBUG", | 293 | "-L", "DEBUG", |
@@ -297,7 +299,7 @@ int main (int argc, char **argv) | |||
297 | GNUNET_GETOPT_OPTION_END | 299 | GNUNET_GETOPT_OPTION_END |
298 | }; | 300 | }; |
299 | 301 | ||
300 | GNUNET_log_setup ("test-lockmanager-api-servercrash", | 302 | GNUNET_log_setup ("test_lockmanager_api_servercrash", |
301 | #if VERBOSE | 303 | #if VERBOSE |
302 | "DEBUG", | 304 | "DEBUG", |
303 | #else | 305 | #else |
@@ -307,7 +309,7 @@ int main (int argc, char **argv) | |||
307 | 309 | ||
308 | ret = | 310 | ret = |
309 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 311 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, |
310 | "test-lockmanager-api-servercrash", | 312 | "test_lockmanager_api_servercrash", |
311 | "nohelp", options, &run, NULL); | 313 | "nohelp", options, &run, NULL); |
312 | 314 | ||
313 | if (GNUNET_OK != ret) | 315 | if (GNUNET_OK != ret) |