diff options
Diffstat (limited to 'src/arm/test_arm_api.c')
-rw-r--r-- | src/arm/test_arm_api.c | 254 |
1 files changed, 129 insertions, 125 deletions
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index 84d6f1bfd..5a06c823c 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.c | |||
@@ -26,9 +26,9 @@ | |||
26 | #include "gnunet_arm_service.h" | 26 | #include "gnunet_arm_service.h" |
27 | #include "gnunet_resolver_service.h" | 27 | #include "gnunet_resolver_service.h" |
28 | 28 | ||
29 | #define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 29 | #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
30 | 30 | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
32 | 32 | ||
33 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 33 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
34 | 34 | ||
@@ -42,139 +42,142 @@ static int phase = 0; | |||
42 | 42 | ||
43 | 43 | ||
44 | static void | 44 | static void |
45 | arm_stop_cb(void *cls, | 45 | arm_stop_cb (void *cls, |
46 | enum GNUNET_ARM_RequestStatus status, | 46 | enum GNUNET_ARM_RequestStatus status, |
47 | enum GNUNET_ARM_Result result) | 47 | enum GNUNET_ARM_Result result) |
48 | { | 48 | { |
49 | op = NULL; | 49 | op = NULL; |
50 | /* (6), a stop request should be sent to ARM successfully */ | 50 | /* (6), a stop request should be sent to ARM successfully */ |
51 | /* ARM should report that it is stopping */ | 51 | /* ARM should report that it is stopping */ |
52 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); | 52 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
53 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); | 53 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); |
54 | GNUNET_break(phase == 6); | 54 | GNUNET_break (phase == 6); |
55 | phase++; | 55 | phase++; |
56 | LOG("Sent 'STOP' request for arm to ARM %s\n", | 56 | LOG ("Sent 'STOP' request for arm to ARM %s\n", |
57 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 57 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : |
58 | GNUNET_SCHEDULER_shutdown(); | 58 | "unsuccessfully"); |
59 | GNUNET_SCHEDULER_shutdown (); | ||
59 | } | 60 | } |
60 | 61 | ||
61 | 62 | ||
62 | static void | 63 | static void |
63 | resolver_stop_cb(void *cls, | 64 | resolver_stop_cb (void *cls, |
64 | enum GNUNET_ARM_RequestStatus status, | 65 | enum GNUNET_ARM_RequestStatus status, |
65 | enum GNUNET_ARM_Result result) | 66 | enum GNUNET_ARM_Result result) |
66 | { | 67 | { |
67 | op = NULL; | 68 | op = NULL; |
68 | /* (5), a stop request should be sent to ARM successfully. | 69 | /* (5), a stop request should be sent to ARM successfully. |
69 | * ARM should report that resolver is stopped. | 70 | * ARM should report that resolver is stopped. |
70 | */ | 71 | */ |
71 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); | 72 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
72 | GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); | 73 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); |
73 | GNUNET_break(phase == 5); | 74 | GNUNET_break (phase == 5); |
74 | LOG("Sent 'STOP' request for resolver to ARM %s\n", | 75 | LOG ("Sent 'STOP' request for resolver to ARM %s\n", |
75 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 76 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : |
77 | "unsuccessfully"); | ||
76 | phase++; | 78 | phase++; |
77 | GNUNET_assert(NULL == op); | 79 | GNUNET_assert (NULL == op); |
78 | op = GNUNET_ARM_request_service_stop(arm, | 80 | op = GNUNET_ARM_request_service_stop (arm, |
79 | "arm", | 81 | "arm", |
80 | &arm_stop_cb, | 82 | &arm_stop_cb, |
81 | NULL); | 83 | NULL); |
82 | } | 84 | } |
83 | 85 | ||
84 | 86 | ||
85 | static void | 87 | static void |
86 | dns_notify(void *cls, | 88 | dns_notify (void *cls, |
87 | const struct sockaddr *addr, | 89 | const struct sockaddr *addr, |
88 | socklen_t addrlen) | 90 | socklen_t addrlen) |
89 | { | 91 | { |
90 | if (addr == NULL) | 92 | if (addr == NULL) |
91 | { | 93 | { |
92 | /* (4), resolver should finish resolving localhost */ | 94 | /* (4), resolver should finish resolving localhost */ |
93 | GNUNET_break(phase == 4); | 95 | GNUNET_break (phase == 4); |
94 | phase++; | 96 | phase++; |
95 | LOG("Finished resolving localhost\n"); | 97 | LOG ("Finished resolving localhost\n"); |
96 | if (ok != 0) | 98 | if (ok != 0) |
97 | ok = 2; | 99 | ok = 2; |
98 | GNUNET_assert(NULL == op); | 100 | GNUNET_assert (NULL == op); |
99 | op = GNUNET_ARM_request_service_stop(arm, | 101 | op = GNUNET_ARM_request_service_stop (arm, |
100 | "resolver", | 102 | "resolver", |
101 | &resolver_stop_cb, | 103 | &resolver_stop_cb, |
102 | NULL); | 104 | NULL); |
103 | return; | 105 | return; |
104 | } | 106 | } |
105 | /* (3), resolver should resolve localhost */ | 107 | /* (3), resolver should resolve localhost */ |
106 | GNUNET_break(phase == 3); | 108 | GNUNET_break (phase == 3); |
107 | LOG("Resolved localhost\n"); | 109 | LOG ("Resolved localhost\n"); |
108 | phase++; | 110 | phase++; |
109 | GNUNET_break(addr != NULL); | 111 | GNUNET_break (addr != NULL); |
110 | ok = 0; | 112 | ok = 0; |
111 | } | 113 | } |
112 | 114 | ||
113 | 115 | ||
114 | static void | 116 | static void |
115 | resolver_start_cb(void *cls, | 117 | resolver_start_cb (void *cls, |
116 | enum GNUNET_ARM_RequestStatus status, | 118 | enum GNUNET_ARM_RequestStatus status, |
117 | enum GNUNET_ARM_Result result) | 119 | enum GNUNET_ARM_Result result) |
118 | { | 120 | { |
119 | op = NULL; | 121 | op = NULL; |
120 | /* (2), the start request for resolver should be sent successfully | 122 | /* (2), the start request for resolver should be sent successfully |
121 | * ARM should report that resolver service is starting. | 123 | * ARM should report that resolver service is starting. |
122 | */ | 124 | */ |
123 | GNUNET_assert(status == GNUNET_ARM_REQUEST_SENT_OK); | 125 | GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); |
124 | GNUNET_break(phase == 2); | 126 | GNUNET_break (phase == 2); |
125 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); | 127 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
126 | LOG("Sent 'START' request for resolver to ARM %s\n", | 128 | LOG ("Sent 'START' request for resolver to ARM %s\n", |
127 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 129 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : |
130 | "unsuccessfully"); | ||
128 | phase++; | 131 | phase++; |
129 | GNUNET_RESOLVER_ip_get("localhost", | 132 | GNUNET_RESOLVER_ip_get ("localhost", |
130 | AF_INET, | 133 | AF_INET, |
131 | TIMEOUT, | 134 | TIMEOUT, |
132 | &dns_notify, NULL); | 135 | &dns_notify, NULL); |
133 | } | 136 | } |
134 | 137 | ||
135 | 138 | ||
136 | static void | 139 | static void |
137 | arm_conn(void *cls, | 140 | arm_conn (void *cls, |
138 | int connected) | 141 | int connected) |
139 | { | 142 | { |
140 | if (GNUNET_SYSERR == connected) | 143 | if (GNUNET_SYSERR == connected) |
141 | { | 144 | { |
142 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
143 | _("Fatal error initializing ARM API.\n")); | 146 | _ ("Fatal error initializing ARM API.\n")); |
144 | GNUNET_SCHEDULER_shutdown(); | 147 | GNUNET_SCHEDULER_shutdown (); |
145 | GNUNET_assert(0); | 148 | GNUNET_assert (0); |
146 | return; | 149 | return; |
147 | } | 150 | } |
148 | if (GNUNET_YES == connected) | 151 | if (GNUNET_YES == connected) |
149 | { | 152 | { |
150 | /* (1), arm connection should be established */ | 153 | /* (1), arm connection should be established */ |
151 | LOG("Connected to ARM\n"); | 154 | LOG ("Connected to ARM\n"); |
152 | GNUNET_break(phase == 1); | 155 | GNUNET_break (phase == 1); |
153 | phase++; | 156 | phase++; |
154 | GNUNET_assert(NULL == op); | 157 | GNUNET_assert (NULL == op); |
155 | op = GNUNET_ARM_request_service_start(arm, | 158 | op = GNUNET_ARM_request_service_start (arm, |
156 | "resolver", | 159 | "resolver", |
157 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 160 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
158 | &resolver_start_cb, | 161 | &resolver_start_cb, |
159 | NULL); | 162 | NULL); |
160 | } | 163 | } |
161 | else | 164 | else |
162 | { | 165 | { |
163 | /* (7), ARM should stop (we disconnect from it) */ | 166 | /* (7), ARM should stop (we disconnect from it) */ |
164 | LOG("Disconnected from ARM\n"); | 167 | LOG ("Disconnected from ARM\n"); |
165 | GNUNET_break(phase == 7); | 168 | GNUNET_break (phase == 7); |
166 | if (phase != 7) | 169 | if (phase != 7) |
167 | ok = 3; | 170 | ok = 3; |
168 | else if (ok == 1) | 171 | else if (ok == 1) |
169 | ok = 0; | 172 | ok = 0; |
170 | } | 173 | } |
171 | } | 174 | } |
172 | 175 | ||
173 | 176 | ||
174 | static void | 177 | static void |
175 | arm_start_cb(void *cls, | 178 | arm_start_cb (void *cls, |
176 | enum GNUNET_ARM_RequestStatus status, | 179 | enum GNUNET_ARM_RequestStatus status, |
177 | enum GNUNET_ARM_Result result) | 180 | enum GNUNET_ARM_Result result) |
178 | { | 181 | { |
179 | op = NULL; | 182 | op = NULL; |
180 | /* (0) The request should be "sent" successfully | 183 | /* (0) The request should be "sent" successfully |
@@ -182,55 +185,56 @@ arm_start_cb(void *cls, | |||
182 | * by itself). | 185 | * by itself). |
183 | * ARM API should report that ARM service is starting. | 186 | * ARM API should report that ARM service is starting. |
184 | */ | 187 | */ |
185 | GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); | 188 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
186 | GNUNET_break(phase == 0); | 189 | GNUNET_break (phase == 0); |
187 | LOG("Sent 'START' request for arm to ARM %s\n", | 190 | LOG ("Sent 'START' request for arm to ARM %s\n", |
188 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 191 | (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : |
189 | GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); | 192 | "unsuccessfully"); |
193 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | ||
190 | phase++; | 194 | phase++; |
191 | } | 195 | } |
192 | 196 | ||
193 | 197 | ||
194 | static void | 198 | static void |
195 | do_shutdown(void *cls) | 199 | do_shutdown (void *cls) |
196 | { | 200 | { |
197 | if (NULL != op) | 201 | if (NULL != op) |
198 | { | 202 | { |
199 | GNUNET_ARM_operation_cancel(op); | 203 | GNUNET_ARM_operation_cancel (op); |
200 | op = NULL; | 204 | op = NULL; |
201 | } | 205 | } |
202 | if (NULL != arm) | 206 | if (NULL != arm) |
203 | { | 207 | { |
204 | GNUNET_ARM_disconnect(arm); | 208 | GNUNET_ARM_disconnect (arm); |
205 | arm = NULL; | 209 | arm = NULL; |
206 | } | 210 | } |
207 | } | 211 | } |
208 | 212 | ||
209 | 213 | ||
210 | static void | 214 | static void |
211 | task(void *cls, | 215 | task (void *cls, |
212 | char *const *args, | 216 | char *const *args, |
213 | const char *cfgfile, | 217 | const char *cfgfile, |
214 | const struct GNUNET_CONFIGURATION_Handle *c) | 218 | const struct GNUNET_CONFIGURATION_Handle *c) |
215 | { | 219 | { |
216 | cfg = c; | 220 | cfg = c; |
217 | arm = GNUNET_ARM_connect(cfg, | 221 | arm = GNUNET_ARM_connect (cfg, |
218 | &arm_conn, | 222 | &arm_conn, |
219 | NULL); | 223 | NULL); |
220 | if (NULL == arm) | 224 | if (NULL == arm) |
221 | return; | 225 | return; |
222 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 226 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
223 | NULL); | 227 | NULL); |
224 | op = GNUNET_ARM_request_service_start(arm, | 228 | op = GNUNET_ARM_request_service_start (arm, |
225 | "arm", | 229 | "arm", |
226 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 230 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
227 | &arm_start_cb, | 231 | &arm_start_cb, |
228 | NULL); | 232 | NULL); |
229 | } | 233 | } |
230 | 234 | ||
231 | 235 | ||
232 | int | 236 | int |
233 | main(int argc, char *argvx[]) | 237 | main (int argc, char *argvx[]) |
234 | { | 238 | { |
235 | char *const argv[] = { | 239 | char *const argv[] = { |
236 | "test-arm-api", | 240 | "test-arm-api", |
@@ -241,13 +245,13 @@ main(int argc, char *argvx[]) | |||
241 | GNUNET_GETOPT_OPTION_END | 245 | GNUNET_GETOPT_OPTION_END |
242 | }; | 246 | }; |
243 | 247 | ||
244 | GNUNET_log_setup("test-arm-api", | 248 | GNUNET_log_setup ("test-arm-api", |
245 | "WARNING", | 249 | "WARNING", |
246 | NULL); | 250 | NULL); |
247 | GNUNET_assert(GNUNET_OK == | 251 | GNUNET_assert (GNUNET_OK == |
248 | GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, | 252 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, |
249 | argv, "test-arm-api", "nohelp", options, | 253 | argv, "test-arm-api", "nohelp", options, |
250 | &task, NULL)); | 254 | &task, NULL)); |
251 | return ok; | 255 | return ok; |
252 | } | 256 | } |
253 | 257 | ||