aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_testing_netjail_lib.h58
-rw-r--r--src/include/gnunet_testing_ng_lib.h399
-rw-r--r--src/testing/Makefile.am2
-rw-r--r--src/testing/testing.c4
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c48
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c25
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c34
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c2
-rw-r--r--src/testing/testing_api_cmd_system_create.c24
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c4
-rw-r--r--src/testing/testing_api_trait_cmd.c79
-rw-r--r--src/testing/testing_api_trait_process.c81
-rw-r--r--src/testing/testing_api_traits.c7
-rw-r--r--src/transport/Makefile.am1
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_broadcast.c33
-rw-r--r--src/transport/test_transport_start_with_config.c1
-rw-r--r--src/transport/transport-testing-cmds.h105
-rw-r--r--src/transport/transport_api_cmd_backchannel_check.c6
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c35
-rw-r--r--src/transport/transport_api_cmd_send_simple.c10
-rw-r--r--src/transport/transport_api_cmd_start_peer.c168
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c9
22 files changed, 259 insertions, 876 deletions
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h
index 334f43c88..7ec6b294b 100644
--- a/src/include/gnunet_testing_netjail_lib.h
+++ b/src/include/gnunet_testing_netjail_lib.h
@@ -351,12 +351,6 @@ GNUNET_TESTING_cmd_system_create (const char *label,
351 const char *testdir); 351 const char *testdir);
352 352
353 353
354int
355GNUNET_TESTING_get_trait_test_system (const struct
356 GNUNET_TESTING_Command *cmd,
357 struct GNUNET_TESTING_System **test_system);
358
359
360/** 354/**
361 * Create command. 355 * Create command.
362 * 356 *
@@ -427,30 +421,8 @@ struct GNUNET_MessageHeader *
427GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv); 421GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv);
428 422
429 423
430/**
431 * Function to get the trait with the async context.
432 *
433 * @param[out] ac GNUNET_TESTING_AsyncContext.
434 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
435 */
436int
437GNUNET_TESTING_get_trait_async_context (
438 const struct GNUNET_TESTING_Command *cmd,
439 struct GNUNET_TESTING_AsyncContext **ac);
440 424
441 425
442/**
443 * Offer handles to testing cmd helper from trait
444 *
445 * @param cmd command to extract the message from.
446 * @param pt pointer to message.
447 * @return #GNUNET_OK on success.
448 */
449enum GNUNET_GenericReturnValue
450GNUNET_TESTING_get_trait_helper_handles (
451 const struct GNUNET_TESTING_Command *cmd,
452 struct GNUNET_HELPER_Handle ***helper);
453
454 426
455struct GNUNET_TESTING_Command 427struct GNUNET_TESTING_Command
456GNUNET_TESTING_cmd_block_until_all_peers_started ( 428GNUNET_TESTING_cmd_block_until_all_peers_started (
@@ -501,28 +473,20 @@ GNUNET_TESTING_cmd_local_test_prepared (const char *label,
501 TESTING_CMD_HELPER_write_cb 473 TESTING_CMD_HELPER_write_cb
502 write_message); 474 write_message);
503 475
504/** 476
505 * Function to get the trait with the struct LocalPreparedState. 477/* ***** Netjail trait support ***** */
506 *
507 * @param[out] lfs struct LocalPreparedState.
508 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
509 *
510 */
511enum GNUNET_GenericReturnValue
512GNUNET_TESTING_get_trait_local_prepared_state (
513 const struct GNUNET_TESTING_Command *cmd,
514 struct LocalPreparedState **lfs);
515 478
516 479
517/** 480/**
518 * Function to get the trait with the internal command state BlockState. 481 * Call #op on all simple traits.
519 *
520 * * @param[out] ac struct BlockState.
521* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
522 */ 482 */
523int 483#define GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS(op) \
524GNUNET_TESTING_get_trait_block_state ( 484 op (test_system, const struct GNUNET_TESTING_System) \
525 const struct GNUNET_TESTING_Command *cmd, 485 op (async_context, const struct GNUNET_TESTING_AsyncContext) \
526 struct BlockState **bs); 486 op (helper_handles, const void *) \
487 op (local_prepared_state, const struct LocalPreparedState) \
488 op (block_state, const struct BlockState)
489
490GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
527 491
528#endif 492#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index c9f5e3e00..c0e534594 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -31,6 +31,14 @@
31#include "gnunet_testing_plugin.h" 31#include "gnunet_testing_plugin.h"
32#include "gnunet_testing_lib.h" 32#include "gnunet_testing_lib.h"
33 33
34/**
35 * Stringify operator.
36 *
37 * @param a some expression to stringify. Must NOT be a macro.
38 * @return same expression as a constant string.
39 */
40#define GNUNET_S(a) #a
41
34 42
35/* ********************* Helper functions ********************* */ 43/* ********************* Helper functions ********************* */
36 44
@@ -195,7 +203,7 @@ struct GNUNET_TESTING_Command
195 /** 203 /**
196 * If "true", the interpreter should not immediately call 204 * If "true", the interpreter should not immediately call
197 * @e finish, even if @e finish is non-NULL. Otherwise, 205 * @e finish, even if @e finish is non-NULL. Otherwise,
198 * #TALER_TESTING_cmd_finish() must be used 206 * #GNUNET_TESTING_cmd_finish() must be used
199 * to ensure that a command actually completed. 207 * to ensure that a command actually completed.
200 */ 208 */
201 bool asynchronous_finish; 209 bool asynchronous_finish;
@@ -575,8 +583,8 @@ GNUNET_TESTING_calculate_num (struct
575 * @return The peer identity wrapping the public key. 583 * @return The peer identity wrapping the public key.
576 */ 584 */
577struct GNUNET_PeerIdentity * 585struct GNUNET_PeerIdentity *
578GNUNET_TESTING_get_pub_key (unsigned int num, struct 586GNUNET_TESTING_get_pub_key (unsigned int num,
579 GNUNET_TESTING_System *tl_system); 587 const struct GNUNET_TESTING_System *tl_system);
580 588
581 589
582/** 590/**
@@ -642,279 +650,120 @@ GNUNET_TESTING_get_trait (const struct GNUNET_TESTING_Trait *traits,
642 650
643/* ****** Specific traits supported by this component ******* */ 651/* ****** Specific traits supported by this component ******* */
644 652
645/**
646 * Obtain location where a command stores a pointer to a process.
647 *
648 * @param cmd command to extract trait from.
649 * @param index which process to pick if @a cmd
650 * has multiple on offer. -- FIXME: remove?
651 * @param[out] processp set to the address of the pointer to the
652 * process.
653 * @return #GNUNET_OK on success.
654 */
655enum GNUNET_GenericReturnValue
656GNUNET_TESTING_get_trait_process (const struct GNUNET_TESTING_Command *cmd,
657 unsigned int index,
658 struct GNUNET_OS_Process ***processp);
659
660
661/**
662 * Offer location where a command stores a pointer to a process.
663 *
664 * @param index offered location index number, in case there are
665 * multiple on offer. // FIXME: remove?
666 * @param processp process location to offer.
667 * @return the trait.
668 */
669struct GNUNET_TESTING_Trait
670GNUNET_TESTING_make_trait_process (unsigned int index,
671 struct GNUNET_OS_Process **processp);
672
673
674/**
675 * Offer number trait, 32-bit version.
676 *
677 * @param index the number's index number. // FIXME: introduce enum?
678 * @param n number to offer.
679 */
680struct GNUNET_TESTING_Trait
681GNUNET_TESTING_make_trait_uint32 (unsigned int index,
682 const uint32_t *n);
683
684
685/**
686 * Obtain a "number" value from @a cmd, 32-bit version.
687 *
688 * @param cmd command to extract the number from.
689 * @param index the number's index number. // FIXME: introduce enum?
690 * @param[out] n set to the number coming from @a cmd.
691 * @return #GNUNET_OK on success.
692 */
693enum GNUNET_GenericReturnValue
694GNUNET_TESTING_get_trait_uint32 (const struct GNUNET_TESTING_Command *cmd,
695 unsigned int index,
696 const uint32_t **n);
697
698
699/**
700 * Offer number trait, 64-bit version.
701 *
702 * @param index the number's index number. // FIXME: introduce enum?
703 * @param n number to offer.
704 */
705struct GNUNET_TESTING_Trait
706GNUNET_TESTING_make_trait_uint64 (unsigned int index,
707 const uint64_t *n);
708
709
710/**
711 * Obtain a "number" value from @a cmd, 64-bit version.
712 *
713 * @param cmd command to extract the number from.
714 * @param index the number's index number. // FIXME: introduce enum?
715 * @param[out] n set to the number coming from @a cmd.
716 * @return #GNUNET_OK on success.
717 */
718enum GNUNET_GenericReturnValue
719GNUNET_TESTING_get_trait_uint64 (const struct GNUNET_TESTING_Command *cmd,
720 unsigned int index,
721 const uint64_t **n);
722
723
724/**
725 * Offer number trait, 64-bit signed version.
726 *
727 * @param index the number's index number. // FIXME: introduce enum?
728 * @param n number to offer.
729 */
730struct GNUNET_TESTING_Trait
731GNUNET_TESTING_make_trait_int64 (unsigned int index,
732 const int64_t *n);
733
734
735/**
736 * Obtain a "number" value from @a cmd, 64-bit signed version.
737 *
738 * @param cmd command to extract the number from.
739 * @param index the number's index number. // FIXME: introduce enum?
740 * @param[out] n set to the number coming from @a cmd.
741 * @return #GNUNET_OK on success.
742 */
743enum GNUNET_GenericReturnValue
744GNUNET_TESTING_get_trait_int64 (const struct GNUNET_TESTING_Command *cmd,
745 unsigned int index,
746 const int64_t **n);
747
748
749/**
750 * Offer a number.
751 *
752 * @param index the number's index number.
753 * @param n the number to offer. // FIXME: introduce enum?
754 * @return #GNUNET_OK on success.
755 */
756struct GNUNET_TESTING_Trait
757GNUNET_TESTING_make_trait_uint (unsigned int index,
758 const unsigned int *i);
759
760
761/**
762 * Obtain a number from @a cmd.
763 *
764 * @param cmd command to extract the number from.
765 * @param index the number's index number. // FIXME: introduce enum?
766 * @param[out] n set to the number coming from @a cmd.
767 * @return #GNUNET_OK on success.
768 */
769enum GNUNET_GenericReturnValue
770GNUNET_TESTING_get_trait_uint (const struct GNUNET_TESTING_Command *cmd,
771 unsigned int index,
772 const unsigned int **n);
773
774/**
775 * Obtain a string from @a cmd.
776 *
777 * @param cmd command to extract the subject from.
778 * @param index index number associated with the transfer
779 * subject to offer. // FIXME: introduce enum?
780 * @param[out] s where to write the offered
781 * string.
782 * @return #GNUNET_OK on success.
783 */
784enum GNUNET_GenericReturnValue
785GNUNET_TESTING_get_trait_string (
786 const struct GNUNET_TESTING_Command *cmd,
787 unsigned int index,
788 const char **s);
789
790
791/**
792 * Offer string subject.
793 *
794 * @param index index number associated with the transfer
795 * subject being offered. // FIXME: introduce enum?
796 * @param s string to offer.
797 * @return the trait.
798 */
799struct GNUNET_TESTING_Trait
800GNUNET_TESTING_make_trait_string (unsigned int index,
801 const char *s);
802
803/**
804 * Offer a command in a trait.
805 *
806 * @param index always zero. Commands offering this
807 * kind of traits do not need this index. For
808 * example, a "meta" CMD returns always the
809 * CMD currently being executed. FIXME: remove!
810 * @param cmd wire details to offer.
811 * @return the trait.
812 */
813struct GNUNET_TESTING_Trait
814GNUNET_TESTING_make_trait_cmd (unsigned int index,
815 const struct GNUNET_TESTING_Command *cmd);
816
817 653
818/** 654/**
819 * Obtain a command from @a cmd. 655 * Create headers for a trait with name @a name for
820 * 656 * statically allocated data of type @a type.
821 * @param cmd command to extract the command from. 657 */
822 * @param index always zero. Commands offering this 658#define GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT(name,type) \
823 * kind of traits do not need this index. For 659 enum GNUNET_GenericReturnValue \
824 * example, a "meta" CMD returns always the 660 GNUNET_TESTING_get_trait_ ## name ( \
825 * CMD currently being executed. FIXME: remove! 661 const struct GNUNET_TESTING_Command *cmd, \
826 * @param[out] _cmd where to write the wire details. 662 type **ret); \
827 * @return #GNUNET_OK on success. 663 struct GNUNET_TESTING_Trait \
828 */ 664 GNUNET_TESTING_make_trait_ ## name ( \
829enum GNUNET_GenericReturnValue 665 type * value);
830GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd, 666
831 unsigned int index, 667
832 struct GNUNET_TESTING_Command **_cmd); 668/**
833 669 * Create C implementation for a trait with name @a name for statically
834 670 * allocated data of type @a type.
835/** 671 */
836 * Obtain a uuid from @a cmd. 672#define GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
837 * 673 enum GNUNET_GenericReturnValue \
838 * @param cmd command to extract the uuid from. 674 GNUNET_TESTING_get_trait_ ## name ( \
839 * @param index which amount to pick if @a cmd has multiple 675 const struct GNUNET_TESTING_Command *cmd, \
840 * on offer // FIXME: introduce enum? 676 type **ret) \
841 * @param[out] uuid where to write the uuid. 677 { \
842 * @return #GNUNET_OK on success. 678 if (NULL == cmd->traits) return GNUNET_SYSERR; \
843 */ 679 return cmd->traits (cmd->cls, \
844enum GNUNET_GenericReturnValue 680 (const void **) ret, \
845GNUNET_TESTING_get_trait_uuid (const struct GNUNET_TESTING_Command *cmd, 681 GNUNET_S (name), \
846 unsigned int index, 682 0); \
847 struct GNUNET_Uuid **uuid); 683 } \
848 684 struct GNUNET_TESTING_Trait \
849 685 GNUNET_TESTING_make_trait_ ## name ( \
850/** 686 type * value) \
851 * Offer a uuid in a trait. 687 { \
852 * 688 struct GNUNET_TESTING_Trait ret = { \
853 * @param index which uuid to offer, in case there are 689 .trait_name = GNUNET_S (name), \
854 * multiple available. // FIXME: introduce enum? 690 .ptr = (const void *) value \
855 * @param uuid the uuid to offer. 691 }; \
856 * @return the trait. 692 return ret; \
857 */ 693 }
858struct GNUNET_TESTING_Trait 694
859GNUNET_TESTING_make_trait_uuid (unsigned int index, 695
860 const struct GNUNET_Uuid *uuid); 696/**
861 697 * Create headers for a trait with name @a name for
862 698 * statically allocated data of type @a type.
863/** 699 */
864 * Obtain a absolute time from @a cmd. 700#define GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT(name,type) \
865 * 701 enum GNUNET_GenericReturnValue \
866 * @param cmd command to extract trait from 702 GNUNET_TESTING_get_trait_ ## name ( \
867 * @param index which time stamp to pick if 703 const struct GNUNET_TESTING_Command *cmd, \
868 * @a cmd has multiple on offer // FIXME: introduce enum? 704 unsigned int index, \
869 * @param[out] time set to the wanted WTID. 705 type **ret); \
870 * @return #GNUNET_OK on success 706 struct GNUNET_TESTING_Trait \
871 */ 707 GNUNET_TESTING_make_trait_ ## name ( \
872enum GNUNET_GenericReturnValue 708 unsigned int index, \
873GNUNET_TESTING_get_trait_absolute_time ( 709 type * value);
874 const struct GNUNET_TESTING_Command *cmd, 710
875 unsigned int index, 711
876 const struct GNUNET_TIME_Absolute **time); 712/**
877 713 * Create C implementation for a trait with name @a name for statically
878 714 * allocated data of type @a type.
879/** 715 */
880 * Offer a absolute time. 716#define GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT(name,type) \
881 * 717 enum GNUNET_GenericReturnValue \
882 * @param index associate the object with this index 718 GNUNET_TESTING_get_trait_ ## name ( \
883 * @param time which object should be returned 719 const struct GNUNET_TESTING_Command *cmd, \
884 * @return the trait. 720 unsigned int index, \
885 */ 721 type **ret) \
886struct GNUNET_TESTING_Trait 722 { \
887GNUNET_TESTING_make_trait_absolute_time ( 723 if (NULL == cmd->traits) return GNUNET_SYSERR; \
888 unsigned int index, 724 return cmd->traits (cmd->cls, \
889 const struct GNUNET_TIME_Absolute *time); 725 (const void **) ret, \
890 726 GNUNET_S (name), \
891 727 index); \
892/** 728 } \
893 * Obtain a relative time from @a cmd. 729 struct GNUNET_TESTING_Trait \
894 * 730 GNUNET_TESTING_make_trait_ ## name ( \
895 * @param cmd command to extract trait from 731 unsigned int index, \
896 * @param index which time to pick if 732 type * value) \
897 * @a cmd has multiple on offer. 733 { \
898 * @param[out] time set to the wanted WTID. 734 struct GNUNET_TESTING_Trait ret = { \
899 * @return #GNUNET_OK on success 735 .index = index, \
900 */ 736 .trait_name = GNUNET_S (name), \
901int 737 .ptr = (const void *) value \
902GNUNET_TESTING_get_trait_relative_time ( 738 }; \
903 const struct GNUNET_TESTING_Command *cmd, 739 return ret; \
904 unsigned int index, 740 }
905 const struct GNUNET_TIME_Relative **time); 741
906 742
907 743/**
908/** 744 * Call #op on all simple traits.
909 * Offer a relative time. 745 */
910 * 746#define GNUNET_TESTING_SIMPLE_TRAITS(op) \
911 * @param index associate the object with this index 747 op (process, struct GNUNET_OS_Process *)
912 * @param time which object should be returned 748
913 * @return the trait. 749
914 */ 750/**
915struct GNUNET_TESTING_Trait 751 * Call #op on all indexed traits.
916GNUNET_TESTING_make_trait_relative_time ( 752 */
917 unsigned int index, 753#define GNUNET_TESTING_INDEXED_TRAITS(op) \
918 const struct GNUNET_TIME_Relative *time); 754 op (uint32, const uint32_t) \
755 op (uint64, const uint64_t) \
756 op (int64, const int64_t) \
757 op (uint, const unsigned int) \
758 op (string, const char) \
759 op (cmd, const struct GNUNET_TESTING_Command) \
760 op (uuid, const struct GNUNET_Uuid) \
761 op (time, const struct GNUNET_TIME_Absolute) \
762 op (absolute_time, const struct GNUNET_TIME_Absolute) \
763 op (relative_time, const struct GNUNET_TIME_Relative)
764
765GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT)
766
767GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT)
919 768
920#endif 769#endif
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index a9a1b5a02..bcb45da70 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -44,8 +44,6 @@ libgnunettesting_la_SOURCES = \
44 testing_api_cmd_system_destroy.c \ 44 testing_api_cmd_system_destroy.c \
45 testing_api_cmd_batch.c \ 45 testing_api_cmd_batch.c \
46 testing_api_loop.c \ 46 testing_api_loop.c \
47 testing_api_trait_cmd.c \
48 testing_api_trait_process.c \
49 testing_api_traits.c 47 testing_api_traits.c
50libgnunettesting_la_LIBADD = \ 48libgnunettesting_la_LIBADD = \
51 $(top_builddir)/src/arm/libgnunetarm.la \ 49 $(top_builddir)/src/arm/libgnunetarm.la \
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 7474d9b5f..fd0701d7d 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -2169,8 +2169,8 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
2169 * @return The peer identity wrapping the public key. 2169 * @return The peer identity wrapping the public key.
2170 */ 2170 */
2171struct GNUNET_PeerIdentity * 2171struct GNUNET_PeerIdentity *
2172GNUNET_TESTING_get_pub_key (unsigned int num, struct 2172GNUNET_TESTING_get_pub_key (unsigned int num,
2173 GNUNET_TESTING_System *tl_system) 2173 const struct GNUNET_TESTING_System *tl_system)
2174{ 2174{
2175 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); 2175 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
2176 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct 2176 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c
index 9360dd02e..f51b2109b 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -55,16 +55,8 @@ block_until_external_trigger_traits (void *cls,
55 struct BlockState *bs = cls; 55 struct BlockState *bs = cls;
56 struct GNUNET_TESTING_AsyncContext *ac = &bs->ac; 56 struct GNUNET_TESTING_AsyncContext *ac = &bs->ac;
57 struct GNUNET_TESTING_Trait traits[] = { 57 struct GNUNET_TESTING_Trait traits[] = {
58 { 58 GNUNET_TESTING_make_trait_async_context ((const void *) ac),
59 .index = 0, 59 GNUNET_TESTING_make_trait_block_state ((const void *) bs),
60 .trait_name = "async_context",
61 .ptr = (const void *) ac,
62 },
63 {
64 .index = 1,
65 .trait_name = "block_state",
66 .ptr = (const void *) bs,
67 },
68 GNUNET_TESTING_trait_end () 60 GNUNET_TESTING_trait_end ()
69 }; 61 };
70 62
@@ -76,42 +68,6 @@ block_until_external_trigger_traits (void *cls,
76 68
77 69
78/** 70/**
79 * Function to get the trait with the internal command state BlockState.
80 *
81 * * @param[out] ac struct BlockState.
82* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
83 */
84int
85GNUNET_TESTING_get_trait_block_state (
86 const struct GNUNET_TESTING_Command *cmd,
87 struct BlockState **bs)
88{
89 return cmd->traits (cmd->cls,
90 (const void **) bs,
91 "block_state",
92 (unsigned int) 1);
93}
94
95
96/**
97 * Function to get the trait with the async context.
98 *
99 * @param[out] ac struct GNUNET_TESTING_AsyncContext.
100 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
101 */
102int
103GNUNET_TESTING_get_trait_async_context (
104 const struct GNUNET_TESTING_Command *cmd,
105 struct GNUNET_TESTING_AsyncContext **ac)
106{
107 return cmd->traits (cmd->cls,
108 (const void **) ac,
109 "async_context",
110 (unsigned int) 0);
111}
112
113
114/**
115 * This function does nothing but to start the cmd. 71 * This function does nothing but to start the cmd.
116 * 72 *
117 */ 73 */
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
index 9dc7dfa9a..1f470a6c1 100644
--- a/src/testing/testing_api_cmd_local_test_prepared.c
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -47,11 +47,7 @@ local_test_prepared_traits (void *cls,
47{ 47{
48 struct LocalPreparedState *lfs = cls; 48 struct LocalPreparedState *lfs = cls;
49 struct GNUNET_TESTING_Trait traits[] = { 49 struct GNUNET_TESTING_Trait traits[] = {
50 { 50 GNUNET_TESTING_make_trait_local_prepared_state ((const void *) lfs),
51 .index = 0,
52 .trait_name = "state",
53 .ptr = (const void *) lfs,
54 },
55 GNUNET_TESTING_trait_end () 51 GNUNET_TESTING_trait_end ()
56 }; 52 };
57 return GNUNET_TESTING_get_trait (traits, 53 return GNUNET_TESTING_get_trait (traits,
@@ -62,25 +58,6 @@ local_test_prepared_traits (void *cls,
62 58
63 59
64/** 60/**
65 * Function to get the trait with the struct LocalPreparedState.
66 *
67 * @param[out] lfs struct LocalPreparedState.
68 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
69 *
70 */
71enum GNUNET_GenericReturnValue
72GNUNET_TESTING_get_trait_local_prepared_state (
73 const struct GNUNET_TESTING_Command *cmd,
74 struct LocalPreparedState **lfs)
75{
76 return cmd->traits (cmd->cls,
77 (const void **) lfs,
78 "state",
79 (unsigned int) 0);
80}
81
82
83/**
84 * The cleanup function of this cmd frees resources the cmd allocated. 61 * The cleanup function of this cmd frees resources the cmd allocated.
85 * 62 *
86 */ 63 */
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 1709a58d2..d24ad3d28 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -86,7 +86,7 @@ struct NetJailState
86 /** 86 /**
87 * Array with handles of helper processes. 87 * Array with handles of helper processes.
88 */ 88 */
89 struct GNUNET_HELPER_Handle **helper; 89 const struct GNUNET_HELPER_Handle **helper;
90 90
91 /** 91 /**
92 * Size of the array NetJailState#helper. 92 * Size of the array NetJailState#helper.
@@ -211,22 +211,18 @@ netjail_exec_cleanup (void *cls)
211 * This function prepares an array with traits. 211 * This function prepares an array with traits.
212 * 212 *
213 */ 213 */
214static int 214static enum GNUNET_GenericReturnValue
215netjail_exec_traits (void *cls, 215netjail_exec_traits (void *cls,
216 const void **ret, 216 const void **ret,
217 const char *trait, 217 const char *trait,
218 unsigned int index) 218 unsigned int index)
219{ 219{
220 struct NetJailState *ns = cls; 220 struct NetJailState *ns = cls;
221 struct GNUNET_HELPER_Handle **helper = ns->helper; 221 const struct GNUNET_HELPER_Handle **helper = ns->helper;
222 222
223 223
224 struct GNUNET_TESTING_Trait traits[] = { 224 struct GNUNET_TESTING_Trait traits[] = {
225 { 225 GNUNET_TESTING_make_trait_helper_handles ((const void **) helper),
226 .index = 0,
227 .trait_name = "helper_handles",
228 .ptr = (const void *) helper,
229 },
230 GNUNET_TESTING_trait_end () 226 GNUNET_TESTING_trait_end ()
231 }; 227 };
232 228
@@ -238,26 +234,6 @@ netjail_exec_traits (void *cls,
238 234
239 235
240/** 236/**
241 * Offer handles to testing cmd helper from trait
242 *
243 * @param cmd command to extract the message from.
244 * @param pt pointer to message.
245 * @return #GNUNET_OK on success.
246 */
247int
248GNUNET_TESTING_get_trait_helper_handles (const struct
249 GNUNET_TESTING_Command *cmd,
250 struct GNUNET_HELPER_Handle ***
251 helper)
252{
253 return cmd->traits (cmd->cls,
254 (const void **) helper,
255 "helper_handles",
256 (unsigned int) 0);
257}
258
259
260/**
261 * Continuation function from GNUNET_HELPER_send() 237 * Continuation function from GNUNET_HELPER_send()
262 * 238 *
263 * @param cls closure 239 * @param cls closure
@@ -287,7 +263,7 @@ send_message_to_locals (
287 ) 263 )
288{ 264{
289 // unsigned int total_number = ns->local_m * ns->global_n + ns->known; 265 // unsigned int total_number = ns->local_m * ns->global_n + ns->known;
290 struct GNUNET_HELPER_Handle *helper; 266 const struct GNUNET_HELPER_Handle *helper;
291 struct TestingSystemCount *tbc; 267 struct TestingSystemCount *tbc;
292 268
293 LOG (GNUNET_ERROR_TYPE_DEBUG, 269 LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index 4b52878c4..caf83ab0e 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -86,7 +86,7 @@ stop_testing_system_run (void *cls,
86 struct GNUNET_TESTING_Interpreter *is) 86 struct GNUNET_TESTING_Interpreter *is)
87{ 87{
88 struct StopHelperState *shs = cls; 88 struct StopHelperState *shs = cls;
89 struct GNUNET_HELPER_Handle **helper; 89 const struct GNUNET_HELPER_Handle **helper;
90 const struct GNUNET_TESTING_Command *start_helper_cmd; 90 const struct GNUNET_TESTING_Command *start_helper_cmd;
91 91
92 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 92 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index 275132684..221bbb8f6 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -77,11 +77,7 @@ system_create_traits (void *cls,
77 struct GNUNET_TESTING_System *test_system = tss->test_system; 77 struct GNUNET_TESTING_System *test_system = tss->test_system;
78 78
79 struct GNUNET_TESTING_Trait traits[] = { 79 struct GNUNET_TESTING_Trait traits[] = {
80 { 80 GNUNET_TESTING_make_trait_test_system ((const void *) test_system),
81 .index = 0,
82 .trait_name = "test_system",
83 .ptr = (const void *) test_system,
84 },
85 GNUNET_TESTING_trait_end () 81 GNUNET_TESTING_trait_end ()
86 }; 82 };
87 83
@@ -93,24 +89,6 @@ system_create_traits (void *cls,
93 89
94 90
95/** 91/**
96 * Function to get the trait with struct GNUNET_TESTING_System
97 *
98 * @param[out] test_system The struct GNUNET_TESTING_System.
99 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
100 */
101int
102GNUNET_TESTING_get_trait_test_system (const struct
103 GNUNET_TESTING_Command *cmd,
104 struct GNUNET_TESTING_System **test_system)
105{
106 return cmd->traits (cmd->cls,
107 (const void **) test_system,
108 "test_system",
109 (unsigned int) 0);
110}
111
112
113/**
114 * The cleanup function of this cmd frees resources the cmd allocated. 92 * The cleanup function of this cmd frees resources the cmd allocated.
115 * 93 *
116 */ 94 */
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index cdfc65d53..5a2440766 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -51,13 +51,13 @@ system_destroy_run (void *cls,
51{ 51{
52 struct TestSystemState *tss = cls; 52 struct TestSystemState *tss = cls;
53 const struct GNUNET_TESTING_Command *system_cmd; 53 const struct GNUNET_TESTING_Command *system_cmd;
54 struct GNUNET_TESTING_System *tl_system; 54 const struct GNUNET_TESTING_System *tl_system;
55 55
56 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 56 system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
57 tss->create_label); 57 tss->create_label);
58 GNUNET_TESTING_get_trait_test_system (system_cmd, 58 GNUNET_TESTING_get_trait_test_system (system_cmd,
59 &tl_system); 59 &tl_system);
60 GNUNET_TESTING_system_destroy (tl_system, 60 GNUNET_TESTING_system_destroy ((struct GNUNET_TESTING_System *) tl_system,
61 GNUNET_YES); 61 GNUNET_YES);
62} 62}
63 63
diff --git a/src/testing/testing_api_trait_cmd.c b/src/testing/testing_api_trait_cmd.c
deleted file mode 100644
index 7afa8b264..000000000
--- a/src/testing/testing_api_trait_cmd.c
+++ /dev/null
@@ -1,79 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_trait_cmd.c
23 * @brief offers CMDs as traits.
24 * @author Marcello Stanisci (GNU Taler testing)
25 * @author t3sserakt
26 */
27#include "platform.h"
28#include "gnunet_testing_ng_lib.h"
29
30#define GNUNET_TESTING_TRAIT_CMD "cmd"
31
32
33/**
34 * Obtain a command from @a cmd.
35 *
36 * @param cmd command to extract the command from.
37 * @param index always zero. Commands offering this
38 * kind of traits do not need this index. For
39 * example, a "batch" CMD returns always the
40 * CMD currently being executed.
41 * @param[out] _cmd where to write the wire details.
42 * @return #GNUNET_OK on success.
43 */
44enum GNUNET_GenericReturnValue
45GNUNET_TESTING_get_trait_cmd (const struct GNUNET_TESTING_Command *cmd,
46 unsigned int index,
47 struct GNUNET_TESTING_Command **_cmd)
48{
49 return cmd->traits (cmd->cls,
50 (const void **) _cmd,
51 GNUNET_TESTING_TRAIT_CMD,
52 index);
53}
54
55
56/**
57 * Offer a command in a trait.
58 *
59 * @param index always zero. Commands offering this
60 * kind of traits do not need this index. For
61 * example, a "meta" CMD returns always the
62 * CMD currently being executed.
63 * @param cmd wire details to offer.
64 * @return the trait.
65 */
66struct GNUNET_TESTING_Trait
67GNUNET_TESTING_make_trait_cmd (unsigned int index,
68 const struct GNUNET_TESTING_Command *cmd)
69{
70 struct GNUNET_TESTING_Trait ret = {
71 .index = index,
72 .trait_name = GNUNET_TESTING_TRAIT_CMD,
73 .ptr = (const struct GNUNET_TESTING_Command *) cmd
74 };
75 return ret;
76}
77
78
79/* end of testing_api_trait_cmd.c */
diff --git a/src/testing/testing_api_trait_process.c b/src/testing/testing_api_trait_process.c
deleted file mode 100644
index 31cdb01df..000000000
--- a/src/testing/testing_api_trait_process.c
+++ /dev/null
@@ -1,81 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_trait_process.c
23 * @brief trait offering process handles.
24 * @author Christian Grothoff (GNU Taler testing)
25 * @author Marcello Stanisci (GNU Taler testing)
26 * @author t3sserakt
27 */
28#include "platform.h"
29#include "gnunet_testing_ng_lib.h"
30
31#define GNUNET_TESTING_TRAIT_PROCESS "process"
32
33
34/**
35 * Obtain location where a command stores a pointer to a process.
36 *
37 * @param cmd command to extract trait from.
38 * @param index which process to pick if @a cmd
39 * has multiple on offer.
40 * @param[out] processp set to the address of the pointer to the
41 * process.
42 * @return #GNUNET_OK on success.
43 */
44int
45GNUNET_TESTING_get_trait_process
46 (const struct GNUNET_TESTING_Command *cmd,
47 unsigned int index,
48 struct GNUNET_OS_Process ***processp)
49{
50 return cmd->traits (cmd->cls,
51 (const void **) processp,
52 GNUNET_TESTING_TRAIT_PROCESS,
53 index);
54}
55
56
57/**
58 * Offer location where a command stores a pointer to a process.
59 *
60 * @param index offered location index number, in case there are
61 * multiple on offer.
62 * @param processp process location to offer.
63 *
64 * @return the trait.
65 */
66struct GNUNET_TESTING_Trait
67GNUNET_TESTING_make_trait_process
68 (unsigned int index,
69 struct GNUNET_OS_Process **processp)
70{
71 struct GNUNET_TESTING_Trait ret = {
72 .index = index,
73 .trait_name = GNUNET_TESTING_TRAIT_PROCESS,
74 .ptr = (const void *) processp
75 };
76
77 return ret;
78}
79
80
81/* end of testing_api_trait_process.c */
diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c
index 2f836ddfa..9b54443a1 100644
--- a/src/testing/testing_api_traits.c
+++ b/src/testing/testing_api_traits.c
@@ -27,8 +27,15 @@
27 */ 27 */
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_testing_ng_lib.h" 29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_testing_netjail_lib.h"
30 31
31 32
33GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
34
35GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_IMPL_INDEXED_TRAIT)
36
37GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
38
32/** 39/**
33 * End a trait array. Usually, commands offer several traits, 40 * End a trait array. Usually, commands offer several traits,
34 * and put them in arrays. 41 * and put them in arrays.
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 423602fea..751bc40c1 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -159,6 +159,7 @@ libgnunettransporttesting_la_LDFLAGS = \
159 $(GN_LIB_LDFLAGS) 159 $(GN_LIB_LDFLAGS)
160 160
161libgnunettransporttesting2_la_SOURCES = \ 161libgnunettransporttesting2_la_SOURCES = \
162 transport_api_traits.c \
162 transport_api_cmd_connecting_peers.c \ 163 transport_api_cmd_connecting_peers.c \
163 transport_api_cmd_backchannel_check.c \ 164 transport_api_cmd_backchannel_check.c \
164 transport_api_cmd_start_peer.c \ 165 transport_api_cmd_start_peer.c \
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
index 526f08e6a..9d6844be1 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
@@ -96,15 +96,15 @@ static void
96handle_test (void *cls, 96handle_test (void *cls,
97 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 97 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
98{ 98{
99 struct GNUNET_TESTING_AsyncContext *ac; 99 const struct GNUNET_TESTING_AsyncContext *ac;
100 100
101 GNUNET_TESTING_get_trait_async_context (&block_receive, 101 GNUNET_TESTING_get_trait_async_context (&block_receive,
102 &ac); 102 &ac);
103 GNUNET_assert (NULL != ac); 103 GNUNET_assert (NULL != ac);
104 if (NULL == ac->cont) 104 if ((GNUNET_NO == ac->finished) && (NULL == ac->cont))
105 GNUNET_TESTING_async_fail (ac); 105 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
106 else 106 else if (GNUNET_NO == ac->finished)
107 GNUNET_TESTING_async_finish (ac); 107 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
108} 108}
109 109
110 110
@@ -115,7 +115,7 @@ handle_test (void *cls,
115static void 115static void
116all_peers_started () 116all_peers_started ()
117{ 117{
118 struct GNUNET_TESTING_AsyncContext *ac; 118 const struct GNUNET_TESTING_AsyncContext *ac;
119 119
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Received message\n"); 121 "Received message\n");
@@ -123,9 +123,9 @@ all_peers_started ()
123 &ac); 123 &ac);
124 GNUNET_assert (NULL != ac); 124 GNUNET_assert (NULL != ac);
125 if (NULL == ac->cont) 125 if (NULL == ac->cont)
126 GNUNET_TESTING_async_fail (ac); 126 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
127 else 127 else
128 GNUNET_TESTING_async_finish (ac); 128 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
129} 129}
130 130
131 131
@@ -168,7 +168,7 @@ static void *
168notify_connect (struct GNUNET_TESTING_Interpreter *is, 168notify_connect (struct GNUNET_TESTING_Interpreter *is,
169 const struct GNUNET_PeerIdentity *peer) 169 const struct GNUNET_PeerIdentity *peer)
170{ 170{
171 struct GNUNET_TESTING_AsyncContext *ac; 171 const struct GNUNET_TESTING_AsyncContext *ac;
172 void *ret = NULL; 172 void *ret = NULL;
173 const struct GNUNET_TESTING_Command *cmd; 173 const struct GNUNET_TESTING_Command *cmd;
174 struct BlockState *bs; 174 struct BlockState *bs;
@@ -186,9 +186,9 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
186 "notify_connect running\n"); 186 "notify_connect running\n");
187 GNUNET_assert (NULL != ac); 187 GNUNET_assert (NULL != ac);
188 if (NULL == ac->cont) 188 if (NULL == ac->cont)
189 GNUNET_TESTING_async_fail (ac); 189 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
190 else 190 else
191 GNUNET_TESTING_async_finish (ac); 191 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
192 } 192 }
193 else 193 else
194 { 194 {
@@ -198,7 +198,9 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
198 LOG (GNUNET_ERROR_TYPE_DEBUG, 198 LOG (GNUNET_ERROR_TYPE_DEBUG,
199 "block state %s\n", 199 "block state %s\n",
200 cmd->label); 200 cmd->label);
201 GNUNET_TESTING_get_trait_block_state (cmd,&bs); 201 GNUNET_TESTING_get_trait_block_state (
202 cmd,
203 (const struct BlockState **) &bs);
202 204
203 LOG (GNUNET_ERROR_TYPE_DEBUG, 205 LOG (GNUNET_ERROR_TYPE_DEBUG,
204 "block state %u\n", 206 "block state %u\n",
@@ -219,15 +221,16 @@ notify_connect (struct GNUNET_TESTING_Interpreter *is,
219static void 221static void
220all_local_tests_prepared () 222all_local_tests_prepared ()
221{ 223{
222 struct LocalPreparedState *lfs; 224 const struct LocalPreparedState *lfs;
223 225
224 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, 226 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
225 &lfs); 227 &lfs);
226 GNUNET_assert (NULL != &lfs->ac); 228 GNUNET_assert (NULL != &lfs->ac);
227 if (NULL == lfs->ac.cont) 229 if (NULL == lfs->ac.cont)
228 GNUNET_TESTING_async_fail (&lfs->ac); 230 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
229 else 231 else
230 GNUNET_TESTING_async_finish (&lfs->ac); 232 GNUNET_TESTING_async_finish ((struct
233 GNUNET_TESTING_AsyncContext *) &lfs->ac);
231} 234}
232 235
233 236
diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c
index 7eb92d629..c3411becc 100644
--- a/src/transport/test_transport_start_with_config.c
+++ b/src/transport/test_transport_start_with_config.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h" 28#include "gnunet_testing_netjail_lib.h"
29#include "transport-testing-cmds.h"
29#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
30 31
31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index d64279aeb..af6f47962 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -49,7 +49,7 @@ struct ConnectPeersState
49 /** 49 /**
50 * The testing system of this node. 50 * The testing system of this node.
51 */ 51 */
52 struct GNUNET_TESTING_System *tl_system; 52 const struct GNUNET_TESTING_System *tl_system;
53 53
54 // Label of the cmd which started the test system. 54 // Label of the cmd which started the test system.
55 const char *create_label; 55 const char *create_label;
@@ -180,7 +180,7 @@ struct StartPeerState
180 180
181 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; 181 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
182 182
183 struct GNUNET_TESTING_System *tl_system; 183 const struct GNUNET_TESTING_System *tl_system;
184 184
185 GNUNET_TRANSPORT_notify_connect_cb notify_connect; 185 GNUNET_TRANSPORT_notify_connect_cb notify_connect;
186 186
@@ -192,26 +192,6 @@ struct StartPeerState
192 192
193 193
194/** 194/**
195 * Function to get the trait with the struct ConnectPeersState.
196 *
197 * @param[out] sps struct ConnectPeersState.
198 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
199 *
200 */
201int
202GNUNET_TRANSPORT_get_trait_connect_peer_state (
203 const struct GNUNET_TESTING_Command *cmd,
204 struct ConnectPeersState **cps);
205
206
207int
208GNUNET_TRANSPORT_get_trait_state (const struct
209 GNUNET_TESTING_Command
210 *cmd,
211 struct StartPeerState **sps);
212
213
214/**
215 * Create command. 195 * Create command.
216 * 196 *
217 * @param label name for command. 197 * @param label name for command.
@@ -305,43 +285,62 @@ GNUNET_TRANSPORT_cmd_backchannel_check (const char *label,
305 topology); 285 topology);
306 286
307 287
288/**
289 * Create headers for a trait with name @a name for
290 * statically allocated data of type @a type.
291 */
292#define GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT(name,type) \
293 enum GNUNET_GenericReturnValue \
294 GNUNET_TRANSPORT_get_trait_ ## name ( \
295 const struct GNUNET_TESTING_Command *cmd, \
296 type **ret); \
297 struct GNUNET_TESTING_Trait \
298 GNUNET_TRANSPORT_make_trait_ ## name ( \
299 type * value);
308 300
309 301
302/**
303 * Create C implementation for a trait with name @a name for statically
304 * allocated data of type @a type.
305 */
306#define GNUNET_TRANSPORT_MAKE_IMPL_SIMPLE_TRAIT(name,type) \
307 enum GNUNET_GenericReturnValue \
308 GNUNET_TRANSPORT_get_trait_ ## name ( \
309 const struct GNUNET_TESTING_Command *cmd, \
310 type **ret) \
311 { \
312 if (NULL == cmd->traits) return GNUNET_SYSERR; \
313 return cmd->traits (cmd->cls, \
314 (const void **) ret, \
315 GNUNET_S (name), \
316 0); \
317 } \
318 struct GNUNET_TESTING_Trait \
319 GNUNET_TRANSPORT_make_trait_ ## name ( \
320 type * value) \
321 { \
322 struct GNUNET_TESTING_Trait ret = { \
323 .trait_name = GNUNET_S (name), \
324 .ptr = (const void *) value \
325 }; \
326 return ret; \
327 }
310 328
311int
312GNUNET_TRANSPORT_get_trait_peer_id (const struct
313 GNUNET_TESTING_Command *cmd,
314 struct GNUNET_PeerIdentity **id);
315
316
317int
318GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
319 GNUNET_TESTING_Command
320 *cmd,
321 struct
322 GNUNET_CONTAINER_MultiShortmap
323 *
324 *
325 connected_peers_map);
326int
327GNUNET_TRANSPORT_get_trait_hello_size (const struct
328 GNUNET_TESTING_Command
329 *cmd,
330 size_t **hello_size);
331 329
332int 330/**
333GNUNET_TRANSPORT_get_trait_hello (const struct 331 * Call #op on all simple traits.
334 GNUNET_TESTING_Command 332 */
335 *cmd, 333#define GNUNET_TRANSPORT_SIMPLE_TRAITS(op) \
336 char **hello); 334 op (peer_id, const struct GNUNET_PeerIdentity) \
335 op (connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \
336 op (hello_size, const size_t) \
337 op (hello, const char) \
338 op (application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \
339 op (connect_peer_state, const struct ConnectPeersState) \
340 op (state, const struct StartPeerState)
337 341
342GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT)
338 343
339int
340GNUNET_TRANSPORT_get_trait_application_handle (const struct
341 GNUNET_TESTING_Command *cmd,
342 struct
343 GNUNET_TRANSPORT_ApplicationHandle
344 **ah);
345 344
346#endif 345#endif
347/* end of transport_testing.h */ 346/* end of transport_testing.h */
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c
index 529b4690b..1bec3abd3 100644
--- a/src/transport/transport_api_cmd_backchannel_check.c
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -69,7 +69,7 @@ struct CheckState
69 /** 69 /**
70 * The testing system of this node. 70 * The testing system of this node.
71 */ 71 */
72 struct GNUNET_TESTING_System *tl_system; 72 const struct GNUNET_TESTING_System *tl_system;
73 73
74 // Label of the cmd which started the test system. 74 // Label of the cmd which started the test system.
75 const char *create_label; 75 const char *create_label;
@@ -404,9 +404,9 @@ backchannel_check_run (void *cls,
404 // char *part_one = "Delivering backchannel message from "; 404 // char *part_one = "Delivering backchannel message from ";
405 // char *part_two = " of type 1460 to udp"; 405 // char *part_two = " of type 1460 to udp";
406 const struct GNUNET_TESTING_Command *system_cmd; 406 const struct GNUNET_TESTING_Command *system_cmd;
407 struct GNUNET_TESTING_System *tl_system; 407 const struct GNUNET_TESTING_System *tl_system;
408 const struct GNUNET_TESTING_Command *peer1_cmd; 408 const struct GNUNET_TESTING_Command *peer1_cmd;
409 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 409 const struct GNUNET_TRANSPORT_ApplicationHandle *ah;
410 // struct GNUNET_PeerIdentity *peer; 410 // struct GNUNET_PeerIdentity *peer;
411 // uint32_t num; 411 // uint32_t num;
412 // struct GNUNET_TESTING_NodeConnection *pos_connection; 412 // struct GNUNET_TESTING_NodeConnection *pos_connection;
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index f65b6f666..fc925675d 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -47,11 +47,11 @@ connect_peers_run (void *cls,
47{ 47{
48 struct ConnectPeersState *cps = cls; 48 struct ConnectPeersState *cps = cls;
49 const struct GNUNET_TESTING_Command *system_cmd; 49 const struct GNUNET_TESTING_Command *system_cmd;
50 struct GNUNET_TESTING_System *tl_system; 50 const struct GNUNET_TESTING_System *tl_system;
51 51
52 52
53 const struct GNUNET_TESTING_Command *peer1_cmd; 53 const struct GNUNET_TESTING_Command *peer1_cmd;
54 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 54 const struct GNUNET_TRANSPORT_ApplicationHandle *ah;
55 struct GNUNET_PeerIdentity *peer; 55 struct GNUNET_PeerIdentity *peer;
56 char *addr; 56 char *addr;
57 enum GNUNET_NetworkType nt = 0; 57 enum GNUNET_NetworkType nt = 0;
@@ -98,7 +98,9 @@ connect_peers_run (void *cls,
98 "validating peer number %u with identity %s\n", 98 "validating peer number %u with identity %s\n",
99 num, 99 num,
100 GNUNET_i2s (peer)); 100 GNUNET_i2s (peer));
101 GNUNET_TRANSPORT_application_validate (ah, 101 GNUNET_TRANSPORT_application_validate ((struct
102 GNUNET_TRANSPORT_ApplicationHandle
103 *) ah,
102 peer, 104 peer,
103 nt, 105 nt,
104 addr); 106 addr);
@@ -176,13 +178,9 @@ connect_peers_traits (void *cls,
176 const char *trait, 178 const char *trait,
177 unsigned int index) 179 unsigned int index)
178{ 180{
179 struct StartPeerState *cps = cls; 181 struct ConnectPeersState *cps = cls;
180 struct GNUNET_TESTING_Trait traits[] = { 182 struct GNUNET_TESTING_Trait traits[] = {
181 { 183 GNUNET_TRANSPORT_make_trait_connect_peer_state ((const void *) cps),
182 .index = 0,
183 .trait_name = "state",
184 .ptr = (const void *) cps,
185 },
186 GNUNET_TESTING_trait_end () 184 GNUNET_TESTING_trait_end ()
187 }; 185 };
188 return GNUNET_TESTING_get_trait (traits, 186 return GNUNET_TESTING_get_trait (traits,
@@ -193,25 +191,6 @@ connect_peers_traits (void *cls,
193 191
194 192
195/** 193/**
196 * Function to get the trait with the struct ConnectPeersState.
197 *
198 * @param[out] sps struct ConnectPeersState.
199 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
200 *
201 */
202enum GNUNET_GenericReturnValue
203GNUNET_TRANSPORT_get_trait_connect_peer_state (
204 const struct GNUNET_TESTING_Command *cmd,
205 struct ConnectPeersState **cps)
206{
207 return cmd->traits (cmd->cls,
208 (const void **) cps,
209 "state",
210 (unsigned int) 0);
211}
212
213
214/**
215 * Create command 194 * Create command
216 * 195 *
217 * @param label name for command 196 * @param label name for command
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index 8b37dbf90..ade0cc914 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -114,7 +114,7 @@ send_simple_run (void *cls,
114 struct GNUNET_TESTING_Interpreter *is) 114 struct GNUNET_TESTING_Interpreter *is)
115{ 115{
116 struct SendSimpleState *sss = cls; 116 struct SendSimpleState *sss = cls;
117 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; 117 const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
118 const struct GNUNET_TESTING_Command *peer1_cmd; 118 const struct GNUNET_TESTING_Command *peer1_cmd;
119 // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); 119 // struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
120 struct GNUNET_HashCode hc; 120 struct GNUNET_HashCode hc;
@@ -124,7 +124,7 @@ send_simple_run (void *cls,
124 uint32_t num; 124 uint32_t num;
125 struct GNUNET_TESTING_NodeConnection *pos_connection; 125 struct GNUNET_TESTING_NodeConnection *pos_connection;
126 const struct GNUNET_TESTING_Command *system_cmd; 126 const struct GNUNET_TESTING_Command *system_cmd;
127 struct GNUNET_TESTING_System *tl_system; 127 const struct GNUNET_TESTING_System *tl_system;
128 128
129 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 129 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
130 sss->start_peer_label); 130 sss->start_peer_label);
@@ -139,8 +139,10 @@ send_simple_run (void *cls,
139 node_connections_head = GNUNET_TESTING_get_connections (sss->num, 139 node_connections_head = GNUNET_TESTING_get_connections (sss->num,
140 sss->topology); 140 sss->topology);
141 141
142 GNUNET_CONTAINER_multishortmap_iterate (connected_peers_map, send_simple_cb, 142 GNUNET_CONTAINER_multishortmap_iterate (
143 sss); 143 (struct GNUNET_CONTAINER_MultiShortmap *)
144 connected_peers_map, send_simple_cb,
145 sss);
144 /*for (int i = 0; i < 1; i++) 146 /*for (int i = 0; i < 1; i++)
145 { 147 {
146 for (pos_connection = node_connections_head; NULL != pos_connection; 148 for (pos_connection = node_connections_head; NULL != pos_connection;
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index 52eacabb2..be2ea25b4 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -167,7 +167,7 @@ start_peer_run (void *cls,
167 char *emsg = NULL; 167 char *emsg = NULL;
168 struct GNUNET_PeerIdentity dummy; 168 struct GNUNET_PeerIdentity dummy;
169 const struct GNUNET_TESTING_Command *system_cmd; 169 const struct GNUNET_TESTING_Command *system_cmd;
170 struct GNUNET_TESTING_System *tl_system; 170 const struct GNUNET_TESTING_System *tl_system;
171 char *home; 171 char *home;
172 char *transport_unix_path; 172 char *transport_unix_path;
173 char *tcp_communicator_unix_path; 173 char *tcp_communicator_unix_path;
@@ -251,7 +251,8 @@ start_peer_run (void *cls,
251 sps->no); 251 sps->no);
252 252
253 if (GNUNET_SYSERR == 253 if (GNUNET_SYSERR ==
254 GNUNET_TESTING_configuration_create (tl_system, 254 GNUNET_TESTING_configuration_create ((struct
255 GNUNET_TESTING_System *) tl_system,
255 sps->cfg)) 256 sps->cfg))
256 { 257 {
257 LOG (GNUNET_ERROR_TYPE_DEBUG, 258 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -262,7 +263,9 @@ start_peer_run (void *cls,
262 return; 263 return;
263 } 264 }
264 265
265 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, 266 sps->peer = GNUNET_TESTING_peer_configure ((struct
267 GNUNET_TESTING_System *) sps->
268 tl_system,
266 sps->cfg, 269 sps->cfg,
267 sps->no, 270 sps->no,
268 NULL, 271 NULL,
@@ -407,36 +410,14 @@ start_peer_traits (void *cls,
407 410
408 411
409 struct GNUNET_TESTING_Trait traits[] = { 412 struct GNUNET_TESTING_Trait traits[] = {
410 { 413 GNUNET_TRANSPORT_make_trait_application_handle ((const void *) ah),
411 .index = 0, 414 GNUNET_TRANSPORT_make_trait_peer_id ((const void *) id),
412 .trait_name = "application_handle", 415 GNUNET_TRANSPORT_make_trait_connected_peers_map ((const
413 .ptr = (const void *) ah, 416 void *)
414 }, 417 connected_peers_map),
415 { 418 GNUNET_TRANSPORT_make_trait_hello ((const void *) hello),
416 .index = 1, 419 GNUNET_TRANSPORT_make_trait_hello_size ((const void *) hello_size),
417 .trait_name = "peer_id", 420 GNUNET_TRANSPORT_make_trait_state ((const void *) sps),
418 .ptr = (const void *) id,
419 },
420 {
421 .index = 2,
422 .trait_name = "connected_peers_map",
423 .ptr = (const void *) connected_peers_map,
424 },
425 {
426 .index = 3,
427 .trait_name = "hello",
428 .ptr = (const void *) hello,
429 },
430 {
431 .index = 4,
432 .trait_name = "hello_size",
433 .ptr = (const void *) hello_size,
434 },
435 {
436 .index = 5,
437 .trait_name = "state",
438 .ptr = (const void *) sps,
439 },
440 GNUNET_TESTING_trait_end () 421 GNUNET_TESTING_trait_end ()
441 }; 422 };
442 423
@@ -448,127 +429,6 @@ start_peer_traits (void *cls,
448 429
449 430
450/** 431/**
451 * Function to get the trait with the struct StartPeerState.
452 *
453 * @param[out] sps struct StartPeerState.
454 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
455 *
456 */
457int
458GNUNET_TRANSPORT_get_trait_state (
459 const struct GNUNET_TESTING_Command *cmd,
460 struct StartPeerState **sps)
461{
462 return cmd->traits (cmd->cls,
463 (const void **) sps,
464 "state",
465 (unsigned int) 5);
466}
467
468
469/**
470 * Function to get the trait with the size of the hello.
471 *
472 * @param[out] hello_size size of hello.
473 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
474 *
475 */
476int
477GNUNET_TRANSPORT_get_trait_hello_size (const struct
478 GNUNET_TESTING_Command
479 *cmd,
480 size_t **hello_size)
481{
482 return cmd->traits (cmd->cls,
483 (const void **) hello_size,
484 "hello_size",
485 (unsigned int) 4);
486}
487
488
489/**
490 * Function to get the trait with the hello.
491 *
492 * @param[out] hello The hello for the peer.
493 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
494 *
495 */
496int
497GNUNET_TRANSPORT_get_trait_hello (const struct
498 GNUNET_TESTING_Command
499 *cmd,
500 char **hello)
501{
502 return cmd->traits (cmd->cls,
503 (const void **) hello,
504 "hello",
505 (unsigned int) 3);
506}
507
508
509/**
510 * Function to get the trait with the map of connected peers.
511 *
512 * @param[out] connected_peers_map The map with connected peers.
513 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
514 *
515 */
516int
517GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
518 GNUNET_TESTING_Command
519 *cmd,
520 struct
521 GNUNET_CONTAINER_MultiShortmap
522 *
523 *
524 connected_peers_map)
525{
526 return cmd->traits (cmd->cls,
527 (const void **) connected_peers_map,
528 "connected_peers_map",
529 (unsigned int) 2);
530}
531
532
533/**
534 * Function to get the trait with the transport application handle.
535 *
536 * @param[out] ah The application handle.
537 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
538 */
539int
540GNUNET_TRANSPORT_get_trait_application_handle (const struct
541 GNUNET_TESTING_Command *cmd,
542 struct
543 GNUNET_TRANSPORT_ApplicationHandle
544 **ah)
545{
546 return cmd->traits (cmd->cls,
547 (const void **) ah,
548 "application_handle",
549 (unsigned int) 0);
550}
551
552
553/**
554 * Function to get the trait with the peer id.
555 *
556 * @param[out] id The peer id.
557 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
558 */
559int
560GNUNET_TRANSPORT_get_trait_peer_id (const struct
561 GNUNET_TESTING_Command *cmd,
562 struct GNUNET_PeerIdentity **id)
563{
564 return cmd->traits (cmd->cls,
565 (const void **) id,
566 "peer_id",
567 (unsigned int) 1);
568}
569
570
571/**
572 * Create command. 432 * Create command.
573 * 433 *
574 * @param label name for command. 434 * @param label name for command.
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
index 97408b083..4ca730add 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -58,7 +58,7 @@ stop_peer_run (void *cls,
58 struct GNUNET_TESTING_Interpreter *is) 58 struct GNUNET_TESTING_Interpreter *is)
59{ 59{
60 struct StopPeerState *stop_ps = cls; 60 struct StopPeerState *stop_ps = cls;
61 struct StartPeerState *sps; 61 const struct StartPeerState *sps;
62 const struct GNUNET_TESTING_Command *start_cmd; 62 const struct GNUNET_TESTING_Command *start_cmd;
63 63
64 start_cmd = GNUNET_TESTING_interpreter_lookup_command (is, 64 start_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
@@ -69,24 +69,20 @@ stop_peer_run (void *cls,
69 if (NULL != sps->pic) 69 if (NULL != sps->pic)
70 { 70 {
71 GNUNET_PEERSTORE_iterate_cancel (sps->pic); 71 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
72 sps->pic = NULL;
73 } 72 }
74 if (NULL != sps->th) 73 if (NULL != sps->th)
75 { 74 {
76 GNUNET_TRANSPORT_core_disconnect (sps->th); 75 GNUNET_TRANSPORT_core_disconnect (sps->th);
77 sps->th = NULL;
78 } 76 }
79 if (NULL != sps->ah) 77 if (NULL != sps->ah)
80 { 78 {
81 GNUNET_TRANSPORT_application_done (sps->ah); 79 GNUNET_TRANSPORT_application_done (sps->ah);
82 sps->ah = NULL;
83 } 80 }
84 if (NULL != sps->ph) 81 if (NULL != sps->ph)
85 { 82 {
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
87 "Disconnecting from PEERSTORE service\n"); 84 "Disconnecting from PEERSTORE service\n");
88 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO); 85 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
89 sps->ph = NULL;
90 } 86 }
91 if (NULL != sps->peer) 87 if (NULL != sps->peer)
92 { 88 {
@@ -99,12 +95,9 @@ stop_peer_run (void *cls,
99 GNUNET_i2s (&sps->id)); 95 GNUNET_i2s (&sps->id));
100 } 96 }
101 GNUNET_TESTING_peer_destroy (sps->peer); 97 GNUNET_TESTING_peer_destroy (sps->peer);
102 sps->peer = NULL;
103 } 98 }
104 if (NULL != sps->rh_task) 99 if (NULL != sps->rh_task)
105 GNUNET_SCHEDULER_cancel (sps->rh_task); 100 GNUNET_SCHEDULER_cancel (sps->rh_task);
106 sps->rh_task = NULL;
107
108} 101}
109 102
110 103