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
96 * Task to simulate artificial delay and change the test stage
99 * @param tc the task context
102 step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
106 case TEST_OP1_STARTED:
107 GNUNET_TESTBED_operation_release_ (op1);
109 case TEST_OP2_STARTED:
110 GNUNET_TESTBED_operation_release_ (op2);
119 * Function to call to start an operation once all
120 * queues the operation is part of declare that the
121 * operation can be activated.
129 GNUNET_assert (&op1 == cls);
130 result = TEST_OP1_STARTED;
131 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &step, NULL);
133 case TEST_OP1_RELEASED:
134 GNUNET_assert (&op2 == cls);
135 result = TEST_OP2_STARTED;
136 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &step, NULL);
145 * Function to call to cancel an operation (release all associated
146 * resources). This can be because of a call to
147 * "GNUNET_TESTBED_operation_cancel" (before the operation generated
148 * an event) or AFTER the operation generated an event due to a call
149 * to "GNUNET_TESTBED_operation_done". Thus it is not guaranteed that
150 * a callback to the 'OperationStart' preceeds the call to
151 * 'OperationRelease'. Implementations of this function are expected
152 * to clean up whatever state is in 'cls' and release all resources
153 * associated with the operation.
156 release_cb (void *cls)
160 case TEST_OP1_STARTED:
161 GNUNET_assert (&op1 == cls);
162 result = TEST_OP1_RELEASED;
164 case TEST_OP2_STARTED:
165 GNUNET_assert (&op2 == cls);
166 result = TEST_OP2_RELEASED;
167 GNUNET_TESTBED_operation_queue_destroy_ (q1);
168 GNUNET_TESTBED_operation_queue_destroy_ (q2);
180 * @param args arguments passed to GNUNET_PROGRAM_run
181 * @param cfgfile the path to configuration file
182 * @param cfg the configuration file handle
185 run (void *cls, char *const *args, const char *cfgfile,
186 const struct GNUNET_CONFIGURATION_Handle *config)
188 q1 = GNUNET_TESTBED_operation_queue_create_ (1);
189 GNUNET_assert (NULL != q1);
190 q2 = GNUNET_TESTBED_operation_queue_create_ (2);
191 GNUNET_assert (NULL != q2);
192 op1 = GNUNET_TESTBED_operation_create_ (&op1, start_cb, release_cb);
193 GNUNET_assert (NULL != op1);
194 op2 = GNUNET_TESTBED_operation_create_ (&op2, start_cb, release_cb);
195 GNUNET_TESTBED_operation_queue_insert_ (q1, op1);
196 GNUNET_TESTBED_operation_queue_insert_ (q2, op1);
197 GNUNET_TESTBED_operation_queue_insert_ (q1, op2);
198 GNUNET_TESTBED_operation_queue_insert_ (q2, op2);
206 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 };
215 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
216 "test_testbed_api_operations", "nohelp", options,
218 if ((GNUNET_OK != ret) || (TEST_OP2_RELEASED != result))
227 /* end of test_testbed_api_operations.c */