diff options
Diffstat (limited to 'src/arm/test_gnunet_service_arm.c')
-rw-r--r-- | src/arm/test_gnunet_service_arm.c | 257 |
1 files changed, 129 insertions, 128 deletions
diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c index cb2c14438..45053a41d 100644 --- a/src/arm/test_gnunet_service_arm.c +++ b/src/arm/test_gnunet_service_arm.c | |||
@@ -34,9 +34,10 @@ | |||
34 | * (by checking if running before starting, so really this time is always waited on | 34 | * (by checking if running before starting, so really this time is always waited on |
35 | * startup (annoying)). | 35 | * startup (annoying)). |
36 | */ | 36 | */ |
37 | #define START_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50) | 37 | #define START_TIMEOUT GNUNET_TIME_relative_multiply ( \ |
38 | GNUNET_TIME_UNIT_MILLISECONDS, 50) | ||
38 | 39 | ||
39 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
40 | 41 | ||
41 | 42 | ||
42 | static int ret = 1; | 43 | static int ret = 1; |
@@ -51,141 +52,141 @@ static const char hostname[] = "www.gnu.org"; /* any domain should do */ | |||
51 | 52 | ||
52 | 53 | ||
53 | static void | 54 | static void |
54 | trigger_disconnect(void *cls) | 55 | trigger_disconnect (void *cls) |
55 | { | 56 | { |
56 | GNUNET_ARM_disconnect(arm); | 57 | GNUNET_ARM_disconnect (arm); |
57 | arm = NULL; | 58 | arm = NULL; |
58 | } | 59 | } |
59 | 60 | ||
60 | 61 | ||
61 | static void | 62 | static void |
62 | arm_stop_cb(void *cls, | 63 | arm_stop_cb (void *cls, |
63 | enum GNUNET_ARM_RequestStatus status, | 64 | enum GNUNET_ARM_RequestStatus status, |
64 | enum GNUNET_ARM_Result result) | 65 | enum GNUNET_ARM_Result result) |
65 | { | 66 | { |
66 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); | 67 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
67 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); | 68 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); |
68 | if (result != GNUNET_ARM_RESULT_STOPPED) | 69 | if (result != GNUNET_ARM_RESULT_STOPPED) |
69 | { | 70 | { |
70 | GNUNET_break(0); | 71 | GNUNET_break (0); |
71 | ret = 4; | 72 | ret = 4; |
72 | } | 73 | } |
73 | GNUNET_SCHEDULER_add_now(&trigger_disconnect, NULL); | 74 | GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL); |
74 | } | 75 | } |
75 | 76 | ||
76 | 77 | ||
77 | static void | 78 | static void |
78 | service_list(void *cls, | 79 | service_list (void *cls, |
79 | enum GNUNET_ARM_RequestStatus rs, | 80 | enum GNUNET_ARM_RequestStatus rs, |
80 | unsigned int count, | 81 | unsigned int count, |
81 | const struct GNUNET_ARM_ServiceInfo *list) | 82 | const struct GNUNET_ARM_ServiceInfo *list) |
82 | { | 83 | { |
83 | unsigned int i; | 84 | unsigned int i; |
84 | 85 | ||
85 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "%u services are are currently running\n", | 87 | "%u services are are currently running\n", |
87 | count); | 88 | count); |
88 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 89 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
89 | goto stop_arm; | 90 | goto stop_arm; |
90 | for (i = 0; i < count; i++) | 91 | for (i = 0; i < count; i++) |
92 | { | ||
93 | if ((0 == strcasecmp (list[i].name, "resolver")) && | ||
94 | (0 == strcasecmp (list[i].binary, "gnunet-service-resolver"))) | ||
91 | { | 95 | { |
92 | if ((0 == strcasecmp(list[i].name, "resolver")) && | 96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
93 | (0 == strcasecmp(list[i].binary, "gnunet-service-resolver"))) | 97 | "Got service list, now stopping arm\n"); |
94 | { | 98 | ret = 0; |
95 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
96 | "Got service list, now stopping arm\n"); | ||
97 | ret = 0; | ||
98 | } | ||
99 | } | 99 | } |
100 | } | ||
100 | 101 | ||
101 | stop_arm: | 102 | stop_arm: |
102 | GNUNET_ARM_request_service_stop(arm, | 103 | GNUNET_ARM_request_service_stop (arm, |
103 | "arm", | 104 | "arm", |
104 | &arm_stop_cb, | 105 | &arm_stop_cb, |
105 | NULL); | 106 | NULL); |
106 | } | 107 | } |
107 | 108 | ||
108 | 109 | ||
109 | static void | 110 | static void |
110 | hostname_resolve_cb(void *cls, | 111 | hostname_resolve_cb (void *cls, |
111 | const struct sockaddr *addr, | 112 | const struct sockaddr *addr, |
112 | socklen_t addrlen) | 113 | socklen_t addrlen) |
113 | { | 114 | { |
114 | if ((0 == ret) || (4 == ret) || (1 == resolved_ok)) | 115 | if ((0 == ret) || (4 == ret) || (1 == resolved_ok)) |
115 | return; | 116 | return; |
116 | if (NULL == addr) | 117 | if (NULL == addr) |
117 | { | 118 | { |
118 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 119 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
119 | "Failed to resolve hostname!\n"); | 120 | "Failed to resolve hostname!\n"); |
120 | GNUNET_break(0); | 121 | GNUNET_break (0); |
121 | ret = 3; | 122 | ret = 3; |
122 | GNUNET_ARM_request_service_stop(arm, | 123 | GNUNET_ARM_request_service_stop (arm, |
123 | "arm", | 124 | "arm", |
124 | &arm_stop_cb, | 125 | &arm_stop_cb, |
125 | NULL); | 126 | NULL); |
126 | return; | 127 | return; |
127 | } | 128 | } |
128 | if (0 == asked_for_a_list) | 129 | if (0 == asked_for_a_list) |
129 | { | 130 | { |
130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
131 | "Resolved hostname, now checking the service list\n"); | 132 | "Resolved hostname, now checking the service list\n"); |
132 | GNUNET_ARM_request_service_list(arm, | 133 | GNUNET_ARM_request_service_list (arm, |
133 | &service_list, | 134 | &service_list, |
134 | NULL); | 135 | NULL); |
135 | asked_for_a_list = 1; | 136 | asked_for_a_list = 1; |
136 | resolved_ok = 1; | 137 | resolved_ok = 1; |
137 | } | 138 | } |
138 | } | 139 | } |
139 | 140 | ||
140 | 141 | ||
141 | static void | 142 | static void |
142 | arm_start_cb(void *cls, | 143 | arm_start_cb (void *cls, |
143 | enum GNUNET_ARM_RequestStatus status, | 144 | enum GNUNET_ARM_RequestStatus status, |
144 | enum GNUNET_ARM_Result result) | 145 | enum GNUNET_ARM_Result result) |
145 | { | 146 | { |
146 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); | 147 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
147 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); | 148 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
148 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
149 | "Trying to resolve a hostname via the resolver service!\n"); | 150 | "Trying to resolve a hostname via the resolver service!\n"); |
150 | /* connect to the resolver service */ | 151 | /* connect to the resolver service */ |
151 | if (NULL == | 152 | if (NULL == |
152 | GNUNET_RESOLVER_ip_get(hostname, | 153 | GNUNET_RESOLVER_ip_get (hostname, |
153 | AF_UNSPEC, | 154 | AF_UNSPEC, |
154 | TIMEOUT, | 155 | TIMEOUT, |
155 | &hostname_resolve_cb, | 156 | &hostname_resolve_cb, |
156 | NULL)) | 157 | NULL)) |
157 | { | 158 | { |
158 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 159 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
159 | "Unable initiate connection to resolver service\n"); | 160 | "Unable initiate connection to resolver service\n"); |
160 | GNUNET_break(0); | 161 | GNUNET_break (0); |
161 | ret = 2; | 162 | ret = 2; |
162 | GNUNET_ARM_request_service_stop(arm, | 163 | GNUNET_ARM_request_service_stop (arm, |
163 | "arm", | 164 | "arm", |
164 | &arm_stop_cb, | 165 | &arm_stop_cb, |
165 | NULL); | 166 | NULL); |
166 | } | 167 | } |
167 | } | 168 | } |
168 | 169 | ||
169 | 170 | ||
170 | static void | 171 | static void |
171 | run(void *cls, | 172 | run (void *cls, |
172 | char *const *args, | 173 | char *const *args, |
173 | const char *cfgfile, | 174 | const char *cfgfile, |
174 | const struct GNUNET_CONFIGURATION_Handle *c) | 175 | const struct GNUNET_CONFIGURATION_Handle *c) |
175 | { | 176 | { |
176 | arm = GNUNET_ARM_connect(c, | 177 | arm = GNUNET_ARM_connect (c, |
177 | NULL, | 178 | NULL, |
178 | NULL); | 179 | NULL); |
179 | GNUNET_ARM_request_service_start(arm, | 180 | GNUNET_ARM_request_service_start (arm, |
180 | "arm", | 181 | "arm", |
181 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 182 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
182 | &arm_start_cb, | 183 | &arm_start_cb, |
183 | NULL); | 184 | NULL); |
184 | } | 185 | } |
185 | 186 | ||
186 | 187 | ||
187 | int | 188 | int |
188 | main(int argc, char *av[]) | 189 | main (int argc, char *av[]) |
189 | { | 190 | { |
190 | static char *const argv[] = { | 191 | static char *const argv[] = { |
191 | "test-gnunet-service-arm", | 192 | "test-gnunet-service-arm", |
@@ -203,62 +204,62 @@ main(int argc, char *av[]) | |||
203 | struct addrinfo *ai; | 204 | struct addrinfo *ai; |
204 | int ret; | 205 | int ret; |
205 | 206 | ||
206 | if (0 != (ret = getaddrinfo(hostname, NULL, NULL, &ai))) | 207 | if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai))) |
207 | { | 208 | { |
208 | fprintf(stderr, | 209 | fprintf (stderr, |
209 | "Failed to resolve `%s', testcase not run.\n", | 210 | "Failed to resolve `%s', testcase not run.\n", |
210 | hostname); | 211 | hostname); |
211 | return 77; | 212 | return 77; |
212 | } | 213 | } |
213 | freeaddrinfo(ai); | 214 | freeaddrinfo (ai); |
214 | } | 215 | } |
215 | #elif HAVE_GETHOSTBYNAME2 | 216 | #elif HAVE_GETHOSTBYNAME2 |
216 | { | 217 | { |
217 | struct hostent *host; | 218 | struct hostent *host; |
218 | 219 | ||
219 | host = gethostbyname2(hostname, AF_INET); | 220 | host = gethostbyname2 (hostname, AF_INET); |
220 | if (NULL == host) | 221 | if (NULL == host) |
221 | host = gethostbyname2(hostname, AF_INET6); | 222 | host = gethostbyname2 (hostname, AF_INET6); |
222 | if (NULL == host) | 223 | if (NULL == host) |
223 | { | 224 | { |
224 | fprintf(stderr, | 225 | fprintf (stderr, |
225 | "Failed to resolve `%s', testcase not run.\n", | 226 | "Failed to resolve `%s', testcase not run.\n", |
226 | hostname); | 227 | hostname); |
227 | return 77; | 228 | return 77; |
228 | } | 229 | } |
229 | } | 230 | } |
230 | #elif HAVE_GETHOSTBYNAME | 231 | #elif HAVE_GETHOSTBYNAME |
231 | { | 232 | { |
232 | struct hostent *host; | 233 | struct hostent *host; |
233 | 234 | ||
234 | host = gethostbyname(hostname); | 235 | host = gethostbyname (hostname); |
235 | if (NULL == host) | 236 | if (NULL == host) |
236 | { | 237 | { |
237 | fprintf(stderr, | 238 | fprintf (stderr, |
238 | "Failed to resolve `%s', testcase not run.\n", | 239 | "Failed to resolve `%s', testcase not run.\n", |
239 | hostname); | 240 | hostname); |
240 | return 77; | 241 | return 77; |
241 | } | 242 | } |
242 | } | 243 | } |
243 | #else | 244 | #else |
244 | fprintf(stderr, | 245 | fprintf (stderr, |
245 | "libc fails to have resolver function, testcase not run.\n"); | 246 | "libc fails to have resolver function, testcase not run.\n"); |
246 | return 77; | 247 | return 77; |
247 | #endif | 248 | #endif |
248 | GNUNET_log_setup("test-gnunet-service-arm", | 249 | GNUNET_log_setup ("test-gnunet-service-arm", |
249 | "WARNING", | 250 | "WARNING", |
250 | NULL); | 251 | NULL); |
251 | GNUNET_break(GNUNET_OK == | 252 | GNUNET_break (GNUNET_OK == |
252 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, | 253 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, |
253 | argv, "test-gnunet-service-arm", | 254 | argv, "test-gnunet-service-arm", |
254 | "nohelp", options, | 255 | "nohelp", options, |
255 | &run, NULL)); | 256 | &run, NULL)); |
256 | if (0 != ret) | 257 | if (0 != ret) |
257 | { | 258 | { |
258 | fprintf(stderr, | 259 | fprintf (stderr, |
259 | "Test failed with error code %d\n", | 260 | "Test failed with error code %d\n", |
260 | ret); | 261 | ret); |
261 | } | 262 | } |
262 | return ret; | 263 | return ret; |
263 | } | 264 | } |
264 | 265 | ||