diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/test_transport_api_reliability.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 209 |
1 files changed, 105 insertions, 104 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 76910a6c8..d8fd2046d 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -48,7 +48,8 @@ | |||
48 | /** | 48 | /** |
49 | * Testcase timeout | 49 | * Testcase timeout |
50 | */ | 50 | */ |
51 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 450 * FACTOR) | 51 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 450 \ |
52 | * FACTOR) | ||
52 | 53 | ||
53 | /** | 54 | /** |
54 | * If we are in an "xhdr" test, the factor by which we divide | 55 | * If we are in an "xhdr" test, the factor by which we divide |
@@ -83,7 +84,7 @@ static char bitmap[TOTAL_MSGS / 8]; | |||
83 | * Get the desired message size for message number @a iter. | 84 | * Get the desired message size for message number @a iter. |
84 | */ | 85 | */ |
85 | static size_t | 86 | static size_t |
86 | get_size(unsigned int iter) | 87 | get_size (unsigned int iter) |
87 | { | 88 | { |
88 | size_t ret; | 89 | size_t ret; |
89 | 90 | ||
@@ -91,7 +92,7 @@ get_size(unsigned int iter) | |||
91 | #ifndef LINUX | 92 | #ifndef LINUX |
92 | /* FreeBSD/OSX etc. Unix DGRAMs do not work | 93 | /* FreeBSD/OSX etc. Unix DGRAMs do not work |
93 | * with large messages */ | 94 | * with large messages */ |
94 | if (0 == strcmp("unix", ccc->test_plugin)) | 95 | if (0 == strcmp ("unix", ccc->test_plugin)) |
95 | ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024); | 96 | ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024); |
96 | #endif | 97 | #endif |
97 | ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000); | 98 | ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000); |
@@ -108,9 +109,9 @@ get_size(unsigned int iter) | |||
108 | * @return message size of the message | 109 | * @return message size of the message |
109 | */ | 110 | */ |
110 | static size_t | 111 | static size_t |
111 | get_size_cnt(unsigned int cnt_down) | 112 | get_size_cnt (unsigned int cnt_down) |
112 | { | 113 | { |
113 | size_t ret = get_size(TOTAL_MSGS / xhdr - 1 - cnt_down); | 114 | size_t ret = get_size (TOTAL_MSGS / xhdr - 1 - cnt_down); |
114 | 115 | ||
115 | total_bytes += ret; | 116 | total_bytes += ret; |
116 | return ret; | 117 | return ret; |
@@ -124,19 +125,19 @@ get_size_cnt(unsigned int cnt_down) | |||
124 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 125 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
125 | */ | 126 | */ |
126 | static int | 127 | static int |
127 | set_bit(unsigned int bitIdx) | 128 | set_bit (unsigned int bitIdx) |
128 | { | 129 | { |
129 | size_t arraySlot; | 130 | size_t arraySlot; |
130 | unsigned int targetBit; | 131 | unsigned int targetBit; |
131 | 132 | ||
132 | if (bitIdx >= sizeof(bitmap) * 8) | 133 | if (bitIdx >= sizeof(bitmap) * 8) |
133 | { | 134 | { |
134 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
135 | "tried to set bit %u of %u(!?!?)\n", | 136 | "tried to set bit %u of %u(!?!?)\n", |
136 | bitIdx, | 137 | bitIdx, |
137 | (unsigned int)sizeof(bitmap) * 8); | 138 | (unsigned int) sizeof(bitmap) * 8); |
138 | return GNUNET_SYSERR; | 139 | return GNUNET_SYSERR; |
139 | } | 140 | } |
140 | arraySlot = bitIdx / 8; | 141 | arraySlot = bitIdx / 8; |
141 | targetBit = (1L << (bitIdx % 8)); | 142 | targetBit = (1L << (bitIdx % 8)); |
142 | bitmap[arraySlot] |= targetBit; | 143 | bitmap[arraySlot] |= targetBit; |
@@ -152,143 +153,143 @@ set_bit(unsigned int bitIdx) | |||
152 | * @return Bit @a bit from @a map | 153 | * @return Bit @a bit from @a map |
153 | */ | 154 | */ |
154 | static int | 155 | static int |
155 | get_bit(const char *map, | 156 | get_bit (const char *map, |
156 | unsigned int bit) | 157 | unsigned int bit) |
157 | { | 158 | { |
158 | if (bit > TOTAL_MSGS) | 159 | if (bit > TOTAL_MSGS) |
159 | { | 160 | { |
160 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
161 | "get bit %u of %u(!?!?)\n", | 162 | "get bit %u of %u(!?!?)\n", |
162 | bit, | 163 | bit, |
163 | (unsigned int)sizeof(bitmap) * 8); | 164 | (unsigned int) sizeof(bitmap) * 8); |
164 | return 0; | 165 | return 0; |
165 | } | 166 | } |
166 | return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; | 167 | return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; |
167 | } | 168 | } |
168 | 169 | ||
169 | 170 | ||
170 | static void | 171 | static void |
171 | custom_shutdown(void *cls) | 172 | custom_shutdown (void *cls) |
172 | { | 173 | { |
173 | unsigned long long delta; | 174 | unsigned long long delta; |
174 | unsigned long long rate; | 175 | unsigned long long rate; |
175 | int ok; | 176 | int ok; |
176 | 177 | ||
177 | /* Calculcate statistics */ | 178 | /* Calculcate statistics */ |
178 | delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us; | 179 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
179 | if (0 == delta) | 180 | if (0 == delta) |
180 | delta = 1; | 181 | delta = 1; |
181 | rate = (1000LL * 1000ll * total_bytes) / (1024 * delta); | 182 | rate = (1000LL * 1000ll * total_bytes) / (1024 * delta); |
182 | fprintf(stderr, | 183 | fprintf (stderr, |
183 | "\nThroughput was %llu KiBytes/s\n", | 184 | "\nThroughput was %llu KiBytes/s\n", |
184 | rate); | 185 | rate); |
185 | { | 186 | { |
186 | char *value_name; | 187 | char *value_name; |
187 | 188 | ||
188 | GNUNET_asprintf(&value_name, | 189 | GNUNET_asprintf (&value_name, |
189 | "unreliable_%s", | 190 | "unreliable_%s", |
190 | ccc->test_plugin); | 191 | ccc->test_plugin); |
191 | GAUGER("TRANSPORT", | 192 | GAUGER ("TRANSPORT", |
192 | value_name, | 193 | value_name, |
193 | (int)rate, | 194 | (int) rate, |
194 | "kb/s"); | 195 | "kb/s"); |
195 | GNUNET_free(value_name); | 196 | GNUNET_free (value_name); |
196 | } | 197 | } |
197 | 198 | ||
198 | ok = 0; | 199 | ok = 0; |
199 | for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++) | 200 | for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++) |
201 | { | ||
202 | if (get_bit (bitmap, i) == 0) | ||
200 | { | 203 | { |
201 | if (get_bit(bitmap, i) == 0) | 204 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
202 | { | 205 | "Did not receive message %d\n", |
203 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 206 | i); |
204 | "Did not receive message %d\n", | 207 | ok = -1; |
205 | i); | ||
206 | ok = -1; | ||
207 | } | ||
208 | } | 208 | } |
209 | } | ||
209 | if (0 != ok) | 210 | if (0 != ok) |
210 | ccc->global_ret = GNUNET_SYSERR; /* fail: messages missing! */ | 211 | ccc->global_ret = GNUNET_SYSERR; /* fail: messages missing! */ |
211 | } | 212 | } |
212 | 213 | ||
213 | 214 | ||
214 | static void | 215 | static void |
215 | notify_receive(void *cls, | 216 | notify_receive (void *cls, |
216 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 217 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
217 | const struct GNUNET_PeerIdentity *sender, | 218 | const struct GNUNET_PeerIdentity *sender, |
218 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) | 219 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) |
219 | { | 220 | { |
220 | static int n; | 221 | static int n; |
221 | unsigned int s; | 222 | unsigned int s; |
222 | char cbuf[GNUNET_MAX_MESSAGE_SIZE - 1]; | 223 | char cbuf[GNUNET_MAX_MESSAGE_SIZE - 1]; |
223 | 224 | ||
224 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) | 225 | if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) |
225 | return; | 226 | return; |
226 | msg_recv = ntohl(hdr->num); | 227 | msg_recv = ntohl (hdr->num); |
227 | s = get_size(ntohl(hdr->num)); | 228 | s = get_size (ntohl (hdr->num)); |
228 | 229 | ||
229 | if (ntohs(hdr->header.size) != s) | 230 | if (ntohs (hdr->header.size) != s) |
230 | { | 231 | { |
231 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
232 | "Expected message %u of size %u, got %u bytes of message %u\n", | 233 | "Expected message %u of size %u, got %u bytes of message %u\n", |
233 | (uint32_t)ntohl(hdr->num), | 234 | (uint32_t) ntohl (hdr->num), |
234 | s, | 235 | s, |
235 | ntohs(hdr->header.size), | 236 | ntohs (hdr->header.size), |
236 | (uint32_t)ntohl(hdr->num)); | 237 | (uint32_t) ntohl (hdr->num)); |
237 | ccc->global_ret = GNUNET_SYSERR; | 238 | ccc->global_ret = GNUNET_SYSERR; |
238 | GNUNET_SCHEDULER_shutdown(); | 239 | GNUNET_SCHEDULER_shutdown (); |
239 | return; | 240 | return; |
240 | } | 241 | } |
241 | 242 | ||
242 | memset(cbuf, | 243 | memset (cbuf, |
243 | ntohl(hdr->num), | 244 | ntohl (hdr->num), |
244 | s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)); | 245 | s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)); |
245 | if (0 != | 246 | if (0 != |
246 | memcmp(cbuf, | 247 | memcmp (cbuf, |
247 | &hdr[1], | 248 | &hdr[1], |
248 | s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))) | 249 | s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))) |
249 | { | 250 | { |
250 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
251 | "Expected message %u with bits %u, but body did not match\n", | 252 | "Expected message %u with bits %u, but body did not match\n", |
252 | (uint32_t)ntohl(hdr->num), | 253 | (uint32_t) ntohl (hdr->num), |
253 | (unsigned char)ntohl(hdr->num)); | 254 | (unsigned char) ntohl (hdr->num)); |
254 | ccc->global_ret = GNUNET_SYSERR; | 255 | ccc->global_ret = GNUNET_SYSERR; |
255 | GNUNET_SCHEDULER_shutdown(); | 256 | GNUNET_SCHEDULER_shutdown (); |
256 | return; | 257 | return; |
257 | } | 258 | } |
258 | #if VERBOSE | 259 | #if VERBOSE |
259 | if (0 == ntohl(hdr->num) % 5) | 260 | if (0 == ntohl (hdr->num) % 5) |
260 | { | 261 | { |
261 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
262 | "Got message %u of size %u\n", | 263 | "Got message %u of size %u\n", |
263 | (uint32_t)ntohl(hdr->num), | 264 | (uint32_t) ntohl (hdr->num), |
264 | ntohs(hdr->header.size)); | 265 | ntohs (hdr->header.size)); |
265 | } | 266 | } |
266 | #endif | 267 | #endif |
267 | n++; | 268 | n++; |
268 | if (GNUNET_SYSERR == set_bit(ntohl(hdr->num))) | 269 | if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) |
269 | { | 270 | { |
270 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 271 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
271 | "Message id %u is bigger than maxmimum number of messages %u expected\n", | 272 | "Message id %u is bigger than maxmimum number of messages %u expected\n", |
272 | (uint32_t)ntohl(hdr->num), | 273 | (uint32_t) ntohl (hdr->num), |
273 | TOTAL_MSGS / xhdr); | 274 | TOTAL_MSGS / xhdr); |
274 | } | 275 | } |
275 | if (0 == (n % (TOTAL_MSGS / xhdr / 100))) | 276 | if (0 == (n % (TOTAL_MSGS / xhdr / 100))) |
276 | { | 277 | { |
277 | fprintf(stderr, "%s", "."); | 278 | fprintf (stderr, "%s", "."); |
278 | } | 279 | } |
279 | if (n == TOTAL_MSGS / xhdr) | 280 | if (n == TOTAL_MSGS / xhdr) |
280 | { | 281 | { |
281 | /* end testcase with success */ | 282 | /* end testcase with success */ |
282 | ccc->global_ret = GNUNET_OK; | 283 | ccc->global_ret = GNUNET_OK; |
283 | GNUNET_SCHEDULER_shutdown(); | 284 | GNUNET_SCHEDULER_shutdown (); |
284 | } | 285 | } |
285 | } | 286 | } |
286 | 287 | ||
287 | 288 | ||
288 | int | 289 | int |
289 | main(int argc, char *argv[]) | 290 | main (int argc, char *argv[]) |
290 | { | 291 | { |
291 | if (0 == strstr(argv[0], "xhdr")) | 292 | if (0 == strstr (argv[0], "xhdr")) |
292 | xhdr = 30; | 293 | xhdr = 30; |
293 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { | 294 | struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { |
294 | .num_messages = TOTAL_MSGS / xhdr, | 295 | .num_messages = TOTAL_MSGS / xhdr, |
@@ -308,11 +309,11 @@ main(int argc, char *argv[]) | |||
308 | 309 | ||
309 | ccc = &my_ccc; | 310 | ccc = &my_ccc; |
310 | sc.ccc = ccc; | 311 | sc.ccc = ccc; |
311 | start_time = GNUNET_TIME_absolute_get(); | 312 | start_time = GNUNET_TIME_absolute_get (); |
312 | if (GNUNET_OK != | 313 | if (GNUNET_OK != |
313 | GNUNET_TRANSPORT_TESTING_main(2, | 314 | GNUNET_TRANSPORT_TESTING_main (2, |
314 | &GNUNET_TRANSPORT_TESTING_connect_check, | 315 | &GNUNET_TRANSPORT_TESTING_connect_check, |
315 | ccc)) | 316 | ccc)) |
316 | return 1; | 317 | return 1; |
317 | return 0; | 318 | return 0; |
318 | } | 319 | } |