gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8595 - gnunet/src/datastore


From: gnunet
Subject: [GNUnet-SVN] r8595 - gnunet/src/datastore
Date: Tue, 16 Jun 2009 20:23:24 -0600

Author: grothoff
Date: 2009-06-16 20:23:24 -0600 (Tue, 16 Jun 2009)
New Revision: 8595

Added:
   gnunet/src/datastore/test_datastore_api_data.conf
Modified:
   gnunet/src/datastore/Makefile.am
   gnunet/src/datastore/perf_datastore_api.c
   gnunet/src/datastore/test_datastore_api.c
Log:
towards compiling tests

Modified: gnunet/src/datastore/Makefile.am
===================================================================
--- gnunet/src/datastore/Makefile.am    2009-06-16 22:57:50 UTC (rev 8594)
+++ gnunet/src/datastore/Makefile.am    2009-06-17 02:23:24 UTC (rev 8595)
@@ -81,3 +81,4 @@
  $(top_builddir)/src/util/libgnunetutil.la  
 
 
+EXTRA_DIST = test_datastore_api_data.conf

Modified: gnunet/src/datastore/perf_datastore_api.c
===================================================================
--- gnunet/src/datastore/perf_datastore_api.c   2009-06-16 22:57:50 UTC (rev 
8594)
+++ gnunet/src/datastore/perf_datastore_api.c   2009-06-17 02:23:24 UTC (rev 
8595)
@@ -18,8 +18,8 @@
      Boston, MA 02111-1307, USA.
 */
 /*
- * @file applications/sqstore_sqlite/sqlitetest2.c
- * @brief Test for the sqstore implementations.
+ * @file datastore/perf_datastore_api.c
+ * @brief performance measurement for the datastore implementation
  * @author Christian Grothoff
  *
  * This testcase inserts a bunch of (variable size) data and then deletes
@@ -42,12 +42,11 @@
  */
 
 #include "platform.h"
-#include "gnunet_util.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_protocols.h"
-#include "gnunet_sqstore_service.h"
-#include "core.h"
+#include "gnunet_datastore_service.h"
 
-#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, 
__LINE__); goto FAILURE;} } while (0)
+static struct GNUNET_DATASTORE_Handle *datastore;
 
 /**
  * Target datastore size (in bytes).
@@ -110,7 +109,7 @@
  * permission to the respective directory in order
  * to obtain all of the performance information.
  */
-#define DB_NAME "/tmp/gnunet-sqlite-sqstore-test/data/fs/"
+#define DB_NAME "/tmp/gnunet-datastore-test/data/fs/"
 
 static unsigned long long stored_bytes;
 
@@ -118,93 +117,81 @@
 
 static unsigned long long stored_ops;
 
-static GNUNET_CronTime start_time;
+static struct GNUNET_TIME_Absolute start_time;
 
 static int
-putValue (GNUNET_SQstore_ServiceAPI * api, int i, int k)
+putValue (int i, int k)
 {
-  GNUNET_DatastoreValue *value;
   size_t size;
   static GNUNET_HashCode key;
   static int ic;
+  static char data[65536];
 
   /* most content is 32k */
-  size = sizeof (GNUNET_DatastoreValue) + 32 * 1024;
-  if (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 16) == 0)  /* but some of 
it is less! */
-    size =
-      sizeof (GNUNET_DatastoreValue) +
-      GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 32 * 1024);
+  size = 32 * 1024;
+  if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0)  /* but 
some of it is less! */
+    size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
   size = size - (size & 7);     /* always multiple of 8 */
 
-  /* generate random key */
-  GNUNET_hash (&key, sizeof (GNUNET_HashCode), &key);
-  value = GNUNET_malloc (size);
-  value->size = htonl (size);
-  value->type = htonl (i);
-  value->priority =
-    htonl (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 100));
-  value->anonymity_level = htonl (i);
-  value->expiration_time =
-    GNUNET_htonll (GNUNET_get_time () +
-                   GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 1000));
-  memset (&value[1], i, size - sizeof (GNUNET_DatastoreValue));
+  GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
+  memset (data, i, size);
   if (i > 255)
