aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_batch.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-12-08 20:51:35 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-12-08 20:51:35 +0900
commit7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e (patch)
treeaaabeaa4b8e8a0afe82d8d7538d271525105da48 /src/testing/testing_api_cmd_batch.c
parentdccf4142eaac44711692c295d81e0103c8042cd2 (diff)
downloadgnunet-7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e.tar.gz
gnunet-7768a7a75ee959b53cf7a7acdfa0a8c7b17de99e.zip
TESTING: Sanitize API. Add new GNUNET_TESTING_command_new API
This commit changes the label member of GNUNET_TRANSPORT_Command to a static, fixed length buffer allocated with the struct itself. The check for the end of a command array should be done by checking the run command instead of the label.
Diffstat (limited to 'src/testing/testing_api_cmd_batch.c')
-rw-r--r--src/testing/testing_api_cmd_batch.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c
index e7ecbf28d..7dc990855 100644
--- a/src/testing/testing_api_cmd_batch.c
+++ b/src/testing/testing_api_cmd_batch.c
@@ -62,13 +62,13 @@ batch_run (void *cls,
62{ 62{
63 struct BatchState *bs = cls; 63 struct BatchState *bs = cls;
64 64
65 if (NULL != bs->batch[bs->batch_ip].label) 65 if (NULL != bs->batch[bs->batch_ip].run)
66 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 66 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
67 "Running batched command: %s\n", 67 "Running batched command: %s\n",
68 bs->batch[bs->batch_ip].label); 68 bs->batch[bs->batch_ip].label);
69 69
70 /* hit end command, leap to next top-level command. */ 70 /* hit end command, leap to next top-level command. */
71 if (NULL == bs->batch[bs->batch_ip].label) 71 if (NULL == bs->batch[bs->batch_ip].run)
72 { 72 {
73 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 73 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
74 "Exiting from batch: %s\n", 74 "Exiting from batch: %s\n",
@@ -96,7 +96,7 @@ batch_cleanup (void *cls)
96 struct BatchState *bs = cls; 96 struct BatchState *bs = cls;
97 97
98 for (unsigned int i = 0; 98 for (unsigned int i = 0;
99 NULL != bs->batch[i].label; 99 NULL != bs->batch[i].run;
100 i++) 100 i++)
101 bs->batch[i].cleanup (bs->batch[i].cls); 101 bs->batch[i].cleanup (bs->batch[i].cls);
102 GNUNET_free (bs->batch); 102 GNUNET_free (bs->batch);
@@ -161,7 +161,7 @@ GNUNET_TESTING_cmd_batch (const char *label,
161 bs = GNUNET_new (struct BatchState); 161 bs = GNUNET_new (struct BatchState);
162 bs->label = label; 162 bs->label = label;
163 /* Get number of commands. */ 163 /* Get number of commands. */
164 for (i = 0; NULL != batch[i].label; i++) 164 for (i = 0; NULL != batch[i].run; i++)
165 /* noop */ 165 /* noop */
166 ; 166 ;
167 167
@@ -170,17 +170,10 @@ GNUNET_TESTING_cmd_batch (const char *label,
170 memcpy (bs->batch, 170 memcpy (bs->batch,
171 batch, 171 batch,
172 sizeof (struct GNUNET_TESTING_Command) * i); 172 sizeof (struct GNUNET_TESTING_Command) * i);
173 { 173 return GNUNET_TESTING_command_new (bs, label,
174 struct GNUNET_TESTING_Command cmd = { 174 &batch_run,
175 .cls = bs, 175 &batch_cleanup,
176 .label = GNUNET_strdup (label), 176 &batch_traits, NULL);
177 .run = &batch_run,
178 .cleanup = &batch_cleanup,
179 .traits = &batch_traits
180 };
181
182 return cmd;
183 }
184} 177}
185 178
186 179
@@ -189,7 +182,7 @@ GNUNET_TESTING_cmd_batch_next_ (void *cls)
189{ 182{
190 struct BatchState *bs = cls; 183 struct BatchState *bs = cls;
191 184
192 if (NULL == bs->batch[bs->batch_ip].label) 185 if (NULL == bs->batch[bs->batch_ip].run)
193 return false; 186 return false;
194 bs->batch[bs->batch_ip].finish_time 187 bs->batch[bs->batch_ip].finish_time
195 = GNUNET_TIME_absolute_get (); 188 = GNUNET_TIME_absolute_get ();