aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-12-13 22:40:46 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-12-13 22:40:46 +0900
commite7b082de7fcdb394deecde4a098aa927bcd72fdb (patch)
tree4f045bb6c68961c599e7cf5783b7429067ccbe97 /src/testing
parent0c9b0159cc1c9aa3464fc41581e4bb53ecc7d1db (diff)
downloadgnunet-e7b082de7fcdb394deecde4a098aa927bcd72fdb.tar.gz
gnunet-e7b082de7fcdb394deecde4a098aa927bcd72fdb.zip
-more namespace cleanup and comments regarding API
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/gnunet-cmds-helper.c2
-rw-r--r--src/testing/testing.h27
-rw-r--r--src/testing/testing_api_cmd_barrier.c58
-rw-r--r--src/testing/testing_api_cmd_barrier_reached.c6
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c15
-rw-r--r--src/testing/testing_api_loop.c40
6 files changed, 65 insertions, 83 deletions
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 458830cb9..4d3da6260 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -419,7 +419,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
419 struct CommandBarrierAdvanced *adm = (struct CommandBarrierAdvanced *) message; 419 struct CommandBarrierAdvanced *adm = (struct CommandBarrierAdvanced *) message;
420 420
421 barrier_name = (const char *) &adm[1]; 421 barrier_name = (const char *) &adm[1];
422 GNUNET_TESTING_finish_attached_cmds (is, barrier_name); 422 TST_interpreter_finish_attached_cmds (is, barrier_name);
423 return GNUNET_OK; 423 return GNUNET_OK;
424 } 424 }
425 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 425 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
diff --git a/src/testing/testing.h b/src/testing/testing.h
index 7372b143e..debcec39a 100644
--- a/src/testing/testing.h
+++ b/src/testing/testing.h
@@ -265,6 +265,8 @@ GNUNET_TESTING_cmd_batch_set_current_ (const struct GNUNET_TESTING_Command *cmd,
265// wait on other peers to reach it. 265// wait on other peers to reach it.
266/** 266/**
267 * FIXME: Documentation 267 * FIXME: Documentation
268 * FIXME: Now this, as it returns a Command, seems to me like it should be
269 * part of the public API?
268 * Create command. 270 * Create command.
269 * 271 *
270 * @param label name for command. 272 * @param label name for command.
@@ -287,9 +289,13 @@ GNUNET_TESTING_cmd_barrier_reached (
287 289
288 290
289/** 291/**
290 * FIXME: Return type
291 * FIXME: Documentation
292 * Can we advance the barrier? 292 * Can we advance the barrier?
293 * FIXME: As this is not in testing.h it should be in another namespace.
294 * Possibly BARRIER_can_advance. However, as this is also used in a netjail cmd,
295 * I am not sure if this needs to be public? Maybe there should be a barrier
296 * trait that returns a barrier where this helper function can be called on?
297 * Barriers are usually also not "advanced" but "crossed" or "passed"
298 * but it seems to me that the word here should correctly be "reached"?
293 * 299 *
294 * @param barrier The barrier in question. 300 * @param barrier The barrier in question.
295 * @return GNUNET_YES if we can advance the barrier, GNUNET_NO if not. 301 * @return GNUNET_YES if we can advance the barrier, GNUNET_NO if not.
@@ -307,7 +313,7 @@ GNUNET_TESTING_can_barrier_advance (struct GNUNET_TESTING_Barrier *barrier);
307 * @param global_node_number The global number of the node to inform. 313 * @param global_node_number The global number of the node to inform.
308 */ 314 */
309void 315void
310GNUNET_TESTING_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is, 316TST_interpreter_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is,
311 const char *barrier_name, 317 const char *barrier_name,
312 unsigned int global_node_number); 318 unsigned int global_node_number);
313 319
@@ -318,12 +324,13 @@ GNUNET_TESTING_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is,
318 * @param barrier The barrier in question. 324 * @param barrier The barrier in question.
319 */ 325 */
320void 326void
321GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, 327TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
322 const char *barrier_name); 328 const char *barrier_name);
323 329
324 330
325/** 331/**
326 * Send Message to master loop that cmds being attached to a barrier. 332 * Send Message to master loop that cmds being attached to a barrier.
333 * FIXME: Unused function
327 * 334 *
328 * @param is The interpreter loop. 335 * @param is The interpreter loop.
329 * @param barrier_name The name of the barrier to advance. 336 * @param barrier_name The name of the barrier to advance.
@@ -341,13 +348,17 @@ GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is,
341 348
342/** 349/**
343 * Getting a node from a map by global node number. 350 * Getting a node from a map by global node number.
351 * FIXME: This is a barrier helper function not related to a command but it is
352 * implemented in the *_cmd_barrier.c file.
353 * Maybe move into a separate file like testing_barrier.c; see also can
354 * barrier advance above
344 * 355 *
345 * @param nodes The map. 356 * @param nodes The map.
346 * @param node_number The global node number. 357 * @param node_number The global node number.
347 * @return The node. 358 * @return The node.
348 */ 359 */
349struct GNUNET_TESTING_NetjailNode * 360struct GNUNET_TESTING_NetjailNode *
350GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, 361GNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier,
351 unsigned int node_number); 362 unsigned int node_number);
352 363
353 364
@@ -357,7 +368,7 @@ GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes,
357 * @param is The interpreter. 368 * @param is The interpreter.
358 */ 369 */
359void 370void
360GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is); 371TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is);
361 372
362 373
363/** 374/**
@@ -368,7 +379,7 @@ GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is);
368 * @return The barrier. 379 * @return The barrier.
369 */ 380 */
370struct GNUNET_TESTING_Barrier * 381struct GNUNET_TESTING_Barrier *
371GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, 382TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is,
372 const char *barrier_name); 383 const char *barrier_name);
373 384
374 385
@@ -379,7 +390,7 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is,
379 * @param barrier The barrier to add. 390 * @param barrier The barrier to add.
380 */ 391 */
381void 392void
382GNUNET_TESTING_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, 393TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is,
383 struct GNUNET_TESTING_Barrier *barrier); 394 struct GNUNET_TESTING_Barrier *barrier);
384 395
385 396
diff --git a/src/testing/testing_api_cmd_barrier.c b/src/testing/testing_api_cmd_barrier.c
index 7e4e67dea..bc4f79eb6 100644
--- a/src/testing/testing_api_cmd_barrier.c
+++ b/src/testing/testing_api_cmd_barrier.c
@@ -43,16 +43,7 @@ struct BarrierState
43 const char *label; 43 const char *label;
44}; 44};
45 45
46 46// FIXME Unused function
47/**
48 * Send Message to master loop that cmds being attached to a barrier.
49 *
50 * @param is The interpreter loop.
51 * @param barrier_name The name of the barrier to advance.
52 * @param subnet_number The number of the subnet.
53 * @param node_number The node to inform.
54 * @param write_message Callback to write messages to the master loop.
55 */
56void 47void
57GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, 48GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is,
58 char *barrier_name, 49 char *barrier_name,
@@ -78,40 +69,6 @@ GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is,
78} 69}
79 70
80 71
81/**
82 * Send Message to netjail nodes that a barrier can be advanced.
83 *
84 * @param is The interpreter loop.
85 * @param barrier_name The name of the barrier to advance.
86 * @param global_node_number The global number of the node to inform.
87 */
88void
89GNUNET_TESTING_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is,
90 const char *barrier_name,
91 unsigned int global_node_number)
92{
93 struct CommandBarrierAdvanced *adm = GNUNET_new (struct
94 CommandBarrierAdvanced);
95 size_t msg_length = sizeof(struct CommandBarrierAdvanced);
96 size_t name_len;
97
98 name_len = strlen (barrier_name) + 1;
99 adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ADVANCED);
100 adm->header.size = htons ((uint16_t) msg_length);
101 memcpy (&adm[1], barrier_name, name_len);
102 GNUNET_TESTING_send_message_to_netjail (is,
103 global_node_number,
104 &adm->header);
105 GNUNET_free (adm);
106}
107
108
109/**
110 * Can we advance the barrier?
111 *
112 * @param barrier The barrier in question.
113 * @return GNUNET_YES if we can advance the barrier, GNUNET_NO if not.
114 */
115unsigned int 72unsigned int
116GNUNET_TESTING_can_barrier_advance (struct GNUNET_TESTING_Barrier *barrier) 73GNUNET_TESTING_can_barrier_advance (struct GNUNET_TESTING_Barrier *barrier)
117{ 74{
@@ -186,18 +143,11 @@ barrier_run (void *cls,
186{ 143{
187 struct BarrierState *brs = cls; 144 struct BarrierState *brs = cls;
188 145
189 GNUNET_TESTING_interpreter_add_barrier (is, brs->barrier); 146 TST_interpreter_add_barrier (is, brs->barrier);
190} 147}
191 148
192/**
193 * Getting a node from a map by global node number.
194 *
195 * @param nodes The map.
196 * @param node_number The global node number.
197 * @return The node.
198 */
199struct GNUNET_TESTING_NetjailNode * 149struct GNUNET_TESTING_NetjailNode *
200GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, 150GNUNET_TESTING_barrier_get_node (struct GNUNET_TESTING_Barrier *barrier,
201 unsigned int node_number) 151 unsigned int node_number)
202{ 152{
203 struct GNUNET_HashCode hc; 153 struct GNUNET_HashCode hc;
@@ -207,7 +157,7 @@ GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes,
207 memcpy (&key, 157 memcpy (&key,
208 &hc, 158 &hc,
209 sizeof (key)); 159 sizeof (key));
210 return GNUNET_CONTAINER_multishortmap_get (nodes, &key); 160 return GNUNET_CONTAINER_multishortmap_get (barrier->nodes, &key);
211} 161}
212 162
213 163
diff --git a/src/testing/testing_api_cmd_barrier_reached.c b/src/testing/testing_api_cmd_barrier_reached.c
index eca422b1d..8d52310c9 100644
--- a/src/testing/testing_api_cmd_barrier_reached.c
+++ b/src/testing/testing_api_cmd_barrier_reached.c
@@ -93,13 +93,13 @@ barrier_reached_run (void *cls,
93 struct GNUNET_TESTING_CommandBarrierReached *msg; 93 struct GNUNET_TESTING_CommandBarrierReached *msg;
94 size_t name_len; 94 size_t name_len;
95 95
96 barrier = GNUNET_TESTING_get_barrier (is, brs->barrier_name); 96 barrier = TST_interpreter_get_barrier (is, brs->barrier_name);
97 if (NULL == barrier) 97 if (NULL == barrier)
98 { 98 {
99 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier); 99 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
100 barrier->shadow = GNUNET_YES; 100 barrier->shadow = GNUNET_YES;
101 barrier->name = brs->label; 101 barrier->name = brs->label;
102 GNUNET_TESTING_interpreter_add_barrier (is, barrier); 102 TST_interpreter_add_barrier (is, barrier);
103 } 103 }
104 barrier->reached++; 104 barrier->reached++;
105 if (GNUNET_TESTING_can_barrier_advance (barrier)) 105 if (GNUNET_TESTING_can_barrier_advance (barrier))
@@ -107,7 +107,7 @@ barrier_reached_run (void *cls,
107 //FIXME cmd uninitialized 107 //FIXME cmd uninitialized
108 GNUNET_assert (NULL != cmd); 108 GNUNET_assert (NULL != cmd);
109 cmd->asynchronous_finish = GNUNET_YES; 109 cmd->asynchronous_finish = GNUNET_YES;
110 GNUNET_TESTING_finish_attached_cmds (is, barrier->name); 110 TST_interpreter_finish_attached_cmds (is, barrier->name);
111 } 111 }
112 else if (GNUNET_NO == brs->asynchronous_finish) 112 else if (GNUNET_NO == brs->asynchronous_finish)
113 { 113 {
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 62b628928..40a23c67c 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -207,6 +207,7 @@ struct TestingSystemCount
207 struct GNUNET_MessageHeader *msg; 207 struct GNUNET_MessageHeader *msg;
208}; 208};
209 209
210
210/** 211/**
211* Code to clean up resource this cmd used. 212* Code to clean up resource this cmd used.
212* 213*
@@ -216,7 +217,7 @@ static void
216netjail_exec_cleanup (void *cls) 217netjail_exec_cleanup (void *cls)
217{ 218{
218 struct NetJailState *ns = cls; 219 struct NetJailState *ns = cls;
219 GNUNET_TESTING_delete_barriers (ns->is); 220 TST_interpreter_delete_barriers (ns->is);
220 GNUNET_free (ns); 221 GNUNET_free (ns);
221} 222}
222 223
@@ -354,9 +355,9 @@ barrier_attached (struct NetJailState *ns, const struct
354 355
355 am = (struct CommandBarrierAttached *) message; 356 am = (struct CommandBarrierAttached *) message;
356 barrier_name = (const char *) &am[1]; 357 barrier_name = (const char *) &am[1];
357 barrier = GNUNET_TESTING_get_barrier (ns->is, barrier_name); 358 barrier = TST_interpreter_get_barrier (ns->is, barrier_name);
358 GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow); 359 GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow);
359 node = GNUNET_TESTING_barrier_get_node (barrier->nodes, am->node_number); 360 node = GNUNET_TESTING_barrier_get_node (barrier, am->node_number);
360 if (NULL == node) 361 if (NULL == node)
361 { 362 {
362 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode); 363 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
@@ -385,12 +386,12 @@ barrier_reached (struct NetJailState *ns, const struct
385 *) message; 386 *) message;
386 387
387 barrier_name = (const char *) &rm[1]; 388 barrier_name = (const char *) &rm[1];
388 barrier = GNUNET_TESTING_get_barrier (ns->is, barrier_name); 389 barrier = TST_interpreter_get_barrier (ns->is, barrier_name);
389 GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow); 390 GNUNET_assert (NULL != barrier && GNUNET_NO == barrier->shadow);
390 barrier->reached++; 391 barrier->reached++;
391 if (GNUNET_TESTING_can_barrier_advance (barrier)) 392 if (GNUNET_TESTING_can_barrier_advance (barrier))
392 { 393 {
393 GNUNET_TESTING_finish_attached_cmds (ns->is, barrier->name); 394 TST_interpreter_finish_attached_cmds (ns->is, barrier->name);
394 } 395 }
395} 396}
396 397
@@ -702,12 +703,12 @@ start_helper (struct NetJailState *ns,
702 703
703 for (pos = barriers->head; NULL != pos; pos = pos->next) 704 for (pos = barriers->head; NULL != pos; pos = pos->next)
704 { 705 {
705 barrier = GNUNET_TESTING_get_barrier (ns->is, pos->barrier_name); 706 barrier = TST_interpreter_get_barrier (ns->is, pos->barrier_name);
706 if (NULL == barrier || GNUNET_YES == barrier->shadow) 707 if (NULL == barrier || GNUNET_YES == barrier->shadow)
707 { 708 {
708 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier); 709 barrier = GNUNET_new (struct GNUNET_TESTING_Barrier);
709 barrier->name = pos->barrier_name; 710 barrier->name = pos->barrier_name;
710 GNUNET_TESTING_interpreter_add_barrier (ns->is, barrier); 711 TST_interpreter_add_barrier (ns->is, barrier);
711 712
712 barrier->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); 713 barrier->nodes = GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
713 } 714 }
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index d7456b91f..7d76979dc 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -665,6 +665,27 @@ GNUNET_TESTING_send_message_to_netjail (struct GNUNET_TESTING_Interpreter *is,
665 is); 665 is);
666} 666}
667 667
668void
669TST_interpreter_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is,
670 const char *barrier_name,
671 unsigned int global_node_number)
672{
673 struct CommandBarrierAdvanced *adm = GNUNET_new (struct
674 CommandBarrierAdvanced);
675 size_t msg_length = sizeof(struct CommandBarrierAdvanced);
676 size_t name_len;
677
678 name_len = strlen (barrier_name) + 1;
679 adm->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ADVANCED);
680 adm->header.size = htons ((uint16_t) msg_length);
681 memcpy (&adm[1], barrier_name, name_len);
682 GNUNET_TESTING_send_message_to_netjail (is,
683 global_node_number,
684 &adm->header);
685 GNUNET_free (adm);
686}
687
688
668 689
669int 690int
670free_barrier_node_cb (void *cls, 691free_barrier_node_cb (void *cls,
@@ -678,9 +699,9 @@ free_barrier_node_cb (void *cls,
678 699
679 if (GNUNET_NO == is->finishing) 700 if (GNUNET_NO == is->finishing)
680 { 701 {
681 GNUNET_TESTING_send_barrier_advance (is, 702 TST_interpreter_send_barrier_advance (is,
682 barrier->name, 703 barrier->name,
683 node->node_number); 704 node->node_number);
684 } 705 }
685 GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node); 706 GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node);
686 return GNUNET_YES; 707 return GNUNET_YES;
@@ -695,7 +716,7 @@ free_barrier_node_cb (void *cls,
695 * @return The barrier. 716 * @return The barrier.
696 */ 717 */
697struct GNUNET_TESTING_Barrier * 718struct GNUNET_TESTING_Barrier *
698GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, 719TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is,
699 const char *barrier_name) 720 const char *barrier_name)
700{ 721{
701 struct GNUNET_HashCode hc; 722 struct GNUNET_HashCode hc;
@@ -718,12 +739,12 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is,
718 * @param barrier The barrier in question. 739 * @param barrier The barrier in question.
719 */ 740 */
720void 741void
721GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, 742TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
722 const char *barrier_name) 743 const char *barrier_name)
723{ 744{
724 struct CommandListEntry *pos; 745 struct CommandListEntry *pos;
725 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; 746 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
726 struct GNUNET_TESTING_Barrier *barrier = GNUNET_TESTING_get_barrier (is, 747 struct GNUNET_TESTING_Barrier *barrier = TST_interpreter_get_barrier (is,
727 barrier_name); 748 barrier_name);
728 749
729 while (NULL != (pos = barrier->cmds_head)) 750 while (NULL != (pos = barrier->cmds_head))
@@ -783,14 +804,13 @@ free_barriers_cb (void *cls,
783 return GNUNET_YES; 804 return GNUNET_YES;
784} 805}
785 806
786
787/** 807/**
788 * Deleting all barriers create in the context of this interpreter. 808 * Deleting all barriers create in the context of this interpreter.
789 * 809 *
790 * @param is The interpreter. 810 * @param is The interpreter.
791 */ 811 */
792void 812void
793GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is) 813TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is)
794{ 814{
795 GNUNET_CONTAINER_multishortmap_iterate (is->barriers, 815 GNUNET_CONTAINER_multishortmap_iterate (is->barriers,
796 free_barriers_cb, 816 free_barriers_cb,
@@ -806,7 +826,7 @@ GNUNET_TESTING_delete_barriers (struct GNUNET_TESTING_Interpreter *is)
806 * @param barrier The barrier to add. 826 * @param barrier The barrier to add.
807 */ 827 */
808void 828void
809GNUNET_TESTING_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, 829TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is,
810 struct GNUNET_TESTING_Barrier *barrier) 830 struct GNUNET_TESTING_Barrier *barrier)
811{ 831{
812 struct GNUNET_HashCode hc; 832 struct GNUNET_HashCode hc;