-    memset (&value[1], i - 255, (size - sizeof (GNUNET_DatastoreValue)) / 2);
-  ((char *) &value[1])[0] = k;
-  if (GNUNET_OK != api->put (&key, value))
-    {
-      GNUNET_free (value);
-      fprintf (stderr, "E");
-      return GNUNET_SYSERR;
-    }
+    memset (data, i - 255, size / 2);
+  data[0] = k;
+  GNUNET_DATASTORE_put (datastore,
+                       0,
+                       &key,
+                       size,
+                       data,
+                       i,
+                       GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 
100),
+                       i,
+                       GNUNET_TIME_relative_to_absolute 
+                       (GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS,
+                                                       
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
+                       NULL, NULL);
   ic++;
 #if REPORT_ID
   if (ic % REP_FREQ == 0)
     fprintf (stderr, "I");
 #endif
-  stored_bytes += ntohl (value->size);
+  stored_bytes += size;
   stored_ops++;
   stored_entries++;
-  GNUNET_free (value);
   return GNUNET_OK;
 }
 
-static int
-iterateDelete (const GNUNET_HashCode * key,
-               const GNUNET_DatastoreValue * val, void *cls,
-               unsigned long long uid)
+
+static void
+iterate_delete (void *cls,
+               const GNUNET_HashCode * key,
+               uint32_t size,
+               const void *data,
+               uint32_t type,
+               uint32_t priority,
+               uint32_t anonymity,
+               struct GNUNET_TIME_Absolute
+               expiration, uint64_t uid)
 {
-  GNUNET_SQstore_ServiceAPI *api = cls;
-  static int dc;
-
-  if (api->getSize () < MAX_SIZE)
-    return GNUNET_SYSERR;
-  if (GNUNET_shutdown_test () == GNUNET_YES)
-    return GNUNET_SYSERR;
-  dc++;
-#if REPORT_ID
-  if (dc % REP_FREQ == 0)
-    fprintf (stderr, "D");
-#endif
-  stored_bytes -= ntohl (val->size);
-  stored_entries--;
-  return GNUNET_NO;
+  GNUNET_DATASTORE_remove (datastore, key, size, data, NULL, NULL);
 }
 
-/**
- * Add testcode here!
- */
-static int
-test (GNUNET_SQstore_ServiceAPI * api)
+
+
+static void
+run (void *cls,
+     struct GNUNET_SCHEDULER_Handle *sched,
+     char *const *args,
+     const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  int i;
   int j;
   unsigned long long size;
   int have_file;
   struct stat sbuf;
+  int i;
 
+  datastore = GNUNET_DATASTORE_connect (cfg, sched);
   have_file = 0 == stat (DB_NAME, &sbuf);
-
   for (i = 0; i < ITERATIONS; i++)
     {
 #if REPORT_ID
@@ -212,18 +199,11 @@
 #endif
       /* insert data equivalent to 1/10th of MAX_SIZE */
       for (j = 0; j < PUT_10; j++)
-        {
-          ASSERT (GNUNET_OK == putValue (api, j, i));
-          if (GNUNET_shutdown_test () == GNUNET_YES)
-            break;
-        }
+       GNUNET_assert (GNUNET_OK == putValue (j, i));
 
       /* trim down below MAX_SIZE again */
       if ((i % 2) == 0)
-        api->iterateLowPriority (0, &iterateDelete, api);
-      else
-        api->iterateExpirationTime (0, &iterateDelete, api);
-
+        GNUNET_DATASTORE_get_random (datastore, &iterate_delete, NULL);
       size = 0;
       if (have_file)
         GNUNET_disk_file_size (NULL, DB_NAME, &size, GNUNET_NO);
@@ -231,8 +211,8 @@
 #if REPORT_ID
                "\n"
 #endif
-               "Useful %llu, API %llu, disk %llu (%.2f%%) / %lluk ops / %llu 
ops/s\n", stored_bytes / 1024,     /* used size in k */
-               api->getSize () / 1024,  /* API-reported size in k */
+               "Useful %llu, disk %llu (%.2f%%) / %lluk ops / %llu ops/s\n", 
+              stored_bytes / 1024,     /* used size in k */
                size / 1024,     /* disk size in kb */
                (100.0 * size / stored_bytes) - 100,     /* overhead */
                (stored_ops * 2 - stored_entries) / 1024,        /* total 
operations (in k) */
@@ -240,45 +220,68 @@
       if (GNUNET_shutdown_test () == GNUNET_YES)
         break;
     }
-  api->drop ();
-  return GNUNET_OK;
 
-FAILURE:
-  api->drop ();
-  return GNUNET_SYSERR;
+  GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
 }
 
