diff options
Diffstat (limited to 'src/core/test_core_api_start_only.c')
-rw-r--r-- | src/core/test_core_api_start_only.c | 228 |
1 files changed, 114 insertions, 114 deletions
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index 92574e3d4..c8a848359 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_core_api_start_only.c | 21 | * @file transport/test_core_api_start_only.c |
22 | * @brief testcase for core_api.c that only starts two peers, | 22 | * @brief testcase for core_api.c that only starts two peers, |
@@ -32,8 +32,7 @@ | |||
32 | 32 | ||
33 | #define MTYPE 12345 | 33 | #define MTYPE 12345 |
34 | 34 | ||
35 | struct PeerContext | 35 | struct PeerContext { |
36 | { | ||
37 | struct GNUNET_CONFIGURATION_Handle *cfg; | 36 | struct GNUNET_CONFIGURATION_Handle *cfg; |
38 | struct GNUNET_CORE_Handle *ch; | 37 | struct GNUNET_CORE_Handle *ch; |
39 | struct GNUNET_PeerIdentity id; | 38 | struct GNUNET_PeerIdentity id; |
@@ -50,157 +49,157 @@ static int ok; | |||
50 | 49 | ||
51 | 50 | ||
52 | static void * | 51 | static void * |
53 | connect_notify (void *cls, | 52 | connect_notify(void *cls, |
54 | const struct GNUNET_PeerIdentity *peer, | 53 | const struct GNUNET_PeerIdentity *peer, |
55 | struct GNUNET_MQ_Handle *mq) | 54 | struct GNUNET_MQ_Handle *mq) |
56 | { | 55 | { |
57 | return NULL; | 56 | return NULL; |
58 | } | 57 | } |
59 | 58 | ||
60 | 59 | ||
61 | static void | 60 | static void |
62 | disconnect_notify (void *cls, | 61 | disconnect_notify(void *cls, |
63 | const struct GNUNET_PeerIdentity *peer, | 62 | const struct GNUNET_PeerIdentity *peer, |
64 | void *internal_cls) | 63 | void *internal_cls) |
65 | { | 64 | { |
66 | } | 65 | } |
67 | 66 | ||
68 | 67 | ||
69 | static struct GNUNET_MQ_MessageHandler handlers[] = { | 68 | static struct GNUNET_MQ_MessageHandler handlers[] = { |
70 | GNUNET_MQ_handler_end () | 69 | GNUNET_MQ_handler_end() |
71 | }; | 70 | }; |
72 | 71 | ||
73 | 72 | ||
74 | static void | 73 | static void |
75 | shutdown_task (void *cls) | 74 | shutdown_task(void *cls) |
76 | { | 75 | { |
77 | GNUNET_CORE_disconnect (p1.ch); | 76 | GNUNET_CORE_disconnect(p1.ch); |
78 | p1.ch = NULL; | 77 | p1.ch = NULL; |
79 | GNUNET_CORE_disconnect (p2.ch); | 78 | GNUNET_CORE_disconnect(p2.ch); |
80 | p2.ch = NULL; | 79 | p2.ch = NULL; |
81 | ok = 0; | 80 | ok = 0; |
82 | } | 81 | } |
83 | 82 | ||
84 | 83 | ||
85 | static void | 84 | static void |
86 | init_notify (void *cls, | 85 | init_notify(void *cls, |
87 | const struct GNUNET_PeerIdentity *my_identity) | 86 | const struct GNUNET_PeerIdentity *my_identity) |
88 | { | 87 | { |
89 | struct PeerContext *p = cls; | 88 | struct PeerContext *p = cls; |
90 | 89 | ||
91 | if (p == &p1) | 90 | if (p == &p1) |
92 | { | 91 | { |
93 | /* connect p2 */ | 92 | /* connect p2 */ |
94 | p2.ch = GNUNET_CORE_connect (p2.cfg, | 93 | p2.ch = GNUNET_CORE_connect(p2.cfg, |
95 | &p2, | 94 | &p2, |
96 | &init_notify, | 95 | &init_notify, |
97 | &connect_notify, | 96 | &connect_notify, |
98 | &disconnect_notify, | 97 | &disconnect_notify, |
99 | handlers); | 98 | handlers); |
100 | } | 99 | } |
101 | else | 100 | else |
102 | { | 101 | { |
103 | GNUNET_assert (p == &p2); | 102 | GNUNET_assert(p == &p2); |
104 | GNUNET_SCHEDULER_cancel (timeout_task_id); | 103 | GNUNET_SCHEDULER_cancel(timeout_task_id); |
105 | timeout_task_id = NULL; | 104 | timeout_task_id = NULL; |
106 | GNUNET_SCHEDULER_add_now (&shutdown_task, | 105 | GNUNET_SCHEDULER_add_now(&shutdown_task, |
107 | NULL); | 106 | NULL); |
108 | } | 107 | } |
109 | } | 108 | } |
110 | 109 | ||
111 | 110 | ||
112 | static void | 111 | static void |
113 | setup_peer (struct PeerContext *p, | 112 | setup_peer(struct PeerContext *p, |
114 | const char *cfgname) | 113 | const char *cfgname) |
115 | { | 114 | { |
116 | char *binary; | 115 | char *binary; |
117 | 116 | ||
118 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 117 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); |
119 | p->cfg = GNUNET_CONFIGURATION_create (); | 118 | p->cfg = GNUNET_CONFIGURATION_create(); |
120 | p->arm_proc = | 119 | p->arm_proc = |
121 | GNUNET_OS_start_process (GNUNET_YES, | 120 | GNUNET_OS_start_process(GNUNET_YES, |
122 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 121 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
123 | NULL, NULL, NULL, | 122 | NULL, NULL, NULL, |
124 | binary, | 123 | binary, |
125 | "gnunet-service-arm", | 124 | "gnunet-service-arm", |
126 | "-c", cfgname, | 125 | "-c", cfgname, |
127 | NULL); | 126 | NULL); |
128 | GNUNET_assert (GNUNET_OK == | 127 | GNUNET_assert(GNUNET_OK == |
129 | GNUNET_CONFIGURATION_load (p->cfg, | 128 | GNUNET_CONFIGURATION_load(p->cfg, |
130 | cfgname)); | 129 | cfgname)); |
131 | GNUNET_free (binary); | 130 | GNUNET_free(binary); |
132 | } | 131 | } |
133 | 132 | ||
134 | 133 | ||
135 | static void | 134 | static void |
136 | timeout_task (void *cls) | 135 | timeout_task(void *cls) |
137 | { | 136 | { |
138 | fprintf (stderr, | 137 | fprintf(stderr, |
139 | "%s", | 138 | "%s", |
140 | "Timeout.\n"); | 139 | "Timeout.\n"); |
141 | if (NULL != p1.ch) | 140 | if (NULL != p1.ch) |
142 | { | 141 | { |
143 | GNUNET_CORE_disconnect (p1.ch); | 142 | GNUNET_CORE_disconnect(p1.ch); |
144 | p1.ch = NULL; | 143 | p1.ch = NULL; |
145 | } | 144 | } |
146 | if (NULL != p2.ch) | 145 | if (NULL != p2.ch) |
147 | { | 146 | { |
148 | GNUNET_CORE_disconnect (p2.ch); | 147 | GNUNET_CORE_disconnect(p2.ch); |
149 | p2.ch = NULL; | 148 | p2.ch = NULL; |
150 | } | 149 | } |
151 | ok = 42; | 150 | ok = 42; |
152 | } | 151 | } |
153 | 152 | ||
154 | 153 | ||
155 | static void | 154 | static void |
156 | run (void *cls, | 155 | run(void *cls, |
157 | char *const *args, | 156 | char *const *args, |
158 | const char *cfgfile, | 157 | const char *cfgfile, |
159 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 158 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
160 | { | 159 | { |
161 | GNUNET_assert (ok == 1); | 160 | GNUNET_assert(ok == 1); |
162 | ok++; | 161 | ok++; |
163 | setup_peer (&p1, "test_core_api_peer1.conf"); | 162 | setup_peer(&p1, "test_core_api_peer1.conf"); |
164 | setup_peer (&p2, "test_core_api_peer2.conf"); | 163 | setup_peer(&p2, "test_core_api_peer2.conf"); |
165 | timeout_task_id = | 164 | timeout_task_id = |
166 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 165 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
167 | (GNUNET_TIME_UNIT_MINUTES, | 166 | (GNUNET_TIME_UNIT_MINUTES, |
168 | TIMEOUT), | 167 | TIMEOUT), |
169 | &timeout_task, | 168 | &timeout_task, |
170 | NULL); | 169 | NULL); |
171 | p1.ch = GNUNET_CORE_connect (p1.cfg, | 170 | p1.ch = GNUNET_CORE_connect(p1.cfg, |
172 | &p1, | 171 | &p1, |
173 | &init_notify, | 172 | &init_notify, |
174 | &connect_notify, | 173 | &connect_notify, |
175 | &disconnect_notify, | 174 | &disconnect_notify, |
176 | handlers); | 175 | handlers); |
177 | } | 176 | } |
178 | 177 | ||
179 | 178 | ||
180 | static void | 179 | static void |
181 | stop_arm (struct PeerContext *p) | 180 | stop_arm(struct PeerContext *p) |
182 | { | 181 | { |
183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 182 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
184 | "Stopping peer\n"); | 183 | "Stopping peer\n"); |
185 | if (0 != GNUNET_OS_process_kill (p->arm_proc, | 184 | if (0 != GNUNET_OS_process_kill(p->arm_proc, |
186 | GNUNET_TERM_SIG)) | 185 | GNUNET_TERM_SIG)) |
187 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 186 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
188 | "kill"); | 187 | "kill"); |
189 | if (GNUNET_OK != | 188 | if (GNUNET_OK != |
190 | GNUNET_OS_process_wait (p->arm_proc)) | 189 | GNUNET_OS_process_wait(p->arm_proc)) |
191 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 190 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, |
192 | "waitpid"); | 191 | "waitpid"); |
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 192 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
194 | "ARM process %u stopped\n", | 193 | "ARM process %u stopped\n", |
195 | (unsigned int) GNUNET_OS_process_get_pid (p->arm_proc)); | 194 | (unsigned int)GNUNET_OS_process_get_pid(p->arm_proc)); |
196 | GNUNET_OS_process_destroy (p->arm_proc); | 195 | GNUNET_OS_process_destroy(p->arm_proc); |
197 | p->arm_proc = NULL; | 196 | p->arm_proc = NULL; |
198 | GNUNET_CONFIGURATION_destroy (p->cfg); | 197 | GNUNET_CONFIGURATION_destroy(p->cfg); |
199 | } | 198 | } |
200 | 199 | ||
201 | 200 | ||
202 | static int | 201 | static int |
203 | check () | 202 | check() |
204 | { | 203 | { |
205 | char *const argv[] = { | 204 | char *const argv[] = { |
206 | "test-core-api-start-only", | 205 | "test-core-api-start-only", |
@@ -211,37 +210,38 @@ check () | |||
211 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 210 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
212 | GNUNET_GETOPT_OPTION_END | 211 | GNUNET_GETOPT_OPTION_END |
213 | }; | 212 | }; |
214 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 213 | |
215 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 214 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1"); |
215 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2"); | ||
216 | 216 | ||
217 | ok = 1; | 217 | ok = 1; |
218 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 218 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, |
219 | argv, | 219 | argv, |
220 | "test-core-api-start-only", | 220 | "test-core-api-start-only", |
221 | "nohelp", | 221 | "nohelp", |
222 | options, | 222 | options, |
223 | &run, | 223 | &run, |
224 | &ok); | 224 | &ok); |
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 225 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
226 | "Test finished\n"); | 226 | "Test finished\n"); |
227 | stop_arm (&p1); | 227 | stop_arm(&p1); |
228 | stop_arm (&p2); | 228 | stop_arm(&p2); |
229 | return ok; | 229 | return ok; |
230 | } | 230 | } |
231 | 231 | ||
232 | 232 | ||
233 | int | 233 | int |
234 | main (int argc, | 234 | main(int argc, |
235 | char *argv[]) | 235 | char *argv[]) |
236 | { | 236 | { |
237 | int ret; | 237 | int ret; |
238 | 238 | ||
239 | GNUNET_log_setup ("test-core-api-start-only", | 239 | GNUNET_log_setup("test-core-api-start-only", |
240 | "WARNING", | 240 | "WARNING", |
241 | NULL); | 241 | NULL); |
242 | ret = check (); | 242 | ret = check(); |
243 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 243 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1"); |
244 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); | 244 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2"); |
245 | return ret; | 245 | return ret; |
246 | } | 246 | } |
247 | 247 | ||