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.c64
1 files changed, 20 insertions, 44 deletions
diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c
index e39489616..080a4880d 100644
--- a/src/testing/testing_api_cmd_batch.c
+++ b/src/testing/testing_api_cmd_batch.c
@@ -119,16 +119,15 @@ batch_traits (void *cls,
119 const char *trait, 119 const char *trait,
120 unsigned int index) 120 unsigned int index)
121{ 121{
122 struct BatchState *bs = cls;
123 // FIXME: these constants should be more global!
122#define CURRENT_CMD_INDEX 0 124#define CURRENT_CMD_INDEX 0
123#define BATCH_INDEX 1 125#define BATCH_INDEX 1
124
125 struct BatchState *bs = cls;
126
127 struct GNUNET_TESTING_Trait traits[] = { 126 struct GNUNET_TESTING_Trait traits[] = {
128 GNUNET_TESTING_make_trait_cmd 127 GNUNET_TESTING_make_trait_cmd (CURRENT_CMD_INDEX,
129 (CURRENT_CMD_INDEX, &bs->batch[bs->batch_ip]), 128 &bs->batch[bs->batch_ip]),
130 GNUNET_TESTING_make_trait_cmd 129 GNUNET_TESTING_make_trait_cmd (BATCH_INDEX,
131 (BATCH_INDEX, bs->batch), 130 bs->batch),
132 GNUNET_TESTING_trait_end () 131 GNUNET_TESTING_trait_end ()
133 }; 132 };
134 133
@@ -185,68 +184,45 @@ GNUNET_TESTING_cmd_batch (const char *label,
185} 184}
186 185
187 186
188/** 187bool
189 * Advance internal pointer to next command. 188GNUNET_TESTING_cmd_batch_next_ (void *cls)
190 *
191 * @param is interpreter state.
192 */
193void
194GNUNET_TESTING_cmd_batch_next (struct GNUNET_TESTING_Interpreter *is)
195{ 189{
196 struct BatchState *bs = is->commands[is->ip].cls; 190 struct BatchState *bs = cls;
197 191
198 if (NULL == bs->batch[bs->batch_ip].label) 192 if (NULL == bs->batch[bs->batch_ip].label)
199 { 193 return false;
200 is->commands[is->ip].finish_time = GNUNET_TIME_absolute_get (); 194 bs->batch[bs->batch_ip].finish_time
201 is->ip++; 195 = GNUNET_TIME_absolute_get ();
202 return;
203 }
204 bs->batch[bs->batch_ip].finish_time = GNUNET_TIME_absolute_get ();
205 bs->batch_ip++; 196 bs->batch_ip++;
197 return true;
206} 198}
207 199
208 200
209/** 201bool
210 * Test if this command is a batch command. 202GNUNET_TESTING_cmd_is_batch_ (const struct GNUNET_TESTING_Command *cmd)
211 *
212 * @return false if not, true if it is a batch command
213 */
214int
215GNUNET_TESTING_cmd_is_batch (const struct GNUNET_TESTING_Command *cmd)
216{ 203{
217 return cmd->run == &batch_run; 204 return cmd->run == &batch_run;
218} 205}
219 206
220 207
221/**
222 * Obtain what command the batch is at.
223 *
224 * @return cmd current batch command
225 */
226struct GNUNET_TESTING_Command * 208struct GNUNET_TESTING_Command *
227GNUNET_TESTING_cmd_batch_get_current (const struct GNUNET_TESTING_Command *cmd) 209GNUNET_TESTING_cmd_batch_get_current_ (const struct GNUNET_TESTING_Command *cmd)
228{ 210{
229 struct BatchState *bs = cmd->cls; 211 struct BatchState *bs = cmd->cls;
230 212
231 GNUNET_assert (cmd->run == &batch_run); 213 GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd));
232 return &bs->batch[bs->batch_ip]; 214 return &bs->batch[bs->batch_ip];
233} 215}
234 216
235 217
236/**
237 * Set what command the batch should be at.
238 *
239 * @param cmd current batch command
240 * @param new_ip where to move the IP
241 */
242void 218void
243GNUNET_TESTING_cmd_batch_set_current (const struct GNUNET_TESTING_Command *cmd, 219GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd,
244 unsigned int new_ip) 220 unsigned int new_ip)
245{ 221{
246 struct BatchState *bs = cmd->cls; 222 struct BatchState *bs = cmd->cls;
247 223
248 /* sanity checks */ 224 /* sanity checks */
249 GNUNET_assert (cmd->run == &batch_run); 225 GNUNET_assert (GNUNET_TESTING_cmd_is_batch_ (cmd));
250 for (unsigned int i = 0; i < new_ip; i++) 226 for (unsigned int i = 0; i < new_ip; i++)
251 GNUNET_assert (NULL != bs->batch[i].label); 227 GNUNET_assert (NULL != bs->batch[i].label);
252 /* actual logic */ 228 /* actual logic */