+
+static int
+check ()
+{
+  int ok = 1 + 2 + 4 + 8;
+  pid_t pid;
+  char *const argv[] = { "perf-datastore-api",
+    "-c",
+    "test_datastore_api_data.conf",
+#if VERBOSE
+    "-L", "DEBUG",
+#endif
+    NULL
+  };
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+  pid = GNUNET_OS_start_process ("gnunet-service-datastore",
+                                 "gnunet-service-datastore",
+#if VERBOSE
+                                 "-L", "DEBUG",
+#endif
+                                 "-c", "perf_datastore_api_data.conf", NULL);
+  sleep (1);
+  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+                      argv, "perf-datastore-api", "nohelp",
+                      options, &run, &ok);
+  if (0 != PLIBC_KILL (pid, SIGTERM))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+      ok = 1;
+    }
+  GNUNET_OS_process_wait(pid);
+  if (ok != 0)
+    fprintf (stderr, "Missed some testcases: %u\n", ok);
+  return ok;
+}
+
+
 int
 main (int argc, char *argv[])
 {
-  GNUNET_SQstore_ServiceAPI *api;
-  int ok;
-  struct GNUNET_GC_Configuration *cfg;
-  struct GNUNET_CronManager *cron;
+  int ret;
 
-  cfg = GNUNET_GC_create ();
-  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
-    {
-      GNUNET_GC_free (cfg);
-      return -1;
-    }
-  cron = GNUNET_cron_create (NULL);
-  GNUNET_CORE_init (NULL, cfg, cron, NULL);
-  api = GNUNET_CORE_request_service ("sqstore");
-  if (api != NULL)
-    {
-      start_time = GNUNET_get_time ();
-      ok = test (api);
-      GNUNET_CORE_release_service (api);
-    }
-  else
-    ok = GNUNET_SYSERR;
-  GNUNET_CORE_done ();
-  GNUNET_cron_destroy (cron);
-  GNUNET_GC_free (cfg);
-  if (ok == GNUNET_SYSERR)
-    return 1;
-  return 0;
+  GNUNET_log_setup ("perf-datastore-api",
+#if VERBOSE
+                    "DEBUG",
+#else
+                    "WARNING",
+#endif
+                    NULL);
+  ret = check ();
+
+  return ret;
 }
 
-/* end of mysqltest2.c */
+
+
+
+
+/* end of perf_datastore_api.c */

Modified: gnunet/src/datastore/test_datastore_api.c
===================================================================
--- gnunet/src/datastore/test_datastore_api.c   2009-06-16 22:57:50 UTC (rev 
8594)
+++ gnunet/src/datastore/test_datastore_api.c   2009-06-17 02:23:24 UTC (rev 
8595)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing 
authors)
+     (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -21,273 +21,286 @@
  * @file datastore/test_datastore_api.c
  * @brief Test for the datastore implementation.
  * @author Christian Grothoff
+ *
+ * TODO:
+ * - test multiple values under same key
+ * - test "update"
+ * - test storage reservations
  */
 
 #include "platform.h"
-#include "gnunet_util.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_protocols.h"
-#include "gnunet_sqstore_service.h"
-#include "core.h"
+#include "gnunet_datastore_service.h"
 
-#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, 
__LINE__); goto FAILURE;} } while (0)
+static struct GNUNET_DATASTORE_Handle *datastore;
 
