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.c
23 * @brief Test cases for lockmanager_api.c
24 * @author Sree Harsha Totakura
28 #include "gnunet_util_lib.h"
29 #include "gnunet_lockmanager_service.h"
30 #include "gnunet_testing_lib-new.h"
33 * Generic logging shortcut
35 #define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
38 #define TIME_REL_SECONDS(min) \
39 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min)
43 * Enumeration of testing steps
60 static enum Test result;
63 * Configuration Handle
65 static const struct GNUNET_CONFIGURATION_Handle *config;
68 * The handle to the lockmanager service
70 static struct GNUNET_LOCKMANAGER_Handle *handle;
75 static struct GNUNET_LOCKMANAGER_LockingRequest *request;
78 * The second locking request
80 static struct GNUNET_LOCKMANAGER_LockingRequest *request2;
83 * Abort task identifier
85 static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
91 * @param tc the task context
94 do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
96 if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
98 GNUNET_SCHEDULER_cancel (abort_task_id);
99 abort_task_id = GNUNET_SCHEDULER_NO_TASK;
102 GNUNET_LOCKMANAGER_cancel_request (request);
103 if (NULL != request2)
104 GNUNET_LOCKMANAGER_cancel_request (request2);
105 GNUNET_LOCKMANAGER_disconnect (handle);
106 GNUNET_SCHEDULER_shutdown ();
114 * @param tc the task context
117 do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
119 LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n");
120 abort_task_id = GNUNET_SCHEDULER_NO_TASK;
122 do_shutdown (cls, tc);
126 * Callback for lock status changes
128 * @param cls the closure from GNUNET_LOCKMANAGER_lock call
130 * @param domain_name the locking domain of the lock
132 * @param lock the lock for which this status is relevant
134 * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
135 * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost
138 status_cb (void *cls,
139 const char *domain_name,
141 enum GNUNET_LOCKMANAGER_Status status)
143 LOG (GNUNET_ERROR_TYPE_DEBUG,
144 "Status change callback called on lock: %d of domain: %s\n",
149 GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
150 GNUNET_assert (NULL != request);
151 //GNUNET_LOCKMANAGER_cancel_request (request);
153 result = LOCK2_ACQUIRE;
154 request2 = GNUNET_LOCKMANAGER_acquire_lock (handle,
155 "GNUNET_LOCKMANAGER_TESTING",
159 GNUNET_assert (NULL != request2);
162 GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
163 GNUNET_assert (NULL != request);
164 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1),
175 * Main point of test execution
179 const struct GNUNET_CONFIGURATION_Handle *cfg,
180 struct GNUNET_TESTING_Peer *peer)
182 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
184 handle = GNUNET_LOCKMANAGER_connect (config);
185 GNUNET_assert (NULL != handle);
186 result = LOCK1_ACQUIRE;
187 request = GNUNET_LOCKMANAGER_acquire_lock (handle,
188 "GNUNET_LOCKMANAGER_TESTING",
192 abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (30),
201 int main (int argc, char **argv)
204 if (0 != GNUNET_TESTING_peer_run ("test_lockmanager_api",
205 "test_lockmanager_api.conf",
208 return (TEST_FAIL == result) ? 1 : 0;
211 /* end of test_lockmanager_api.c */