diff options
Diffstat (limited to 'src/core/test_core_api_start_only.c')
-rw-r--r-- | src/core/test_core_api_start_only.c | 107 |
1 files changed, 50 insertions, 57 deletions
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index b6ad19b77..36d964796 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c | |||
@@ -68,14 +68,13 @@ static int ok; | |||
68 | static void | 68 | static void |
69 | connect_notify (void *cls, | 69 | connect_notify (void *cls, |
70 | const struct GNUNET_PeerIdentity *peer, | 70 | const struct GNUNET_PeerIdentity *peer, |
71 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 71 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
72 | { | 72 | { |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static void | 76 | static void |
77 | disconnect_notify (void *cls, | 77 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) |
78 | const struct GNUNET_PeerIdentity *peer) | ||
79 | { | 78 | { |
80 | } | 79 | } |
81 | 80 | ||
@@ -84,7 +83,7 @@ static int | |||
84 | inbound_notify (void *cls, | 83 | inbound_notify (void *cls, |
85 | const struct GNUNET_PeerIdentity *other, | 84 | const struct GNUNET_PeerIdentity *other, |
86 | const struct GNUNET_MessageHeader *message, | 85 | const struct GNUNET_MessageHeader *message, |
87 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 86 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
88 | { | 87 | { |
89 | return GNUNET_OK; | 88 | return GNUNET_OK; |
90 | } | 89 | } |
@@ -94,7 +93,7 @@ static int | |||
94 | outbound_notify (void *cls, | 93 | outbound_notify (void *cls, |
95 | const struct GNUNET_PeerIdentity *other, | 94 | const struct GNUNET_PeerIdentity *other, |
96 | const struct GNUNET_MessageHeader *message, | 95 | const struct GNUNET_MessageHeader *message, |
97 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 96 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
98 | { | 97 | { |
99 | return GNUNET_OK; | 98 | return GNUNET_OK; |
100 | } | 99 | } |
@@ -106,8 +105,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = { | |||
106 | 105 | ||
107 | 106 | ||
108 | static void | 107 | static void |
109 | shutdown_task (void *cls, | 108 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
110 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
111 | { | 109 | { |
112 | GNUNET_CORE_disconnect (p1.ch); | 110 | GNUNET_CORE_disconnect (p1.ch); |
113 | p1.ch = NULL; | 111 | p1.ch = NULL; |
@@ -130,24 +128,24 @@ init_notify (void *cls, | |||
130 | GNUNET_assert (server != NULL); | 128 | GNUNET_assert (server != NULL); |
131 | GNUNET_assert (p->ch == server); | 129 | GNUNET_assert (p->ch == server); |
132 | if (cls == &p1) | 130 | if (cls == &p1) |
133 | { | 131 | { |
134 | /* connect p2 */ | 132 | /* connect p2 */ |
135 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, | 133 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, |
136 | &p2, | 134 | &p2, |
137 | &init_notify, | 135 | &init_notify, |
138 | &connect_notify, | 136 | &connect_notify, |
139 | &disconnect_notify, | 137 | &disconnect_notify, |
140 | NULL, | 138 | NULL, |
141 | &inbound_notify, | 139 | &inbound_notify, |
142 | GNUNET_YES, | 140 | GNUNET_YES, |
143 | &outbound_notify, GNUNET_YES, handlers); | 141 | &outbound_notify, GNUNET_YES, handlers); |
144 | } | 142 | } |
145 | else | 143 | else |
146 | { | 144 | { |
147 | GNUNET_assert (cls == &p2); | 145 | GNUNET_assert (cls == &p2); |
148 | GNUNET_SCHEDULER_cancel (timeout_task_id); | 146 | GNUNET_SCHEDULER_cancel (timeout_task_id); |
149 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 147 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); |
150 | } | 148 | } |
151 | } | 149 | } |
152 | 150 | ||
153 | 151 | ||
@@ -157,31 +155,30 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
157 | p->cfg = GNUNET_CONFIGURATION_create (); | 155 | p->cfg = GNUNET_CONFIGURATION_create (); |
158 | #if START_ARM | 156 | #if START_ARM |
159 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 157 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
160 | "gnunet-service-arm", | 158 | "gnunet-service-arm", |
161 | #if VERBOSE | 159 | #if VERBOSE |
162 | "-L", "DEBUG", | 160 | "-L", "DEBUG", |
163 | #endif | 161 | #endif |
164 | "-c", cfgname, NULL); | 162 | "-c", cfgname, NULL); |
165 | #endif | 163 | #endif |
166 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 164 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
167 | } | 165 | } |
168 | 166 | ||
169 | 167 | ||
170 | static void | 168 | static void |
171 | timeout_task (void *cls, | 169 | timeout_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
172 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
173 | { | 170 | { |
174 | fprintf (stderr, "Timeout.\n"); | 171 | fprintf (stderr, "Timeout.\n"); |
175 | if (p1.ch != NULL) | 172 | if (p1.ch != NULL) |
176 | { | 173 | { |
177 | GNUNET_CORE_disconnect (p1.ch); | 174 | GNUNET_CORE_disconnect (p1.ch); |
178 | p1.ch = NULL; | 175 | p1.ch = NULL; |
179 | } | 176 | } |
180 | if (p2.ch != NULL) | 177 | if (p2.ch != NULL) |
181 | { | 178 | { |
182 | GNUNET_CORE_disconnect (p2.ch); | 179 | GNUNET_CORE_disconnect (p2.ch); |
183 | p2.ch = NULL; | 180 | p2.ch = NULL; |
184 | } | 181 | } |
185 | ok = 42; | 182 | ok = 42; |
186 | } | 183 | } |
187 | 184 | ||
@@ -190,39 +187,35 @@ timeout_task (void *cls, | |||
190 | static void | 187 | static void |
191 | run (void *cls, | 188 | run (void *cls, |
192 | char *const *args, | 189 | char *const *args, |
193 | const char *cfgfile, | 190 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
194 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
195 | { | 191 | { |
196 | GNUNET_assert (ok == 1); | 192 | GNUNET_assert (ok == 1); |
197 | OKPP; | 193 | OKPP; |
198 | setup_peer (&p1, "test_core_api_peer1.conf"); | 194 | setup_peer (&p1, "test_core_api_peer1.conf"); |
199 | setup_peer (&p2, "test_core_api_peer2.conf"); | 195 | setup_peer (&p2, "test_core_api_peer2.conf"); |
200 | timeout_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, TIMEOUT), | 196 | timeout_task_id = |
201 | &timeout_task, | 197 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
202 | NULL); | 198 | (GNUNET_TIME_UNIT_MINUTES, TIMEOUT), |
203 | p1.ch = GNUNET_CORE_connect (p1.cfg, 1, | 199 | &timeout_task, NULL); |
204 | &p1, | 200 | p1.ch = |
205 | &init_notify, | 201 | GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, |
206 | &connect_notify, | 202 | &disconnect_notify, NULL, &inbound_notify, |
207 | &disconnect_notify, | 203 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); |
208 | NULL, | ||
209 | &inbound_notify, | ||
210 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | ||
211 | } | 204 | } |
212 | 205 | ||
213 | 206 | ||
214 | static void | 207 | static void |
215 | stop_arm (struct PeerContext *p) | 208 | stop_arm (struct PeerContext *p) |
216 | { | 209 | { |
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n"); |
218 | "Stopping peer\n"); | ||
219 | #if START_ARM | 211 | #if START_ARM |
220 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 212 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
221 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 213 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
222 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 214 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
223 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 215 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
225 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 217 | "ARM process %u stopped\n", |
218 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
226 | GNUNET_OS_process_close (p->arm_proc); | 219 | GNUNET_OS_process_close (p->arm_proc); |
227 | p->arm_proc = NULL; | 220 | p->arm_proc = NULL; |
228 | #endif | 221 | #endif |
@@ -249,9 +242,9 @@ check () | |||
249 | 242 | ||
250 | ok = 1; | 243 | ok = 1; |
251 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 244 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
252 | argv, "test-core-api-start-only", "nohelp", options, &run, &ok); | 245 | argv, "test-core-api-start-only", "nohelp", options, &run, |
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 246 | &ok); |
254 | "Test finished\n"); | 247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test finished\n"); |
255 | stop_arm (&p1); | 248 | stop_arm (&p1); |
256 | stop_arm (&p2); | 249 | stop_arm (&p2); |
257 | return ok; | 250 | return ok; |