2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file lockmanager/test_lockmanager_api_lockrelease.c
23 * @brief Test cases for lockmanager_api where client disconnects abruptly
24 * @author Sree Harsha Totakura
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testing_lib-new.h"
30 #include "gnunet_lockmanager_service.h"
33 * Generic Logging shorthand
35 #define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
39 * Relative seconds shorthand
41 #define TIME_REL_SECONDS(min) \
42 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min)
45 * Various steps of the test
60 * Client 1 has got the lock successfully; Client 2 should try to acquire
61 * the lock now; after some time client 1 has to release the lock
63 TEST_CLIENT1_LOCK_SUCCESS,
66 * Client 2 has got the lock; Should release it and call shutdown
68 TEST_CLIENT2_LOCK_SUCCESS,
74 static enum Test result;
77 * Configuration Handle
79 static const struct GNUNET_CONFIGURATION_Handle *config;
82 * The handle to the lockmanager service
84 static struct GNUNET_LOCKMANAGER_Handle *handle;
87 * A second client handle to the lockmanager service
89 static struct GNUNET_LOCKMANAGER_Handle *handle2;
94 static struct GNUNET_LOCKMANAGER_LockingRequest *request;
97 * The locking request of second client
99 static struct GNUNET_LOCKMANAGER_LockingRequest *request2;
102 * Abort task identifier
104 static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
111 * @param tc the task context
114 do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
116 if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
118 GNUNET_SCHEDULER_cancel (abort_task_id);
119 abort_task_id = GNUNET_SCHEDULER_NO_TASK;
121 GNUNET_LOCKMANAGER_disconnect (handle);
122 GNUNET_LOCKMANAGER_disconnect (handle2);
130 * @param tc the task context
133 do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
135 LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n");
136 abort_task_id = GNUNET_SCHEDULER_NO_TASK;
138 do_shutdown (cls, tc);
143 * Callback for lock status changes
145 * @param cls the handle
147 * @param domain_name the locking domain of the lock
149 * @param lock the lock for which this status is relevant
151 * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
152 * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost
155 status_cb (void *cls,
156 const char *domain_name,
158 enum GNUNET_LOCKMANAGER_Status status)
160 LOG (GNUNET_ERROR_TYPE_DEBUG,
161 "Status change callback called on lock: %d of domain: %s\n",
163 GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
167 GNUNET_assert (handle == cls);
168 result = TEST_CLIENT1_LOCK_SUCCESS;
169 request2 = GNUNET_LOCKMANAGER_acquire_lock (handle2,
170 "GNUNET_LOCKMANAGER_TESTING",
174 GNUNET_assert (NULL != request2);
175 GNUNET_LOCKMANAGER_cancel_request (request);
178 case TEST_CLIENT1_LOCK_SUCCESS:
179 GNUNET_assert (handle2 == cls);
180 result = TEST_CLIENT2_LOCK_SUCCESS;
181 GNUNET_LOCKMANAGER_cancel_request (request2);
182 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1),
187 GNUNET_assert (0); /* We should never reach here */
194 * Main point of test execution
198 const struct GNUNET_CONFIGURATION_Handle *cfg,
199 struct GNUNET_TESTING_Peer *peer)
201 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
204 handle = GNUNET_LOCKMANAGER_connect (config);
205 GNUNET_assert (NULL != handle);
206 handle2 = GNUNET_LOCKMANAGER_connect (config);
208 request = GNUNET_LOCKMANAGER_acquire_lock (handle,
209 "GNUNET_LOCKMANAGER_TESTING",
213 GNUNET_assert (NULL != request);
214 abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10),
223 int main (int argc, char **argv)
225 if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api_lockrelease",
226 "test_lockmanager_api.conf",
229 return (TEST_CLIENT2_LOCK_SUCCESS != result) ? 1 : 0;
232 /* end of test_lockmanager_api_lockrelease.c */