-static GNUNET_CronTime now;
+static struct GNUNET_TIME_Absolute now;
 
-static GNUNET_DatastoreValue *
-initValue (int i)
+
+static size_t
+get_size (int i)
 {
-  GNUNET_DatastoreValue *value;
+  return 8 * i;
+}
 
-  value = GNUNET_malloc (sizeof (GNUNET_DatastoreValue) + 8 * i);
-  value->size = htonl (sizeof (GNUNET_DatastoreValue) + 8 * i);
-  value->type = htonl (i);
-  value->priority = htonl (i + 1);
-  value->anonymity_level = htonl (i);
-  value->expiration_time = GNUNET_htonll (now - i * GNUNET_CRON_SECONDS);
-  memset (&value[1], i, 8 * i);
-  return value;
+
+static const void *
+get_data (int i)
+{
+  static char buf[60000]; 
+  memset (buf, i, 8 * i);
+  return buf;
 }
 
+
 static int
-checkValue (const GNUNET_HashCode * key,
-            const GNUNET_DatastoreValue * val, void *closure,
-            unsigned long long uid)
+get_type(int i)
 {
-  int i;
-  int ret;
-  GNUNET_DatastoreValue *value;
+  return i;
+}
 
-  i = *(int *) closure;
-  value = initValue (i);
-  if ((value->size == val->size) &&
-      (0 == memcmp (val, value, ntohl (val->size))))
-    ret = GNUNET_OK;
-  else
-    {
-      /*
-         printf("Wanted: %u, %llu; got %u, %llu - %d\n",
-         ntohl(value->size), GNUNET_ntohll(value->expiration_time),
-         ntohl(val->size), GNUNET_ntohll(val->expiration_time),
-         memcmp(val, value, ntohl(val->size))); */
-      ret = GNUNET_SYSERR;
-    }
-  GNUNET_free (value);
-  return ret;
+
+static int 
+get_priority (int i)
+{
+  return i+1;
 }
 
+
 static int
-iterateUp (const GNUNET_HashCode * key, const GNUNET_DatastoreValue * val,
-           int *closure, unsigned long long uid)
+get_anonymity(int i)
 {
-  int ret;
-
-  ret = checkValue (key, val, closure, uid);
-  (*closure) += 2;
-  return ret;
+  return i;
 }
 
-static int
-iterateDown (const GNUNET_HashCode * key,
-             const GNUNET_DatastoreValue * val, int *closure,
-             unsigned long long uid)
+
+static struct GNUNET_TIME_Absolute 
+get_expiration (int i)
 {
-  int ret;
+  struct GNUNET_TIME_Absolute av;
 
-  (*closure) -= 2;
-  ret = checkValue (key, val, closure, uid);
-  return ret;
+  av.value = now.value - i * 1000;
+  return av;
 }
 
-static int
-iterateDelete (const GNUNET_HashCode * key,
-               const GNUNET_DatastoreValue * val, void *closure,
-               unsigned long long uid)
+
+static void
+check_success (void *cls,
+              int success,
+              const char *msg)
 {
-  return GNUNET_NO;
+  GNUNET_assert (GNUNET_OK == success);
 }
 
-static int
-iteratePriority (const GNUNET_HashCode * key,
-                 const GNUNET_DatastoreValue * val,
-                 GNUNET_SQstore_ServiceAPI * api, unsigned long long uid)
+
+static void
+check_failure (void *cls,
+              int success,
+              const char *msg)
 {
-  api->update (uid, 4, 0);
-  return GNUNET_OK;
+  GNUNET_assert (GNUNET_OK != success);
+  GNUNET_assert (NULL != msg);
 }
 
