diff options
Diffstat (limited to 'src/testing/testing_api_cmd_block_until_external_trigger.c')
-rw-r--r-- | src/testing/testing_api_cmd_block_until_external_trigger.c | 63 |
1 files changed, 56 insertions, 7 deletions
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 b416fa595..aeb9ffda3 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c | |||
@@ -39,9 +39,14 @@ | |||
39 | struct BlockState | 39 | struct BlockState |
40 | { | 40 | { |
41 | /** | 41 | /** |
42 | * Flag to indicate if all peers have started. | 42 | * Context for our asynchronous completion. |
43 | */ | 43 | */ |
44 | unsigned int *stop_blocking; | 44 | struct GNUNET_TESTING_AsyncContext ac; |
45 | |||
46 | /** | ||
47 | * The label of this command. | ||
48 | */ | ||
49 | const char *label; | ||
45 | }; | 50 | }; |
46 | 51 | ||
47 | 52 | ||
@@ -57,6 +62,47 @@ block_until_all_peers_started_cleanup (void *cls) | |||
57 | GNUNET_free (bs); | 62 | GNUNET_free (bs); |
58 | } | 63 | } |
59 | 64 | ||
65 | static int | ||
66 | block_until_external_trigger_traits (void *cls, | ||
67 | const void **ret, | ||
68 | const char *trait, | ||
69 | unsigned int index) | ||
70 | { | ||
71 | struct BlockState *bs = cls; | ||
72 | struct GNUNET_TESTING_AsyncContext *ac = &bs->ac; | ||
73 | struct GNUNET_TESTING_Trait traits[] = { | ||
74 | { | ||
75 | .index = 0, | ||
76 | .trait_name = "async_context", | ||
77 | .ptr = (const void *) ac, | ||
78 | }, | ||
79 | GNUNET_TESTING_trait_end () | ||
80 | }; | ||
81 | |||
82 | return GNUNET_TESTING_get_trait (traits, | ||
83 | ret, | ||
84 | trait, | ||
85 | index); | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Function to get the trait with the async context. | ||
91 | * | ||
92 | * @param[out] ac GNUNET_TESTING_AsyncContext. | ||
93 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
94 | */ | ||
95 | int | ||
96 | GNUNET_TESTING_get_trait_async_context ( | ||
97 | const struct GNUNET_TESTING_Command *cmd, | ||
98 | struct GNUNET_TESTING_AsyncContext **ac) | ||
99 | { | ||
100 | return cmd->traits (cmd->cls, | ||
101 | (const void **) ac, | ||
102 | "async_context", | ||
103 | (unsigned int) 0); | ||
104 | } | ||
105 | |||
60 | 106 | ||
61 | /** | 107 | /** |
62 | * This function does nothing but to start the cmd. | 108 | * This function does nothing but to start the cmd. |
@@ -66,8 +112,11 @@ static void | |||
66 | block_until_all_peers_started_run (void *cls, | 112 | block_until_all_peers_started_run (void *cls, |
67 | struct GNUNET_TESTING_Interpreter *is) | 113 | struct GNUNET_TESTING_Interpreter *is) |
68 | { | 114 | { |
115 | struct BlockState *bs = cls; | ||
116 | |||
69 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
70 | "block_until_all_peers_started_run!\n"); | 118 | "block %s running!\n", |
119 | bs->label); | ||
71 | } | 120 | } |
72 | 121 | ||
73 | 122 | ||
@@ -79,20 +128,20 @@ block_until_all_peers_started_run (void *cls, | |||
79 | * @return command. | 128 | * @return command. |
80 | */ | 129 | */ |
81 | struct GNUNET_TESTING_Command | 130 | struct GNUNET_TESTING_Command |
82 | GNUNET_TESTING_cmd_block_until_external_trigger (const char *label, | 131 | GNUNET_TESTING_cmd_block_until_external_trigger (const char *label) |
83 | unsigned int * | ||
84 | stop_blocking) | ||
85 | { | 132 | { |
86 | struct BlockState *bs; | 133 | struct BlockState *bs; |
87 | 134 | ||
88 | bs = GNUNET_new (struct BlockState); | 135 | bs = GNUNET_new (struct BlockState); |
89 | bs->stop_blocking = stop_blocking; | 136 | bs->label = label; |
90 | { | 137 | { |
91 | struct GNUNET_TESTING_Command cmd = { | 138 | struct GNUNET_TESTING_Command cmd = { |
92 | .cls = bs, | 139 | .cls = bs, |
93 | .label = label, | 140 | .label = label, |
94 | .run = &block_until_all_peers_started_run, | 141 | .run = &block_until_all_peers_started_run, |
142 | .ac = &bs->ac, | ||
95 | .cleanup = &block_until_all_peers_started_cleanup, | 143 | .cleanup = &block_until_all_peers_started_cleanup, |
144 | .traits = block_until_external_trigger_traits | ||
96 | }; | 145 | }; |
97 | 146 | ||
98 | return cmd; | 147 | return cmd; |