aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_loop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_loop.c')
-rw-r--r--src/testing/testing_api_loop.c151
1 files changed, 76 insertions, 75 deletions
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 7d719afc0..3ff7d2957 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -239,6 +239,81 @@ GNUNET_TESTING_interpreter_lookup_command_all (
239} 239}
240 240
241 241
242int
243free_barrier_node_cb (void *cls,
244 const struct GNUNET_ShortHashCode *key,
245 void *value)
246{
247 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls = cls;
248 struct GNUNET_TESTING_NetjailNode *node = value;
249 struct GNUNET_TESTING_Barrier *barrier = free_barrier_node_cb_cls->barrier;
250 struct GNUNET_TESTING_Interpreter *is = free_barrier_node_cb_cls->is;
251
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "free_barrier_node_cb\n");
254 if (GNUNET_NO == is->finishing)
255 {
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
257 "TST_interpreter_send_barrier_crossable\n");
258 TST_interpreter_send_barrier_crossable (is,
259 barrier->name,
260 node->node_number);
261 }
262 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (
263 barrier->nodes, key, node));
264 return GNUNET_YES;
265}
266
267
268int
269free_barriers_cb (void *cls,
270 const struct GNUNET_ShortHashCode *key,
271 void *value)
272{
273 struct GNUNET_TESTING_Interpreter *is = cls;
274 struct GNUNET_TESTING_Barrier *barrier = value;
275 struct CommandListEntry *pos;
276 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
277
278 if (NULL != barrier->nodes)
279 {
280 free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
281 free_barrier_node_cb_cls->barrier = barrier;
282 free_barrier_node_cb_cls->is = is;
283 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
284 free_barrier_node_cb,
285 free_barrier_node_cb_cls);
286 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
287 barrier->nodes = NULL;
288 }
289
290 while (NULL != (pos = barrier->cmds_head))
291 {
292 GNUNET_CONTAINER_DLL_remove (barrier->cmds_head,
293 barrier->cmds_tail,
294 pos);
295 GNUNET_free (pos);
296 }
297 GNUNET_free (barrier);
298 return GNUNET_YES;
299}
300
301
302/**
303 * Deleting all barriers create in the context of this interpreter.
304 *
305 * @param is The interpreter.
306 */
307static void
308interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is)
309{
310 GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
311 free_barriers_cb,
312 is);
313 GNUNET_CONTAINER_multishortmap_destroy (is->barriers);
314}
315
316
242/** 317/**
243 * Finish the test run, return the final result. 318 * Finish the test run, return the final result.
244 * 319 *
@@ -285,6 +360,7 @@ finish_test (void *cls)
285 GNUNET_free (is->commands); 360 GNUNET_free (is->commands);
286 is->rc (is->rc_cls, 361 is->rc (is->rc_cls,
287 is->result); 362 is->result);
363 interpreter_delete_barriers (is);
288 GNUNET_free (is->helper); 364 GNUNET_free (is->helper);
289 GNUNET_free (is); 365 GNUNET_free (is);
290} 366}
@@ -687,32 +763,6 @@ TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is,
687} 763}
688 764
689 765
690int
691free_barrier_node_cb (void *cls,
692 const struct GNUNET_ShortHashCode *key,
693 void *value)
694{
695 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls = cls;
696 struct GNUNET_TESTING_NetjailNode *node = value;
697 struct GNUNET_TESTING_Barrier *barrier = free_barrier_node_cb_cls->barrier;
698 struct GNUNET_TESTING_Interpreter *is = free_barrier_node_cb_cls->is;
699
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
701 "free_barrier_node_cb\n");
702 if (GNUNET_NO == is->finishing)
703 {
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
705 "TST_interpreter_send_barrier_crossable\n");
706 TST_interpreter_send_barrier_crossable (is,
707 barrier->name,
708 node->node_number);
709 }
710 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (
711 barrier->nodes, key, node));
712 return GNUNET_YES;
713}
714
715
716/** 766/**
717 * Getting a barrier from the interpreter. 767 * Getting a barrier from the interpreter.
718 * 768 *
@@ -797,55 +847,6 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
797} 847}
798 848
799 849
800int
801free_barriers_cb (void *cls,
802 const struct GNUNET_ShortHashCode *key,
803 void *value)
804{
805 struct GNUNET_TESTING_Interpreter *is = cls;
806 struct GNUNET_TESTING_Barrier *barrier = value;
807 struct CommandListEntry *pos;
808 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
809
810 if (NULL != barrier->nodes)
811 {
812 free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
813 free_barrier_node_cb_cls->barrier = barrier;
814 free_barrier_node_cb_cls->is = is;
815 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
816 free_barrier_node_cb,
817 free_barrier_node_cb_cls);
818 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
819 barrier->nodes = NULL;
820 }
821
822 while (NULL != (pos = barrier->cmds_head))
823 {
824 GNUNET_CONTAINER_DLL_remove (barrier->cmds_head,
825 barrier->cmds_tail,
826 pos);
827 GNUNET_free (pos);
828 }
829 GNUNET_free (barrier);
830 return GNUNET_YES;
831}
832
833
834/**
835 * Deleting all barriers create in the context of this interpreter.
836 *
837 * @param is The interpreter.
838 */
839void
840TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is)
841{
842 GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
843 free_barriers_cb,
844 is);
845 GNUNET_CONTAINER_multishortmap_destroy (is->barriers);
846}
847
848
849/** 850/**
850 * Add a barrier to the loop. 851 * Add a barrier to the loop.
851 * 852 *