-static int
-priorityCheck (const GNUNET_HashCode * key,
-               const GNUNET_DatastoreValue * val, int *closure,
-               unsigned long long uid)
+
+static void 
+check_value (void *cls,
+            const GNUNET_HashCode * key,
+            uint32_t size,
+            const void *data,
+            uint32_t type,
+            uint32_t priority,
+            uint32_t anonymity,
+            struct GNUNET_TIME_Absolute
+            expiration, uint64_t uid)
 {
-  int id;
+  int *iptr = cls;
+  int i;
 
-  id = (*closure);
-  if (id + 1 == ntohl (val->priority))
-    return GNUNET_OK;
-  fprintf (stderr,
-           "Wrong priority, wanted %u got %u\n", id + 1,
-           ntohl (val->priority));
-  return GNUNET_SYSERR;
+  if (key == NULL)
+    return;
+  i = *iptr;
+  GNUNET_assert (size == get_size (i));
+  GNUNET_assert (0 == memcmp (data, get_data(i), size));
+  GNUNET_assert (type == get_type (i));
+  GNUNET_assert (priority == get_priority (i));
+  GNUNET_assert (anonymity == get_anonymity(i));
+  GNUNET_assert (expiration.value == get_expiration(i).value);
 }
 
-static int
-multipleCheck (const GNUNET_HashCode * key,
-               const GNUNET_DatastoreValue * val,
-               GNUNET_DatastoreValue ** last, unsigned long long uid)
+
+static void 
+delete_value (void *cls,
+            const GNUNET_HashCode * key,
+            uint32_t size,
+            const void *data,
+            uint32_t type,
+            uint32_t priority,
+            uint32_t anonymity,
+            struct GNUNET_TIME_Absolute
+            expiration, uint64_t uid)
 {
-  if (*last != NULL)
-    {
-      if (((*last)->size == val->size) &&
-          (0 == memcmp (*last, val, ntohl (val->size))))
-        return GNUNET_SYSERR;   /* duplicate! */
-      GNUNET_free (*last);
-    }
-  *last = GNUNET_malloc (ntohl (val->size));
-  memcpy (*last, val, ntohl (val->size));
-  return GNUNET_OK;
+  if (key == NULL)
+    return;
+  GNUNET_DATASTORE_remove (datastore,
+                          key,
+                          size,
+                          data,
+                          &check_success,
+                          NULL);
+  ((int*)key)[0]++;
+  GNUNET_DATASTORE_remove (datastore,
+                          key,
+                          size,
+                          data,
+                          &check_failure,
+                          NULL);
 }
 
 
