diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-03-28 09:32:38 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-03-28 09:32:38 +0000 |
commit | d03ca6000941d0cee31fff6469f4f1aa00b8efb3 (patch) | |
tree | 8eb9df346fb08c3059bb941a5911ba3fa1b2135b /src/arm/test_arm_api.c | |
parent | 4050bda2c2f530ba392bd5473c66298602072008 (diff) | |
download | gnunet-d03ca6000941d0cee31fff6469f4f1aa00b8efb3.tar.gz gnunet-d03ca6000941d0cee31fff6469f4f1aa00b8efb3.zip |
-test cleanup
Diffstat (limited to 'src/arm/test_arm_api.c')
-rw-r--r-- | src/arm/test_arm_api.c | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index 65e8b7797..271746e6b 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #include "gnunet_program_lib.h" | 30 | #include "gnunet_program_lib.h" |
31 | #include "gnunet_resolver_service.h" | 31 | #include "gnunet_resolver_service.h" |
32 | 32 | ||
33 | #define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
34 | |||
33 | #define START_ARM GNUNET_YES | 35 | #define START_ARM GNUNET_YES |
34 | 36 | ||
35 | #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1500) | 37 | #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1500) |
@@ -53,7 +55,7 @@ arm_stop_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStat | |||
53 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING); | 55 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPING); |
54 | GNUNET_break (phase == 6); | 56 | GNUNET_break (phase == 6); |
55 | phase++; | 57 | phase++; |
56 | FPRINTF (stderr, "Sent 'STOP' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 58 | LOG ("Sent 'STOP' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
57 | } | 59 | } |
58 | 60 | ||
59 | static void | 61 | static void |
@@ -65,7 +67,7 @@ resolver_stop_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_Reques | |||
65 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 67 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
66 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); | 68 | GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); |
67 | GNUNET_break (phase == 5); | 69 | GNUNET_break (phase == 5); |
68 | FPRINTF (stderr, "Sent 'STOP' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 70 | LOG ("Sent 'STOP' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
69 | phase++; | 71 | phase++; |
70 | #if START_ARM | 72 | #if START_ARM |
71 | GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); | 73 | GNUNET_ARM_request_service_stop (arm, "arm", TIMEOUT, arm_stop_cb, NULL); |
@@ -83,7 +85,7 @@ dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) | |||
83 | /* (4), resolver should finish resolving localhost */ | 85 | /* (4), resolver should finish resolving localhost */ |
84 | GNUNET_break (phase == 4); | 86 | GNUNET_break (phase == 4); |
85 | phase++; | 87 | phase++; |
86 | FPRINTF (stderr, "%s", "Finished resolving localhost\n"); | 88 | LOG ("Finished resolving localhost\n"); |
87 | if (ok != 0) | 89 | if (ok != 0) |
88 | ok = 2; | 90 | ok = 2; |
89 | GNUNET_ARM_request_service_stop (arm, "resolver", TIMEOUT, resolver_stop_cb, NULL); | 91 | GNUNET_ARM_request_service_stop (arm, "resolver", TIMEOUT, resolver_stop_cb, NULL); |
@@ -91,7 +93,7 @@ dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) | |||
91 | } | 93 | } |
92 | /* (3), resolver should resolve localhost */ | 94 | /* (3), resolver should resolve localhost */ |
93 | GNUNET_break (phase == 3); | 95 | GNUNET_break (phase == 3); |
94 | FPRINTF (stderr, "%s", "Resolved localhost\n"); | 96 | LOG ("Resolved localhost\n"); |
95 | phase++; | 97 | phase++; |
96 | GNUNET_break (addr != NULL); | 98 | GNUNET_break (addr != NULL); |
97 | ok = 0; | 99 | ok = 0; |
@@ -106,7 +108,7 @@ resolver_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_Reque | |||
106 | GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); | 108 | GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); |
107 | GNUNET_break (phase == 2); | 109 | GNUNET_break (phase == 2); |
108 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 110 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
109 | FPRINTF (stderr, "Sent 'START' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 111 | LOG ("Sent 'START' request for resolver to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
110 | phase++; | 112 | phase++; |
111 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL); | 113 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL); |
112 | } | 114 | } |
@@ -118,8 +120,10 @@ trigger_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
118 | } | 120 | } |
119 | 121 | ||
120 | 122 | ||
121 | void | 123 | static void |
122 | arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, char connected) | 124 | arm_conn (void *cls, |
125 | struct GNUNET_ARM_Handle *arm, | ||
126 | int connected) | ||
123 | { | 127 | { |
124 | if (GNUNET_SYSERR == connected) | 128 | if (GNUNET_SYSERR == connected) |
125 | { | 129 | { |
@@ -132,7 +136,7 @@ arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, char connected) | |||
132 | if (GNUNET_YES == connected) | 136 | if (GNUNET_YES == connected) |
133 | { | 137 | { |
134 | /* (1), arm connection should be established */ | 138 | /* (1), arm connection should be established */ |
135 | FPRINTF (stderr, "%s", "Connected to ARM\n"); | 139 | LOG ("Connected to ARM\n"); |
136 | GNUNET_break (phase == 1); | 140 | GNUNET_break (phase == 1); |
137 | phase++; | 141 | phase++; |
138 | GNUNET_ARM_request_service_start (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, resolver_start_cb, NULL); | 142 | GNUNET_ARM_request_service_start (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, resolver_start_cb, NULL); |
@@ -140,7 +144,7 @@ arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, char connected) | |||
140 | else | 144 | else |
141 | { | 145 | { |
142 | /* (7), ARM should stop (we disconnect from it) */ | 146 | /* (7), ARM should stop (we disconnect from it) */ |
143 | FPRINTF (stderr, "%s", "Disconnected from ARM\n"); | 147 | LOG ("Disconnected from ARM\n"); |
144 | GNUNET_break (phase == 7); | 148 | GNUNET_break (phase == 7); |
145 | if (phase != 7) | 149 | if (phase != 7) |
146 | ok = 3; | 150 | ok = 3; |
@@ -150,15 +154,16 @@ arm_conn (void *cls, struct GNUNET_ARM_Handle *arm, char connected) | |||
150 | } | 154 | } |
151 | } | 155 | } |
152 | 156 | ||
153 | void | 157 | |
158 | static void | ||
154 | srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status) | 159 | srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status) |
155 | { | 160 | { |
156 | FPRINTF (stderr, "Service %s is %u\n", service, status); | 161 | LOG ("Service %s is %u\n", service, status); |
157 | switch (phase) | 162 | switch (phase) |
158 | { | 163 | { |
159 | default: | 164 | default: |
160 | FPRINTF (stderr, "Unexpectedly got status %u for service %s\n", status, | 165 | LOG ("Unexpectedly got status %u for service %s\n", status, |
161 | service); | 166 | service); |
162 | GNUNET_break (0); | 167 | GNUNET_break (0); |
163 | ok = 2; | 168 | ok = 2; |
164 | #if START_ARM | 169 | #if START_ARM |
@@ -167,8 +172,13 @@ srv_status (void *cls, const char *service, enum GNUNET_ARM_ServiceStatus status | |||
167 | } | 172 | } |
168 | } | 173 | } |
169 | 174 | ||
175 | |||
170 | static void | 176 | static void |
171 | arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result) | 177 | arm_start_cb (void *cls, |
178 | struct GNUNET_ARM_Handle *h, | ||
179 | enum GNUNET_ARM_RequestStatus status, | ||
180 | const char *servicename, | ||
181 | enum GNUNET_ARM_Result result) | ||
172 | { | 182 | { |
173 | /* (0) The request should be "sent" successfully | 183 | /* (0) The request should be "sent" successfully |
174 | * ("sent", because it isn't going anywhere, ARM API starts ARM service | 184 | * ("sent", because it isn't going anywhere, ARM API starts ARM service |
@@ -177,11 +187,12 @@ arm_start_cb (void *cls, struct GNUNET_ARM_Handle *h, enum GNUNET_ARM_RequestSta | |||
177 | */ | 187 | */ |
178 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); | 188 | GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); |
179 | GNUNET_break (phase == 0); | 189 | GNUNET_break (phase == 0); |
180 | FPRINTF (stderr, "Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); | 190 | LOG ("Sent 'START' request for arm to ARM %s\n", (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); |
181 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); | 191 | GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); |
182 | phase++; | 192 | phase++; |
183 | } | 193 | } |
184 | 194 | ||
195 | |||
185 | static void | 196 | static void |
186 | task (void *cls, char *const *args, const char *cfgfile, | 197 | task (void *cls, char *const *args, const char *cfgfile, |
187 | const struct GNUNET_CONFIGURATION_Handle *c) | 198 | const struct GNUNET_CONFIGURATION_Handle *c) |
@@ -201,7 +212,7 @@ task (void *cls, char *const *args, const char *cfgfile, | |||
201 | else | 212 | else |
202 | GNUNET_free (armconfig); | 213 | GNUNET_free (armconfig); |
203 | } | 214 | } |
204 | arm = GNUNET_ARM_connect (cfg, arm_conn, NULL); | 215 | arm = GNUNET_ARM_connect (cfg, &arm_conn, NULL); |
205 | if (NULL == arm) | 216 | if (NULL == arm) |
206 | return; | 217 | return; |
207 | #if START_ARM | 218 | #if START_ARM |
@@ -213,9 +224,8 @@ task (void *cls, char *const *args, const char *cfgfile, | |||
213 | } | 224 | } |
214 | 225 | ||
215 | 226 | ||
216 | 227 | int | |
217 | static int | 228 | main (int argc, char *argvx[]) |
218 | check () | ||
219 | { | 229 | { |
220 | char *const argv[] = { | 230 | char *const argv[] = { |
221 | "test-arm-api", | 231 | "test-arm-api", |
@@ -225,6 +235,9 @@ check () | |||
225 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 235 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
226 | GNUNET_GETOPT_OPTION_END | 236 | GNUNET_GETOPT_OPTION_END |
227 | }; | 237 | }; |
238 | GNUNET_log_setup ("test-arm-api", | ||
239 | "WARNING", | ||
240 | NULL); | ||
228 | GNUNET_assert (GNUNET_OK == | 241 | GNUNET_assert (GNUNET_OK == |
229 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 242 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
230 | argv, "test-arm-api", "nohelp", options, | 243 | argv, "test-arm-api", "nohelp", options, |
@@ -232,18 +245,4 @@ check () | |||
232 | return ok; | 245 | return ok; |
233 | } | 246 | } |
234 | 247 | ||
235 | int | ||
236 | main (int argc, char *argv[]) | ||
237 | { | ||
238 | int ret; | ||
239 | |||
240 | |||
241 | GNUNET_log_setup ("test-arm-api", | ||
242 | "WARNING", | ||
243 | NULL); | ||
244 | ret = check (); | ||
245 | |||
246 | return ret; | ||
247 | } | ||
248 | |||
249 | /* end of test_arm_api.c */ | 248 | /* end of test_arm_api.c */ |