diff options
Diffstat (limited to 'src/testing')
22 files changed, 995 insertions, 991 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 39e85c4ac..a9a1b5a02 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am | |||
@@ -18,9 +18,6 @@ libexec_PROGRAMS = \ | |||
18 | 18 | ||
19 | plugindir = $(libdir)/gnunet | 19 | plugindir = $(libdir)/gnunet |
20 | 20 | ||
21 | plugin_LTLIBRARIES = \ | ||
22 | libgnunet_test_testing_plugin_testcmd.la | ||
23 | |||
24 | lib_LTLIBRARIES = \ | 21 | lib_LTLIBRARIES = \ |
25 | libgnunettesting.la | 22 | libgnunettesting.la |
26 | 23 | ||
@@ -31,24 +28,12 @@ gnunet_cmds_helper_LDADD = $(XLIB) \ | |||
31 | libgnunettesting.la \ | 28 | libgnunettesting.la \ |
32 | $(LTLIBINTL) $(Z_LIBS) | 29 | $(LTLIBINTL) $(Z_LIBS) |
33 | 30 | ||
34 | libgnunet_test_testing_plugin_testcmd_la_SOURCES = \ | ||
35 | test_testing_plugin_testcmd.c | ||
36 | libgnunet_test_testing_plugin_testcmd_la_LIBADD = \ | ||
37 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
38 | $(top_builddir)/src/arm/libgnunetarm.la \ | ||
39 | libgnunettesting.la \ | ||
40 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
41 | $(LTLIBINTL) | ||
42 | libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \ | ||
43 | $(GN_PLUGIN_LDFLAGS) | ||
44 | |||
45 | |||
46 | libgnunettesting_la_SOURCES = \ | 31 | libgnunettesting_la_SOURCES = \ |
47 | testing_api_cmd_end.c \ | 32 | testing_api_cmd_end.c \ |
48 | testing_api_cmd_finish.c \ | 33 | testing_api_cmd_finish.c \ |
49 | testing_api_cmd_local_test_finished.c \ | 34 | testing_api_cmd_local_test_finished.c \ |
35 | testing_api_cmd_local_test_prepared.c \ | ||
50 | testing_api_cmd_send_peer_ready.c \ | 36 | testing_api_cmd_send_peer_ready.c \ |
51 | testing_api_cmd_block_until_all_peers_started.c \ | ||
52 | testing_api_cmd_block_until_external_trigger.c \ | 37 | testing_api_cmd_block_until_external_trigger.c \ |
53 | testing_api_cmd_netjail_start.c \ | 38 | testing_api_cmd_netjail_start.c \ |
54 | testing_api_cmd_netjail_start_testsystem.c \ | 39 | testing_api_cmd_netjail_start_testsystem.c \ |
@@ -58,8 +43,6 @@ libgnunettesting_la_SOURCES = \ | |||
58 | testing_api_cmd_system_create.c \ | 43 | testing_api_cmd_system_create.c \ |
59 | testing_api_cmd_system_destroy.c \ | 44 | testing_api_cmd_system_destroy.c \ |
60 | testing_api_cmd_batch.c \ | 45 | testing_api_cmd_batch.c \ |
61 | testing_api_cmd_hello_world.c \ | ||
62 | testing_api_cmd_hello_world_birth.c \ | ||
63 | testing_api_loop.c \ | 46 | testing_api_loop.c \ |
64 | testing_api_trait_cmd.c \ | 47 | testing_api_trait_cmd.c \ |
65 | testing_api_trait_process.c \ | 48 | testing_api_trait_process.c \ |
@@ -93,8 +76,6 @@ list_keys_LDADD = \ | |||
93 | 76 | ||
94 | 77 | ||
95 | check_PROGRAMS = \ | 78 | check_PROGRAMS = \ |
96 | test_testing_api_cmd_netjail \ | ||
97 | test_testing_hello_world \ | ||
98 | test_testing_portreservation \ | 79 | test_testing_portreservation \ |
99 | test_testing_servicestartup \ | 80 | test_testing_servicestartup \ |
100 | test_testing_peerstartup \ | 81 | test_testing_peerstartup \ |
@@ -104,32 +85,12 @@ check_PROGRAMS = \ | |||
104 | if ENABLE_TEST_RUN | 85 | if ENABLE_TEST_RUN |
105 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 86 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
106 | TESTS = \ | 87 | TESTS = \ |
107 | test_testing_api_cmd_netjail \ | ||
108 | test_testing_hello_world \ | ||
109 | test_testing_portreservation \ | 88 | test_testing_portreservation \ |
110 | test_testing_peerstartup \ | 89 | test_testing_peerstartup \ |
111 | test_testing_peerstartup2 \ | 90 | test_testing_peerstartup2 \ |
112 | test_testing_servicestartup | 91 | test_testing_servicestartup |
113 | endif | 92 | endif |
114 | 93 | ||
115 | #test_testing_topology_SOURCES = \ | ||
116 | # test_testing_topology.c | ||
117 | #test_testing_topology_LDADD = \ | ||
118 | # libgnunettesting.la \ | ||
119 | # $(top_builddir)/src/util/libgnunetutil.la | ||
120 | |||
121 | test_testing_api_cmd_netjail_SOURCES = \ | ||
122 | test_testing_api_cmd_netjail.c | ||
123 | test_testing_api_cmd_netjail_LDADD = \ | ||
124 | libgnunettesting.la \ | ||
125 | $(top_builddir)/src/util/libgnunetutil.la | ||
126 | |||
127 | test_testing_hello_world_SOURCES = \ | ||
128 | test_testing_hello_world.c | ||
129 | test_testing_hello_world_LDADD = \ | ||
130 | libgnunettesting.la \ | ||
131 | $(top_builddir)/src/util/libgnunetutil.la | ||
132 | |||
133 | test_testing_portreservation_SOURCES = \ | 94 | test_testing_portreservation_SOURCES = \ |
134 | test_testing_portreservation.c | 95 | test_testing_portreservation.c |
135 | test_testing_portreservation_LDADD = \ | 96 | test_testing_portreservation_LDADD = \ |
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c index e50db0cf6..f90cc3cc4 100644 --- a/src/testing/gnunet-cmds-helper.c +++ b/src/testing/gnunet-cmds-helper.c | |||
@@ -142,6 +142,16 @@ struct NodeIdentifier | |||
142 | * | 142 | * |
143 | */ | 143 | */ |
144 | char *local_m; | 144 | char *local_m; |
145 | |||
146 | /** | ||
147 | * Shall we read the topology from file, or from a string. | ||
148 | */ | ||
149 | unsigned int *read_file; | ||
150 | |||
151 | /** | ||
152 | * String with topology data or name of topology file. | ||
153 | */ | ||
154 | char *topology_data; | ||
145 | }; | 155 | }; |
146 | 156 | ||
147 | /** | 157 | /** |
@@ -402,7 +412,8 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) | |||
402 | strcat (node_ip, plugin->m); | 412 | strcat (node_ip, plugin->m); |
403 | 413 | ||
404 | plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, | 414 | plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, |
405 | plugin->n, plugin->local_m); | 415 | plugin->n, plugin->local_m, ni->topology_data, |
416 | ni->read_file); | ||
406 | 417 | ||
407 | GNUNET_free (binary); | 418 | GNUNET_free (binary); |
408 | 419 | ||
@@ -418,9 +429,19 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) | |||
418 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( | 429 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( |
419 | message->type)) | 430 | message->type)) |
420 | { | 431 | { |
432 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
433 | "all peers started\n"); | ||
421 | plugin->api->all_peers_started (); | 434 | plugin->api->all_peers_started (); |
422 | return GNUNET_OK; | 435 | return GNUNET_OK; |
423 | } | 436 | } |
437 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED == ntohs ( | ||
438 | message->type)) | ||
439 | { | ||
440 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
441 | "all local tests prepared\n"); | ||
442 | plugin->api->all_local_tests_prepared (); | ||
443 | return GNUNET_OK; | ||
444 | } | ||
424 | else | 445 | else |
425 | { | 446 | { |
426 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 447 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); |
@@ -549,6 +570,10 @@ main (int argc, char **argv) | |||
549 | struct GNUNET_GETOPT_CommandLineOption options[] = | 570 | struct GNUNET_GETOPT_CommandLineOption options[] = |
550 | { GNUNET_GETOPT_OPTION_END }; | 571 | { GNUNET_GETOPT_OPTION_END }; |
551 | int ret; | 572 | int ret; |
573 | int i; | ||
574 | size_t topology_data_length = 0; | ||
575 | unsigned int read_file; | ||
576 | char cr[1] = "\n"; | ||
552 | 577 | ||
553 | GNUNET_log_setup ("gnunet-cmds-helper", | 578 | GNUNET_log_setup ("gnunet-cmds-helper", |
554 | "DEBUG", | 579 | "DEBUG", |
@@ -559,6 +584,30 @@ main (int argc, char **argv) | |||
559 | ni->m = argv[3]; | 584 | ni->m = argv[3]; |
560 | ni->n = argv[4]; | 585 | ni->n = argv[4]; |
561 | 586 | ||
587 | sscanf (argv[5], "%u", &read_file); | ||
588 | |||
589 | if (1 == read_file) | ||
590 | ni->topology_data = argv[6]; | ||
591 | else | ||
592 | { | ||
593 | for (i = 6; i<argc; i++) | ||
594 | topology_data_length += strlen (argv[i]) + 1; | ||
595 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
596 | "topo data length %lu\n", | ||
597 | topology_data_length); | ||
598 | ni->topology_data = GNUNET_malloc (topology_data_length); | ||
599 | for (i = 6; i<argc; i++) | ||
600 | { | ||
601 | strcat (ni->topology_data, argv[i]); | ||
602 | strcat (ni->topology_data, cr); | ||
603 | } | ||
604 | } | ||
605 | ni->read_file = &read_file; | ||
606 | ni->topology_data[topology_data_length - 1] = '\0'; | ||
607 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
608 | "topo data %s\n", | ||
609 | ni->topology_data); | ||
610 | |||
562 | status = GNUNET_OK; | 611 | status = GNUNET_OK; |
563 | if (NULL == | 612 | if (NULL == |
564 | (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) | 613 | (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) |
diff --git a/src/testing/test_testing_api_cmd_netjail.c b/src/testing/test_testing_api_cmd_netjail.c deleted file mode 100644 index aeddfb7c9..000000000 --- a/src/testing/test_testing_api_cmd_netjail.c +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/test_testbed_api_cmd_netjail.c | ||
23 | * @brief Test case executing a script in a network name space. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Return value of the test. | ||
33 | * | ||
34 | */ | ||
35 | static unsigned int rv = 0; | ||
36 | |||
37 | |||
38 | /** | ||
39 | * Main function to run the test cases. | ||
40 | * | ||
41 | * @param cls not used. | ||
42 | * | ||
43 | */ | ||
44 | static void | ||
45 | run (void *cls) | ||
46 | { | ||
47 | struct GNUNET_TESTING_Command commands[] = { | ||
48 | GNUNET_TESTING_cmd_netjail_start ("netjail-start-1", | ||
49 | "2", | ||
50 | "2"), | ||
51 | GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1", | ||
52 | "2", | ||
53 | "2", | ||
54 | "libgnunet_plugin_testcmd", | ||
55 | &rv), | ||
56 | GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed", | ||
57 | "netjail-start-testbed-1", | ||
58 | "2", | ||
59 | "2"), | ||
60 | GNUNET_TESTING_cmd_netjail_stop ("netjail-stop-1", | ||
61 | "2", | ||
62 | "2"), | ||
63 | GNUNET_TESTING_cmd_end () | ||
64 | }; | ||
65 | |||
66 | GNUNET_TESTING_run (NULL, | ||
67 | commands, | ||
68 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
69 | } | ||
70 | |||
71 | |||
72 | int | ||
73 | main (int argc, | ||
74 | char *const *argv) | ||
75 | { | ||
76 | int rv = 0; | ||
77 | |||
78 | GNUNET_log_setup ("test-netjail", | ||
79 | "DEBUG", | ||
80 | NULL); | ||
81 | GNUNET_SCHEDULER_run (&run, | ||
82 | NULL); | ||
83 | |||
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
85 | "Test finished!\n"); | ||
86 | return rv; | ||
87 | } | ||
diff --git a/src/testing/test_testing_hello_world.c b/src/testing/test_testing_hello_world.c deleted file mode 100644 index 6300e26a4..000000000 --- a/src/testing/test_testing_hello_world.c +++ /dev/null | |||
@@ -1,68 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/test_testing_hello_world.c | ||
23 | * @brief hello world test case | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
30 | /** | ||
31 | * Main function to run the test cases. | ||
32 | * | ||
33 | * @param cls not used. | ||
34 | * | ||
35 | */ | ||
36 | static void | ||
37 | run (void *cls) | ||
38 | { | ||
39 | (void *) cls; | ||
40 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | ||
41 | |||
42 | struct GNUNET_TESTING_Command commands[] = { | ||
43 | GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0", | ||
44 | &now), | ||
45 | GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""), | ||
46 | GNUNET_TESTING_cmd_end () | ||
47 | }; | ||
48 | |||
49 | GNUNET_TESTING_run (NULL, | ||
50 | commands, | ||
51 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
52 | } | ||
53 | |||
54 | int | ||
55 | main (int argc, | ||
56 | char *const *argv) | ||
57 | { | ||
58 | int rv = 0; | ||
59 | |||
60 | GNUNET_log_setup ("test-hello-world", | ||
61 | "DEBUG", | ||
62 | NULL); | ||
63 | |||
64 | GNUNET_SCHEDULER_run (&run, | ||
65 | NULL); | ||
66 | |||
67 | return rv; | ||
68 | } | ||
diff --git a/src/testing/test_testing_plugin_testcmd.c b/src/testing/test_testing_plugin_testcmd.c deleted file mode 100644 index 32e2b38a7..000000000 --- a/src/testing/test_testing_plugin_testcmd.c +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file testbed/plugin_testcmd.c | ||
22 | * @brief a plugin to provide the API for running test cases. | ||
23 | * @author t3sserakt | ||
24 | * | ||
25 | * // FIXME: too verbose, no logic to return final status, will segv! | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_testing_ng_lib.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_testing_ng_lib.h" | ||
31 | |||
32 | /** | ||
33 | * Generic logging shortcut | ||
34 | */ | ||
35 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
36 | |||
37 | |||
38 | // FIXME: bad global! | ||
39 | unsigned int are_all_peers_started; | ||
40 | |||
41 | |||
42 | static void | ||
43 | all_peers_started () | ||
44 | { | ||
45 | are_all_peers_started = GNUNET_YES; | ||
46 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
47 | "setting are_all_peers_started: %d\n", | ||
48 | are_all_peers_started); | ||
49 | } | ||
50 | |||
51 | |||
52 | static void | ||
53 | start_testcase (TESTING_CMD_HELPER_write_cb write_message, | ||
54 | char *router_ip, | ||
55 | char *node_ip, | ||
56 | char *n, | ||
57 | char *m, | ||
58 | char *local_m) | ||
59 | { | ||
60 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | ||
61 | |||
62 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
63 | "We got here 6!\n"); | ||
64 | |||
65 | are_all_peers_started = GNUNET_NO; | ||
66 | |||
67 | struct GNUNET_TESTING_Command commands[] = { | ||
68 | GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0", | ||
69 | &now), | ||
70 | GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""), | ||
71 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1", | ||
72 | write_message), | ||
73 | GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1", | ||
74 | &are_all_peers_started), | ||
75 | GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1", | ||
76 | write_message) | ||
77 | }; | ||
78 | |||
79 | GNUNET_TESTING_run (commands, | ||
80 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
81 | NULL, /* FIXME: pass continuation! */ | ||
82 | NULL); | ||
83 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
84 | "We got here 7!\n"); | ||
85 | |||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Entry point for the plugin. | ||
91 | * | ||
92 | * @param cls NULL | ||
93 | * @return the exported block API | ||
94 | */ | ||
95 | void * | ||
96 | libgnunet_plugin_testcmd_init (void *cls) | ||
97 | { | ||
98 | struct GNUNET_TESTING_PluginFunctions *api; | ||
99 | |||
100 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); | ||
101 | api->start_testcase = &start_testcase; | ||
102 | api->all_peers_started = &all_peers_started; | ||
103 | return api; | ||
104 | } | ||
105 | |||
106 | |||
107 | /** | ||
108 | * Exit point from the plugin. | ||
109 | * | ||
110 | * @param cls the return value from #libgnunet_plugin_block_test_init | ||
111 | * @return NULL | ||
112 | */ | ||
113 | void * | ||
114 | libgnunet_plugin_testcmd_done (void *cls) | ||
115 | { | ||
116 | struct GNUNET_TESTING_PluginFunctions *api = cls; | ||
117 | |||
118 | GNUNET_free (api); | ||
119 | return NULL; | ||
120 | } | ||
121 | |||
122 | |||
123 | |||
diff --git a/src/testing/testing.c b/src/testing/testing.c index 766c7b084..4ccf93c6b 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -33,11 +33,20 @@ | |||
33 | #include "gnunet_util_lib.h" | 33 | #include "gnunet_util_lib.h" |
34 | #include "gnunet_arm_service.h" | 34 | #include "gnunet_arm_service.h" |
35 | #include "gnunet_testing_lib.h" | 35 | #include "gnunet_testing_lib.h" |
36 | #include "gnunet_testing_ng_lib.h" | 36 | #include "gnunet_testing_netjail_lib.h" |
37 | #include "testing_cmds.h" | 37 | #include "testing_cmds.h" |
38 | 38 | ||
39 | #define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) | 39 | #define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) |
40 | 40 | ||
41 | #define CONNECT_ADDRESS_TEMPLATE "%s-192.168.15.%u:60002" | ||
42 | |||
43 | #define ROUTER_CONNECT_ADDRESS_TEMPLATE "%s-92.68.150.%u:60002" | ||
44 | |||
45 | #define KNOWN_CONNECT_ADDRESS_TEMPLATE "%s-92.68.151.%u:60002" | ||
46 | |||
47 | #define PREFIX_TCP "tcp" | ||
48 | |||
49 | #define PREFIX_UDP "udp" | ||
41 | 50 | ||
42 | /** | 51 | /** |
43 | * Lowest port used for GNUnet testing. Should be high enough to not | 52 | * Lowest port used for GNUnet testing. Should be high enough to not |
@@ -1789,7 +1798,7 @@ get_first_value (char *line) | |||
1789 | memcpy (copy, line, slen); | 1798 | memcpy (copy, line, slen); |
1790 | token = strtok_r (copy, ":", &rest); | 1799 | token = strtok_r (copy, ":", &rest); |
1791 | token = strtok_r (NULL, ":", &rest); | 1800 | token = strtok_r (NULL, ":", &rest); |
1792 | sscanf (token, "%u", &ret); | 1801 | GNUNET_assert (1 == sscanf (token, "%u", &ret)); |
1793 | GNUNET_free (copy); | 1802 | GNUNET_free (copy); |
1794 | return ret; | 1803 | return ret; |
1795 | } | 1804 | } |
@@ -1855,7 +1864,7 @@ get_second_value (char *line) | |||
1855 | token = strtok_r (copy, ":", &rest); | 1864 | token = strtok_r (copy, ":", &rest); |
1856 | token = strtok_r (NULL, ":", &rest); | 1865 | token = strtok_r (NULL, ":", &rest); |
1857 | token = strtok_r (NULL, ":", &rest); | 1866 | token = strtok_r (NULL, ":", &rest); |
1858 | sscanf (token, "%u", &ret); | 1867 | GNUNET_assert (1 == sscanf (token, "%u", &ret)); |
1859 | GNUNET_free (copy); | 1868 | GNUNET_free (copy); |
1860 | return ret; | 1869 | return ret; |
1861 | } | 1870 | } |
@@ -1901,7 +1910,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1901 | unsigned int namespace_n; | 1910 | unsigned int namespace_n; |
1902 | char *rest = NULL; | 1911 | char *rest = NULL; |
1903 | char *rest2 = NULL; | 1912 | char *rest2 = NULL; |
1904 | struct GNUNET_TESTING_ADDRESS_PREFIX *prefix; | 1913 | struct GNUNET_TESTING_AddressPrefix *prefix; |
1905 | 1914 | ||
1906 | node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection); | 1915 | node_connection = GNUNET_new (struct GNUNET_TESTING_NodeConnection); |
1907 | node_connection->node = node; | 1916 | node_connection->node = node; |
@@ -1914,7 +1923,7 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1914 | { | 1923 | { |
1915 | node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE; | 1924 | node_connection->node_type = GNUNET_TESTING_GLOBAL_NODE; |
1916 | token = strtok_r (NULL, ":", &rest); | 1925 | token = strtok_r (NULL, ":", &rest); |
1917 | sscanf (token, "%u", &node_n); | 1926 | GNUNET_assert (1 == sscanf (token, "%u", &node_n)); |
1918 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1927 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1919 | "node_n %u\n", | 1928 | "node_n %u\n", |
1920 | node_n); | 1929 | node_n); |
@@ -1925,19 +1934,21 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1925 | { | 1934 | { |
1926 | node_connection->node_type = GNUNET_TESTING_SUBNET_NODE; | 1935 | node_connection->node_type = GNUNET_TESTING_SUBNET_NODE; |
1927 | token = strtok_r (NULL, ":", &rest); | 1936 | token = strtok_r (NULL, ":", &rest); |
1928 | sscanf (token, "%u", &node_n); | ||
1929 | node_connection->node_n = node_n; | ||
1930 | token = strtok_r (NULL, ":", &rest); | ||
1931 | sscanf (token, "%u", &namespace_n); | 1937 | sscanf (token, "%u", &namespace_n); |
1932 | node_connection->namespace_n = namespace_n; | 1938 | node_connection->namespace_n = namespace_n; |
1939 | token = strtok_r (NULL, ":", &rest); | ||
1940 | sscanf (token, "%u", &node_n); | ||
1941 | node_connection->node_n = node_n; | ||
1933 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1942 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1934 | "node_n %u namespace_n %u\n", | 1943 | "node_n %u namespace_n %u node->node_n %u node->namespace_n %u\n", |
1935 | node_n, | 1944 | node_n, |
1936 | namespace_n); | 1945 | namespace_n, |
1946 | node->node_n, | ||
1947 | node->namespace_n); | ||
1937 | } | 1948 | } |
1938 | while (NULL != (token = strtok_r (NULL, ":", &rest))) | 1949 | while (NULL != (token = strtok_r (NULL, ":", &rest))) |
1939 | { | 1950 | { |
1940 | prefix = GNUNET_new (struct GNUNET_TESTING_ADDRESS_PREFIX); | 1951 | prefix = GNUNET_new (struct GNUNET_TESTING_AddressPrefix); |
1941 | token2 = strtok_r (token, "}", &rest2); | 1952 | token2 = strtok_r (token, "}", &rest2); |
1942 | if (NULL != token2) | 1953 | if (NULL != token2) |
1943 | { | 1954 | { |
@@ -1959,6 +1970,9 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1959 | GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head, | 1970 | GNUNET_CONTAINER_DLL_insert (node_connection->address_prefixes_head, |
1960 | node_connection->address_prefixes_tail, | 1971 | node_connection->address_prefixes_tail, |
1961 | prefix); | 1972 | prefix); |
1973 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1974 | "address_prefix %s\n", | ||
1975 | prefix->address_prefix); | ||
1962 | } | 1976 | } |
1963 | 1977 | ||
1964 | GNUNET_free (copy); | 1978 | GNUNET_free (copy); |
@@ -1982,13 +1996,16 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1982 | if (NULL != temp) | 1996 | if (NULL != temp) |
1983 | { | 1997 | { |
1984 | slen = strlen (temp) + 1; | 1998 | slen = strlen (temp) + 1; |
1985 | copy = malloc (slen); | 1999 | copy = GNUNET_malloc (slen); |
1986 | memcpy (copy, temp, slen); | 2000 | memcpy (copy, temp, slen); |
1987 | strtok_r (copy, ":", &rest); | 2001 | strtok_r (copy, ":", &rest); |
1988 | value = strtok_r (rest, "|", &rest2); | 2002 | value = strtok_r (rest, "|", &rest2); |
1989 | 2003 | ||
1990 | while (NULL != value) | 2004 | while (NULL != value) |
1991 | { | 2005 | { |
2006 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2007 | "node_connections value %s\n", | ||
2008 | value); | ||
1992 | node_connection = get_connect_value (value, node); | 2009 | node_connection = get_connect_value (value, node); |
1993 | GNUNET_CONTAINER_DLL_insert (node->node_connections_head, | 2010 | GNUNET_CONTAINER_DLL_insert (node->node_connections_head, |
1994 | node->node_connections_tail, | 2011 | node->node_connections_tail, |
@@ -1999,7 +2016,319 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node) | |||
1999 | value = strtok_r (NULL, "|", &rest2); | 2016 | value = strtok_r (NULL, "|", &rest2); |
2000 | 2017 | ||
2001 | } | 2018 | } |
2019 | GNUNET_free (copy); | ||
2020 | } | ||
2021 | } | ||
2022 | |||
2023 | |||
2024 | static int | ||
2025 | log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value) | ||
2026 | { | ||
2027 | struct GNUNET_TESTING_NetjailNode *node = value; | ||
2028 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
2029 | struct GNUNET_TESTING_AddressPrefix *pos_prefix; | ||
2030 | |||
2031 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2032 | "plugin: %s space: %u node: %u global: %u\n", | ||
2033 | node->plugin, | ||
2034 | node->namespace_n, | ||
2035 | node->node_n, | ||
2036 | node->is_global); | ||
2037 | |||
2038 | for (pos_connection = node->node_connections_head; NULL != pos_connection; | ||
2039 | pos_connection = pos_connection->next) | ||
2040 | { | ||
2041 | |||
2042 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2043 | "namespace_n: %u node_n: %u node_type: %u\n", | ||
2044 | pos_connection->namespace_n, | ||
2045 | pos_connection->node_n, | ||
2046 | pos_connection->node_type); | ||
2047 | |||
2048 | for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix; | ||
2049 | pos_prefix = | ||
2050 | pos_prefix->next) | ||
2051 | { | ||
2052 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2053 | "prefix: %s\n", | ||
2054 | pos_prefix->address_prefix); | ||
2055 | } | ||
2056 | } | ||
2057 | return GNUNET_YES; | ||
2058 | } | ||
2059 | |||
2060 | |||
2061 | static int | ||
2062 | log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value) | ||
2063 | { | ||
2064 | struct GNUNET_TESTING_NetjailNamespace *namespace = value; | ||
2065 | |||
2066 | GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL); | ||
2067 | return GNUNET_YES; | ||
2068 | } | ||
2069 | |||
2070 | |||
2071 | static int | ||
2072 | log_topo (struct GNUNET_TESTING_NetjailTopology *topology) | ||
2073 | { | ||
2074 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2075 | "plugin: %s spaces: %u nodes: %u known: %u\n", | ||
2076 | topology->plugin, | ||
2077 | topology->namespaces_n, | ||
2078 | topology->nodes_m, | ||
2079 | topology->nodes_x); | ||
2080 | |||
2081 | GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces, | ||
2082 | log_namespaces, NULL); | ||
2083 | GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes, | ||
2084 | NULL); | ||
2085 | return GNUNET_YES; | ||
2086 | } | ||
2087 | |||
2088 | |||
2089 | /** | ||
2090 | * Get the connections to other nodes for a specific node. | ||
2091 | * | ||
2092 | * @param num The specific node we want the connections for. | ||
2093 | * @param topology The topology we get the connections from. | ||
2094 | * @return The connections of the node. | ||
2095 | */ | ||
2096 | struct GNUNET_TESTING_NodeConnection * | ||
2097 | GNUNET_TESTING_get_connections (unsigned int num, struct | ||
2098 | GNUNET_TESTING_NetjailTopology *topology) | ||
2099 | { | ||
2100 | struct GNUNET_TESTING_NetjailNode *node; | ||
2101 | struct GNUNET_ShortHashCode *hkey; | ||
2102 | struct GNUNET_HashCode hc; | ||
2103 | struct GNUNET_TESTING_NetjailNamespace *namespace; | ||
2104 | unsigned int namespace_n, node_m; | ||
2105 | struct GNUNET_TESTING_NodeConnection *node_connections = NULL; | ||
2106 | |||
2107 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2108 | "gaga 1\n"); | ||
2109 | log_topo (topology); | ||
2110 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2111 | "gaga 2\n"); | ||
2112 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
2113 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2114 | "num: %u \n", | ||
2115 | num); | ||
2116 | if (topology->nodes_x >= num) | ||
2117 | { | ||
2118 | |||
2119 | GNUNET_CRYPTO_hash (&num, sizeof(num), &hc); | ||
2120 | memcpy (hkey, | ||
2121 | &hc, | ||
2122 | sizeof (*hkey)); | ||
2123 | node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals, | ||
2124 | hkey); | ||
2125 | node_connections = node->node_connections_head; | ||
2126 | } | ||
2127 | else | ||
2128 | { | ||
2129 | namespace_n = (unsigned int) ceil ((double) (num - topology->nodes_x) | ||
2130 | / topology->nodes_m); | ||
2131 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2132 | "ceil num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n", | ||
2133 | num, | ||
2134 | topology->nodes_x, | ||
2135 | topology->nodes_m, | ||
2136 | namespace_n); | ||
2137 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
2138 | GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc); | ||
2139 | memcpy (hkey, | ||
2140 | &hc, | ||
2141 | sizeof (*hkey)); | ||
2142 | namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces, | ||
2143 | hkey); | ||
2144 | node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1); | ||
2145 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | ||
2146 | GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc); | ||
2147 | memcpy (hkey, | ||
2148 | &hc, | ||
2149 | sizeof (*hkey)); | ||
2150 | node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes, | ||
2151 | hkey); | ||
2152 | node_connections = node->node_connections_head; | ||
2153 | } | ||
2154 | |||
2155 | GNUNET_free (hkey); | ||
2156 | return node_connections; | ||
2157 | } | ||
2158 | |||
2159 | |||
2160 | /** | ||
2161 | * Retrieve the public key from the test system with the unique node id. | ||
2162 | * | ||
2163 | * @param num The unique node id. | ||
2164 | * @param tl_system The test system. | ||
2165 | * @return The peer identity wrapping the public key. | ||
2166 | */ | ||
2167 | struct GNUNET_PeerIdentity * | ||
2168 | GNUNET_TESTING_get_pub_key (unsigned int num, struct | ||
2169 | GNUNET_TESTING_System *tl_system) | ||
2170 | { | ||
2171 | struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); | ||
2172 | struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct | ||
2173 | GNUNET_CRYPTO_EddsaPublicKey); | ||
2174 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct | ||
2175 | GNUNET_CRYPTO_EddsaPrivateKey); | ||
2176 | |||
2177 | priv_key = GNUNET_TESTING_hostkey_get (tl_system, | ||
2178 | num, | ||
2179 | peer); | ||
2180 | |||
2181 | GNUNET_CRYPTO_eddsa_key_get_public (priv_key, | ||
2182 | pub_key); | ||
2183 | peer->public_key = *pub_key; | ||
2184 | GNUNET_free (priv_key); | ||
2185 | GNUNET_free (pub_key); | ||
2186 | return peer; | ||
2187 | } | ||
2188 | |||
2189 | |||
2190 | int | ||
2191 | free_nodes_cb (void *cls, | ||
2192 | const struct GNUNET_ShortHashCode *key, | ||
2193 | void *value) | ||
2194 | { | ||
2195 | (void) cls; | ||
2196 | struct GNUNET_TESTING_NetjailNode *node = value; | ||
2197 | struct GNUNET_TESTING_NodeConnection *pos_connection; | ||
2198 | struct GNUNET_TESTING_NodeConnection *tmp_connection; | ||
2199 | struct GNUNET_TESTING_AddressPrefix *pos_prefix; | ||
2200 | struct GNUNET_TESTING_AddressPrefix *tmp_prefix; | ||
2201 | |||
2202 | pos_connection = node->node_connections_head; | ||
2203 | |||
2204 | while (NULL != pos_connection->next) | ||
2205 | { | ||
2206 | pos_prefix = pos_connection->address_prefixes_head; | ||
2207 | while (NULL != pos_prefix->next) | ||
2208 | { | ||
2209 | tmp_prefix = pos_prefix->next; | ||
2210 | GNUNET_free (pos_prefix); | ||
2211 | pos_prefix = tmp_prefix; | ||
2212 | } | ||
2213 | tmp_connection = pos_connection->next; | ||
2214 | GNUNET_free (pos_connection); | ||
2215 | pos_connection = tmp_connection; | ||
2216 | } | ||
2217 | return GNUNET_OK; | ||
2218 | } | ||
2219 | |||
2220 | |||
2221 | int | ||
2222 | free_namespaces_cb (void *cls, | ||
2223 | const struct GNUNET_ShortHashCode *key, | ||
2224 | void *value) | ||
2225 | { | ||
2226 | (void) cls; | ||
2227 | struct GNUNET_TESTING_NetjailNamespace *namespace = value; | ||
2228 | |||
2229 | GNUNET_free (namespace->router); | ||
2230 | GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, free_nodes_cb, | ||
2231 | NULL); | ||
2232 | return GNUNET_OK; | ||
2233 | |||
2234 | } | ||
2235 | |||
2236 | |||
2237 | /** | ||
2238 | * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. | ||
2239 | * | ||
2240 | * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated. | ||
2241 | */ | ||
2242 | void | ||
2243 | GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology) | ||
2244 | { | ||
2245 | GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces, | ||
2246 | free_namespaces_cb, NULL); | ||
2247 | GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, free_nodes_cb, | ||
2248 | NULL); | ||
2249 | GNUNET_free (topology); | ||
2250 | } | ||
2251 | |||
2252 | /** | ||
2253 | * Calculate the unique id identifying a node from a given connction. | ||
2254 | * | ||
2255 | * @param node_connection The connection we calculate the id from. | ||
2256 | * @param topology The topology we get all needed information from. | ||
2257 | * @return The unique id of the node from the connection. | ||
2258 | */ | ||
2259 | unsigned int | ||
2260 | GNUNET_TESTING_calculate_num (struct | ||
2261 | GNUNET_TESTING_NodeConnection *node_connection, | ||
2262 | struct GNUNET_TESTING_NetjailTopology *topology) | ||
2263 | { | ||
2264 | unsigned int n, m, num; | ||
2265 | |||
2266 | n = node_connection->namespace_n; | ||
2267 | m = node_connection->node_n; | ||
2268 | |||
2269 | if (0 == n) | ||
2270 | num = m; | ||
2271 | else | ||
2272 | num = (n - 1) * topology->nodes_m + m + topology->nodes_x; | ||
2273 | |||
2274 | return num; | ||
2275 | } | ||
2276 | |||
2277 | |||
2278 | /** | ||
2279 | * Get the address for a specific communicator from a connection. | ||
2280 | * | ||
2281 | * @param connection The connection we like to have the address from. | ||
2282 | * @param prefix The communicator protocol prefix. | ||
2283 | * @return The address of the communicator. | ||
2284 | */ | ||
2285 | char * | ||
2286 | GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, | ||
2287 | char *prefix) | ||
2288 | { | ||
2289 | struct GNUNET_TESTING_NetjailNode *node; | ||
2290 | char *addr; | ||
2291 | char *template; | ||
2292 | |||
2293 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2294 | "node_n: %u\n", | ||
2295 | connection->node_n); | ||
2296 | |||
2297 | node = connection->node; | ||
2298 | if (connection->namespace_n == node->namespace_n) | ||
2299 | { | ||
2300 | template = CONNECT_ADDRESS_TEMPLATE; | ||
2301 | } | ||
2302 | else if (0 == connection->namespace_n) | ||
2303 | { | ||
2304 | template = KNOWN_CONNECT_ADDRESS_TEMPLATE; | ||
2305 | } | ||
2306 | else | ||
2307 | { | ||
2308 | template = ROUTER_CONNECT_ADDRESS_TEMPLATE; | ||
2309 | } | ||
2310 | |||
2311 | if (0 == strcmp (PREFIX_TCP, prefix)) | ||
2312 | { | ||
2313 | |||
2314 | GNUNET_asprintf (&addr, | ||
2315 | template, | ||
2316 | prefix, | ||
2317 | connection->node_n); | ||
2318 | } | ||
2319 | else if (0 == strcmp (PREFIX_UDP, prefix)) | ||
2320 | { | ||
2321 | GNUNET_asprintf (&addr, | ||
2322 | template, | ||
2323 | prefix, | ||
2324 | connection->node_n); | ||
2002 | } | 2325 | } |
2326 | else | ||
2327 | { | ||
2328 | GNUNET_assert (0); | ||
2329 | } | ||
2330 | |||
2331 | return addr; | ||
2003 | } | 2332 | } |
2004 | 2333 | ||
2005 | 2334 | ||
@@ -2029,68 +2358,42 @@ GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv) | |||
2029 | 2358 | ||
2030 | 2359 | ||
2031 | /** | 2360 | /** |
2032 | * Getting the topology from file. | 2361 | * Parse the topology data. |
2033 | * | 2362 | * |
2034 | * @param filename The name of the topology file. | 2363 | * @param data The topology data. |
2035 | * @return The GNUNET_TESTING_NetjailTopology | 2364 | * @return The GNUNET_TESTING_NetjailTopology |
2036 | */ | 2365 | */ |
2037 | struct GNUNET_TESTING_NetjailTopology * | 2366 | struct GNUNET_TESTING_NetjailTopology * |
2038 | GNUNET_TESTING_get_topo_from_file (const char *filename) | 2367 | GNUNET_TESTING_get_topo_from_string (char *data) |
2039 | { | 2368 | { |
2040 | uint64_t fs; | ||
2041 | char *data; | ||
2042 | char *token; | 2369 | char *token; |
2043 | char *key; | 2370 | char *key = NULL; |
2044 | unsigned int out; | 2371 | unsigned int out; |
2045 | char *rest = NULL; | 2372 | char *rest = NULL; |
2046 | char *value; | 2373 | char *value; |
2374 | char *value2; | ||
2047 | int ret; | 2375 | int ret; |
2048 | struct GNUNET_TESTING_NetjailTopology *topo = GNUNET_new (struct | 2376 | struct GNUNET_TESTING_NetjailTopology *topo; |
2049 | GNUNET_TESTING_NetjailTopology); | ||
2050 | struct GNUNET_TESTING_NetjailNode *node; | 2377 | struct GNUNET_TESTING_NetjailNode *node; |
2051 | struct GNUNET_TESTING_NetjailRouter *router; | 2378 | struct GNUNET_TESTING_NetjailRouter *router; |
2052 | struct GNUNET_TESTING_NetjailNamespace *namespace; | 2379 | struct GNUNET_TESTING_NetjailNamespace *namespace; |
2053 | struct GNUNET_ShortHashCode *hkey; | 2380 | struct GNUNET_ShortHashCode *hkey; |
2054 | struct GNUNET_HashCode hc; | 2381 | struct GNUNET_HashCode hc; |
2055 | 2382 | ||
2383 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2384 | "data %s\n", | ||
2385 | data); | ||
2386 | token = strtok_r (data, "\n", &rest); | ||
2387 | topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology); | ||
2056 | topo->map_namespaces = | 2388 | topo->map_namespaces = |
2057 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | 2389 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); |
2058 | topo->map_globals = | 2390 | topo->map_globals = |
2059 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | 2391 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); |
2060 | 2392 | ||
2061 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
2062 | { | ||
2063 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2064 | _ ("Topology file %s not found\n"), | ||
2065 | filename); | ||
2066 | return NULL; | ||
2067 | } | ||
2068 | if (GNUNET_OK != | ||
2069 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | ||
2070 | { | ||
2071 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2072 | _ ("Topology file %s has no data\n"), | ||
2073 | filename); | ||
2074 | return NULL; | ||
2075 | } | ||
2076 | data = GNUNET_malloc (fs); | ||
2077 | if (fs != GNUNET_DISK_fn_read (filename, data, fs)) | ||
2078 | { | ||
2079 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2080 | _ ("Topology file %s cannot be read\n"), | ||
2081 | filename); | ||
2082 | GNUNET_free (data); | ||
2083 | return NULL; | ||
2084 | } | ||
2085 | |||
2086 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2087 | "data: %s\n", | ||
2088 | data); | ||
2089 | |||
2090 | token = strtok_r (data, "\n", &rest); | ||
2091 | |||
2092 | while (NULL != token) | 2393 | while (NULL != token) |
2093 | { | 2394 | { |
2395 | if (NULL != key) | ||
2396 | free (key); | ||
2094 | key = get_key (token); | 2397 | key = get_key (token); |
2095 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2398 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2096 | "In the loop with token: %s beginning with %s\n", | 2399 | "In the loop with token: %s beginning with %s\n", |
@@ -2201,12 +2504,12 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) | |||
2201 | 2504 | ||
2202 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2505 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2203 | "Get value for key udp_port on R.\n"); | 2506 | "Get value for key udp_port on R.\n"); |
2204 | value = get_value ("udp_port", token); | 2507 | value2 = get_value ("udp_port", token); |
2205 | ret = sscanf (value, "%u", &(router->udp_port)); | 2508 | ret = sscanf (value2, "%u", &(router->udp_port)); |
2206 | GNUNET_break (0 != ret && 1 >= router->udp_port); | 2509 | GNUNET_break (0 != ret && 1 >= router->udp_port); |
2207 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2510 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2208 | "udp_port: %s\n", | 2511 | "udp_port: %s\n", |
2209 | value); | 2512 | value2); |
2210 | 2513 | ||
2211 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( | 2514 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( |
2212 | topo->map_namespaces, | 2515 | topo->map_namespaces, |
@@ -2297,8 +2600,64 @@ GNUNET_TESTING_get_topo_from_file (const char *filename) | |||
2297 | node_connections (token, node); | 2600 | node_connections (token, node); |
2298 | } | 2601 | } |
2299 | token = strtok_r (NULL, "\n", &rest); | 2602 | token = strtok_r (NULL, "\n", &rest); |
2603 | if (NULL != token) | ||
2604 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2605 | "Next token %s\n", | ||
2606 | token); | ||
2607 | } | ||
2608 | |||
2609 | return topo; | ||
2610 | } | ||
2611 | |||
2612 | |||
2613 | /** | ||
2614 | * Getting the topology from file. | ||
2615 | * | ||
2616 | * @param filename The name of the topology file. | ||
2617 | * @return The GNUNET_TESTING_NetjailTopology | ||
2618 | */ | ||
2619 | struct GNUNET_TESTING_NetjailTopology * | ||
2620 | GNUNET_TESTING_get_topo_from_file (const char *filename) | ||
2621 | { | ||
2622 | uint64_t fs; | ||
2623 | char *data; | ||
2624 | struct GNUNET_TESTING_NetjailTopology *topo; | ||
2625 | |||
2626 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
2627 | { | ||
2628 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2629 | _ ("Topology file %s not found\n"), | ||
2630 | filename); | ||
2631 | return NULL; | ||
2632 | } | ||
2633 | if (GNUNET_OK != | ||
2634 | GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) | ||
2635 | { | ||
2636 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2637 | _ ("Topology file %s has no data\n"), | ||
2638 | filename); | ||
2639 | return NULL; | ||
2640 | } | ||
2641 | data = GNUNET_malloc (fs); | ||
2642 | if (fs != GNUNET_DISK_fn_read (filename, data, fs)) | ||
2643 | { | ||
2644 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2645 | _ ("Topology file %s cannot be read\n"), | ||
2646 | filename); | ||
2647 | GNUNET_free (data); | ||
2648 | return NULL; | ||
2300 | } | 2649 | } |
2301 | 2650 | ||
2651 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2652 | "data: %s\n", | ||
2653 | data); | ||
2654 | |||
2655 | data[fs] = '\0'; | ||
2656 | |||
2657 | topo = GNUNET_TESTING_get_topo_from_string (data); | ||
2658 | |||
2659 | GNUNET_free (data); | ||
2660 | |||
2302 | return topo; | 2661 | return topo; |
2303 | } | 2662 | } |
2304 | 2663 | ||
diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c deleted file mode 100644 index 763713e15..000000000 --- a/src/testing/testing_api_cmd_block_until_all_peers_started.c +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing_api_cmd_block_until_all_peers_started.c | ||
23 | * @brief cmd to block the interpreter loop until all peers started. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testing_ng_lib.h" | ||
29 | |||
30 | /** | ||
31 | * Generic logging shortcut | ||
32 | */ | ||
33 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
34 | |||
35 | /** | ||
36 | * Struct with information for callbacks. | ||
37 | * | ||
38 | */ | ||
39 | struct BlockState | ||
40 | { | ||
41 | /** | ||
42 | * Context for our asynchronous completion. | ||
43 | */ | ||
44 | struct GNUNET_TESTING_AsyncContext ac; | ||
45 | |||
46 | /** | ||
47 | * Flag to indicate if all peers have started. | ||
48 | * | ||
49 | */ | ||
50 | unsigned int *all_peers_started; | ||
51 | }; | ||
52 | |||
53 | |||
54 | /** | ||
55 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
56 | * | ||
57 | */ | ||
58 | static void | ||
59 | block_until_all_peers_started_cleanup (void *cls) | ||
60 | { | ||
61 | struct BlockState *bs = cls; | ||
62 | |||
63 | GNUNET_free (bs); | ||
64 | } | ||
65 | |||
66 | |||
67 | /** | ||
68 | * This function does nothing but to start the cmd. | ||
69 | * | ||
70 | */ | ||
71 | static void | ||
72 | block_until_all_peers_started_run (void *cls, | ||
73 | struct GNUNET_TESTING_Interpreter *is) | ||
74 | { | ||
75 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
76 | "block_until_all_peers_started_run!\n"); | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Create command. | ||
82 | * | ||
83 | * @param label name for command. | ||
84 | * @param all_peers_started Flag which will be set from outside. | ||
85 | * @return command. | ||
86 | */ | ||
87 | struct GNUNET_TESTING_Command | ||
88 | GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, | ||
89 | unsigned int * | ||
90 | all_peers_started) | ||
91 | { | ||
92 | struct BlockState *bs; | ||
93 | |||
94 | bs = GNUNET_new (struct BlockState); | ||
95 | bs->all_peers_started = all_peers_started; | ||
96 | { | ||
97 | struct GNUNET_TESTING_Command cmd = { | ||
98 | .cls = bs, | ||
99 | .label = label, | ||
100 | .run = &block_until_all_peers_started_run, | ||
101 | .ac = &bs->ac, | ||
102 | .cleanup = &block_until_all_peers_started_cleanup | ||
103 | }; | ||
104 | |||
105 | return cmd; | ||
106 | } | ||
107 | } | ||
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 aeb9ffda3..7ff554280 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | ||
29 | 30 | ||
30 | /** | 31 | /** |
31 | * Generic logging shortcut | 32 | * Generic logging shortcut |
diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c index 3ac0871a5..47199d3d6 100644 --- a/src/testing/testing_api_cmd_finish.c +++ b/src/testing/testing_api_cmd_finish.c | |||
@@ -25,6 +25,8 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
27 | #include "gnunet_testing_ng_lib.h" | 27 | #include "gnunet_testing_ng_lib.h" |
28 | #include "gnunet_testing_netjail_lib.h" | ||
29 | |||
28 | 30 | ||
29 | /** | 31 | /** |
30 | * Struct to use for command-specific context information closure of a command waiting | 32 | * Struct to use for command-specific context information closure of a command waiting |
diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c deleted file mode 100644 index 73dcd6dff..000000000 --- a/src/testing/testing_api_cmd_hello_world.c +++ /dev/null | |||
@@ -1,126 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/testing_api_cmd_hello_world.c | ||
23 | * @brief implementation of a hello world command. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | |||
29 | struct HelloWorldState | ||
30 | { | ||
31 | char *message; | ||
32 | const char *birthLabel; | ||
33 | }; | ||
34 | |||
35 | |||
36 | /** | ||
37 | * | ||
38 | * | ||
39 | * @param cls closure | ||
40 | */ | ||
41 | static void | ||
42 | hello_world_cleanup (void *cls) | ||
43 | { | ||
44 | struct HelloWorldState *hs = cls; | ||
45 | |||
46 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
47 | "Cleaning up message %s\n", | ||
48 | hs->message); | ||
49 | GNUNET_free (hs); | ||
50 | } | ||
51 | |||
52 | |||
53 | /** | ||
54 | * | ||
55 | * | ||
56 | * @param cls closure. | ||
57 | * @param[out] ret result | ||
58 | * @param trait name of the trait. | ||
59 | * @param index index number of the object to offer. | ||
60 | * @return #GNUNET_OK on success. | ||
61 | */ | ||
62 | static enum GNUNET_GenericReturnValue | ||
63 | hello_world_traits (void *cls, | ||
64 | const void **ret, | ||
65 | const char *trait, | ||
66 | unsigned int index) | ||
67 | { | ||
68 | return GNUNET_NO; | ||
69 | } | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Run the "hello world" CMD. | ||
74 | * | ||
75 | * @param cls closure. | ||
76 | * @param is interpreter state. | ||
77 | */ | ||
78 | static void | ||
79 | hello_world_run (void *cls, | ||
80 | struct GNUNET_TESTING_Interpreter *is) | ||
81 | { | ||
82 | struct HelloWorldState *hs = cls; | ||
83 | const struct GNUNET_TESTING_Command *birth_cmd; | ||
84 | |||
85 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
86 | "%s\n", | ||
87 | hs->message); | ||
88 | birth_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
89 | hs->birthLabel); | ||
90 | GNUNET_TESTING_get_trait_what_am_i (birth_cmd, | ||
91 | &hs->message); | ||
92 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
93 | "Now I am a %s\n", | ||
94 | hs->message); | ||
95 | } | ||
96 | |||
97 | |||
98 | /** | ||
99 | * Create command. | ||
100 | * | ||
101 | * @param label name for command. | ||
102 | * @param message initial message. | ||
103 | * @return command. | ||
104 | */ | ||
105 | struct GNUNET_TESTING_Command | ||
106 | GNUNET_TESTING_cmd_hello_world (const char *label, | ||
107 | const char *birthLabel, | ||
108 | char *message) | ||
109 | { | ||
110 | struct HelloWorldState *hs; | ||
111 | |||
112 | hs = GNUNET_new (struct HelloWorldState); | ||
113 | hs->message = "Hello World, I was nobody!"; | ||
114 | hs->birthLabel = birthLabel; | ||
115 | { | ||
116 | struct GNUNET_TESTING_Command cmd = { | ||
117 | .cls = hs, | ||
118 | .label = label, | ||
119 | .run = &hello_world_run, | ||
120 | .cleanup = &hello_world_cleanup, | ||
121 | .traits = &hello_world_traits | ||
122 | }; | ||
123 | |||
124 | return cmd; | ||
125 | } | ||
126 | } | ||
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c deleted file mode 100644 index 8415b99f0..000000000 --- a/src/testing/testing_api_cmd_hello_world_birth.c +++ /dev/null | |||
@@ -1,161 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/testing_api_cmd_hello_world.c | ||
23 | * @brief implementation of a hello world command. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testing_ng_lib.h" | ||
29 | |||
30 | struct HelloWorldBirthState | ||
31 | { | ||
32 | struct GNUNET_TIME_Absolute *date; | ||
33 | char *what_am_i; | ||
34 | }; | ||
35 | |||
36 | /** | ||
37 | * | ||
38 | * | ||
39 | * @param cls closure | ||
40 | * @param cmd current CMD being cleaned up. | ||
41 | */ | ||
42 | static void | ||
43 | hello_world_birth_cleanup (void *cls) | ||
44 | { | ||
45 | struct HelloWorldBirthState *hbs = cls; | ||
46 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
47 | "Finished birth of %s\n", | ||
48 | hbs->what_am_i); | ||
49 | } | ||
50 | |||
51 | |||
52 | /** | ||
53 | * | ||
54 | * | ||
55 | * @param cls closure. | ||
56 | * @param[out] ret result | ||
57 | * @param trait name of the trait. | ||
58 | * @param index index number of the object to offer. | ||
59 | * @return #GNUNET_OK on success. | ||
60 | */ | ||
61 | static int | ||
62 | hello_world_birth_traits (void *cls, | ||
63 | const void **ret, | ||
64 | const char *trait, | ||
65 | unsigned int index) | ||
66 | { | ||
67 | struct HelloWorldBirthState *hbs = cls; | ||
68 | const char *what_am_i = hbs->what_am_i; | ||
69 | |||
70 | struct GNUNET_TESTING_Trait traits[] = { | ||
71 | { | ||
72 | .index = 0, | ||
73 | .trait_name = "what_am_i", | ||
74 | .ptr = (const void *) what_am_i, | ||
75 | }, | ||
76 | GNUNET_TESTING_trait_end () | ||
77 | }; | ||
78 | |||
79 | return GNUNET_TESTING_get_trait (traits, | ||
80 | ret, | ||
81 | trait, | ||
82 | index); | ||
83 | } | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Run the "hello world" CMD. | ||
88 | * | ||
89 | * @param cls closure. | ||
90 | * @param cmd CMD being run. | ||
91 | * @param is interpreter state. | ||
92 | */ | ||
93 | static void | ||
94 | hello_world_birth_run (void *cls, | ||
95 | struct GNUNET_TESTING_Interpreter *is) | ||
96 | { | ||
97 | struct HelloWorldBirthState *hbs = cls; | ||
98 | struct GNUNET_TIME_Relative relative; | ||
99 | |||
100 | relative = GNUNET_TIME_absolute_get_difference (*hbs->date, | ||
101 | GNUNET_TIME_absolute_get ()); | ||
102 | |||
103 | if (0 == relative.rel_value_us % 10) | ||
104 | { | ||
105 | hbs->what_am_i = "creature!"; | ||
106 | } | ||
107 | else if (0 == relative.rel_value_us % 2) | ||
108 | { | ||
109 | hbs->what_am_i = "girl!"; | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | hbs->what_am_i = "boy!"; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Offer data from trait | ||
120 | * | ||
121 | * @param cmd command to extract the message from. | ||
122 | * @param pt pointer to message. | ||
123 | * @return #GNUNET_OK on success. | ||
124 | */ | ||
125 | int | ||
126 | GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd, | ||
127 | char **what_am_i) | ||
128 | { | ||
129 | return cmd->traits (cmd->cls, | ||
130 | (const void **) what_am_i, | ||
131 | "what_am_i", | ||
132 | (unsigned int) 0); | ||
133 | } | ||
134 | |||
135 | |||
136 | /** | ||
137 | * Create command. | ||
138 | * | ||
139 | * @param label name for command. | ||
140 | * @param now when the command was started. | ||
141 | * @return command. | ||
142 | */ | ||
143 | struct GNUNET_TESTING_Command | ||
144 | GNUNET_TESTING_cmd_hello_world_birth (const char *label, | ||
145 | struct GNUNET_TIME_Absolute *now) | ||
146 | { | ||
147 | struct HelloWorldBirthState *hbs; | ||
148 | |||
149 | hbs = GNUNET_new (struct HelloWorldBirthState); | ||
150 | hbs->date = now; | ||
151 | |||
152 | struct GNUNET_TESTING_Command cmd = { | ||
153 | .cls = hbs, | ||
154 | .label = label, | ||
155 | .run = &hello_world_birth_run, | ||
156 | .cleanup = &hello_world_birth_cleanup, | ||
157 | .traits = &hello_world_birth_traits | ||
158 | }; | ||
159 | |||
160 | return cmd; | ||
161 | } | ||
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c index 0e7e214dc..709c6b62f 100644 --- a/src/testing/testing_api_cmd_local_test_finished.c +++ b/src/testing/testing_api_cmd_local_test_finished.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | ||
29 | #include "testing_cmds.h" | 30 | #include "testing_cmds.h" |
30 | 31 | ||
31 | /** | 32 | /** |
@@ -64,7 +65,6 @@ local_test_finished_cleanup (void *cls) | |||
64 | { | 65 | { |
65 | struct LocalFinishedState *lfs = cls; | 66 | struct LocalFinishedState *lfs = cls; |
66 | 67 | ||
67 | GNUNET_free (lfs->reply); | ||
68 | GNUNET_free (lfs); | 68 | GNUNET_free (lfs); |
69 | } | 69 | } |
70 | 70 | ||
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c new file mode 100644 index 000000000..9dc7dfa9a --- /dev/null +++ b/src/testing/testing_api_cmd_local_test_prepared.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing_api_cmd_local_test_prepared.c | ||
23 | * @brief cmd to block the interpreter loop until all peers started. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testing_ng_lib.h" | ||
29 | #include "gnunet_testing_netjail_lib.h" | ||
30 | #include "testing_cmds.h" | ||
31 | |||
32 | /** | ||
33 | * Generic logging shortcut | ||
34 | */ | ||
35 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
36 | |||
37 | |||
38 | /** | ||
39 | * This function prepares an array with traits. | ||
40 | * | ||
41 | */ | ||
42 | enum GNUNET_GenericReturnValue | ||
43 | local_test_prepared_traits (void *cls, | ||
44 | const void **ret, | ||
45 | const char *trait, | ||
46 | unsigned int index) | ||
47 | { | ||
48 | struct LocalPreparedState *lfs = cls; | ||
49 | struct GNUNET_TESTING_Trait traits[] = { | ||
50 | { | ||
51 | .index = 0, | ||
52 | .trait_name = "state", | ||
53 | .ptr = (const void *) lfs, | ||
54 | }, | ||
55 | GNUNET_TESTING_trait_end () | ||
56 | }; | ||
57 | return GNUNET_TESTING_get_trait (traits, | ||
58 | ret, | ||
59 | trait, | ||
60 | index); | ||
61 | } | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Function to get the trait with the struct LocalPreparedState. | ||
66 | * | ||
67 | * @param[out] lfs struct LocalPreparedState. | ||
68 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
69 | * | ||
70 | */ | ||
71 | enum GNUNET_GenericReturnValue | ||
72 | GNUNET_TESTING_get_trait_local_prepared_state ( | ||
73 | const struct GNUNET_TESTING_Command *cmd, | ||
74 | struct LocalPreparedState **lfs) | ||
75 | { | ||
76 | return cmd->traits (cmd->cls, | ||
77 | (const void **) lfs, | ||
78 | "state", | ||
79 | (unsigned int) 0); | ||
80 | } | ||
81 | |||
82 | |||
83 | /** | ||
84 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
85 | * | ||
86 | */ | ||
87 | static void | ||
88 | local_test_prepared_cleanup (void *cls) | ||
89 | { | ||
90 | struct LocalPreparedState *lfs = cls; | ||
91 | |||
92 | GNUNET_free (lfs); | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TESTS_PREPARED message to the master loop. | ||
98 | * | ||
99 | */ | ||
100 | static void | ||
101 | local_test_prepared_run (void *cls, | ||
102 | struct GNUNET_TESTING_Interpreter *is) | ||
103 | { | ||
104 | struct LocalPreparedState *lfs = cls; | ||
105 | |||
106 | struct GNUNET_CMDS_LOCAL_TEST_PREPARED *reply; | ||
107 | size_t msg_length; | ||
108 | |||
109 | msg_length = sizeof(struct GNUNET_CMDS_LOCAL_TEST_PREPARED); | ||
110 | reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_TEST_PREPARED); | ||
111 | reply->header.type = htons ( | ||
112 | GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED); | ||
113 | reply->header.size = htons ((uint16_t) msg_length); | ||
114 | lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); | ||
115 | } | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Create command. | ||
120 | * | ||
121 | * @param label name for command. | ||
122 | * @param write_message Callback to write messages to the master loop. | ||
123 | * @param all_local_tests_prepared Flag which will be set from outside. | ||
124 | * @return command. | ||
125 | */ | ||
126 | struct GNUNET_TESTING_Command | ||
127 | GNUNET_TESTING_cmd_local_test_prepared (const char *label, | ||
128 | TESTING_CMD_HELPER_write_cb | ||
129 | write_message) | ||
130 | { | ||
131 | struct LocalPreparedState *lfs; | ||
132 | |||
133 | lfs = GNUNET_new (struct LocalPreparedState); | ||
134 | lfs->write_message = write_message; | ||
135 | |||
136 | struct GNUNET_TESTING_Command cmd = { | ||
137 | .cls = lfs, | ||
138 | .label = label, | ||
139 | .run = &local_test_prepared_run, | ||
140 | .ac = &lfs->ac, | ||
141 | .cleanup = &local_test_prepared_cleanup, | ||
142 | .traits = &local_test_prepared_traits | ||
143 | }; | ||
144 | |||
145 | return cmd; | ||
146 | } | ||
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c index 35fb90f3c..2ff70c33e 100644 --- a/src/testing/testing_api_cmd_netjail_start.c +++ b/src/testing/testing_api_cmd_netjail_start.c | |||
@@ -26,8 +26,11 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | ||
29 | 30 | ||
30 | #define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh" | 31 | #define NETJAIL_START_SCRIPT "netjail_start.sh" |
32 | |||
33 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
31 | 34 | ||
32 | /** | 35 | /** |
33 | * Struct to hold information for callbacks. | 36 | * Struct to hold information for callbacks. |
@@ -53,6 +56,10 @@ struct NetJailState | |||
53 | */ | 56 | */ |
54 | char *topology_config; | 57 | char *topology_config; |
55 | 58 | ||
59 | /** | ||
60 | * Shall we read the topology from file, or from a string. | ||
61 | */ | ||
62 | unsigned int *read_file; | ||
56 | }; | 63 | }; |
57 | 64 | ||
58 | 65 | ||
@@ -70,11 +77,15 @@ netjail_start_cleanup (void *cls) | |||
70 | 77 | ||
71 | if (NULL != ns->cwh) | 78 | if (NULL != ns->cwh) |
72 | { | 79 | { |
80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
81 | "Cancel child\n"); | ||
73 | GNUNET_wait_child_cancel (ns->cwh); | 82 | GNUNET_wait_child_cancel (ns->cwh); |
74 | ns->cwh = NULL; | 83 | ns->cwh = NULL; |
75 | } | 84 | } |
76 | if (NULL != ns->start_proc) | 85 | if (NULL != ns->start_proc) |
77 | { | 86 | { |
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
88 | "Kill process\n"); | ||
78 | GNUNET_assert (0 == | 89 | GNUNET_assert (0 == |
79 | GNUNET_OS_process_kill (ns->start_proc, | 90 | GNUNET_OS_process_kill (ns->start_proc, |
80 | SIGKILL)); | 91 | SIGKILL)); |
@@ -100,6 +111,7 @@ child_completed_callback (void *cls, | |||
100 | 111 | ||
101 | GNUNET_OS_process_destroy (ns->start_proc); | 112 | GNUNET_OS_process_destroy (ns->start_proc); |
102 | ns->start_proc = NULL; | 113 | ns->start_proc = NULL; |
114 | ns->cwh = NULL; | ||
103 | if (0 == exit_code) | 115 | if (0 == exit_code) |
104 | { | 116 | { |
105 | GNUNET_TESTING_async_finish (&ns->ac); | 117 | GNUNET_TESTING_async_finish (&ns->ac); |
@@ -127,20 +139,28 @@ netjail_start_run (void *cls, | |||
127 | struct NetJailState *ns = cls; | 139 | struct NetJailState *ns = cls; |
128 | char pid[15]; | 140 | char pid[15]; |
129 | enum GNUNET_GenericReturnValue helper_check; | 141 | enum GNUNET_GenericReturnValue helper_check; |
142 | char *data_dir; | ||
143 | char *script_name; | ||
144 | char *read_file; | ||
145 | |||
146 | data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | ||
147 | GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_START_SCRIPT); | ||
148 | GNUNET_asprintf (&read_file, "%u", *(ns->read_file)); | ||
130 | 149 | ||
131 | // FIXME: NETJAIL_START_SCRIPT like this is bad, | ||
132 | // use location from share/gnunet/ of installed | ||
133 | // binary in case libgnunettesting is used as a lib! | ||
134 | helper_check = GNUNET_OS_check_helper_binary ( | 150 | helper_check = GNUNET_OS_check_helper_binary ( |
135 | NETJAIL_START_SCRIPT, | 151 | script_name, |
136 | GNUNET_YES, | 152 | GNUNET_YES, |
137 | NULL); | 153 | NULL); |
138 | 154 | ||
155 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
156 | "script_name %s\n", | ||
157 | script_name); | ||
158 | |||
139 | if (GNUNET_NO == helper_check) | 159 | if (GNUNET_NO == helper_check) |
140 | { | 160 | { |
141 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
142 | "No SUID for %s!\n", | 162 | "No SUID for %s!\n", |
143 | NETJAIL_START_SCRIPT); | 163 | script_name); |
144 | GNUNET_TESTING_interpreter_fail (is); | 164 | GNUNET_TESTING_interpreter_fail (is); |
145 | return; | 165 | return; |
146 | } | 166 | } |
@@ -148,7 +168,7 @@ netjail_start_run (void *cls, | |||
148 | { | 168 | { |
149 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 169 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
150 | "%s not found!\n", | 170 | "%s not found!\n", |
151 | NETJAIL_START_SCRIPT); | 171 | script_name); |
152 | GNUNET_TESTING_interpreter_fail (is); | 172 | GNUNET_TESTING_interpreter_fail (is); |
153 | return; | 173 | return; |
154 | } | 174 | } |
@@ -159,9 +179,10 @@ netjail_start_run (void *cls, | |||
159 | getpid ()); | 179 | getpid ()); |
160 | { | 180 | { |
161 | char *const script_argv[] = { | 181 | char *const script_argv[] = { |
162 | NETJAIL_START_SCRIPT, | 182 | script_name, |
163 | ns->topology_config, | 183 | ns->topology_config, |
164 | pid, | 184 | pid, |
185 | read_file, | ||
165 | NULL | 186 | NULL |
166 | }; | 187 | }; |
167 | 188 | ||
@@ -170,7 +191,7 @@ netjail_start_run (void *cls, | |||
170 | NULL, | 191 | NULL, |
171 | NULL, | 192 | NULL, |
172 | NULL, | 193 | NULL, |
173 | NETJAIL_START_SCRIPT, | 194 | script_name, |
174 | script_argv); | 195 | script_argv); |
175 | } | 196 | } |
176 | ns->cwh = GNUNET_wait_child (ns->start_proc, | 197 | ns->cwh = GNUNET_wait_child (ns->start_proc, |
@@ -189,12 +210,14 @@ netjail_start_run (void *cls, | |||
189 | */ | 210 | */ |
190 | struct GNUNET_TESTING_Command | 211 | struct GNUNET_TESTING_Command |
191 | GNUNET_TESTING_cmd_netjail_start (const char *label, | 212 | GNUNET_TESTING_cmd_netjail_start (const char *label, |
192 | char *topology_config) | 213 | char *topology_config, |
214 | unsigned int *read_file) | ||
193 | { | 215 | { |
194 | struct NetJailState *ns; | 216 | struct NetJailState *ns; |
195 | 217 | ||
196 | ns = GNUNET_new (struct NetJailState); | 218 | ns = GNUNET_new (struct NetJailState); |
197 | ns->topology_config = topology_config; | 219 | ns->topology_config = topology_config; |
220 | ns->read_file = read_file; | ||
198 | { | 221 | { |
199 | struct GNUNET_TESTING_Command cmd = { | 222 | struct GNUNET_TESTING_Command cmd = { |
200 | .cls = ns, | 223 | .cls = ns, |
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c index a1d71c436..89c193de5 100644 --- a/src/testing/testing_api_cmd_netjail_start_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c | |||
@@ -25,9 +25,15 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_testing_ng_lib.h" | 27 | #include "gnunet_testing_ng_lib.h" |
28 | #include "gnunet_testing_netjail_lib.h" | ||
28 | #include "testing_cmds.h" | 29 | #include "testing_cmds.h" |
29 | 30 | ||
30 | #define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh" | 31 | #define NETJAIL_EXEC_SCRIPT "netjail_exec.sh" |
32 | |||
33 | /** | ||
34 | * Generic logging shortcut | ||
35 | */ | ||
36 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
31 | 37 | ||
32 | /** | 38 | /** |
33 | * Struct to store messages send/received by the helper into a DLL | 39 | * Struct to store messages send/received by the helper into a DLL |
@@ -62,6 +68,12 @@ struct HelperMessage | |||
62 | struct NetJailState | 68 | struct NetJailState |
63 | { | 69 | { |
64 | /** | 70 | /** |
71 | * Global state of the interpreter, used by a command | ||
72 | * to access information about other commands. | ||
73 | */ | ||
74 | struct GNUNET_TESTING_Interpreter *is; | ||
75 | |||
76 | /** | ||
65 | * Context for our asynchronous completion. | 77 | * Context for our asynchronous completion. |
66 | */ | 78 | */ |
67 | struct GNUNET_TESTING_AsyncContext ac; | 79 | struct GNUNET_TESTING_AsyncContext ac; |
@@ -72,24 +84,6 @@ struct NetJailState | |||
72 | struct GNUNET_TESTING_NetjailTopology *topology; | 84 | struct GNUNET_TESTING_NetjailTopology *topology; |
73 | 85 | ||
74 | /** | 86 | /** |
75 | * Pointer to the return value of the test. | ||
76 | * | ||
77 | */ | ||
78 | unsigned int *rv; | ||
79 | |||
80 | /** | ||
81 | * Head of the DLL which stores messages received by the helper. | ||
82 | * | ||
83 | */ | ||
84 | struct HelperMessage *hp_messages_head; | ||
85 | |||
86 | /** | ||
87 | * Tail of the DLL which stores messages received by the helper. | ||
88 | * | ||
89 | */ | ||
90 | struct HelperMessage *hp_messages_tail; | ||
91 | |||
92 | /** | ||
93 | * Array with handles of helper processes. | 87 | * Array with handles of helper processes. |
94 | */ | 88 | */ |
95 | struct GNUNET_HELPER_Handle **helper; | 89 | struct GNUNET_HELPER_Handle **helper; |
@@ -118,27 +112,6 @@ struct NetJailState | |||
118 | */ | 112 | */ |
119 | unsigned int known; | 113 | unsigned int known; |
120 | 114 | ||
121 | /** | ||
122 | * The send handle for the helper | ||
123 | */ | ||
124 | struct GNUNET_HELPER_SendHandle **shandle; | ||
125 | |||
126 | /** | ||
127 | * Size of the array NetJailState#shandle. | ||
128 | * | ||
129 | */ | ||
130 | unsigned int n_shandle; | ||
131 | |||
132 | /** | ||
133 | * The messages send to the helper. | ||
134 | */ | ||
135 | struct GNUNET_MessageHeader **msg; | ||
136 | |||
137 | /** | ||
138 | * Size of the array NetJailState#msg. | ||
139 | * | ||
140 | */ | ||
141 | unsigned int n_msg; | ||
142 | 115 | ||
143 | /** | 116 | /** |
144 | * Number of test environments started. | 117 | * Number of test environments started. |
@@ -156,7 +129,13 @@ struct NetJailState | |||
156 | * Number of local tests finished. | 129 | * Number of local tests finished. |
157 | * | 130 | * |
158 | */ | 131 | */ |
159 | unsigned int number_of_local_test_finished; | 132 | unsigned int number_of_local_tests_finished; |
133 | |||
134 | /** | ||
135 | * Number of local tests prepared to finish. | ||
136 | * | ||
137 | */ | ||
138 | unsigned int number_of_local_tests_prepared; | ||
160 | 139 | ||
161 | /** | 140 | /** |
162 | * Name of the test case plugin the helper will load. | 141 | * Name of the test case plugin the helper will load. |
@@ -165,16 +144,14 @@ struct NetJailState | |||
165 | char *plugin_name; | 144 | char *plugin_name; |
166 | 145 | ||
167 | /** | 146 | /** |
168 | * HEAD of the DLL containing TestingSystemCount. | 147 | * Shall we read the topology from file, or from a string. |
169 | * | ||
170 | */ | 148 | */ |
171 | struct TestingSystemCount *tbcs_head; | 149 | unsigned int *read_file; |
172 | 150 | ||
173 | /** | 151 | /** |
174 | * TAIL of the DLL containing TestingSystemCount. | 152 | * String with topology data or name of topology file. |
175 | * | ||
176 | */ | 153 | */ |
177 | struct TestingSystemCount *tbcs_tail; | 154 | char *topology_data; |
178 | }; | 155 | }; |
179 | 156 | ||
180 | /** | 157 | /** |
@@ -194,6 +171,11 @@ struct TestingSystemCount | |||
194 | struct TestingSystemCount *prev; | 171 | struct TestingSystemCount *prev; |
195 | 172 | ||
196 | /** | 173 | /** |
174 | * The send handle for the helper | ||
175 | */ | ||
176 | struct GNUNET_HELPER_SendHandle *shandle; | ||
177 | |||
178 | /** | ||
197 | * The number of the test environment. | 179 | * The number of the test environment. |
198 | * | 180 | * |
199 | */ | 181 | */ |
@@ -204,6 +186,11 @@ struct TestingSystemCount | |||
204 | * | 186 | * |
205 | */ | 187 | */ |
206 | struct NetJailState *ns; | 188 | struct NetJailState *ns; |
189 | |||
190 | /** | ||
191 | * The messages send to the helper. | ||
192 | */ | ||
193 | struct GNUNET_MessageHeader *msg; | ||
207 | }; | 194 | }; |
208 | 195 | ||
209 | /** | 196 | /** |
@@ -215,23 +202,7 @@ static void | |||
215 | netjail_exec_cleanup (void *cls) | 202 | netjail_exec_cleanup (void *cls) |
216 | { | 203 | { |
217 | struct NetJailState *ns = cls; | 204 | struct NetJailState *ns = cls; |
218 | struct HelperMessage *message_pos; | ||
219 | struct TestingSystemCount *tbc_pos; | ||
220 | 205 | ||
221 | while (NULL != (message_pos = ns->hp_messages_head)) | ||
222 | { | ||
223 | GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head, | ||
224 | ns->hp_messages_tail, | ||
225 | message_pos); | ||
226 | GNUNET_free (message_pos); | ||
227 | } | ||
228 | while (NULL != (tbc_pos = ns->tbcs_head)) | ||
229 | { | ||
230 | GNUNET_CONTAINER_DLL_remove (ns->tbcs_head, | ||
231 | ns->tbcs_tail, | ||
232 | tbc_pos); | ||
233 | GNUNET_free (tbc_pos); | ||
234 | } | ||
235 | GNUNET_free (ns); | 206 | GNUNET_free (ns); |
236 | } | 207 | } |
237 | 208 | ||
@@ -248,7 +219,6 @@ netjail_exec_traits (void *cls, | |||
248 | { | 219 | { |
249 | struct NetJailState *ns = cls; | 220 | struct NetJailState *ns = cls; |
250 | struct GNUNET_HELPER_Handle **helper = ns->helper; | 221 | struct GNUNET_HELPER_Handle **helper = ns->helper; |
251 | struct HelperMessage *hp_messages_head = ns->hp_messages_head; | ||
252 | 222 | ||
253 | 223 | ||
254 | struct GNUNET_TESTING_Trait traits[] = { | 224 | struct GNUNET_TESTING_Trait traits[] = { |
@@ -257,11 +227,6 @@ netjail_exec_traits (void *cls, | |||
257 | .trait_name = "helper_handles", | 227 | .trait_name = "helper_handles", |
258 | .ptr = (const void *) helper, | 228 | .ptr = (const void *) helper, |
259 | }, | 229 | }, |
260 | { | ||
261 | .index = 1, | ||
262 | .trait_name = "hp_msgs_head", | ||
263 | .ptr = (const void *) hp_messages_head, | ||
264 | }, | ||
265 | GNUNET_TESTING_trait_end () | 230 | GNUNET_TESTING_trait_end () |
266 | }; | 231 | }; |
267 | 232 | ||
@@ -304,49 +269,87 @@ static void | |||
304 | clear_msg (void *cls, int result) | 269 | clear_msg (void *cls, int result) |
305 | { | 270 | { |
306 | struct TestingSystemCount *tbc = cls; | 271 | struct TestingSystemCount *tbc = cls; |
307 | struct NetJailState *ns = tbc->ns; | ||
308 | 272 | ||
309 | GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); | 273 | GNUNET_assert (NULL != tbc->shandle); |
310 | ns->shandle[tbc->count - 1] = NULL; | 274 | GNUNET_free (tbc->shandle); |
311 | GNUNET_free (ns->msg[tbc->count - 1]); | 275 | tbc->shandle = NULL; |
312 | ns->msg[tbc->count - 1] = NULL; | 276 | GNUNET_free (tbc->msg); |
277 | tbc->msg = NULL; | ||
313 | } | 278 | } |
314 | 279 | ||
315 | 280 | ||
316 | static void | 281 | static void |
317 | send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) | 282 | send_message_to_locals ( |
283 | unsigned int i, | ||
284 | unsigned int j, | ||
285 | struct NetJailState *ns, | ||
286 | struct GNUNET_MessageHeader *header | ||
287 | ) | ||
318 | { | 288 | { |
319 | unsigned int total_number = ns->local_m * ns->global_n + ns->known; | 289 | // unsigned int total_number = ns->local_m * ns->global_n + ns->known; |
320 | struct GNUNET_CMDS_ALL_PEERS_STARTED *reply; | ||
321 | size_t msg_length; | ||
322 | struct GNUNET_HELPER_Handle *helper; | 290 | struct GNUNET_HELPER_Handle *helper; |
323 | struct TestingSystemCount *tbc; | 291 | struct TestingSystemCount *tbc; |
324 | 292 | ||
293 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
294 | "send message of type %u to locals\n", | ||
295 | header->type); | ||
325 | tbc = GNUNET_new (struct TestingSystemCount); | 296 | tbc = GNUNET_new (struct TestingSystemCount); |
326 | tbc->ns = ns; | 297 | tbc->ns = ns; |
327 | // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone. | 298 | // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone. |
328 | if (0 == i) | 299 | if (0 == i) |
329 | tbc->count = j + total_number; | 300 | tbc->count = j; // + total_number; |
330 | else | 301 | else |
331 | tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known; | 302 | tbc->count = (i - 1) * ns->local_m + j + ns->known; // + total_number ; |
303 | |||
304 | helper = ns->helper[tbc->count - 1];// - total_number]; | ||
332 | 305 | ||
333 | helper = ns->helper[tbc->count - 1 - total_number]; | ||
334 | msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED); | ||
335 | reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED); | ||
336 | reply->header.type = htons ( | ||
337 | GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED); | ||
338 | reply->header.size = htons ((uint16_t) msg_length); | ||
339 | 306 | ||
340 | GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); | ||
341 | 307 | ||
342 | struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( | 308 | struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( |
343 | helper, | 309 | helper, |
344 | &reply->header, | 310 | header, |
345 | GNUNET_NO, | 311 | GNUNET_NO, |
346 | &clear_msg, | 312 | &clear_msg, |
347 | tbc); | 313 | tbc); |
348 | 314 | ||
349 | GNUNET_array_append (ns->shandle, ns->n_shandle, sh); | 315 | tbc->shandle = sh; |
316 | // GNUNET_array_append (tbc->shandle, tbc->n_shandle, sh); | ||
317 | } | ||
318 | |||
319 | |||
320 | static void | ||
321 | send_all_local_tests_prepared (unsigned int i, unsigned int j, struct | ||
322 | NetJailState *ns) | ||
323 | { | ||
324 | struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED *reply; | ||
325 | size_t msg_length; | ||
326 | |||
327 | |||
328 | msg_length = sizeof(struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED); | ||
329 | reply = GNUNET_new (struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED); | ||
330 | reply->header.type = htons ( | ||
331 | GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED); | ||
332 | reply->header.size = htons ((uint16_t) msg_length); | ||
333 | |||
334 | send_message_to_locals (i, j, ns, &reply->header); | ||
335 | } | ||
336 | |||
337 | |||
338 | static void | ||
339 | send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) | ||
340 | { | ||
341 | |||
342 | struct GNUNET_CMDS_ALL_PEERS_STARTED *reply; | ||
343 | size_t msg_length; | ||
344 | |||
345 | |||
346 | msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED); | ||
347 | reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED); | ||
348 | reply->header.type = htons ( | ||
349 | GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED); | ||
350 | reply->header.size = htons ((uint16_t) msg_length); | ||
351 | |||
352 | send_message_to_locals (i, j, ns, &reply->header); | ||
350 | } | 353 | } |
351 | 354 | ||
352 | 355 | ||
@@ -365,11 +368,67 @@ send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns) | |||
365 | static int | 368 | static int |
366 | helper_mst (void *cls, const struct GNUNET_MessageHeader *message) | 369 | helper_mst (void *cls, const struct GNUNET_MessageHeader *message) |
367 | { | 370 | { |
368 | struct TestingSystemCount *tbc = cls; | 371 | // struct TestingSystemCount *tbc = cls; |
369 | struct NetJailState *ns = tbc->ns; | 372 | struct NetJailState *ns = cls; |
370 | struct HelperMessage *hp_msg; | 373 | struct HelperMessage *hp_msg; |
371 | unsigned int total_number = ns->local_m * ns->global_n + ns->known; | 374 | unsigned int total_number = ns->local_m * ns->global_n + ns->known; |
375 | // uint16_t message_type = ntohs (message->type); | ||
376 | |||
377 | /*switch (message_type) | ||
378 | { | ||
379 | case GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY: | ||
380 | ns->number_of_testsystems_started++; | ||
381 | break; | ||
382 | case GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED: | ||
383 | ns->number_of_peers_started++; | ||
384 | if (ns->number_of_peers_started == total_number) | ||
385 | { | ||
386 | for (int i = 1; i <= ns->known; i++) | ||
387 | { | ||
388 | send_all_peers_started (0,i, ns); | ||
389 | } | ||
390 | for (int i = 1; i <= ns->global_n; i++) | ||
391 | { | ||
392 | for (int j = 1; j <= ns->local_m; j++) | ||
393 | { | ||
394 | send_all_peers_started (i,j, ns); | ||
395 | } | ||
396 | } | ||
397 | ns->number_of_peers_started = 0; | ||
398 | } | ||
399 | break; | ||
400 | case GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED: | ||
401 | ns->number_of_local_tests_prepared++; | ||
402 | if (ns->number_of_local_tests_prepared == total_number) | ||
403 | { | ||
404 | for (int i = 1; i <= ns->known; i++) | ||
405 | { | ||
406 | send_all_local_tests_prepared (0,i, ns); | ||
407 | } | ||
372 | 408 | ||
409 | for (int i = 1; i <= ns->global_n; i++) | ||
410 | { | ||
411 | for (int j = 1; j <= ns->local_m; j++) | ||
412 | { | ||
413 | send_all_local_tests_prepared (i,j, ns); | ||
414 | } | ||
415 | } | ||
416 | } | ||
417 | break; | ||
418 | case GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED: | ||
419 | ns->number_of_local_tests_finished++; | ||
420 | if (ns->number_of_local_tests_finished == total_number) | ||
421 | { | ||
422 | GNUNET_TESTING_async_finish (&ns->ac); | ||
423 | } | ||
424 | break; | ||
425 | default: | ||
426 | hp_msg = GNUNET_new (struct HelperMessage); | ||
427 | hp_msg->bytes_msg = message->size; | ||
428 | memcpy (&hp_msg[1], message, message->size); | ||
429 | GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail, | ||
430 | hp_msg); | ||
431 | }*/ | ||
373 | if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) | 432 | if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) |
374 | { | 433 | { |
375 | ns->number_of_testsystems_started++; | 434 | ns->number_of_testsystems_started++; |
@@ -395,26 +454,52 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) | |||
395 | ns->number_of_peers_started = 0; | 454 | ns->number_of_peers_started = 0; |
396 | } | 455 | } |
397 | } | 456 | } |
457 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED == ntohs ( | ||
458 | message->type)) | ||
459 | { | ||
460 | ns->number_of_local_tests_prepared++; | ||
461 | if (ns->number_of_local_tests_prepared == total_number) | ||
462 | { | ||
463 | for (int i = 1; i <= ns->known; i++) | ||
464 | { | ||
465 | send_all_local_tests_prepared (0,i, ns); | ||
466 | } | ||
467 | |||
468 | for (int i = 1; i <= ns->global_n; i++) | ||
469 | { | ||
470 | for (int j = 1; j <= ns->local_m; j++) | ||
471 | { | ||
472 | send_all_local_tests_prepared (i,j, ns); | ||
473 | } | ||
474 | } | ||
475 | } | ||
476 | } | ||
398 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( | 477 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( |
399 | message->type)) | 478 | message->type)) |
400 | { | 479 | { |
401 | ns->number_of_local_test_finished++; | 480 | ns->number_of_local_tests_finished++; |
402 | if (ns->number_of_local_test_finished == total_number) | 481 | if (ns->number_of_local_tests_finished == total_number) |
403 | { | 482 | { |
404 | GNUNET_TESTING_async_finish (&ns->ac); | 483 | GNUNET_TESTING_async_finish (&ns->ac); |
405 | } | 484 | } |
406 | } | 485 | } |
407 | else | 486 | else |
408 | { | 487 | { |
409 | hp_msg = GNUNET_new (struct HelperMessage); | 488 | // We received a message we can not handle. |
410 | hp_msg->bytes_msg = message->size; | 489 | GNUNET_assert (0); |
411 | memcpy (&hp_msg[1], message, message->size); | ||
412 | GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail, | ||
413 | hp_msg); | ||
414 | } | 490 | } |
415 | 491 | ||
416 | 492 | ||
417 | 493 | LOG (GNUNET_ERROR_TYPE_DEBUG, | |
494 | "total %u sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n", | ||
495 | total_number, | ||
496 | ns->number_of_testsystems_started, | ||
497 | ns->number_of_peers_started, | ||
498 | ns->number_of_local_tests_prepared, | ||
499 | ns->number_of_local_tests_finished, | ||
500 | ns->local_m, | ||
501 | ns->global_n, | ||
502 | ns->known); | ||
418 | 503 | ||
419 | 504 | ||
420 | 505 | ||
@@ -433,7 +518,7 @@ exp_cb (void *cls) | |||
433 | struct TestingSystemCount *tbc = cls; | 518 | struct TestingSystemCount *tbc = cls; |
434 | 519 | ||
435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); | 520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); |
436 | GNUNET_TESTING_interpreter_fail (tbc->ns->ac.is); | 521 | GNUNET_TESTING_async_fail (&(tbc->ns->ac)); |
437 | } | 522 | } |
438 | 523 | ||
439 | 524 | ||
@@ -469,16 +554,21 @@ create_helper_init_msg_ (const char *plugin_name) | |||
469 | * | 554 | * |
470 | */ | 555 | */ |
471 | static void | 556 | static void |
472 | start_helper (struct NetJailState *ns, struct | 557 | start_helper (struct NetJailState *ns, |
473 | GNUNET_CONFIGURATION_Handle *config, | ||
474 | unsigned int m, | 558 | unsigned int m, |
475 | unsigned int n) | 559 | unsigned int n) |
476 | { | 560 | { |
477 | struct GNUNET_HELPER_Handle *helper; | 561 | struct GNUNET_HELPER_Handle *helper; |
478 | struct GNUNET_CMDS_HelperInit *msg; | 562 | struct GNUNET_CMDS_HelperInit *msg; |
479 | struct TestingSystemCount *tbc; | 563 | struct TestingSystemCount *tbc; |
480 | char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id, | 564 | char *m_char; |
481 | *plugin; | 565 | char *n_char; |
566 | char *global_n_char; | ||
567 | char *local_m_char; | ||
568 | char *known_char; | ||
569 | char *node_id; | ||
570 | char *plugin; | ||
571 | char *read_file; | ||
482 | pid_t pid; | 572 | pid_t pid; |
483 | unsigned int script_num; | 573 | unsigned int script_num; |
484 | struct GNUNET_ShortHashCode *hkey; | 574 | struct GNUNET_ShortHashCode *hkey; |
@@ -486,6 +576,9 @@ start_helper (struct NetJailState *ns, struct | |||
486 | struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; | 576 | struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; |
487 | struct GNUNET_TESTING_NetjailNode *node; | 577 | struct GNUNET_TESTING_NetjailNode *node; |
488 | struct GNUNET_TESTING_NetjailNamespace *namespace; | 578 | struct GNUNET_TESTING_NetjailNamespace *namespace; |
579 | char *data_dir; | ||
580 | char *script_name; | ||
581 | char *topology_data; | ||
489 | 582 | ||
490 | 583 | ||
491 | if (0 == n) | 584 | if (0 == n) |
@@ -502,59 +595,66 @@ start_helper (struct NetJailState *ns, struct | |||
502 | GNUNET_asprintf (&node_id, "%06x-%08x\n", | 595 | GNUNET_asprintf (&node_id, "%06x-%08x\n", |
503 | pid, | 596 | pid, |
504 | script_num); | 597 | script_num); |
598 | // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data); | ||
599 | GNUNET_asprintf (&read_file, "%u", *(ns->read_file)); | ||
505 | 600 | ||
506 | 601 | data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | |
507 | char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, | 602 | GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_EXEC_SCRIPT); |
508 | m_char, | ||
509 | n_char, | ||
510 | GNUNET_OS_get_libexec_binary_path ( | ||
511 | HELPER_CMDS_BINARY), | ||
512 | global_n_char, | ||
513 | local_m_char, | ||
514 | node_id, | ||
515 | NULL}; | ||
516 | |||
517 | unsigned int helper_check = GNUNET_OS_check_helper_binary ( | 603 | unsigned int helper_check = GNUNET_OS_check_helper_binary ( |
518 | NETJAIL_EXEC_SCRIPT, | 604 | script_name, |
519 | GNUNET_YES, | 605 | GNUNET_YES, |
520 | NULL); | 606 | NULL); |
521 | 607 | ||
522 | tbc = GNUNET_new (struct TestingSystemCount); | 608 | tbc = GNUNET_new (struct TestingSystemCount); |
523 | tbc->ns = ns; | 609 | tbc->ns = ns; |
524 | if (0 == n) | ||
525 | tbc->count = m; | ||
526 | else | ||
527 | tbc->count = (n - 1) * ns->local_m + m + ns->known; | ||
528 | |||
529 | GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, | ||
530 | tbc); | ||
531 | |||
532 | 610 | ||
533 | if (GNUNET_NO == helper_check) | 611 | if (GNUNET_NO == helper_check) |
534 | { | 612 | { |
535 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 613 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
536 | "No SUID for %s!\n", | 614 | "No SUID for %s!\n", |
537 | NETJAIL_EXEC_SCRIPT); | 615 | script_name); |
538 | GNUNET_TESTING_interpreter_fail (ns->ac.is); | 616 | GNUNET_TESTING_interpreter_fail (ns->is); |
539 | } | 617 | } |
540 | else if (GNUNET_NO == helper_check) | 618 | else if (GNUNET_NO == helper_check) |
541 | { | 619 | { |
542 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 620 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
543 | "%s not found!\n", | 621 | "%s not found!\n", |
544 | NETJAIL_EXEC_SCRIPT); | 622 | script_name); |
545 | GNUNET_TESTING_interpreter_fail (ns->ac.is); | 623 | GNUNET_TESTING_interpreter_fail (ns->is); |
546 | } | 624 | } |
547 | 625 | ||
548 | GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( | 626 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
549 | GNUNET_YES, | 627 | "sysstarted %u peersstarted %u prep %u finished %u %u %u %u\n", |
550 | NETJAIL_EXEC_SCRIPT, | 628 | ns->number_of_testsystems_started, |
551 | script_argv, | 629 | ns->number_of_peers_started, |
552 | &helper_mst, | 630 | ns->number_of_local_tests_prepared, |
553 | &exp_cb, | 631 | ns->number_of_local_tests_finished, |
554 | tbc)); | 632 | ns->local_m, |
555 | 633 | ns->global_n, | |
556 | helper = ns->helper[tbc->count - 1]; | 634 | ns->known); |
635 | { | ||
636 | char *const script_argv[] = {script_name, | ||
637 | m_char, | ||
638 | n_char, | ||
639 | GNUNET_OS_get_libexec_binary_path ( | ||
640 | HELPER_CMDS_BINARY), | ||
641 | global_n_char, | ||
642 | local_m_char, | ||
643 | node_id, | ||
644 | read_file, | ||
645 | ns->topology_data, | ||
646 | NULL}; | ||
647 | helper = GNUNET_HELPER_start ( | ||
648 | GNUNET_YES, | ||
649 | script_name, | ||
650 | script_argv, | ||
651 | &helper_mst, | ||
652 | &exp_cb, | ||
653 | ns); | ||
654 | GNUNET_array_append (ns->helper, ns->n_helper, helper); | ||
655 | } | ||
557 | 656 | ||
657 | tbc->count = ns->n_helper; | ||
558 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); | 658 | hkey = GNUNET_new (struct GNUNET_ShortHashCode); |
559 | 659 | ||
560 | plugin = topology->plugin; | 660 | plugin = topology->plugin; |
@@ -606,22 +706,22 @@ start_helper (struct NetJailState *ns, struct | |||
606 | 706 | ||
607 | msg = create_helper_init_msg_ (plugin); | 707 | msg = create_helper_init_msg_ (plugin); |
608 | 708 | ||
609 | GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); | 709 | // GNUNET_array_append (tbc->shandle, tbc->n_shandle, |
610 | 710 | tbc->shandle = GNUNET_HELPER_send ( | |
611 | GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( | 711 | helper, |
612 | helper, | 712 | &msg->header, |
613 | &msg->header, | 713 | GNUNET_NO, |
614 | GNUNET_NO, | 714 | &clear_msg, |
615 | &clear_msg, | 715 | tbc); // ); |
616 | tbc)); | ||
617 | 716 | ||
618 | if (NULL == ns->shandle[tbc->count - 1]) | 717 | if (NULL == tbc->shandle)// [tbc->count - 1]) |
619 | { | 718 | { |
620 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 719 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
621 | "Send handle is NULL!\n"); | 720 | "Send handle is NULL!\n"); |
622 | GNUNET_free (msg); | 721 | GNUNET_free (msg); |
623 | GNUNET_TESTING_interpreter_fail (ns->ac.is); | 722 | GNUNET_TESTING_interpreter_fail (ns->is); |
624 | } | 723 | } |
724 | GNUNET_free (hkey); | ||
625 | } | 725 | } |
626 | 726 | ||
627 | 727 | ||
@@ -637,12 +737,11 @@ netjail_exec_run (void *cls, | |||
637 | struct GNUNET_TESTING_Interpreter *is) | 737 | struct GNUNET_TESTING_Interpreter *is) |
638 | { | 738 | { |
639 | struct NetJailState *ns = cls; | 739 | struct NetJailState *ns = cls; |
640 | struct GNUNET_CONFIGURATION_Handle *config = | ||
641 | GNUNET_CONFIGURATION_create (); | ||
642 | 740 | ||
741 | ns->is = is; | ||
643 | for (int i = 1; i <= ns->known; i++) | 742 | for (int i = 1; i <= ns->known; i++) |
644 | { | 743 | { |
645 | start_helper (ns, config, | 744 | start_helper (ns, |
646 | i, | 745 | i, |
647 | 0); | 746 | 0); |
648 | } | 747 | } |
@@ -651,7 +750,7 @@ netjail_exec_run (void *cls, | |||
651 | { | 750 | { |
652 | for (int j = 1; j <= ns->local_m; j++) | 751 | for (int j = 1; j <= ns->local_m; j++) |
653 | { | 752 | { |
654 | start_helper (ns, config, | 753 | start_helper (ns, |
655 | j, | 754 | j, |
656 | i); | 755 | i); |
657 | } | 756 | } |
@@ -663,24 +762,28 @@ netjail_exec_run (void *cls, | |||
663 | * Create command. | 762 | * Create command. |
664 | * | 763 | * |
665 | * @param label Name for the command. | 764 | * @param label Name for the command. |
666 | * @param topology_config Configuration file for the test topology. | 765 | * @param topology The complete topology information. |
766 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. | ||
767 | * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology. | ||
667 | * @return command. | 768 | * @return command. |
668 | */ | 769 | */ |
669 | struct GNUNET_TESTING_Command | 770 | struct GNUNET_TESTING_Command |
670 | GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, | 771 | GNUNET_TESTING_cmd_netjail_start_testing_system ( |
671 | const char *topology_config) | 772 | const char *label, |
773 | struct GNUNET_TESTING_NetjailTopology *topology, | ||
774 | unsigned int *read_file, | ||
775 | char *topology_data) | ||
672 | { | 776 | { |
673 | struct NetJailState *ns; | 777 | struct NetJailState *ns; |
674 | 778 | ||
675 | struct GNUNET_TESTING_NetjailTopology *topology = | ||
676 | GNUNET_TESTING_get_topo_from_file (topology_config); | ||
677 | |||
678 | ns = GNUNET_new (struct NetJailState); | 779 | ns = GNUNET_new (struct NetJailState); |
679 | ns->local_m = topology->nodes_m; | 780 | ns->local_m = topology->nodes_m; |
680 | ns->global_n = topology->namespaces_n; | 781 | ns->global_n = topology->namespaces_n; |
681 | ns->known = topology->nodes_x; | 782 | ns->known = topology->nodes_x; |
682 | ns->plugin_name = topology->plugin; | 783 | ns->plugin_name = topology->plugin; |
683 | ns->topology = topology; | 784 | ns->topology = topology; |
785 | ns->read_file = read_file; | ||
786 | ns->topology_data = topology_data; | ||
684 | 787 | ||
685 | struct GNUNET_TESTING_Command cmd = { | 788 | struct GNUNET_TESTING_Command cmd = { |
686 | .cls = ns, | 789 | .cls = ns, |
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c index 5033272a3..e3bf7da62 100644 --- a/src/testing/testing_api_cmd_netjail_stop.c +++ b/src/testing/testing_api_cmd_netjail_stop.c | |||
@@ -26,12 +26,10 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | ||
29 | 30 | ||
30 | 31 | ||
31 | #define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh" | 32 | #define NETJAIL_STOP_SCRIPT "netjail_stop.sh" |
32 | |||
33 | // Child Wait handle | ||
34 | static struct GNUNET_ChildWaitHandle *cwh; | ||
35 | 33 | ||
36 | /** | 34 | /** |
37 | * Struct to hold information for callbacks. | 35 | * Struct to hold information for callbacks. |
@@ -44,6 +42,9 @@ struct NetJailState | |||
44 | */ | 42 | */ |
45 | struct GNUNET_TESTING_AsyncContext ac; | 43 | struct GNUNET_TESTING_AsyncContext ac; |
46 | 44 | ||
45 | // Child Wait handle | ||
46 | struct GNUNET_ChildWaitHandle *cwh; | ||
47 | |||
47 | /** | 48 | /** |
48 | * Configuration file for the test topology. | 49 | * Configuration file for the test topology. |
49 | */ | 50 | */ |
@@ -54,6 +55,11 @@ struct NetJailState | |||
54 | */ | 55 | */ |
55 | struct GNUNET_OS_Process *stop_proc; | 56 | struct GNUNET_OS_Process *stop_proc; |
56 | 57 | ||
58 | /** | ||
59 | * Shall we read the topology from file, or from a string. | ||
60 | */ | ||
61 | unsigned int *read_file; | ||
62 | |||
57 | }; | 63 | }; |
58 | 64 | ||
59 | 65 | ||
@@ -66,10 +72,10 @@ netjail_stop_cleanup (void *cls) | |||
66 | { | 72 | { |
67 | struct NetJailState *ns = cls; | 73 | struct NetJailState *ns = cls; |
68 | 74 | ||
69 | if (NULL != cwh) | 75 | if (NULL != ns->cwh) |
70 | { | 76 | { |
71 | GNUNET_wait_child_cancel (cwh); | 77 | GNUNET_wait_child_cancel (ns->cwh); |
72 | cwh = NULL; | 78 | ns->cwh = NULL; |
73 | } | 79 | } |
74 | if (NULL != ns->stop_proc) | 80 | if (NULL != ns->stop_proc) |
75 | { | 81 | { |
@@ -95,7 +101,7 @@ child_completed_callback (void *cls, | |||
95 | { | 101 | { |
96 | struct NetJailState *ns = cls; | 102 | struct NetJailState *ns = cls; |
97 | 103 | ||
98 | cwh = NULL; // WTF? globals!?!?! | 104 | ns->cwh = NULL; |
99 | GNUNET_OS_process_destroy (ns->stop_proc); | 105 | GNUNET_OS_process_destroy (ns->stop_proc); |
100 | ns->stop_proc = NULL; | 106 | ns->stop_proc = NULL; |
101 | if (0 == exit_code) | 107 | if (0 == exit_code) |
@@ -121,16 +127,16 @@ netjail_stop_run (void *cls, | |||
121 | { | 127 | { |
122 | struct NetJailState *ns = cls; | 128 | struct NetJailState *ns = cls; |
123 | char *pid; | 129 | char *pid; |
130 | char *data_dir; | ||
131 | char *script_name; | ||
132 | char *read_file; | ||
124 | 133 | ||
125 | GNUNET_asprintf (&pid, | 134 | |
126 | "%u", | 135 | data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); |
127 | getpid ()); | 136 | GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_STOP_SCRIPT); |
128 | char *const script_argv[] = {NETJAIL_STOP_SCRIPT, | 137 | GNUNET_asprintf (&read_file, "%u", *(ns->read_file)); |
129 | ns->topology_config, | ||
130 | pid, | ||
131 | NULL}; | ||
132 | unsigned int helper_check = GNUNET_OS_check_helper_binary ( | 138 | unsigned int helper_check = GNUNET_OS_check_helper_binary ( |
133 | NETJAIL_STOP_SCRIPT, | 139 | script_name, |
134 | GNUNET_YES, | 140 | GNUNET_YES, |
135 | NULL); | 141 | NULL); |
136 | 142 | ||
@@ -138,39 +144,50 @@ netjail_stop_run (void *cls, | |||
138 | { | 144 | { |
139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
140 | "No SUID for %s!\n", | 146 | "No SUID for %s!\n", |
141 | NETJAIL_STOP_SCRIPT); | 147 | script_name); |
142 | GNUNET_TESTING_interpreter_fail (is); | 148 | GNUNET_TESTING_interpreter_fail (is); |
143 | } | 149 | } |
144 | else if (GNUNET_NO == helper_check) | 150 | else if (GNUNET_NO == helper_check) |
145 | { | 151 | { |
146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 152 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
147 | "%s not found!\n", | 153 | "%s not found!\n", |
148 | NETJAIL_STOP_SCRIPT); | 154 | script_name); |
149 | GNUNET_TESTING_interpreter_fail (is); | 155 | GNUNET_TESTING_interpreter_fail (is); |
150 | } | 156 | } |
151 | 157 | ||
152 | ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, | 158 | GNUNET_asprintf (&pid, |
153 | NULL, | 159 | "%u", |
154 | NULL, | 160 | getpid ()); |
155 | NULL, | 161 | { |
156 | NETJAIL_STOP_SCRIPT, | 162 | char *const script_argv[] = {script_name, |
157 | script_argv); | 163 | ns->topology_config, |
158 | 164 | pid, | |
159 | cwh = GNUNET_wait_child (ns->stop_proc, | 165 | read_file, |
160 | &child_completed_callback, | 166 | NULL}; |
161 | ns); | 167 | ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, |
162 | GNUNET_break (NULL != cwh); | 168 | NULL, |
169 | NULL, | ||
170 | NULL, | ||
171 | script_name, | ||
172 | script_argv); | ||
173 | } | ||
174 | ns->cwh = GNUNET_wait_child (ns->stop_proc, | ||
175 | &child_completed_callback, | ||
176 | ns); | ||
177 | GNUNET_break (NULL != ns->cwh); | ||
163 | } | 178 | } |
164 | 179 | ||
165 | 180 | ||
166 | struct GNUNET_TESTING_Command | 181 | struct GNUNET_TESTING_Command |
167 | GNUNET_TESTING_cmd_netjail_stop (const char *label, | 182 | GNUNET_TESTING_cmd_netjail_stop (const char *label, |
168 | char *topology_config) | 183 | char *topology_config, |
184 | unsigned int *read_file) | ||
169 | { | 185 | { |
170 | struct NetJailState *ns; | 186 | struct NetJailState *ns; |
171 | 187 | ||
172 | ns = GNUNET_new (struct NetJailState); | 188 | ns = GNUNET_new (struct NetJailState); |
173 | ns->topology_config = topology_config; | 189 | ns->topology_config = topology_config; |
190 | ns->read_file = read_file; | ||
174 | { | 191 | { |
175 | struct GNUNET_TESTING_Command cmd = { | 192 | struct GNUNET_TESTING_Command cmd = { |
176 | .cls = ns, | 193 | .cls = ns, |
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c index d3754153d..4b52878c4 100644 --- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c +++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_testing_ng_lib.h" | 27 | #include "gnunet_testing_ng_lib.h" |
28 | #include "gnunet_testing_netjail_lib.h" | ||
28 | #include "testing_cmds.h" | 29 | #include "testing_cmds.h" |
29 | 30 | ||
30 | 31 | ||
@@ -35,6 +36,11 @@ | |||
35 | struct StopHelperState | 36 | struct StopHelperState |
36 | { | 37 | { |
37 | 38 | ||
39 | /** | ||
40 | * The complete topology information. | ||
41 | */ | ||
42 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
43 | |||
38 | const char *helper_start_label; | 44 | const char *helper_start_label; |
39 | 45 | ||
40 | /** | 46 | /** |
@@ -63,21 +69,9 @@ struct StopHelperState | |||
63 | static void | 69 | static void |
64 | stop_testing_system_cleanup (void *cls) | 70 | stop_testing_system_cleanup (void *cls) |
65 | { | 71 | { |
72 | struct StopHelperState *shs = cls; | ||
66 | 73 | ||
67 | } | 74 | GNUNET_free (shs); |
68 | |||
69 | |||
70 | /** | ||
71 | * Trait function of this cmd does nothing. | ||
72 | * | ||
73 | */ | ||
74 | static int | ||
75 | stop_testing_system_traits (void *cls, | ||
76 | const void **ret, | ||
77 | const char *trait, | ||
78 | unsigned int index) | ||
79 | { | ||
80 | return GNUNET_OK; | ||
81 | } | 75 | } |
82 | 76 | ||
83 | 77 | ||
@@ -95,7 +89,7 @@ stop_testing_system_run (void *cls, | |||
95 | struct GNUNET_HELPER_Handle **helper; | 89 | struct GNUNET_HELPER_Handle **helper; |
96 | const struct GNUNET_TESTING_Command *start_helper_cmd; | 90 | const struct GNUNET_TESTING_Command *start_helper_cmd; |
97 | 91 | ||
98 | start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (NULL, | 92 | start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (is, |
99 | shs-> | 93 | shs-> |
100 | helper_start_label); | 94 | helper_start_label); |
101 | GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, | 95 | GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd, |
@@ -130,31 +124,29 @@ stop_testing_system_run (void *cls, | |||
130 | * | 124 | * |
131 | * @param label name for command. | 125 | * @param label name for command. |
132 | * @param helper_start_label label of the cmd to start the test system. | 126 | * @param helper_start_label label of the cmd to start the test system. |
133 | * @param topology_config Configuration file for the test topology. | 127 | * @param topology The complete topology information. |
134 | * @return command. | 128 | * @return command. |
135 | */ | 129 | */ |
136 | struct GNUNET_TESTING_Command | 130 | struct GNUNET_TESTING_Command |
137 | GNUNET_TESTING_cmd_stop_testing_system (const char *label, | 131 | GNUNET_TESTING_cmd_stop_testing_system ( |
138 | const char *helper_start_label, | 132 | const char *label, |
139 | const char *topology_config) | 133 | const char *helper_start_label, |
134 | struct GNUNET_TESTING_NetjailTopology *topology) | ||
140 | { | 135 | { |
141 | struct StopHelperState *shs; | 136 | struct StopHelperState *shs; |
142 | 137 | ||
143 | struct GNUNET_TESTING_NetjailTopology *topology = | ||
144 | GNUNET_TESTING_get_topo_from_file (topology_config); | ||
145 | |||
146 | shs = GNUNET_new (struct StopHelperState); | 138 | shs = GNUNET_new (struct StopHelperState); |
147 | shs->helper_start_label = helper_start_label; | 139 | shs->helper_start_label = helper_start_label; |
148 | shs->local_m = topology->nodes_m; | 140 | shs->local_m = topology->nodes_m; |
149 | shs->global_n = topology->namespaces_n; | 141 | shs->global_n = topology->namespaces_n; |
150 | shs->known = topology->nodes_x; | 142 | shs->known = topology->nodes_x; |
143 | shs->topology = topology; | ||
151 | 144 | ||
152 | struct GNUNET_TESTING_Command cmd = { | 145 | struct GNUNET_TESTING_Command cmd = { |
153 | .cls = shs, | 146 | .cls = shs, |
154 | .label = label, | 147 | .label = label, |
155 | .run = &stop_testing_system_run, | 148 | .run = &stop_testing_system_run, |
156 | .cleanup = &stop_testing_system_cleanup, | 149 | .cleanup = &stop_testing_system_cleanup, |
157 | .traits = &stop_testing_system_traits | ||
158 | }; | 150 | }; |
159 | 151 | ||
160 | return cmd; | 152 | return cmd; |
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c index 8b4c11deb..5bbabce51 100644 --- a/src/testing/testing_api_cmd_send_peer_ready.c +++ b/src/testing/testing_api_cmd_send_peer_ready.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | ||
29 | #include "testing_cmds.h" | 30 | #include "testing_cmds.h" |
30 | 31 | ||
31 | 32 | ||
@@ -72,7 +73,6 @@ send_peer_ready_cleanup (void *cls) | |||
72 | { | 73 | { |
73 | struct SendPeerReadyState *sprs = cls; | 74 | struct SendPeerReadyState *sprs = cls; |
74 | 75 | ||
75 | GNUNET_free (sprs->reply); | ||
76 | GNUNET_free (sprs); | 76 | GNUNET_free (sprs); |
77 | } | 77 | } |
78 | 78 | ||
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c index 820adf1bd..275132684 100644 --- a/src/testing/testing_api_cmd_system_create.c +++ b/src/testing/testing_api_cmd_system_create.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | ||
29 | #include "gnunet_testing_lib.h" | 30 | #include "gnunet_testing_lib.h" |
30 | 31 | ||
31 | /** | 32 | /** |
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c index 338123d91..cdfc65d53 100644 --- a/src/testing/testing_api_cmd_system_destroy.c +++ b/src/testing/testing_api_cmd_system_destroy.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testing_ng_lib.h" | 28 | #include "gnunet_testing_ng_lib.h" |
29 | #include "gnunet_testing_netjail_lib.h" | ||
29 | #include "gnunet_testing_lib.h" | 30 | #include "gnunet_testing_lib.h" |
30 | 31 | ||
31 | 32 | ||
diff --git a/src/testing/testing_cmds.h b/src/testing/testing_cmds.h index 09e4f2dcb..12db87d19 100644 --- a/src/testing/testing_cmds.h +++ b/src/testing/testing_cmds.h | |||
@@ -87,6 +87,23 @@ struct GNUNET_CMDS_LOCAL_FINISHED | |||
87 | enum GNUNET_GenericReturnValue result; | 87 | enum GNUNET_GenericReturnValue result; |
88 | }; | 88 | }; |
89 | 89 | ||
90 | struct GNUNET_CMDS_LOCAL_TEST_PREPARED | ||
91 | { | ||
92 | /** | ||
93 | * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED | ||
94 | */ | ||
95 | struct GNUNET_MessageHeader header; | ||
96 | }; | ||
97 | |||
98 | struct GNUNET_CMDS_ALL_LOCAL_TESTS_PREPARED | ||
99 | { | ||
100 | /** | ||
101 | * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_LOCAL_TESTS_PREPARED | ||
102 | */ | ||
103 | struct GNUNET_MessageHeader header; | ||
104 | }; | ||
105 | |||
90 | GNUNET_NETWORK_STRUCT_END | 106 | GNUNET_NETWORK_STRUCT_END |
107 | |||
91 | #endif | 108 | #endif |
92 | /* end of testing_cmds.h */ | 109 | /* end of testing_cmds.h */ |
diff --git a/src/testing/topo.sh b/src/testing/topo.sh index 090c3053f..0046622b6 100755 --- a/src/testing/topo.sh +++ b/src/testing/topo.sh | |||
@@ -20,8 +20,7 @@ extract_attributes() | |||
20 | number=$(echo $line|cut -d \| -f 1| cut -c 2-|cut -d : -f 2 ) | 20 | number=$(echo $line|cut -d \| -f 1| cut -c 2-|cut -d : -f 2 ) |
21 | echo $number | 21 | echo $number |
22 | fi | 22 | fi |
23 | 23 | ||
24 | |||
25 | nf=$(echo $line|awk -F: '{print NF}') | 24 | nf=$(echo $line|awk -F: '{print NF}') |
26 | for ((i=2;i<=$nf;i++)) | 25 | for ((i=2;i<=$nf;i++)) |
27 | do | 26 | do |
@@ -67,6 +66,11 @@ while read line; do | |||
67 | then | 66 | then |
68 | GLOBAL_N=$(cut -d : -f 2 <<< $line) | 67 | GLOBAL_N=$(cut -d : -f 2 <<< $line) |
69 | echo $GLOBAL_N | 68 | echo $GLOBAL_N |
69 | for ((i=1;i<=$GLOBAL_N;i++)) | ||
70 | do | ||
71 | R_TCP[$i]=0 | ||
72 | R_UDP[$i]=0 | ||
73 | done | ||
70 | elif [ "$key" = "X" ] | 74 | elif [ "$key" = "X" ] |
71 | then | 75 | then |
72 | KNOWN=$(cut -d : -f 2 <<< $line) | 76 | KNOWN=$(cut -d : -f 2 <<< $line) |