-/**
- * Add testcode here!
- */
-static int
-test (GNUNET_SQstore_ServiceAPI * api)
+
+static void 
+check_nothing (void *cls,
+            const GNUNET_HashCode * key,
+            uint32_t size,
+            const void *data,
+            uint32_t type,
+            uint32_t priority,
+            uint32_t anonymity,
+            struct GNUNET_TIME_Absolute
+            expiration, uint64_t uid)
 {
-  GNUNET_DatastoreValue *value;
+  GNUNET_assert (key == NULL);
+}
+
+
+
+static void
+run (void *cls,
+     struct GNUNET_SCHEDULER_Handle *sched,
+     char *const *args,
+     const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
+{
   GNUNET_HashCode key;
-  unsigned long long oldSize;
   int i;
+  int *iptr;
 
-  now = 1000000;
-  oldSize = api->getSize ();
+  datastore = GNUNET_DATASTORE_connect (cfg, sched);
+  now.value = 1000000;
   for (i = 0; i < 256; i++)
     {
-      value = initValue (i);
       memset (&key, 256 - i, sizeof (GNUNET_HashCode));
-      ASSERT (GNUNET_OK == api->put (&key, value));
-      GNUNET_free (value);
+      GNUNET_DATASTORE_put (datastore,
+                           0,
+                           &key,
+                           get_size (i),
+                           get_data (i),
+                           get_type (i),
+                           get_priority (i),
+                           get_anonymity (i),
+                           get_expiration (i),
+                           &check_success,
+                           NULL);
     }
-  ASSERT (oldSize < api->getSize ());
   for (i = 255; i >= 0; i--)
     {
       memset (&key, 256 - i, sizeof (GNUNET_HashCode));
-      ASSERT (1 == api->get (&key, NULL, i, &checkValue, (void *) &i));
+      iptr = GNUNET_malloc(sizeof(int));
+      *iptr = i;
+      GNUNET_DATASTORE_get (datastore, 
+                           &key,
+                           get_type (i),
+                           &check_value,
+                           iptr);
     }
-  ASSERT (256 ==
-          api->iterateLowPriority (GNUNET_ECRS_BLOCKTYPE_ANY, NULL, NULL));
-  ASSERT (256 ==
-          api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY, NULL, NULL));
   for (i = 255; i >= 0; i--)
     {
       memset (&key, 256 - i, sizeof (GNUNET_HashCode));
-      ASSERT (1 == api->get (&key, NULL, i, &checkValue, (void *) &i));
+      iptr = GNUNET_malloc(sizeof(int));
+      *iptr = i;
+      GNUNET_DATASTORE_get (datastore, 
+                           &key,
+                           get_type (i),
+                           &delete_value,
+                           iptr);
     }
-
-  oldSize = api->getSize ();
-  for (i = 255; i >= 0; i -= 2)
+  for (i = 255; i >= 0; i--)
     {
       memset (&key, 256 - i, sizeof (GNUNET_HashCode));
-      value = initValue (i);
-      if (1 != api->get (&key, NULL, 0, &iterateDelete, NULL))
-        {
-          GNUNET_free (value);
-          ASSERT (0);
-        }
-      GNUNET_free (value);
+      iptr = GNUNET_malloc(sizeof(int));
+      *iptr = i;
+      GNUNET_DATASTORE_get (datastore, 
+                           &key,
+                           get_type (i),
+                           &check_nothing,
+                           iptr);
     }
-  ASSERT (oldSize > api->getSize ());
-  i = 0;
-  ASSERT (128 == api->iterateLowPriority (GNUNET_ECRS_BLOCKTYPE_ANY,
-                                          (GNUNET_DatastoreValueIterator) &
-                                          iterateUp, &i));
-  ASSERT (256 == i);
-  ASSERT (128 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
-                                             (GNUNET_DatastoreValueIterator) &
-                                             iterateDown, &i));
-  ASSERT (0 == i);
-  ASSERT (128 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
-                                             (GNUNET_DatastoreValueIterator) &
-                                             iterateDelete, api));
-  i = 0;
-  ASSERT (0 ==
-          api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
-                                      (GNUNET_DatastoreValueIterator) &
-                                      iterateDown, &i));
-  i = 42;
-  value = initValue (i);
-  memset (&key, 256 - i, sizeof (GNUNET_HashCode));
-  api->put (&key, value);
-  ASSERT (1 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
-                                           (GNUNET_DatastoreValueIterator) &
-                                           priorityCheck, &i));
-  ASSERT (1 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
-                                           (GNUNET_DatastoreValueIterator) &
-                                           priorityCheck, &i));
-  ASSERT (1 ==
-          api->iterateAllNow ((GNUNET_DatastoreValueIterator) &
-                              iteratePriority, api));
-  i += 4;
-  ASSERT (1 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
-                                           (GNUNET_DatastoreValueIterator) &
-                                           priorityCheck, &i));
-  GNUNET_free (value);
+  /* check reservations */
 
+  /* check update */
+
   /* test multiple results */
-  value = initValue (i + 1);
-  api->put (&key, value);
-  GNUNET_free (value);
 
