aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_datastore_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-10 11:18:59 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-10 11:18:59 +0000
commit5d2bfbd4a69f87c99083fc60954c884af69258f4 (patch)
tree9fb3f83ca4e8f5bc2d8d770086882ff1ab27a56c /src/datastore/test_datastore_api.c
parent00abe8aad5a33c716a02e20cc8257f055edca869 (diff)
downloadgnunet-5d2bfbd4a69f87c99083fc60954c884af69258f4.tar.gz
gnunet-5d2bfbd4a69f87c99083fc60954c884af69258f4.zip
-using testing in datastore tests
Diffstat (limited to 'src/datastore/test_datastore_api.c')
-rw-r--r--src/datastore/test_datastore_api.c101
1 files changed, 13 insertions, 88 deletions
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index 4c0736619..cfeac86db 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -30,10 +30,8 @@
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_protocols.h" 31#include "gnunet_protocols.h"
32#include "gnunet_datastore_service.h" 32#include "gnunet_datastore_service.h"
33#include "gnunet_testing_lib-new.h"
33 34
34#define VERBOSE GNUNET_NO
35
36#define START_DATASTORE GNUNET_YES
37 35
38/** 36/**
39 * How long until we give up on transmitting the message? 37 * How long until we give up on transmitting the message?
@@ -314,16 +312,12 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
314 struct CpsRunContext *crc = cls; 312 struct CpsRunContext *crc = cls;
315 313
316 ok = (int) crc->phase; 314 ok = (int) crc->phase;
317#if VERBOSE
318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test in phase %u\n", crc->phase); 315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test in phase %u\n", crc->phase);
319#endif
320 switch (crc->phase) 316 switch (crc->phase)
321 { 317 {
322 case RP_PUT: 318 case RP_PUT:
323#if VERBOSE
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT", 319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT",
325 crc->i); 320 crc->i);
326#endif
327 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 321 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
328 GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i), 322 GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i),
329 get_data (crc->i), get_type (crc->i), 323 get_data (crc->i), get_type (crc->i),
@@ -336,10 +330,8 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
336 break; 330 break;
337 case RP_GET: 331 case RP_GET:
338 crc->i--; 332 crc->i--;
339#if VERBOSE
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET", 333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
341 crc->i); 334 crc->i);
342#endif
343 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 335 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
344 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, 336 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key,
345 get_type (crc->i), 1, 1, TIMEOUT, &check_value, 337 get_type (crc->i), 1, 1, TIMEOUT, &check_value,
@@ -347,10 +339,8 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
347 break; 339 break;
348 case RP_DEL: 340 case RP_DEL:
349 crc->i--; 341 crc->i--;
350#if VERBOSE
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "DEL", 342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "DEL",
352 crc->i); 343 crc->i);
353#endif
354 crc->data = NULL; 344 crc->data = NULL;
355 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 345 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
356 GNUNET_assert (NULL != 346 GNUNET_assert (NULL !=
@@ -359,10 +349,8 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
359 &delete_value, crc)); 349 &delete_value, crc));
360 break; 350 break;
361 case RP_DO_DEL: 351 case RP_DO_DEL:
362#if VERBOSE
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "DO_DEL", 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "DO_DEL",
364 crc->i); 353 crc->i);
365#endif
366 if (crc->i == 0) 354 if (crc->i == 0)
367 { 355 {
368 crc->i = ITERATIONS; 356 crc->i = ITERATIONS;
@@ -379,10 +367,8 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
379 break; 367 break;
380 case RP_DELVALIDATE: 368 case RP_DELVALIDATE:
381 crc->i--; 369 crc->i--;
382#if VERBOSE
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", 370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n",
384 "DEL-VALIDATE", crc->i); 371 "DEL-VALIDATE", crc->i);
385#endif
386 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 372 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
387 GNUNET_assert (NULL != 373 GNUNET_assert (NULL !=
388 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, 374 GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key,
@@ -433,9 +419,7 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
433 &check_update, crc)); 419 &check_update, crc));
434 break; 420 break;
435 case RP_DONE: 421 case RP_DONE:
436#if VERBOSE
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n"); 422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
438#endif
439 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); 423 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
440 GNUNET_free (crc); 424 GNUNET_free (crc);
441 ok = 0; 425 ok = 0;
@@ -479,7 +463,7 @@ run_tests (void *cls, int32_t success, struct GNUNET_TIME_Absolute min_expiratio
479 463
480 464
481static void 465static void
482run (void *cls, char *const *args, const char *cfgfile, 466run (void *cls,
483 const struct GNUNET_CONFIGURATION_Handle *cfg) 467 const struct GNUNET_CONFIGURATION_Handle *cfg)
484{ 468{
485 struct CpsRunContext *crc; 469 struct CpsRunContext *crc;
@@ -504,88 +488,29 @@ run (void *cls, char *const *args, const char *cfgfile,
504} 488}
505 489
506 490
507static int
508check ()
509{
510 char cfg_name[128];
511
512#if START_DATASTORE
513 struct GNUNET_OS_Process *proc;
514#endif
515 char *const argv[] = {
516 "test-datastore-api",
517 "-c",
518 cfg_name,
519#if VERBOSE
520 "-L", "DEBUG",
521#endif
522 NULL
523 };
524 struct GNUNET_GETOPT_CommandLineOption options[] = {
525 GNUNET_GETOPT_OPTION_END
526 };
527 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
528 "test_datastore_api_data_%s.conf", plugin_name);
529#if START_DATASTORE
530 proc =
531 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
532 "gnunet-service-arm",
533#if VERBOSE
534 "-L", "DEBUG",
535#endif
536 "-c", cfg_name, NULL);
537#endif
538 GNUNET_assert (NULL != proc);
539 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
540 "test-datastore-api", "nohelp", options, &run, NULL);
541#if START_DATASTORE
542 sleep (1); /* give datastore chance to receive 'DROP' request */
543 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
544 {
545 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
546 ok = 1;
547 }
548 GNUNET_OS_process_wait (proc);
549 GNUNET_OS_process_destroy (proc);
550 proc = NULL;
551#endif
552 if (ok != 0)
553 FPRINTF (stderr, "Missed some testcases: %u\n", ok);
554 return ok;
555}
556
557int 491int
558main (int argc, char *argv[]) 492main (int argc, char *argv[])
559{ 493{
560 int ret;
561 char *pos; 494 char *pos;
562 char dir_name[128]; 495 char cfg_name[128];
563 496
564 sleep (1);
565 /* determine name of plugin to use */ 497 /* determine name of plugin to use */
566 plugin_name = argv[0]; 498 plugin_name = argv[0];
567 while (NULL != (pos = strstr (plugin_name, "_"))) 499 while (NULL != (pos = strstr (plugin_name, "_")))
568 plugin_name = pos + 1; 500 plugin_name = pos + 1;
569 if (NULL != (pos = strstr (plugin_name, "."))) 501 if (NULL != (pos = strstr (plugin_name, ".")))
570 pos[0] = 0; 502 pos[0] = '\0';
571 else 503 else
572 pos = (char *) plugin_name; 504 pos = (char *) plugin_name;
573 505 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
574 GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s", 506 "test_datastore_api_data_%s.conf", plugin_name);
575 plugin_name); 507 if (0 !=
576 GNUNET_DISK_directory_remove (dir_name); 508 GNUNET_TESTING_peer_run ("test-gnunet-datastore",
577 GNUNET_log_setup ("test-datastore-api", 509 cfg_name,
578#if VERBOSE 510 &run,
579 "DEBUG", 511 NULL))
580#else 512 return 1;
581 "WARNING", 513 return ok;
582#endif
583 NULL);
584 ret = check ();
585 if (pos != plugin_name)
586 pos[0] = '.';
587 GNUNET_DISK_directory_remove (dir_name);
588 return ret;
589} 514}
590 515
591/* end of test_datastore_api.c */ 516/* end of test_datastore_api.c */