diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-09 12:07:26 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-09 12:07:26 +0900 |
commit | 4f46e2f2e72a07871b14c0a9aed70438616c4dd5 (patch) | |
tree | f4b904d75ec9fc977aa662d6c8ed0a4d71a22097 /src/include | |
parent | 1b3f6f366fc62e5519bb73fefe8c21c2eed20edf (diff) | |
download | gnunet-4f46e2f2e72a07871b14c0a9aed70438616c4dd5.tar.gz gnunet-4f46e2f2e72a07871b14c0a9aed70438616c4dd5.zip |
TESTING: Fix TESTING-NG API to follow naming conventions
Rename structs and functions to follow GNUnet naming conventions.
Some structs may actually also be private, a review is necessary.
The barrier API was modified in order to untangle Barriers and
lists of Barriers.
This is a rough draft, it needs fixes wrt memory leaks.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_testing_barrier.h | 106 | ||||
-rw-r--r-- | src/include/gnunet_testing_netjail_lib.h | 32 | ||||
-rw-r--r-- | src/include/gnunet_testing_ng_lib.h | 15 | ||||
-rw-r--r-- | src/include/gnunet_testing_plugin.h | 15 |
4 files changed, 62 insertions, 106 deletions
diff --git a/src/include/gnunet_testing_barrier.h b/src/include/gnunet_testing_barrier.h index 4a3d87ec7..ed4624e1b 100644 --- a/src/include/gnunet_testing_barrier.h +++ b/src/include/gnunet_testing_barrier.h | |||
@@ -27,74 +27,44 @@ | |||
27 | #ifndef GNUNET_TESTING_BARRIER_LIB_H | 27 | #ifndef GNUNET_TESTING_BARRIER_LIB_H |
28 | #define GNUNET_TESTING_BARRIER_LIB_H | 28 | #define GNUNET_TESTING_BARRIER_LIB_H |
29 | 29 | ||
30 | #include "gnunet_testing_lib.h" | 30 | #define GNUNET_TESTING_BARRIER_MAX 32 |
31 | #include "gnunet_testing_netjail_lib.h" | ||
32 | 31 | ||
33 | struct GNUNET_TESTING_Barrier | 32 | #include "gnunet_testing_plugin.h" |
34 | { | ||
35 | /** | ||
36 | * Pointer to the previous prefix in the DLL. | ||
37 | */ | ||
38 | struct GNUNET_TESTING_Barrier *prev; | ||
39 | |||
40 | /** | ||
41 | * Pointer to the next prefix in the DLL. | ||
42 | */ | ||
43 | struct GNUNET_TESTING_Barrier *next; | ||
44 | |||
45 | /** | ||
46 | * Head of the DLL with local commands the barrier is attached too. | ||
47 | */ | ||
48 | struct GNUNET_TESTING_Command *cmds_head; | ||
49 | |||
50 | /** | ||
51 | * Tail of the DLL with local commands the barrier is attached too. | ||
52 | */ | ||
53 | struct GNUNET_TESTING_Command *cmds_tail; | ||
54 | |||
55 | /** | ||
56 | * Hash map containing the global known nodes which are not natted. | ||
57 | */ | ||
58 | struct GNUNET_CONTAINER_MultiShortmap *nodes; | ||
59 | 33 | ||
60 | /** | 34 | /** |
61 | * Name of the barrier. | 35 | * A testing barrier |
62 | */ | 36 | * FIXME better description |
63 | const char *name; | 37 | */ |
64 | 38 | struct GNUNET_TESTING_Barrier; | |
65 | /** | ||
66 | * Is this barrier running on the master. | ||
67 | */ | ||
68 | unsigned int running_on_master; | ||
69 | 39 | ||
70 | /** | 40 | /** |
71 | * Number of commands attached to this barrier. | 41 | * An entry for a barrier list |
72 | */ | 42 | */ |
73 | unsigned int expected_reaches; | 43 | struct GNUNET_TESTING_BarrierListEntry |
44 | { | ||
45 | /* DLL */ | ||
46 | struct GNUNET_TESTING_BarrierListEntry *next; | ||
74 | 47 | ||
75 | /** | 48 | /* DLL */ |
76 | * Number of commands which reached this barrier. | 49 | struct GNUNET_TESTING_BarrierListEntry *prev; |
77 | */ | ||
78 | unsigned int reached; | ||
79 | 50 | ||
80 | /** | 51 | /* The barrier */ |
81 | * Percentage of of commands which need to reach the barrier to change state. | 52 | struct GNUNET_TESTING_Barrier *barrier; |
82 | * Can not be used together with to_be_reached; | 53 | }; |
83 | */ | ||
84 | double percentage_to_be_reached; | ||
85 | 54 | ||
86 | /** | 55 | /** |
87 | * Number of commands which need to reach the barrier to change state. | 56 | * A list to hold barriers provided by plugins |
88 | * Can not be used together with percentage_to_be_reached; | 57 | */ |
89 | */ | 58 | struct GNUNET_TESTING_BarrierList |
90 | unsigned int number_to_be_reached; | 59 | { |
60 | /** List head **/ | ||
61 | struct GNUNET_TESTING_BarrierListEntry *head; | ||
91 | 62 | ||
92 | /* | 63 | /** List tail **/ |
93 | * No barrier locally. Shadow created. Real barrier created elsewhere. | 64 | struct GNUNET_TESTING_BarrierListEntry *tail; |
94 | */ | ||
95 | unsigned int shadow; | ||
96 | }; | 65 | }; |
97 | 66 | ||
67 | |||
98 | /** | 68 | /** |
99 | * Message send to a child loop to inform the child loop about a barrier being advanced. | 69 | * Message send to a child loop to inform the child loop about a barrier being advanced. |
100 | */ | 70 | */ |
@@ -112,7 +82,7 @@ struct GNUNET_TESTING_CommandBarrierAdvanced | |||
112 | }; | 82 | }; |
113 | 83 | ||
114 | /** | 84 | /** |
115 | * Message send by a child loop to inform the master loop how much | 85 | * Message send by a child loop to inform the master loop how much |
116 | * GNUNET_CMDS_BARRIER_REACHED messages the child will send. | 86 | * GNUNET_CMDS_BARRIER_REACHED messages the child will send. |
117 | */ | 87 | */ |
118 | struct GNUNET_TESTING_CommandBarrierAttached | 88 | struct GNUNET_TESTING_CommandBarrierAttached |
@@ -162,17 +132,11 @@ struct GNUNET_TESTING_CommandBarrierReached | |||
162 | unsigned int expected_number_of_reached_messages; | 132 | unsigned int expected_number_of_reached_messages; |
163 | }; | 133 | }; |
164 | 134 | ||
165 | |||
166 | /** | 135 | /** |
167 | * Adding a node to the map of nodes of a barrier. | 136 | * Create a new #GNUNET_TESTING_Barrier |
168 | * | ||
169 | * @param nodes Map of nodes. | ||
170 | * @param node The node to add. | ||
171 | */ | 137 | */ |
172 | void | 138 | struct GNUNET_TESTING_Barrier* |
173 | GNUNET_TESTING_barrier_add_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, | 139 | GNUNET_TESTING_barrier_new (const char *testcase_name); |
174 | struct GNUNET_TESTING_NetjailNode *node); | ||
175 | |||
176 | 140 | ||
177 | struct GNUNET_TESTING_Command | 141 | struct GNUNET_TESTING_Command |
178 | GNUNET_TESTING_cmd_barrier_create ( | 142 | GNUNET_TESTING_cmd_barrier_create ( |
@@ -203,7 +167,7 @@ GNUNET_TESTING_cmd_barrier_reached ( | |||
203 | unsigned int asynchronous_finish, | 167 | unsigned int asynchronous_finish, |
204 | unsigned int node_number, | 168 | unsigned int node_number, |
205 | unsigned int running_on_master, | 169 | unsigned int running_on_master, |
206 | TESTING_CMD_HELPER_write_cb write_message); | 170 | GNUNET_TESTING_cmd_helper_write_cb write_message); |
207 | 171 | ||
208 | 172 | ||
209 | /** | 173 | /** |
@@ -253,7 +217,7 @@ GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, | |||
253 | char *barrier_name, | 217 | char *barrier_name, |
254 | unsigned int global_node_number, | 218 | unsigned int global_node_number, |
255 | unsigned int expected_reaches, | 219 | unsigned int expected_reaches, |
256 | TESTING_CMD_HELPER_write_cb write_message); | 220 | GNUNET_TESTING_cmd_helper_write_cb write_message); |
257 | 221 | ||
258 | 222 | ||
259 | /** | 223 | /** |
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h index 8d1295c98..53cae38c6 100644 --- a/src/include/gnunet_testing_netjail_lib.h +++ b/src/include/gnunet_testing_netjail_lib.h | |||
@@ -27,11 +27,10 @@ | |||
27 | #ifndef GNUNET_TESTING_NETJAIL_LIB_H | 27 | #ifndef GNUNET_TESTING_NETJAIL_LIB_H |
28 | #define GNUNET_TESTING_NETJAIL_LIB_H | 28 | #define GNUNET_TESTING_NETJAIL_LIB_H |
29 | 29 | ||
30 | |||
31 | #include "gnunet_util_lib.h" | ||
32 | #include "gnunet_testing_plugin.h" | ||
33 | #include "gnunet_testing_ng_lib.h" | 30 | #include "gnunet_testing_ng_lib.h" |
31 | #include "gnunet_testing_plugin.h" | ||
34 | 32 | ||
33 | struct GNUNET_TESTING_AsyncContext; | ||
35 | 34 | ||
36 | /** | 35 | /** |
37 | * Router of a netjail subnet. | 36 | * Router of a netjail subnet. |
@@ -342,7 +341,10 @@ unsigned int | |||
342 | GNUNET_TESTING_calculate_num (struct | 341 | GNUNET_TESTING_calculate_num (struct |
343 | GNUNET_TESTING_NodeConnection *node_connection, | 342 | GNUNET_TESTING_NodeConnection *node_connection, |
344 | struct GNUNET_TESTING_NetjailTopology *topology); | 343 | struct GNUNET_TESTING_NetjailTopology *topology); |
345 | struct TestState | 344 | |
345 | // FIXME this was not namespaced. Is this correct here? Why are the cmd_helpers | ||
346 | // defined in _plugin?? | ||
347 | struct GNUNET_TESTING_TestState | ||
346 | { | 348 | { |
347 | /** | 349 | /** |
348 | * The head of the DLL with barriers of the test case. | 350 | * The head of the DLL with barriers of the test case. |
@@ -358,12 +360,12 @@ struct TestState | |||
358 | * Callback to write messages to the master loop. | 360 | * Callback to write messages to the master loop. |
359 | * | 361 | * |
360 | */ | 362 | */ |
361 | TESTING_CMD_HELPER_write_cb write_message; | 363 | GNUNET_TESTING_cmd_helper_write_cb write_message; |
362 | 364 | ||
363 | /** | 365 | /** |
364 | * Callback to notify the helper test case has finished. | 366 | * Callback to notify the helper test case has finished. |
365 | */ | 367 | */ |
366 | TESTING_CMD_HELPER_finish_cb finished_cb; | 368 | GNUNET_TESTING_cmd_helper_finish_cb finished_cb; |
367 | 369 | ||
368 | /** | 370 | /** |
369 | * The name for a specific test environment directory. | 371 | * The name for a specific test environment directory. |
@@ -387,12 +389,12 @@ struct TestState | |||
387 | * Struct with information for callbacks. | 389 | * Struct with information for callbacks. |
388 | * | 390 | * |
389 | */ | 391 | */ |
390 | struct BlockState | 392 | struct GNUNET_TESTING_BlockState |
391 | { | 393 | { |
392 | /** | 394 | /** |
393 | * Context for our asynchronous completion. | 395 | * Context for our asynchronous completion. |
394 | */ | 396 | */ |
395 | struct GNUNET_TESTING_AsyncContext ac; | 397 | struct GNUNET_TESTING_AsyncContext *ac; |
396 | 398 | ||
397 | /** | 399 | /** |
398 | * The label of this command. | 400 | * The label of this command. |
@@ -409,7 +411,7 @@ struct BlockState | |||
409 | * Struct to hold information for callbacks. | 411 | * Struct to hold information for callbacks. |
410 | * | 412 | * |
411 | */ | 413 | */ |
412 | struct LocalPreparedState | 414 | struct GNUNET_TESTING_LocalPreparedState |
413 | { | 415 | { |
414 | /** | 416 | /** |
415 | * Context for our asynchronous completion. | 417 | * Context for our asynchronous completion. |
@@ -420,7 +422,7 @@ struct LocalPreparedState | |||
420 | * Callback to write messages to the master loop. | 422 | * Callback to write messages to the master loop. |
421 | * | 423 | * |
422 | */ | 424 | */ |
423 | TESTING_CMD_HELPER_write_cb write_message; | 425 | GNUNET_TESTING_cmd_helper_write_cb write_message; |
424 | }; | 426 | }; |
425 | 427 | ||
426 | /** | 428 | /** |
@@ -538,7 +540,7 @@ GNUNET_TESTING_cmd_block_until_external_trigger ( | |||
538 | */ | 540 | */ |
539 | struct GNUNET_TESTING_Command | 541 | struct GNUNET_TESTING_Command |
540 | GNUNET_TESTING_cmd_send_peer_ready (const char *label, | 542 | GNUNET_TESTING_cmd_send_peer_ready (const char *label, |
541 | TESTING_CMD_HELPER_write_cb write_message); | 543 | GNUNET_TESTING_cmd_helper_write_cb write_message); |
542 | 544 | ||
543 | 545 | ||
544 | /** | 546 | /** |
@@ -551,7 +553,7 @@ GNUNET_TESTING_cmd_send_peer_ready (const char *label, | |||
551 | struct GNUNET_TESTING_Command | 553 | struct GNUNET_TESTING_Command |
552 | GNUNET_TESTING_cmd_local_test_finished ( | 554 | GNUNET_TESTING_cmd_local_test_finished ( |
553 | const char *label, | 555 | const char *label, |
554 | TESTING_CMD_HELPER_write_cb write_message); | 556 | GNUNET_TESTING_cmd_helper_write_cb write_message); |
555 | 557 | ||
556 | /** | 558 | /** |
557 | * Create command. | 559 | * Create command. |
@@ -562,7 +564,7 @@ GNUNET_TESTING_cmd_local_test_finished ( | |||
562 | */ | 564 | */ |
563 | struct GNUNET_TESTING_Command | 565 | struct GNUNET_TESTING_Command |
564 | GNUNET_TESTING_cmd_local_test_prepared (const char *label, | 566 | GNUNET_TESTING_cmd_local_test_prepared (const char *label, |
565 | TESTING_CMD_HELPER_write_cb | 567 | GNUNET_TESTING_cmd_helper_write_cb |
566 | write_message); | 568 | write_message); |
567 | 569 | ||
568 | 570 | ||
@@ -576,8 +578,8 @@ GNUNET_TESTING_cmd_local_test_prepared (const char *label, | |||
576 | op (test_system, const struct GNUNET_TESTING_System) \ | 578 | op (test_system, const struct GNUNET_TESTING_System) \ |
577 | op (async_context, const struct GNUNET_TESTING_AsyncContext) \ | 579 | op (async_context, const struct GNUNET_TESTING_AsyncContext) \ |
578 | op (helper_handles, const struct GNUNET_HELPER_Handle *) \ | 580 | op (helper_handles, const struct GNUNET_HELPER_Handle *) \ |
579 | op (local_prepared_state, const struct LocalPreparedState) \ | 581 | op (local_prepared_state, const struct GNUNET_TESTING_LocalPreparedState) \ |
580 | op (block_state, const struct BlockState) | 582 | op (block_state, const struct GNUNET_TESTING_BlockState) |
581 | 583 | ||
582 | GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | 584 | GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) |
583 | 585 | ||
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h index 0b4c05a59..d218a65db 100644 --- a/src/include/gnunet_testing_ng_lib.h +++ b/src/include/gnunet_testing_ng_lib.h | |||
@@ -29,7 +29,6 @@ | |||
29 | 29 | ||
30 | 30 | ||
31 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
32 | #include "gnunet_testing_plugin.h" | ||
33 | #include "gnunet_testing_lib.h" | 32 | #include "gnunet_testing_lib.h" |
34 | 33 | ||
35 | /** | 34 | /** |
@@ -134,18 +133,6 @@ GNUNET_TESTING_command_new (void *cls, | |||
134 | */ | 133 | */ |
135 | struct GNUNET_TESTING_Command | 134 | struct GNUNET_TESTING_Command |
136 | { | 135 | { |
137 | // FIXME: This should not be here. Looking at the code commands are used | ||
138 | // in arrays. Not lists. | ||
139 | /** | ||
140 | * Pointer to the previous command in the DLL. | ||
141 | */ | ||
142 | struct GNUNET_TESTING_Command *prev; | ||
143 | |||
144 | /** | ||
145 | * Pointer to the next command in the DLL. | ||
146 | */ | ||
147 | struct GNUNET_TESTING_Command *next; | ||
148 | |||
149 | /** | 136 | /** |
150 | * Closure for all commands with command-specific context information. | 137 | * Closure for all commands with command-specific context information. |
151 | */ | 138 | */ |
@@ -466,7 +453,7 @@ GNUNET_TESTING_get_barrier (struct GNUNET_TESTING_Interpreter *is, | |||
466 | * @param barrier The barrier to add. | 453 | * @param barrier The barrier to add. |
467 | */ | 454 | */ |
468 | void | 455 | void |
469 | GNUNET_TESTING_barrier_add (struct GNUNET_TESTING_Interpreter *is, | 456 | GNUNET_TESTING_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, |
470 | struct GNUNET_TESTING_Barrier *barrier); | 457 | struct GNUNET_TESTING_Barrier *barrier); |
471 | 458 | ||
472 | 459 | ||
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h index 312a7bfe5..d986fabcd 100644 --- a/src/include/gnunet_testing_plugin.h +++ b/src/include/gnunet_testing_plugin.h | |||
@@ -38,18 +38,21 @@ extern "C" | |||
38 | #endif | 38 | #endif |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | struct GNUNET_TESTING_Barrier; | ||
42 | |||
43 | //FIXME documentation for both functions | ||
41 | typedef void | 44 | typedef void |
42 | (*TESTING_CMD_HELPER_write_cb) (struct GNUNET_MessageHeader *message, | 45 | (*GNUNET_TESTING_cmd_helper_write_cb) (struct GNUNET_MessageHeader *message, |
43 | size_t msg_length); | 46 | size_t msg_length); |
44 | 47 | ||
45 | typedef void | 48 | typedef void |
46 | (*TESTING_CMD_HELPER_finish_cb) (); | 49 | (*GNUNET_TESTING_cmd_helper_finish_cb) (); |
47 | 50 | ||
48 | // FIXME documentation | 51 | // FIXME documentation |
49 | // FIXME: Why are n, m, local_m strings? | 52 | // FIXME: Why are n, m, local_m strings? |
50 | // FIXME: Why is topology_data a string and not a GNUNET_TESTING_NetworkTopology?? | 53 | // FIXME: Why is topology_data a string and not a GNUNET_TESTING_NetworkTopology?? |
51 | typedef void | 54 | typedef void |
52 | (*GNUNET_TESTING_PLUGIN_StartTestCase) (TESTING_CMD_HELPER_write_cb | 55 | (*GNUNET_TESTING_PLUGIN_StartTestCase) (GNUNET_TESTING_cmd_helper_write_cb |
53 | write_message, | 56 | write_message, |
54 | const char *router_ip, | 57 | const char *router_ip, |
55 | const char *node_ip, | 58 | const char *node_ip, |
@@ -58,7 +61,7 @@ typedef void | |||
58 | const char *local_m, | 61 | const char *local_m, |
59 | const char *topology_data, | 62 | const char *topology_data, |
60 | unsigned int *read_file, | 63 | unsigned int *read_file, |
61 | TESTING_CMD_HELPER_finish_cb finish_cb); | 64 | GNUNET_TESTING_cmd_helper_finish_cb finish_cb); |
62 | 65 | ||
63 | 66 | ||
64 | typedef void | 67 | typedef void |
@@ -71,8 +74,8 @@ typedef void | |||
71 | typedef void | 74 | typedef void |
72 | (*GNUNET_TESTING_PLUGIN_BARRIER_ADVANCED) (const char *barrier_name); | 75 | (*GNUNET_TESTING_PLUGIN_BARRIER_ADVANCED) (const char *barrier_name); |
73 | 76 | ||
74 | typedef struct GNUNET_TESTING_Barrier * | 77 | typedef struct GNUNET_TESTING_BarrierList* |
75 | (*GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS) (); | 78 | (*GNUNET_TESTING_PLUGIN_GET_WAITING_FOR_BARRIERS) (void); |
76 | 79 | ||
77 | 80 | ||
78 | // FIXME documentation | 81 | // FIXME documentation |