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