diff options
Diffstat (limited to 'src/include/gnunet_testing_ng_lib.h')
-rw-r--r-- | src/include/gnunet_testing_ng_lib.h | 399 |
1 files changed, 124 insertions, 275 deletions
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 | */ |
577 | struct GNUNET_PeerIdentity * | 585 | struct GNUNET_PeerIdentity * |
578 | GNUNET_TESTING_get_pub_key (unsigned int num, struct | 586 | GNUNET_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 | */ | ||
655 | enum GNUNET_GenericReturnValue | ||
656 | GNUNET_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 | */ | ||
669 | struct GNUNET_TESTING_Trait | ||
670 | GNUNET_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 | */ | ||
680 | struct GNUNET_TESTING_Trait | ||
681 | GNUNET_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 | */ | ||
693 | enum GNUNET_GenericReturnValue | ||
694 | GNUNET_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 | */ | ||
705 | struct GNUNET_TESTING_Trait | ||
706 | GNUNET_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 | */ | ||
718 | enum GNUNET_GenericReturnValue | ||
719 | GNUNET_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 | */ | ||
730 | struct GNUNET_TESTING_Trait | ||
731 | GNUNET_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 | */ | ||
743 | enum GNUNET_GenericReturnValue | ||
744 | GNUNET_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 | */ | ||
756 | struct GNUNET_TESTING_Trait | ||
757 | GNUNET_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 | */ | ||
769 | enum GNUNET_GenericReturnValue | ||
770 | GNUNET_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 | */ | ||
784 | enum GNUNET_GenericReturnValue | ||
785 | GNUNET_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 | */ | ||
799 | struct GNUNET_TESTING_Trait | ||
800 | GNUNET_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 | */ | ||
813 | struct GNUNET_TESTING_Trait | ||
814 | GNUNET_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 ( \ |
829 | enum GNUNET_GenericReturnValue | 665 | type * value); |
830 | GNUNET_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, \ |
844 | enum GNUNET_GenericReturnValue | 680 | (const void **) ret, \ |
845 | GNUNET_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 | } |
858 | struct GNUNET_TESTING_Trait | 694 | |
859 | GNUNET_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 ( \ |
872 | enum GNUNET_GenericReturnValue | 708 | unsigned int index, \ |
873 | GNUNET_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) \ |
886 | struct GNUNET_TESTING_Trait | 722 | { \ |
887 | GNUNET_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), \ |
901 | int | 737 | .ptr = (const void *) value \ |
902 | GNUNET_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 | /** |
915 | struct GNUNET_TESTING_Trait | 751 | * Call #op on all indexed traits. |
916 | GNUNET_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 | |||
765 | GNUNET_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | ||
766 | |||
767 | GNUNET_TESTING_INDEXED_TRAITS (GNUNET_TESTING_MAKE_DECL_INDEXED_TRAIT) | ||
919 | 768 | ||
920 | #endif | 769 | #endif |