(no commit message)
[oweals/gnunet.git] / src / datastore / perf_datastore_api.c
index 8b040c22254247694c0f8f686eb412cde387dd9f..1f7c828e005435c4a36ba95c4aab480de32e7e58 100644 (file)
@@ -93,7 +93,6 @@ enum RunPhase
 
 struct CpsRunContext
 {
-  struct GNUNET_SCHEDULER_Handle *sched;
   const struct GNUNET_CONFIGURATION_Handle *cfg;
   enum RunPhase phase;
   int j;
@@ -101,7 +100,7 @@ struct CpsRunContext
   int i;
 
   GNUNET_HashCode key;
-  uint32_t esize;
+  size_t esize;
   char data[65536];
 };
 
@@ -140,8 +139,7 @@ check_success (void *cls,
       else
        crc->phase = RP_CUT;
     }
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    &run_continuation,
+  GNUNET_SCHEDULER_add_continuation (&run_continuation,
                                     crc,
                                     GNUNET_SCHEDULER_REASON_PREREQ_DONE);
 }
@@ -166,8 +164,7 @@ remove_next(void *cls,
   fprintf (stderr, "D");
 #endif
   GNUNET_assert (GNUNET_OK == success);
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    &run_continuation,
+  GNUNET_SCHEDULER_add_continuation (&run_continuation,
                                     crc,
                                     GNUNET_SCHEDULER_REASON_PREREQ_DONE);
 }
@@ -197,7 +194,7 @@ do_delete (void *cls,
 static void 
 delete_value (void *cls,
              const GNUNET_HashCode * key,
-             uint32_t size,
+             size_t size,
              const void *data,
              enum GNUNET_BLOCK_Type type,
              uint32_t priority,
@@ -212,14 +209,12 @@ delete_value (void *cls,
       if (stored_bytes < MAX_SIZE)
        {
          crc->phase = RP_REPORT;
-         GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                            &run_continuation,
+         GNUNET_SCHEDULER_add_continuation (&run_continuation,
                                             crc,
                                             GNUNET_SCHEDULER_REASON_PREREQ_DONE);
          return;     
        }
-      GNUNET_SCHEDULER_add_with_priority (crc->sched,
-                                         GNUNET_SCHEDULER_PRIORITY_HIGH,
+      GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
                                          &do_delete,
                                          crc);
       return;
@@ -295,11 +290,10 @@ run_continuation (void *cls,
                "Stored %llu kB / %lluk ops / %llu ops/s\n", 
               stored_bytes / 1024,     /* used size in k */
                stored_ops / 1024,        /* total operations (in k) */
-               1000 * stored_ops / (1 + GNUNET_TIME_absolute_get_duration(start_time).value));
+               1000 * stored_ops / (1 + GNUNET_TIME_absolute_get_duration(start_time).rel_value));
       crc->phase = RP_PUT;
       crc->j = 0;
-      GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                        &run_continuation,
+      GNUNET_SCHEDULER_add_continuation (&run_continuation,
                                         crc,
                                         GNUNET_SCHEDULER_REASON_PREREQ_DONE);
       break;
@@ -314,32 +308,62 @@ run_continuation (void *cls,
 }
 
 
+
+static void
+run_tests (void *cls,
+          int success,
+          const char *msg)
+{
+  struct CpsRunContext *crc = cls;
+
+  if (success != GNUNET_YES)
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
+              msg);
+      GNUNET_free (crc);
+      return;
+    }
+  GNUNET_SCHEDULER_add_continuation (&run_continuation,
+                                    crc,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
 static void
 run (void *cls,
-     struct GNUNET_SCHEDULER_Handle *sched,
      char *const *args,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct CpsRunContext *crc;
+  static GNUNET_HashCode zkey;
 
-  datastore = GNUNET_DATASTORE_connect (cfg, sched);
+  datastore = GNUNET_DATASTORE_connect (cfg);
   start_time = GNUNET_TIME_absolute_get ();
   crc = GNUNET_malloc(sizeof(struct CpsRunContext));
-  crc->sched = sched;
   crc->cfg = cfg;
   crc->phase = RP_PUT;
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+  if (NULL ==
+      GNUNET_DATASTORE_put (datastore, 0,
+                           &zkey, 4, "TEST",
+                           GNUNET_BLOCK_TYPE_TEST,
+                           0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
+                           0, 1, GNUNET_TIME_UNIT_MINUTES,
+                           &run_tests, crc))
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed.\n");
+      ok = 1;
+      GNUNET_free (crc);
+    }
 }
 
 
 static int
 check ()
 {
-  pid_t pid;
+  struct GNUNET_OS_Process *proc;
   char cfg_name[128];
   char *const argv[] = { 
     "perf-datastore-api",
@@ -358,21 +382,23 @@ check ()
                   sizeof (cfg_name),
                   "test_datastore_api_data_%s.conf",
                   plugin_name);
-  pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+  proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
                                  "gnunet-service-arm",
 #if VERBOSE
                                  "-L", "DEBUG",
 #endif
-                                 "-c", "test_datastore_api_data.conf", NULL);
+                                 "-c", cfg_name, NULL);
   GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
                       argv, "perf-datastore-api", "nohelp",
                       options, &run, NULL);
-  if (0 != PLIBC_KILL (pid, SIGTERM))
+  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
     {
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
       ok = 1;
     }
-  GNUNET_OS_process_wait(pid);
+  GNUNET_OS_process_wait (proc);
+  GNUNET_OS_process_close (proc);
+  proc = NULL;
   return ok;
 }