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