-  value = NULL;
-  ASSERT (2 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
-                                           (GNUNET_DatastoreValueIterator) &
-                                           multipleCheck, &value));
-  GNUNET_free (value);
-  ASSERT (2 ==
-          api->iterateAllNow ((GNUNET_DatastoreValueIterator) & iterateDelete,
-                              api));
-  ASSERT (0 ==
-          api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY, NULL, NULL));
-  api->drop ();
+  GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
+}
 
-  return GNUNET_OK;
 
-FAILURE:
-  api->drop ();
-  return GNUNET_SYSERR;
+
+static int
+check ()
+{
+  int ok = 1 + 2 + 4 + 8;
+  pid_t pid;
+  char *const argv[] = { "test-datastore-api",
+    "-c",
+    "test_datastore_api_data.conf",
+#if VERBOSE
+    "-L", "DEBUG",
+#endif
+    NULL
+  };
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+  pid = GNUNET_OS_start_process ("gnunet-service-datastore",
+                                 "gnunet-service-datastore",
+#if VERBOSE
+                                 "-L", "DEBUG",
+#endif
+                                 "-c", "test_datastore_api_data.conf", NULL);
+  sleep (1);
+  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+                      argv, "test-datastore-api", "nohelp",
+                      options, &run, &ok);
+  if (0 != PLIBC_KILL (pid, SIGTERM))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+      ok = 1;
+    }
+  GNUNET_OS_process_wait(pid);
+  if (ok != 0)
+    fprintf (stderr, "Missed some testcases: %u\n", ok);
+  return ok;
 }
 
 int
 main (int argc, char *argv[])
 {
-  GNUNET_SQstore_ServiceAPI *api;
-  int ok;
-  struct GNUNET_GC_Configuration *cfg;
-  struct GNUNET_CronManager *cron;
+  int ret;
 
-  cfg = GNUNET_GC_create ();
-  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
-    {
-      GNUNET_GC_free (cfg);
-      return -1;
-    }
-  cron = GNUNET_cron_create (NULL);
-  GNUNET_CORE_init (NULL, cfg, cron, NULL);
-  api = GNUNET_CORE_request_service ("sqstore");
-  if (api != NULL)
-    {
-      ok = test (api);
-      GNUNET_CORE_release_service (api);
-    }
-  else
-    ok = GNUNET_SYSERR;
-  GNUNET_CORE_done ();
-  GNUNET_cron_destroy (cron);
-  GNUNET_GC_free (cfg);
-  if (ok == GNUNET_SYSERR)
-    return 1;
-  return 0;
+  GNUNET_log_setup ("test-datastore-api",
+#if VERBOSE
+                    "DEBUG",
+#else
+                    "WARNING",
+#endif
+                    NULL);
+  ret = check ();
+
+  return ret;
 }
 
+
+
 /* end of test_datastore_api.c */

Added: gnunet/src/datastore/test_datastore_api_data.conf
===================================================================
--- gnunet/src/datastore/test_datastore_api_data.conf                           
(rev 0)
+++ gnunet/src/datastore/test_datastore_api_data.conf   2009-06-17 02:23:24 UTC 
(rev 8595)
@@ -0,0 +1,22 @@
+[PATHS]
+SERVICEHOME = /tmp/test-gnunetd-datastore/
+
+[datastore]
+PORT = 22654
+HOSTNAME = localhost
+HOME = $SERVICEHOME
+CONFIG = $DEFAULTCONFIG
+BINARY = gnunet-service-datastore
+ACCEPT_FROM = 127.0.0.1;
+ACCEPT_FROM6 = ::1;
+ALLOW_SHUTDOWN = YES
+QUOTA = 1000000
+BLOOMFILTER = $SERVICEHOME/fs/bloomfilter
+# USERNAME = 
+# MAXBUF =
+# TIMEOUT =
+# DISABLEV6 =
+# BINDTO =
+# REJECT_FROM =
+# REJECT_FROM6 =
+# PREFIX =





reply via email to

[Prev in Thread] Current Thread [Next in Thread]