aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_batch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_batch.c')
-rw-r--r--src/testing/testing_api_cmd_batch.c86
1 files changed, 30 insertions, 56 deletions
diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c
index af260f80d..080a4880d 100644
--- a/src/testing/testing_api_cmd_batch.c
+++ b/src/testing/testing_api_cmd_batch.c
@@ -39,6 +39,11 @@ struct BatchState
39 struct GNUNET_TESTING_Command *batch; 39 struct GNUNET_TESTING_Command *batch;
40 40
41 /** 41 /**
42 * Our label.
43 */
44 const char *label;
45
46 /**
42 * Internal command pointer. 47 * Internal command pointer.
43 */ 48 */
44 unsigned int batch_ip; 49 unsigned int batch_ip;
@@ -49,12 +54,10 @@ struct BatchState
49 * Run the command. 54 * Run the command.
50 * 55 *
51 * @param cls closure. 56 * @param cls closure.
52 * @param cmd the command being executed.
53 * @param is the interpreter state. 57 * @param is the interpreter state.
54 */ 58 */
55static void 59static void
56batch_run (void *cls, 60batch_run (void *cls,
57 const struct GNUNET_TESTING_Command *cmd,
58 struct GNUNET_TESTING_Interpreter *is) 61 struct GNUNET_TESTING_Interpreter *is)
59{ 62{
60 struct BatchState *bs = cls; 63 struct BatchState *bs = cls;
@@ -69,7 +72,7 @@ batch_run (void *cls,
69 { 72 {
70 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 73 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
71 "Exiting from batch: %s\n", 74 "Exiting from batch: %s\n",
72 cmd->label); 75 bs->label);
73 return; 76 return;
74 } 77 }
75 bs->batch[bs->batch_ip].start_time 78 bs->batch[bs->batch_ip].start_time
@@ -77,7 +80,6 @@ batch_run (void *cls,
77 = GNUNET_TIME_absolute_get (); 80 = GNUNET_TIME_absolute_get ();
78 bs->batch[bs->batch_ip].num_tries = 1; 81 bs->batch[bs->batch_ip].num_tries = 1;
79 bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls, 82 bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls,
80 &bs->batch[bs->batch_ip],
81 is); 83 is);
82} 84}
83 85
@@ -87,20 +89,16 @@ batch_run (void *cls,
87 * cancel a pending operation thereof. 89 * cancel a pending operation thereof.
88 * 90 *
89 * @param cls closure. 91 * @param cls closure.
90 * @param cmd the command which is being cleaned up.
91 */ 92 */
92static void 93static void
93batch_cleanup (void *cls, 94batch_cleanup (void *cls)
94 const struct GNUNET_TESTING_Command *cmd)
95{ 95{
96 struct BatchState *bs = cls; 96 struct BatchState *bs = cls;
97 97
98 (void) cmd;
99 for (unsigned int i = 0; 98 for (unsigned int i = 0;
100 NULL != bs->batch[i].label; 99 NULL != bs->batch[i].label;
101 i++) 100 i++)
102 bs->batch[i].cleanup (bs->batch[i].cls, 101 bs->batch[i].cleanup (bs->batch[i].cls);
103 &bs->batch[i]);
104 GNUNET_free (bs->batch); 102 GNUNET_free (bs->batch);
105 GNUNET_free (bs); 103 GNUNET_free (bs);
106} 104}
@@ -115,22 +113,21 @@ batch_cleanup (void *cls,
115 * @param index index number of the object to offer. 113 * @param index index number of the object to offer.
116 * @return #GNUNET_OK on success. 114 * @return #GNUNET_OK on success.
117 */ 115 */
118static int 116static enum GNUNET_GenericReturnValue
119batch_traits (void *cls, 117batch_traits (void *cls,
120 const void **ret, 118 const void **ret,
121 const char *trait, 119 const char *trait,
122 unsigned int index) 120 unsigned int index)
123{ 121{
122 struct BatchState *bs = cls;
123 // FIXME: these constants should be more global!
124#define CURRENT_CMD_INDEX 0 124#define CURRENT_CMD_INDEX 0
125#define BATCH_INDEX 1 125#define BATCH_INDEX 1
126
127 struct BatchState *bs = cls;
128
129 struct GNUNET_TESTING_Trait traits[] = { 126 struct GNUNET_TESTING_Trait traits[] = {
130 GNUNET_TESTING_make_trait_cmd 127 GNUNET_TESTING_make_trait_cmd (CURRENT_CMD_INDEX,
131 (CURRENT_CMD_INDEX, &bs->batch[bs->batch_ip]), 128 &bs->batch[bs->batch_ip]),
132 GNUNET_TESTING_make_trait_cmd 129 GNUNET_TESTING_make_trait_cmd (BATCH_INDEX,
133 (BATCH_INDEX, bs->batch), 130 bs->batch),
134 GNUNET_TESTING_trait_end () 131 GNUNET_TESTING_trait_end ()
135 }; 132 };
136 133
@@ -162,7 +159,7 @@ GNUNET_TESTING_cmd_batch (const char *label,
162 unsigned int i; 159 unsigned int i;
163 160
164 bs = GNUNET_new (struct BatchState); 161 bs = GNUNET_new (struct BatchState);
165 162 bs->label = label;
166 /* Get number of commands. */ 163 /* Get number of commands. */
167 for (i = 0; NULL != batch[i].label; i++) 164 for (i = 0; NULL != batch[i].label; i++)
168 /* noop */ 165 /* noop */
@@ -187,68 +184,45 @@ GNUNET_TESTING_cmd_batch (const char *label,
187} 184}
188 185
189 186
190/** 187bool
191 * Advance internal pointer to next command. 188GNUNET_TESTING_cmd_batch_next_ (void *cls)
192 *
193 * @param is interpreter state.
194 */
195void
196GNUNET_TESTING_cmd_batch_next (struct GNUNET_TESTING_Interpreter *is)
197{ 189{
198 struct BatchState *bs = is->commands[is->ip].cls; 190 struct BatchState *bs = cls;
199 191
200 if (NULL == bs->batch[bs->batch_ip].label) 192 if (NULL == bs->batch[bs->batch_ip].label)
201 { 193 return false;
202 is->commands[is->ip].finish_time = GNUNET_TIME_absolute_get (); 194 bs->batch[bs->batch_ip].finish_time
203 is->ip++; 195 = GNUNET_TIME_absolute_get ();
204 return;
205 }
206 bs->batch[bs->batch_ip].finish_time = GNUNET_TIME_absolute_get ();
207 bs->batch_ip++; 196 bs->batch_ip++;
197 return true;
208} 198}
209 199
210 200
211/** 201bool
212 * Test if this command is a batch command. 202GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd)
213 *
214 * @return false if not, true if it is a batch command
215 */
216int
217GNUNET_TESTING_cmd_is_batch (const struct GNUNET_TESTING_Command *cmd)
218{ 203{
219 return cmd->run == &batch_run; 204 return cmd->run == &batch_run;
220} 205}
221 206
222 207
223/**
224 * Obtain what command the batch is at.
225 *
226 * @return cmd current batch command
227 */
228struct GNUNET_TESTING_Command * 208struct GNUNET_TESTING_Command *
229GNUNET_TESTING_cmd_batch_get_current (const struct GNUNET_TESTING_Command *cmd) 209GNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd)
230{ 210{
231 struct BatchState *bs = cmd->cls; 211 struct BatchState *bs = cmd->cls;
232 212
233 GNUNET_assert (cmd->run == &batch_run); 213 GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd));
234 return &bs->batch[bs->batch_ip]; 214 return &bs->batch[bs->batch_ip];
235} 215}
236 216
237 217
238/**
239 * Set what command the batch should be at.
240 *
241 * @param cmd current batch command
242 * @param new_ip where to move the IP
243 */
244void 218void
245GNUNET_TESTING_cmd_batch_set_current (const struct GNUNET_TESTING_Command *cmd, 219GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd,
246 unsigned int new_ip) 220 unsigned int new_ip)
247{ 221{
248 struct BatchState *bs = cmd->cls; 222 struct BatchState *bs = cmd->cls;
249 223
250 /* sanity checks */ 224 /* sanity checks */
251 GNUNET_assert (cmd->run == &batch_run); 225 GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd));
252 for (unsigned int i = 0; i < new_ip; i++) 226 for (unsigned int i = 0; i < new_ip; i++)
253 GNUNET_assert (NULL != bs->batch[i].label); 227 GNUNET_assert (NULL != bs->batch[i].label);
254 /* actual logic */ 228 /* actual logic */