diff options
Diffstat (limited to 'src/datastore/test_datastore_api.c')
-rw-r--r-- | src/datastore/test_datastore_api.c | 696 |
1 files changed, 355 insertions, 341 deletions
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index ee78a8cfc..56a7cdd3b 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.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 datastore/test_datastore_api.c | 21 | * @file datastore/test_datastore_api.c |
22 | * @brief Test for the basic datastore API. | 22 | * @brief Test for the basic datastore API. |
@@ -37,7 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
41 | 41 | ||
42 | #define ITERATIONS 256 | 42 | #define ITERATIONS 256 |
43 | 43 | ||
@@ -60,45 +60,45 @@ static const char *plugin_name; | |||
60 | 60 | ||
61 | 61 | ||
62 | static size_t | 62 | static size_t |
63 | get_size (int i) | 63 | get_size(int i) |
64 | { | 64 | { |
65 | return 8 * i; | 65 | return 8 * i; |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | static const void * | 69 | static const void * |
70 | get_data (int i) | 70 | get_data(int i) |
71 | { | 71 | { |
72 | static char buf[60000]; | 72 | static char buf[60000]; |
73 | 73 | ||
74 | memset (buf, i, 8 * i); | 74 | memset(buf, i, 8 * i); |
75 | return buf; | 75 | return buf; |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | static int | 79 | static int |
80 | get_type (int i) | 80 | get_type(int i) |
81 | { | 81 | { |
82 | return i + 1; | 82 | return i + 1; |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | static int | 86 | static int |
87 | get_priority (int i) | 87 | get_priority(int i) |
88 | { | 88 | { |
89 | return i + 1; | 89 | return i + 1; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | static int | 93 | static int |
94 | get_anonymity (int i) | 94 | get_anonymity(int i) |
95 | { | 95 | { |
96 | return i; | 96 | return i; |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | static struct GNUNET_TIME_Absolute | 100 | static struct GNUNET_TIME_Absolute |
101 | get_expiration (int i) | 101 | get_expiration(int i) |
102 | { | 102 | { |
103 | struct GNUNET_TIME_Absolute av; | 103 | struct GNUNET_TIME_Absolute av; |
104 | 104 | ||
@@ -110,8 +110,7 @@ get_expiration (int i) | |||
110 | /** | 110 | /** |
111 | * Which phase of the process are we in? | 111 | * Which phase of the process are we in? |
112 | */ | 112 | */ |
113 | enum RunPhase | 113 | enum RunPhase { |
114 | { | ||
115 | /** | 114 | /** |
116 | * We are done (shutting down normally). | 115 | * We are done (shutting down normally). |
117 | */ | 116 | */ |
@@ -143,8 +142,7 @@ enum RunPhase | |||
143 | * benchmark. Could right now be global, but this allows | 142 | * benchmark. Could right now be global, but this allows |
144 | * us to theoretically run multiple clients "in parallel". | 143 | * us to theoretically run multiple clients "in parallel". |
145 | */ | 144 | */ |
146 | struct CpsRunContext | 145 | struct CpsRunContext { |
147 | { | ||
148 | /** | 146 | /** |
149 | * Execution phase we are in. | 147 | * Execution phase we are in. |
150 | */ | 148 | */ |
@@ -167,7 +165,7 @@ struct CpsRunContext | |||
167 | * @param cls the `struct CpsRunContext` | 165 | * @param cls the `struct CpsRunContext` |
168 | */ | 166 | */ |
169 | static void | 167 | static void |
170 | run_continuation (void *cls); | 168 | run_continuation(void *cls); |
171 | 169 | ||
172 | 170 | ||
173 | /** | 171 | /** |
@@ -182,49 +180,102 @@ run_continuation (void *cls); | |||
182 | * @param msg NULL on success, otherwise an error message | 180 | * @param msg NULL on success, otherwise an error message |
183 | */ | 181 | */ |
184 | static void | 182 | static void |
185 | check_success (void *cls, | 183 | check_success(void *cls, |
186 | int success, | 184 | int success, |
187 | struct GNUNET_TIME_Absolute min_expiration, | 185 | struct GNUNET_TIME_Absolute min_expiration, |
188 | const char *msg) | 186 | const char *msg) |
189 | { | 187 | { |
190 | struct CpsRunContext *crc = cls; | 188 | struct CpsRunContext *crc = cls; |
191 | 189 | ||
192 | if (GNUNET_OK != success) | 190 | if (GNUNET_OK != success) |
193 | { | 191 | { |
194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 192 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
195 | "Operation %d/%d not successful: `%s'\n", | 193 | "Operation %d/%d not successful: `%s'\n", |
196 | crc->phase, | 194 | crc->phase, |
197 | crc->i, | 195 | crc->i, |
198 | msg); | 196 | msg); |
199 | crc->phase = RP_ERROR; | 197 | crc->phase = RP_ERROR; |
200 | } | 198 | } |
201 | GNUNET_free_non_null (crc->data); | 199 | GNUNET_free_non_null(crc->data); |
202 | crc->data = NULL; | 200 | crc->data = NULL; |
203 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 201 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); |
204 | } | 202 | } |
205 | 203 | ||
206 | 204 | ||
207 | static void | 205 | static void |
208 | get_reserved (void *cls, | 206 | get_reserved(void *cls, |
209 | int success, | 207 | int success, |
210 | struct GNUNET_TIME_Absolute min_expiration, | 208 | struct GNUNET_TIME_Absolute min_expiration, |
211 | const char *msg) | 209 | const char *msg) |
212 | { | 210 | { |
213 | struct CpsRunContext *crc = cls; | 211 | struct CpsRunContext *crc = cls; |
214 | 212 | ||
215 | if (0 >= success) | 213 | if (0 >= success) |
216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 214 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
217 | "Error obtaining reservation: `%s'\n", | 215 | "Error obtaining reservation: `%s'\n", |
218 | msg); | 216 | msg); |
219 | GNUNET_assert (0 < success); | 217 | GNUNET_assert(0 < success); |
220 | crc->rid = success; | 218 | crc->rid = success; |
221 | GNUNET_SCHEDULER_add_now (&run_continuation, | 219 | GNUNET_SCHEDULER_add_now(&run_continuation, |
222 | crc); | 220 | crc); |
223 | } | 221 | } |
224 | 222 | ||
225 | 223 | ||
226 | static void | 224 | static void |
227 | check_value (void *cls, | 225 | check_value(void *cls, |
226 | const struct GNUNET_HashCode *key, | ||
227 | size_t size, | ||
228 | const void *data, | ||
229 | enum GNUNET_BLOCK_Type type, | ||
230 | uint32_t priority, | ||
231 | uint32_t anonymity, | ||
232 | uint32_t replication, | ||
233 | struct GNUNET_TIME_Absolute expiration, | ||
234 | uint64_t uid) | ||
235 | { | ||
236 | struct CpsRunContext *crc = cls; | ||
237 | int i; | ||
238 | |||
239 | i = crc->i; | ||
240 | if (NULL == key) | ||
241 | { | ||
242 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
243 | "Value check failed (got NULL key) in %d/%d\n", | ||
244 | crc->phase, | ||
245 | crc->i); | ||
246 | crc->phase = RP_ERROR; | ||
247 | GNUNET_SCHEDULER_add_now(&run_continuation, | ||
248 | crc); | ||
249 | return; | ||
250 | } | ||
251 | #if 0 | ||
252 | fprintf(stderr, | ||
253 | "Check value got `%s' of size %u, type %d, expire %s\n", | ||
254 | GNUNET_h2s(key), (unsigned int)size, type, | ||
255 | GNUNET_STRINGS_absolute_time_to_string(expiration)); | ||
256 | fprintf(stderr, | ||
257 | "Check value iteration %d wants size %u, type %d, expire %s\n", i, | ||
258 | (unsigned int)get_size(i), get_type(i), | ||
259 | GNUNET_STRINGS_absolute_time_to_string(get_expiration(i))); | ||
260 | #endif | ||
261 | GNUNET_assert(size == get_size(i)); | ||
262 | GNUNET_assert(0 == memcmp(data, get_data(i), size)); | ||
263 | GNUNET_assert(type == get_type(i)); | ||
264 | GNUNET_assert(priority == get_priority(i)); | ||
265 | GNUNET_assert(anonymity == get_anonymity(i)); | ||
266 | GNUNET_assert(expiration.abs_value_us == get_expiration(i).abs_value_us); | ||
267 | if (crc->i == 0) | ||
268 | { | ||
269 | crc->phase = RP_DEL; | ||
270 | crc->i = ITERATIONS; | ||
271 | } | ||
272 | GNUNET_SCHEDULER_add_now(&run_continuation, | ||
273 | crc); | ||
274 | } | ||
275 | |||
276 | |||
277 | static void | ||
278 | delete_value(void *cls, | ||
228 | const struct GNUNET_HashCode *key, | 279 | const struct GNUNET_HashCode *key, |
229 | size_t size, | 280 | size_t size, |
230 | const void *data, | 281 | const void *data, |
@@ -236,48 +287,21 @@ check_value (void *cls, | |||
236 | uint64_t uid) | 287 | uint64_t uid) |
237 | { | 288 | { |
238 | struct CpsRunContext *crc = cls; | 289 | struct CpsRunContext *crc = cls; |
239 | int i; | ||
240 | 290 | ||
241 | i = crc->i; | 291 | GNUNET_assert(NULL == crc->data); |
242 | if (NULL == key) | 292 | GNUNET_assert(NULL != key); |
243 | { | 293 | crc->size = size; |
244 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 294 | crc->key = *key; |
245 | "Value check failed (got NULL key) in %d/%d\n", | 295 | crc->data = GNUNET_malloc(size); |
246 | crc->phase, | 296 | GNUNET_memcpy(crc->data, data, size); |
247 | crc->i); | 297 | crc->phase = RP_DO_DEL; |
248 | crc->phase = RP_ERROR; | 298 | GNUNET_SCHEDULER_add_now(&run_continuation, |
249 | GNUNET_SCHEDULER_add_now (&run_continuation, | 299 | crc); |
250 | crc); | ||
251 | return; | ||
252 | } | ||
253 | #if 0 | ||
254 | fprintf (stderr, | ||
255 | "Check value got `%s' of size %u, type %d, expire %s\n", | ||
256 | GNUNET_h2s (key), (unsigned int) size, type, | ||
257 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | ||
258 | fprintf (stderr, | ||
259 | "Check value iteration %d wants size %u, type %d, expire %s\n", i, | ||
260 | (unsigned int) get_size (i), get_type (i), | ||
261 | GNUNET_STRINGS_absolute_time_to_string (get_expiration(i))); | ||
262 | #endif | ||
263 | GNUNET_assert (size == get_size (i)); | ||
264 | GNUNET_assert (0 == memcmp (data, get_data (i), size)); | ||
265 | GNUNET_assert (type == get_type (i)); | ||
266 | GNUNET_assert (priority == get_priority (i)); | ||
267 | GNUNET_assert (anonymity == get_anonymity (i)); | ||
268 | GNUNET_assert (expiration.abs_value_us == get_expiration (i).abs_value_us); | ||
269 | if (crc->i == 0) | ||
270 | { | ||
271 | crc->phase = RP_DEL; | ||
272 | crc->i = ITERATIONS; | ||
273 | } | ||
274 | GNUNET_SCHEDULER_add_now (&run_continuation, | ||
275 | crc); | ||
276 | } | 300 | } |
277 | 301 | ||
278 | 302 | ||
279 | static void | 303 | static void |
280 | delete_value (void *cls, | 304 | check_nothing(void *cls, |
281 | const struct GNUNET_HashCode *key, | 305 | const struct GNUNET_HashCode *key, |
282 | size_t size, | 306 | size_t size, |
283 | const void *data, | 307 | const void *data, |
@@ -290,20 +314,16 @@ delete_value (void *cls, | |||
290 | { | 314 | { |
291 | struct CpsRunContext *crc = cls; | 315 | struct CpsRunContext *crc = cls; |
292 | 316 | ||
293 | GNUNET_assert (NULL == crc->data); | 317 | GNUNET_assert(key == NULL); |
294 | GNUNET_assert (NULL != key); | 318 | if (crc->i == 0) |
295 | crc->size = size; | 319 | crc->phase = RP_RESERVE; |
296 | crc->key = *key; | 320 | GNUNET_SCHEDULER_add_now(&run_continuation, |
297 | crc->data = GNUNET_malloc (size); | 321 | crc); |
298 | GNUNET_memcpy (crc->data, data, size); | ||
299 | crc->phase = RP_DO_DEL; | ||
300 | GNUNET_SCHEDULER_add_now (&run_continuation, | ||
301 | crc); | ||
302 | } | 322 | } |
303 | 323 | ||
304 | 324 | ||
305 | static void | 325 | static void |
306 | check_nothing (void *cls, | 326 | check_multiple(void *cls, |
307 | const struct GNUNET_HashCode *key, | 327 | const struct GNUNET_HashCode *key, |
308 | size_t size, | 328 | size_t size, |
309 | const void *data, | 329 | const void *data, |
@@ -316,45 +336,25 @@ check_nothing (void *cls, | |||
316 | { | 336 | { |
317 | struct CpsRunContext *crc = cls; | 337 | struct CpsRunContext *crc = cls; |
318 | 338 | ||
319 | GNUNET_assert (key == NULL); | 339 | GNUNET_assert(key != NULL); |
320 | if (crc->i == 0) | ||
321 | crc->phase = RP_RESERVE; | ||
322 | GNUNET_SCHEDULER_add_now (&run_continuation, | ||
323 | crc); | ||
324 | } | ||
325 | |||
326 | |||
327 | static void | ||
328 | check_multiple (void *cls, | ||
329 | const struct GNUNET_HashCode *key, | ||
330 | size_t size, | ||
331 | const void *data, | ||
332 | enum GNUNET_BLOCK_Type type, | ||
333 | uint32_t priority, | ||
334 | uint32_t anonymity, | ||
335 | uint32_t replication, | ||
336 | struct GNUNET_TIME_Absolute expiration, | ||
337 | uint64_t uid) | ||
338 | { | ||
339 | struct CpsRunContext *crc = cls; | ||
340 | |||
341 | GNUNET_assert (key != NULL); | ||
342 | switch (crc->phase) | 340 | switch (crc->phase) |
343 | { | 341 | { |
344 | case RP_GET_MULTIPLE: | 342 | case RP_GET_MULTIPLE: |
345 | crc->phase = RP_GET_MULTIPLE_NEXT; | 343 | crc->phase = RP_GET_MULTIPLE_NEXT; |
346 | crc->first_uid = uid; | 344 | crc->first_uid = uid; |
347 | break; | 345 | break; |
348 | case RP_GET_MULTIPLE_NEXT: | 346 | |
349 | GNUNET_assert (uid != crc->first_uid); | 347 | case RP_GET_MULTIPLE_NEXT: |
350 | crc->phase = RP_DONE; | 348 | GNUNET_assert(uid != crc->first_uid); |
351 | break; | 349 | crc->phase = RP_DONE; |
352 | default: | 350 | break; |
353 | GNUNET_break (0); | 351 | |
354 | crc->phase = RP_ERROR; | 352 | default: |
355 | break; | 353 | GNUNET_break(0); |
356 | } | 354 | crc->phase = RP_ERROR; |
357 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 355 | break; |
356 | } | ||
357 | GNUNET_SCHEDULER_add_now(&run_continuation, crc); | ||
358 | } | 358 | } |
359 | 359 | ||
360 | 360 | ||
@@ -365,166 +365,177 @@ check_multiple (void *cls, | |||
365 | * @param cls the `struct CpsRunContext` | 365 | * @param cls the `struct CpsRunContext` |
366 | */ | 366 | */ |
367 | static void | 367 | static void |
368 | run_continuation (void *cls) | 368 | run_continuation(void *cls) |
369 | { | 369 | { |
370 | struct CpsRunContext *crc = cls; | 370 | struct CpsRunContext *crc = cls; |
371 | 371 | ||
372 | ok = (int) crc->phase; | 372 | ok = (int)crc->phase; |
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 373 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
374 | "Test in phase %u\n", | 374 | "Test in phase %u\n", |
375 | crc->phase); | 375 | crc->phase); |
376 | switch (crc->phase) | 376 | switch (crc->phase) |
377 | { | 377 | { |
378 | case RP_PUT: | 378 | case RP_PUT: |
379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 379 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
380 | "Executing PUT number %u\n", | 380 | "Executing PUT number %u\n", |
381 | crc->i); | 381 | crc->i); |
382 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 382 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); |
383 | GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i), | 383 | GNUNET_DATASTORE_put(datastore, 0, &crc->key, get_size(crc->i), |
384 | get_data (crc->i), get_type (crc->i), | 384 | get_data(crc->i), get_type(crc->i), |
385 | get_priority (crc->i), get_anonymity (crc->i), 0, | 385 | get_priority(crc->i), get_anonymity(crc->i), 0, |
386 | get_expiration (crc->i), 1, 1, | 386 | get_expiration(crc->i), 1, 1, |
387 | &check_success, crc); | 387 | &check_success, crc); |
388 | crc->i++; | 388 | crc->i++; |
389 | if (crc->i == ITERATIONS) | 389 | if (crc->i == ITERATIONS) |
390 | crc->phase = RP_GET; | 390 | crc->phase = RP_GET; |
391 | break; | 391 | break; |
392 | case RP_GET: | 392 | |
393 | crc->i--; | 393 | case RP_GET: |
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 394 | crc->i--; |
395 | "Executing GET number %u\n", | 395 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
396 | crc->i); | 396 | "Executing GET number %u\n", |
397 | GNUNET_CRYPTO_hash (&crc->i, | 397 | crc->i); |
398 | sizeof (int), | 398 | GNUNET_CRYPTO_hash(&crc->i, |
399 | &crc->key); | 399 | sizeof(int), |
400 | GNUNET_DATASTORE_get_key (datastore, | 400 | &crc->key); |
401 | 0, | 401 | GNUNET_DATASTORE_get_key(datastore, |
402 | false, | 402 | 0, |
403 | &crc->key, | 403 | false, |
404 | get_type (crc->i), | 404 | &crc->key, |
405 | 1, | 405 | get_type(crc->i), |
406 | 1, | 406 | 1, |
407 | &check_value, | 407 | 1, |
408 | crc); | 408 | &check_value, |
409 | break; | 409 | crc); |
410 | case RP_DEL: | 410 | break; |
411 | crc->i--; | 411 | |
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 412 | case RP_DEL: |
413 | "Executing DEL number %u\n", | 413 | crc->i--; |
414 | crc->i); | 414 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
415 | crc->data = NULL; | 415 | "Executing DEL number %u\n", |
416 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 416 | crc->i); |
417 | GNUNET_assert (NULL != | 417 | crc->data = NULL; |
418 | GNUNET_DATASTORE_get_key (datastore, | 418 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); |
419 | GNUNET_assert(NULL != | ||
420 | GNUNET_DATASTORE_get_key(datastore, | ||
419 | 0, | 421 | 0, |
420 | false, | 422 | false, |
421 | &crc->key, | 423 | &crc->key, |
422 | get_type (crc->i), | 424 | get_type(crc->i), |
423 | 1, | 425 | 1, |
424 | 1, | 426 | 1, |
425 | &delete_value, | 427 | &delete_value, |
426 | crc)); | 428 | crc)); |
427 | break; | 429 | break; |
428 | case RP_DO_DEL: | 430 | |
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 431 | case RP_DO_DEL: |
430 | "Executing DO_DEL number %u\n", | 432 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
431 | crc->i); | 433 | "Executing DO_DEL number %u\n", |
432 | if (crc->i == 0) | 434 | crc->i); |
433 | { | 435 | if (crc->i == 0) |
434 | crc->i = ITERATIONS; | 436 | { |
435 | crc->phase = RP_DELVALIDATE; | 437 | crc->i = ITERATIONS; |
436 | } | 438 | crc->phase = RP_DELVALIDATE; |
437 | else | 439 | } |
438 | { | 440 | else |
439 | crc->phase = RP_DEL; | 441 | { |
440 | } | 442 | crc->phase = RP_DEL; |
441 | GNUNET_assert (NULL != | 443 | } |
442 | GNUNET_DATASTORE_remove (datastore, &crc->key, crc->size, | 444 | GNUNET_assert(NULL != |
445 | GNUNET_DATASTORE_remove(datastore, &crc->key, crc->size, | ||
443 | crc->data, 1, 1, | 446 | crc->data, 1, 1, |
444 | &check_success, crc)); | 447 | &check_success, crc)); |
445 | break; | 448 | break; |
446 | case RP_DELVALIDATE: | 449 | |
447 | crc->i--; | 450 | case RP_DELVALIDATE: |
448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | crc->i--; |
449 | "Executing DELVALIDATE number %u\n", | 452 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
450 | crc->i); | 453 | "Executing DELVALIDATE number %u\n", |
451 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 454 | crc->i); |
452 | GNUNET_assert (NULL != | 455 | GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); |
453 | GNUNET_DATASTORE_get_key (datastore, | 456 | GNUNET_assert(NULL != |
457 | GNUNET_DATASTORE_get_key(datastore, | ||
454 | 0, | 458 | 0, |
455 | false, | 459 | false, |
456 | &crc->key, | 460 | &crc->key, |
457 | get_type (crc->i), | 461 | get_type(crc->i), |
458 | 1, | 462 | 1, |
459 | 1, | 463 | 1, |
460 | &check_nothing, | 464 | &check_nothing, |
461 | crc)); | 465 | crc)); |
462 | break; | 466 | break; |
463 | case RP_RESERVE: | 467 | |
464 | crc->phase = RP_PUT_MULTIPLE; | 468 | case RP_RESERVE: |
465 | GNUNET_DATASTORE_reserve (datastore, 128 * 1024, 2, | 469 | crc->phase = RP_PUT_MULTIPLE; |
466 | &get_reserved, crc); | 470 | GNUNET_DATASTORE_reserve(datastore, 128 * 1024, 2, |
467 | break; | 471 | &get_reserved, crc); |
468 | case RP_PUT_MULTIPLE: | 472 | break; |
469 | crc->phase = RP_PUT_MULTIPLE_NEXT; | 473 | |
470 | GNUNET_DATASTORE_put (datastore, crc->rid, &crc->key, get_size (42), | 474 | case RP_PUT_MULTIPLE: |
471 | get_data (42), get_type (42), get_priority (42), | 475 | crc->phase = RP_PUT_MULTIPLE_NEXT; |
472 | get_anonymity (42), 0, get_expiration (42), 1, 1, | 476 | GNUNET_DATASTORE_put(datastore, crc->rid, &crc->key, get_size(42), |
473 | &check_success, crc); | 477 | get_data(42), get_type(42), get_priority(42), |
474 | break; | 478 | get_anonymity(42), 0, get_expiration(42), 1, 1, |
475 | case RP_PUT_MULTIPLE_NEXT: | 479 | &check_success, crc); |
476 | crc->phase = RP_GET_MULTIPLE; | 480 | break; |
477 | GNUNET_DATASTORE_put (datastore, crc->rid, | 481 | |
478 | &crc->key, | 482 | case RP_PUT_MULTIPLE_NEXT: |
479 | get_size (43), | 483 | crc->phase = RP_GET_MULTIPLE; |
480 | get_data (43), | 484 | GNUNET_DATASTORE_put(datastore, crc->rid, |
481 | get_type (42), | 485 | &crc->key, |
482 | get_priority (43), | 486 | get_size(43), |
483 | get_anonymity (43), | 487 | get_data(43), |
484 | 0, | 488 | get_type(42), |
485 | get_expiration (43), | 489 | get_priority(43), |
486 | 1, 1, | 490 | get_anonymity(43), |
487 | &check_success, crc); | 491 | 0, |
488 | break; | 492 | get_expiration(43), |
489 | case RP_GET_MULTIPLE: | 493 | 1, 1, |
490 | GNUNET_assert (NULL != | 494 | &check_success, crc); |
491 | GNUNET_DATASTORE_get_key (datastore, | 495 | break; |
496 | |||
497 | case RP_GET_MULTIPLE: | ||
498 | GNUNET_assert(NULL != | ||
499 | GNUNET_DATASTORE_get_key(datastore, | ||
492 | 0, | 500 | 0, |
493 | false, | 501 | false, |
494 | &crc->key, | 502 | &crc->key, |
495 | get_type (42), | 503 | get_type(42), |
496 | 1, | 504 | 1, |
497 | 1, | 505 | 1, |
498 | &check_multiple, | 506 | &check_multiple, |
499 | crc)); | 507 | crc)); |
500 | break; | 508 | break; |
501 | case RP_GET_MULTIPLE_NEXT: | 509 | |
502 | GNUNET_assert (NULL != | 510 | case RP_GET_MULTIPLE_NEXT: |
503 | GNUNET_DATASTORE_get_key (datastore, | 511 | GNUNET_assert(NULL != |
512 | GNUNET_DATASTORE_get_key(datastore, | ||
504 | crc->first_uid + 1, | 513 | crc->first_uid + 1, |
505 | false, | 514 | false, |
506 | &crc->key, | 515 | &crc->key, |
507 | get_type (42), | 516 | get_type(42), |
508 | 1, | 517 | 1, |
509 | 1, | 518 | 1, |
510 | &check_multiple, | 519 | &check_multiple, |
511 | crc)); | 520 | crc)); |
512 | break; | 521 | break; |
513 | case RP_DONE: | 522 | |
514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 523 | case RP_DONE: |
515 | "Finished, disconnecting\n"); | 524 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
516 | GNUNET_DATASTORE_disconnect (datastore, | 525 | "Finished, disconnecting\n"); |
517 | GNUNET_YES); | 526 | GNUNET_DATASTORE_disconnect(datastore, |
518 | GNUNET_free (crc); | 527 | GNUNET_YES); |
519 | ok = 0; | 528 | GNUNET_free(crc); |
520 | break; | 529 | ok = 0; |
521 | case RP_ERROR: | 530 | break; |
522 | GNUNET_DATASTORE_disconnect (datastore, | 531 | |
523 | GNUNET_YES); | 532 | case RP_ERROR: |
524 | GNUNET_free (crc); | 533 | GNUNET_DATASTORE_disconnect(datastore, |
525 | ok = 43; | 534 | GNUNET_YES); |
526 | break; | 535 | GNUNET_free(crc); |
527 | } | 536 | ok = 43; |
537 | break; | ||
538 | } | ||
528 | } | 539 | } |
529 | 540 | ||
530 | 541 | ||
@@ -541,37 +552,40 @@ run_continuation (void *cls) | |||
541 | * @param msg NULL on success, otherwise an error message | 552 | * @param msg NULL on success, otherwise an error message |
542 | */ | 553 | */ |
543 | static void | 554 | static void |
544 | run_tests (void *cls, | 555 | run_tests(void *cls, |
545 | int32_t success, | 556 | int32_t success, |
546 | struct GNUNET_TIME_Absolute min_expiration, | 557 | struct GNUNET_TIME_Absolute min_expiration, |
547 | const char *msg) | 558 | const char *msg) |
548 | { | 559 | { |
549 | struct CpsRunContext *crc = cls; | 560 | struct CpsRunContext *crc = cls; |
550 | 561 | ||
551 | switch (success) | 562 | switch (success) |
552 | { | 563 | { |
553 | case GNUNET_YES: | 564 | case GNUNET_YES: |
554 | GNUNET_SCHEDULER_add_now (&run_continuation, | 565 | GNUNET_SCHEDULER_add_now(&run_continuation, |
555 | crc); | 566 | crc); |
556 | return; | 567 | return; |
557 | case GNUNET_NO: | 568 | |
558 | fprintf (stderr, | 569 | case GNUNET_NO: |
559 | "%s", "Test 'put' operation failed, key already exists (!?)\n"); | 570 | fprintf(stderr, |
560 | GNUNET_DATASTORE_disconnect (datastore, | 571 | "%s", "Test 'put' operation failed, key already exists (!?)\n"); |
561 | GNUNET_YES); | 572 | GNUNET_DATASTORE_disconnect(datastore, |
562 | GNUNET_free (crc); | 573 | GNUNET_YES); |
563 | return; | 574 | GNUNET_free(crc); |
564 | case GNUNET_SYSERR: | 575 | return; |
565 | fprintf (stderr, | 576 | |
566 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 577 | case GNUNET_SYSERR: |
567 | msg); | 578 | fprintf(stderr, |
568 | GNUNET_DATASTORE_disconnect (datastore, | 579 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
569 | GNUNET_YES); | 580 | msg); |
570 | GNUNET_free (crc); | 581 | GNUNET_DATASTORE_disconnect(datastore, |
571 | return; | 582 | GNUNET_YES); |
572 | default: | 583 | GNUNET_free(crc); |
573 | GNUNET_assert (0); | 584 | return; |
574 | } | 585 | |
586 | default: | ||
587 | GNUNET_assert(0); | ||
588 | } | ||
575 | } | 589 | } |
576 | 590 | ||
577 | 591 | ||
@@ -585,36 +599,36 @@ run_tests (void *cls, | |||
585 | * @param peer peer handle (unused) | 599 | * @param peer peer handle (unused) |
586 | */ | 600 | */ |
587 | static void | 601 | static void |
588 | run (void *cls, | 602 | run(void *cls, |
589 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 603 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
590 | struct GNUNET_TESTING_Peer *peer) | 604 | struct GNUNET_TESTING_Peer *peer) |
591 | { | 605 | { |
592 | struct CpsRunContext *crc; | 606 | struct CpsRunContext *crc; |
593 | static struct GNUNET_HashCode zkey; | 607 | static struct GNUNET_HashCode zkey; |
594 | 608 | ||
595 | crc = GNUNET_new (struct CpsRunContext); | 609 | crc = GNUNET_new(struct CpsRunContext); |
596 | crc->phase = RP_PUT; | 610 | crc->phase = RP_PUT; |
597 | now = GNUNET_TIME_absolute_get (); | 611 | now = GNUNET_TIME_absolute_get(); |
598 | datastore = GNUNET_DATASTORE_connect (cfg); | 612 | datastore = GNUNET_DATASTORE_connect(cfg); |
599 | if (NULL == | 613 | if (NULL == |
600 | GNUNET_DATASTORE_put (datastore, | 614 | GNUNET_DATASTORE_put(datastore, |
601 | 0, | 615 | 0, |
602 | &zkey, | 616 | &zkey, |
603 | 4, | 617 | 4, |
604 | "TEST", | 618 | "TEST", |
605 | GNUNET_BLOCK_TYPE_TEST, | 619 | GNUNET_BLOCK_TYPE_TEST, |
606 | 0, 0, 0, | 620 | 0, 0, 0, |
607 | GNUNET_TIME_relative_to_absolute | 621 | GNUNET_TIME_relative_to_absolute |
608 | (GNUNET_TIME_UNIT_SECONDS), | 622 | (GNUNET_TIME_UNIT_SECONDS), |
609 | 0, 1, | 623 | 0, 1, |
610 | &run_tests, crc)) | 624 | &run_tests, crc)) |
611 | { | 625 | { |
612 | fprintf (stderr, | 626 | fprintf(stderr, |
613 | "%s", | 627 | "%s", |
614 | "Test 'put' operation failed.\n"); | 628 | "Test 'put' operation failed.\n"); |
615 | ok = 1; | 629 | ok = 1; |
616 | GNUNET_free (crc); | 630 | GNUNET_free(crc); |
617 | } | 631 | } |
618 | } | 632 | } |
619 | 633 | ||
620 | 634 | ||
@@ -627,8 +641,8 @@ run (void *cls, | |||
627 | * 0 for "reset to empty" | 641 | * 0 for "reset to empty" |
628 | */ | 642 | */ |
629 | static void | 643 | static void |
630 | duc_dummy (void *cls, | 644 | duc_dummy(void *cls, |
631 | int delta) | 645 | int delta) |
632 | { | 646 | { |
633 | /* intentionally empty */ | 647 | /* intentionally empty */ |
634 | } | 648 | } |
@@ -638,42 +652,42 @@ duc_dummy (void *cls, | |||
638 | * check if plugin is actually working | 652 | * check if plugin is actually working |
639 | */ | 653 | */ |
640 | static int | 654 | static int |
641 | test_plugin (const char *cfg_name) | 655 | test_plugin(const char *cfg_name) |
642 | { | 656 | { |
643 | char libname[128]; | 657 | char libname[128]; |
644 | struct GNUNET_CONFIGURATION_Handle *cfg; | 658 | struct GNUNET_CONFIGURATION_Handle *cfg; |
645 | struct GNUNET_DATASTORE_PluginFunctions *api; | 659 | struct GNUNET_DATASTORE_PluginFunctions *api; |
646 | struct GNUNET_DATASTORE_PluginEnvironment env; | 660 | struct GNUNET_DATASTORE_PluginEnvironment env; |
647 | 661 | ||
648 | cfg = GNUNET_CONFIGURATION_create (); | 662 | cfg = GNUNET_CONFIGURATION_create(); |
649 | if (GNUNET_OK != | 663 | if (GNUNET_OK != |
650 | GNUNET_CONFIGURATION_load (cfg, | 664 | GNUNET_CONFIGURATION_load(cfg, |
651 | cfg_name)) | 665 | cfg_name)) |
652 | { | 666 | { |
653 | GNUNET_CONFIGURATION_destroy (cfg); | 667 | GNUNET_CONFIGURATION_destroy(cfg); |
654 | fprintf (stderr, | 668 | fprintf(stderr, |
655 | "Failed to load configuration %s\n", | 669 | "Failed to load configuration %s\n", |
656 | cfg_name); | 670 | cfg_name); |
657 | return 1; | 671 | return 1; |
658 | } | 672 | } |
659 | memset (&env, 0, sizeof (env)); | 673 | memset(&env, 0, sizeof(env)); |
660 | env.cfg = cfg; | 674 | env.cfg = cfg; |
661 | env.duc = &duc_dummy; | 675 | env.duc = &duc_dummy; |
662 | GNUNET_snprintf (libname, | 676 | GNUNET_snprintf(libname, |
663 | sizeof (libname), | 677 | sizeof(libname), |
664 | "libgnunet_plugin_datastore_%s", | 678 | "libgnunet_plugin_datastore_%s", |
665 | plugin_name); | 679 | plugin_name); |
666 | api = GNUNET_PLUGIN_load (libname, &env); | 680 | api = GNUNET_PLUGIN_load(libname, &env); |
667 | if (NULL == api) | 681 | if (NULL == api) |
668 | { | 682 | { |
669 | GNUNET_CONFIGURATION_destroy (cfg); | 683 | GNUNET_CONFIGURATION_destroy(cfg); |
670 | fprintf (stderr, | 684 | fprintf(stderr, |
671 | "Failed to load plugin `%s'\n", | 685 | "Failed to load plugin `%s'\n", |
672 | libname); | 686 | libname); |
673 | return 77; | 687 | return 77; |
674 | } | 688 | } |
675 | GNUNET_PLUGIN_unload (libname, api); | 689 | GNUNET_PLUGIN_unload(libname, api); |
676 | GNUNET_CONFIGURATION_destroy (cfg); | 690 | GNUNET_CONFIGURATION_destroy(cfg); |
677 | return 0; | 691 | return 0; |
678 | } | 692 | } |
679 | 693 | ||
@@ -688,26 +702,26 @@ test_plugin (const char *cfg_name) | |||
688 | * @return 0 on success | 702 | * @return 0 on success |
689 | */ | 703 | */ |
690 | int | 704 | int |
691 | main (int argc, | 705 | main(int argc, |
692 | char *argv[]) | 706 | char *argv[]) |
693 | { | 707 | { |
694 | char cfg_name[PATH_MAX]; | 708 | char cfg_name[PATH_MAX]; |
695 | int ret; | 709 | int ret; |
696 | 710 | ||
697 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 711 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
698 | GNUNET_snprintf (cfg_name, | 712 | GNUNET_snprintf(cfg_name, |
699 | sizeof (cfg_name), | 713 | sizeof(cfg_name), |
700 | "test_datastore_api_data_%s.conf", | 714 | "test_datastore_api_data_%s.conf", |
701 | plugin_name); | 715 | plugin_name); |
702 | ret = test_plugin (cfg_name); | 716 | ret = test_plugin(cfg_name); |
703 | if (0 != ret) | 717 | if (0 != ret) |
704 | return ret; | 718 | return ret; |
705 | /* run actual test */ | 719 | /* run actual test */ |
706 | if (0 != | 720 | if (0 != |
707 | GNUNET_TESTING_peer_run ("test-gnunet-datastore", | 721 | GNUNET_TESTING_peer_run("test-gnunet-datastore", |
708 | cfg_name, | 722 | cfg_name, |
709 | &run, | 723 | &run, |
710 | NULL)) | 724 | NULL)) |
711 | return 1; | 725 | return 1; |
712 | return ok; | 726 | return ok; |
713 | } | 727 | } |