diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-09 12:07:26 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-09 12:07:26 +0900 |
commit | 4f46e2f2e72a07871b14c0a9aed70438616c4dd5 (patch) | |
tree | f4b904d75ec9fc977aa662d6c8ed0a4d71a22097 /src/testing/testing_api_loop.c | |
parent | 1b3f6f366fc62e5519bb73fefe8c21c2eed20edf (diff) | |
download | gnunet-4f46e2f2e72a07871b14c0a9aed70438616c4dd5.tar.gz gnunet-4f46e2f2e72a07871b14c0a9aed70438616c4dd5.zip |
TESTING: Fix TESTING-NG API to follow naming conventions
Rename structs and functions to follow GNUnet naming conventions.
Some structs may actually also be private, a review is necessary.
The barrier API was modified in order to untangle Barriers and
lists of Barriers.
This is a rough draft, it needs fixes wrt memory leaks.
Diffstat (limited to 'src/testing/testing_api_loop.c')
-rw-r--r-- | src/testing/testing_api_loop.c | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c index da95500f7..f133956cf 100644 --- a/src/testing/testing_api_loop.c +++ b/src/testing/testing_api_loop.c | |||
@@ -28,7 +28,9 @@ | |||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_testing_ng_lib.h" | 30 | #include "gnunet_testing_ng_lib.h" |
31 | #include "gnunet_testing_plugin.h" | ||
31 | #include "gnunet_testing_barrier.h" | 32 | #include "gnunet_testing_barrier.h" |
33 | #include "gnunet_testing_netjail_lib.h" | ||
32 | #include "testing.h" | 34 | #include "testing.h" |
33 | 35 | ||
34 | /** | 36 | /** |
@@ -71,7 +73,7 @@ struct GNUNET_TESTING_Interpreter | |||
71 | /** | 73 | /** |
72 | * Map with barriers for this loop. | 74 | * Map with barriers for this loop. |
73 | */ | 75 | */ |
74 | struct GNUNET_CONTAINER_MultiShortmap *barriers; | 76 | struct GNUNET_CONTAINER_MultiShortmap *barriers; |
75 | 77 | ||
76 | /** | 78 | /** |
77 | * Number of GNUNET_TESTING_Command in commands. | 79 | * Number of GNUNET_TESTING_Command in commands. |
@@ -528,17 +530,17 @@ GNUNET_TESTING_command_new (void *cls, | |||
528 | GNUNET_TESTING_CommandGetTraits traits, | 530 | GNUNET_TESTING_CommandGetTraits traits, |
529 | struct GNUNET_TESTING_AsyncContext *ac) | 531 | struct GNUNET_TESTING_AsyncContext *ac) |
530 | { | 532 | { |
531 | struct GNUNET_TESTING_Command cmd = { | 533 | struct GNUNET_TESTING_Command cmd = { |
532 | .cls = cls, | 534 | .cls = cls, |
533 | .run = run, | 535 | .run = run, |
534 | .ac = ac, | 536 | .ac = ac, |
535 | .cleanup = cleanup, | 537 | .cleanup = cleanup, |
536 | .traits = traits | 538 | .traits = traits |
537 | }; | 539 | }; |
538 | memset (&cmd, 0, sizeof (cmd)); | 540 | memset (&cmd, 0, sizeof (cmd)); |
539 | strncpy (cmd.label, label, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH); | 541 | strncpy (cmd.label, label, GNUNET_TESTING_CMD_MAX_LABEL_LENGTH); |
540 | 542 | ||
541 | return cmd; | 543 | return cmd; |
542 | 544 | ||
543 | } | 545 | } |
544 | 546 | ||
@@ -649,8 +651,8 @@ GNUNET_TESTING_send_message_to_netjail (struct GNUNET_TESTING_Interpreter *is, | |||
649 | const struct GNUNET_HELPER_Handle *helper; | 651 | const struct GNUNET_HELPER_Handle *helper; |
650 | 652 | ||
651 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
652 | "send message of type %u to locals\n", | 654 | "send message of type %u to locals\n", |
653 | header->type); | 655 | header->type); |
654 | helper = is->helper[global_node_number - 1]; | 656 | helper = is->helper[global_node_number - 1]; |
655 | struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( | 657 | struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( |
656 | (struct GNUNET_HELPER_Handle *) helper, | 658 | (struct GNUNET_HELPER_Handle *) helper, |
@@ -691,18 +693,19 @@ void | |||
691 | GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, | 693 | GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, |
692 | struct GNUNET_TESTING_Barrier *barrier) | 694 | struct GNUNET_TESTING_Barrier *barrier) |
693 | { | 695 | { |
694 | struct GNUNET_TESTING_Command *pos; | 696 | struct CommandListEntry *pos; |
695 | struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; | 697 | struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; |
696 | 698 | ||
697 | while (NULL != (pos = barrier->cmds_head)) | 699 | while (NULL != (pos = barrier->cmds_head)) |
698 | { | 700 | { |
699 | if (GNUNET_NO == pos->ac->finished && GNUNET_NO == pos->asynchronous_finish) | 701 | if (GNUNET_NO == pos->command->ac->finished && |
702 | GNUNET_NO == pos->command->asynchronous_finish) | ||
700 | { | 703 | { |
701 | GNUNET_TESTING_async_finish (pos->ac); | 704 | GNUNET_TESTING_async_finish (pos->command->ac); |
702 | } | 705 | } |
703 | else if (GNUNET_NO == pos->ac->finished) | 706 | else if (GNUNET_NO == pos->command->ac->finished) |
704 | { | 707 | { |
705 | pos->asynchronous_finish = GNUNET_YES; | 708 | pos->command->asynchronous_finish = GNUNET_YES; |
706 | } | 709 | } |
707 | GNUNET_CONTAINER_DLL_remove (barrier->cmds_head, | 710 | GNUNET_CONTAINER_DLL_remove (barrier->cmds_head, |
708 | barrier->cmds_tail, | 711 | barrier->cmds_tail, |
@@ -715,7 +718,8 @@ GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, | |||
715 | free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); | 718 | free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); |
716 | free_barrier_node_cb_cls->barrier = barrier; | 719 | free_barrier_node_cb_cls->barrier = barrier; |
717 | free_barrier_node_cb_cls->is = is; | 720 | free_barrier_node_cb_cls->is = is; |
718 | GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, free_barrier_node_cb, free_barrier_node_cb_cls); | 721 | GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, free_barrier_node_cb, |
722 | free_barrier_node_cb_cls); | ||
719 | GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes); | 723 | GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes); |
720 | GNUNET_free (free_barrier_node_cb_cls); | 724 | GNUNET_free (free_barrier_node_cb_cls); |
721 | } | 725 | } |
@@ -723,18 +727,19 @@ GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, | |||
723 | 727 | ||
724 | int | 728 | int |
725 | free_barriers_cb (void *cls, | 729 | free_barriers_cb (void *cls, |
726 | const struct GNUNET_ShortHashCode *key, | 730 | const struct GNUNET_ShortHashCode *key, |
727 | void *value) | 731 | void *value) |
728 | { | 732 | { |
729 | struct GNUNET_TESTING_Interpreter *is = cls; | 733 | struct GNUNET_TESTING_Interpreter *is = cls; |
730 | struct GNUNET_TESTING_Barrier *barrier = value; | 734 | struct GNUNET_TESTING_Barrier *barrier = value; |
731 | struct GNUNET_TESTING_Command *pos; | 735 | struct CommandListEntry *pos; |
732 | struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; | 736 | struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; |
733 | 737 | ||
734 | free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); | 738 | free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); |
735 | free_barrier_node_cb_cls->barrier = barrier; | 739 | free_barrier_node_cb_cls->barrier = barrier; |
736 | free_barrier_node_cb_cls->is = is; | 740 | free_barrier_node_cb_cls->is = is; |
737 | GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, free_barrier_node_cb, free_barrier_node_cb_cls); | 741 | GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, free_barrier_node_cb, |
742 | free_barrier_node_cb_cls); | ||
738 | GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes); | 743 | GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes); |
739 | 744 | ||
740 | while (NULL != (pos = barrier->cmds_head)) | 745 | while (NULL != (pos = barrier->cmds_head)) |
@@ -778,12 +783,12 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, | |||
778 | struct GNUNET_ShortHashCode create_key; | 783 | struct GNUNET_ShortHashCode create_key; |
779 | struct GNUNET_TESTING_Barrier *barrier; | 784 | struct GNUNET_TESTING_Barrier *barrier; |
780 | 785 | ||
781 | GNUNET_CRYPTO_hash (barrier_name, strlen(barrier_name), &hc); | 786 | GNUNET_CRYPTO_hash (barrier_name, strlen (barrier_name), &hc); |
782 | memcpy (&create_key, | 787 | memcpy (&create_key, |
783 | &hc, | 788 | &hc, |
784 | sizeof (create_key)); | 789 | sizeof (create_key)); |
785 | barrier = GNUNET_CONTAINER_multishortmap_get (is->barriers, &create_key); | 790 | barrier = GNUNET_CONTAINER_multishortmap_get (is->barriers, &create_key); |
786 | //GNUNET_free (create_key); | 791 | // GNUNET_free (create_key); |
787 | return barrier; | 792 | return barrier; |
788 | } | 793 | } |
789 | 794 | ||
@@ -794,16 +799,16 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, | |||
794 | * @param barrier The barrier to add. | 799 | * @param barrier The barrier to add. |
795 | */ | 800 | */ |
796 | void | 801 | void |
797 | GNUNET_TESTING_barrier_add (struct GNUNET_TESTING_Interpreter *is, | 802 | GNUNET_TESTING_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, |
798 | struct GNUNET_TESTING_Barrier *barrier) | 803 | struct GNUNET_TESTING_Barrier *barrier) |
799 | { | 804 | { |
800 | struct GNUNET_HashCode hc; | 805 | struct GNUNET_HashCode hc; |
801 | struct GNUNET_ShortHashCode create_key; | 806 | struct GNUNET_ShortHashCode create_key; |
802 | 807 | ||
803 | GNUNET_CRYPTO_hash (barrier->name, strlen(barrier->name), &hc); | 808 | GNUNET_CRYPTO_hash (barrier->name, strlen (barrier->name), &hc); |
804 | memcpy (&create_key, | 809 | memcpy (&create_key, |
805 | &hc, | 810 | &hc, |
806 | sizeof (create_key)); | 811 | sizeof (create_key)); |
807 | GNUNET_CONTAINER_multishortmap_put (is->barriers, | 812 | GNUNET_CONTAINER_multishortmap_put (is->barriers, |
808 | &create_key, | 813 | &create_key, |
809 | barrier, | 814 | barrier, |