2 This file is part of GNUnet
3 (C) 2008--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 3, 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 testbed/test_testbed_api_operations.c
23 * @brief tests cases for testbed_api_operations.c
24 * @author Sree Harsha Totakura
28 #include "gnunet_util_lib.h"
29 #include "testbed_api_operations.h"
32 * Generic logging shortcut
34 #define LOG(kind,...) \
35 GNUNET_log (kind, __VA_ARGS__)
40 struct OperationQueue *q1;
45 struct OperationQueue *q2;
48 * This operation should go into both queues and block op2 until it is done
50 struct GNUNET_TESTBED_Operation *op1;
53 * This operation should go into q1 and q2
55 struct GNUNET_TESTBED_Operation *op2;
59 * Enumeration of test stages
69 * op1 has been started
74 * op1 has been released
97 * Task to simulate artificial delay and change the test stage
100 * @param tc the task context
103 step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
107 case TEST_OP1_STARTED:
108 GNUNET_TESTBED_operation_release_ (op1);
110 case TEST_OP2_STARTED:
111 GNUNET_TESTBED_operation_release_ (op2);
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.
130 GNUNET_assert (&op1 == cls);
131 result = TEST_OP1_STARTED;
132 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &step, NULL);
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);
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.
157 release_cb (void *cls)
161 case TEST_OP1_STARTED:
162 GNUNET_assert (&op1 == cls);
163 result = TEST_OP1_RELEASED;
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);
181 * @param args arguments passed to GNUNET_PROGRAM_run
182 * @param cfgfile the path to configuration file
183 * @param cfg the configuration file handle
186 run (void *cls, char *const *args, const char *cfgfile,
187 const struct GNUNET_CONFIGURATION_Handle *config)
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, start_cb, release_cb);
194 GNUNET_assert (NULL != op1);
195 op2 = GNUNET_TESTBED_operation_create_ (&op2, start_cb, release_cb);
196 GNUNET_TESTBED_operation_queue_insert_ (q1, op1);
197 GNUNET_TESTBED_operation_queue_insert_ (q2, op1);
198 GNUNET_TESTBED_operation_queue_insert_ (q1, op2);
199 GNUNET_TESTBED_operation_queue_insert_ (q2, op2);
206 int main (int argc, char **argv)
209 char *const argv2[] =
210 {"test_testbed_api_operations", "-c", "test_testbed_api.conf", NULL};
211 struct GNUNET_GETOPT_CommandLineOption options[] =
212 {GNUNET_GETOPT_OPTION_END};
214 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
215 "test_testbed_api_operations", "nohelp", options,
217 if ((GNUNET_OK != ret) || (TEST_OP2_RELEASED != result))