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.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index f53e1ecdb..db0a00c22 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -123,7 +123,7 @@ struct FreeBarrierNodeCbCls
123}; 123};
124 124
125 125
126const struct GNUNET_TESTING_Command * 126static const struct GNUNET_TESTING_Command *
127get_command (struct GNUNET_TESTING_Interpreter *is, 127get_command (struct GNUNET_TESTING_Interpreter *is,
128 const char *label, 128 const char *label,
129 unsigned int future) 129 unsigned int future)
@@ -265,7 +265,7 @@ free_barrier_node_cb (void *cls,
265} 265}
266 266
267 267
268int 268static int
269free_barriers_cb (void *cls, 269free_barriers_cb (void *cls,
270 const struct GNUNET_ShortHashCode *key, 270 const struct GNUNET_ShortHashCode *key,
271 void *value) 271 void *value)
@@ -574,14 +574,19 @@ GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands,
574 is = GNUNET_new (struct GNUNET_TESTING_Interpreter); 574 is = GNUNET_new (struct GNUNET_TESTING_Interpreter);
575 is->rc = rc; 575 is->rc = rc;
576 is->rc_cls = rc_cls; 576 is->rc_cls = rc_cls;
577 is->barriers = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); 577 is->barriers = GNUNET_CONTAINER_multishortmap_create (1,
578 false);
578 /* get the number of commands */ 579 /* get the number of commands */
579 for (i = 0; NULL != commands[i].run; i++) 580 for (i = 0; NULL != commands[i].run; i++)
580 ; 581 ;
581 is->cmds_n = i + 1; 582 is->cmds_n = i + 1;
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u commands\n", i); 583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
583 is->commands = GNUNET_new_array (is->cmds_n, 584 "Got %u commands\n",
584 struct GNUNET_TESTING_Command); 585 i);
586 is->commands = GNUNET_malloc_large ( (i + 1)
587 * sizeof (struct
588 GNUNET_TESTING_Command));
589 GNUNET_assert (NULL != is->commands);
585 memcpy (is->commands, 590 memcpy (is->commands,
586 commands, 591 commands,
587 sizeof (struct GNUNET_TESTING_Command) * i); 592 sizeof (struct GNUNET_TESTING_Command) * i);
@@ -611,12 +616,28 @@ GNUNET_TESTING_command_new (void *cls,
611 .cleanup = cleanup, 616 .cleanup = cleanup,
612 .traits = traits 617 .traits = traits
613 }; 618 };
614 memset (&cmd.label, 0, sizeof (cmd.label));
615 if (NULL != label)
616 strncpy (cmd.label, label, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH);
617 619
620 GNUNET_assert (NULL != run);
621 if (NULL != label)
622 {
623 GNUNET_assert (strlen (label) <=
624 GNUNET_TESTING_CMD_MAX_LABEL_LENGTH);
625 strncpy (cmd.label,
626 label,
627 GNUNET_TESTING_CMD_MAX_LABEL_LENGTH);
628 }
618 return cmd; 629 return cmd;
630}
631
632
633struct GNUNET_TESTING_Command
634GNUNET_TESTING_cmd_end (void)
635{
636 struct GNUNET_TESTING_Command cmd = {
637 .run = NULL
638 };
619 639
640 return cmd;
620} 641}
621 642
622 643
@@ -685,9 +706,9 @@ loop_run (void *cls)
685 * Continuation function from GNUNET_HELPER_send() 706 * Continuation function from GNUNET_HELPER_send()
686 * 707 *
687 * @param cls closure 708 * @param cls closure
688 * @param result GNUNET_OK on success, 709 * @param result #GNUNET_OK on success,
689 * GNUNET_NO if helper process died 710 * #GNUNET_NO if helper process died
690 * GNUNET_SYSERR during GNUNET_HELPER_stop 711 * #GNUNET_SYSERR during GNUNET_HELPER_stop()
691 */ 712 */
692static void 713static void
693clear_msg (void *cls, int result) 714clear_msg (void *cls, int result)
@@ -745,7 +766,6 @@ TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is,
745 struct CommandBarrierCrossable *adm; 766 struct CommandBarrierCrossable *adm;
746 size_t msg_length; 767 size_t msg_length;
747 size_t name_len; 768 size_t name_len;
748 char *terminator = "\0";
749 769
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
751 "send barrier name %s barrier_name\n", 771 "send barrier name %s barrier_name\n",
@@ -797,7 +817,6 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
797 const char *barrier_name) 817 const char *barrier_name)
798{ 818{
799 struct CommandListEntry *pos; 819 struct CommandListEntry *pos;
800 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
801 struct GNUNET_TESTING_Barrier *barrier = TST_interpreter_get_barrier (is, 820 struct GNUNET_TESTING_Barrier *barrier = TST_interpreter_get_barrier (is,
802 barrier_name); 821 barrier_name);
803 822
@@ -830,17 +849,18 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
830 } 849 }
831 if (NULL != barrier->nodes) 850 if (NULL != barrier->nodes)
832 { 851 {
833 free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); 852 struct FreeBarrierNodeCbCls free_barrier_node_cb_cls = {
834 free_barrier_node_cb_cls->barrier = barrier; 853 .barrier = barrier,
835 free_barrier_node_cb_cls->is = is; 854 .is = is
855 };
856
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
837 "freeing nodes\n"); 858 "freeing nodes\n");
838 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, 859 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
839 free_barrier_node_cb, 860 &free_barrier_node_cb,
840 free_barrier_node_cb_cls); 861 &free_barrier_node_cb_cls);
841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
842 "nodes freed\n"); 863 "nodes freed\n");
843 GNUNET_free (free_barrier_node_cb_cls);
844 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes); 864 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
845 barrier->nodes = NULL; 865 barrier->nodes = NULL;
846 } 866 }