-cleaner
[oweals/gnunet.git] / src / peerinfo / perf_peerinfo_api.c
index e69b487d5e01b8ecc68877d9719caf1c640fb885..a1e309d649580d610b1f60a36ee86b19878c332f 100755 (executable)
 */
 
 /**
- * @file peerinfo/test_peerinfo_hammer.c
+ * @file peerinfo/perf_peerinfo_api.c
  * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service
  * @author Nathan Evans
  */
 
 #include "platform.h"
 #include "gnunet_hello_lib.h"
-#include "gnunet_getopt_lib.h"
-#include "gnunet_os_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib-new.h"
 #include "gnunet_peerinfo_service.h"
-#include "gnunet_program_lib.h"
-#include "gnunet_time_lib.h"
 #include "peerinfo.h"
 #include <gauger.h>
 
@@ -38,8 +36,6 @@
 
 #define NUM_REQUESTS 5000
 
-static const struct GNUNET_CONFIGURATION_Handle *cfg;
-
 static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS];
 
 static struct GNUNET_PEERINFO_Handle *h;
@@ -53,12 +49,6 @@ static int
 check_it (void *cls, const struct GNUNET_HELLO_Address *address,
           struct GNUNET_TIME_Absolute expiration)
 {
-#if DEBUG
-  if (addrlen > 0)
-  {
-    FPRINTF (stderr, "name: %s, addr: %s\n", tname, (const char *) addr);
-  }
-#endif
   return GNUNET_OK;
 }
 
@@ -98,7 +88,7 @@ add_peer (size_t i)
   memset (&pkey, i, sizeof (pkey));
   GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
   h2 = GNUNET_HELLO_create (&pkey, &address_generator, &i);
-  GNUNET_PEERINFO_add_peer (h, h2);
+  GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
   GNUNET_free (h2);
 }
 
@@ -107,17 +97,8 @@ static void
 process (void *cls, const struct GNUNET_PeerIdentity *peer,
          const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 {
-  if (peer == NULL)
-  {
-#if DEBUG
-    FPRINTF (stderr, "Process received NULL response\n");
-#endif
-  }
-  else
+  if (NULL != peer)
   {
-#if DEBUG
-    FPRINTF (stderr, "Processed a peer\n");
-#endif
     numpeers++;
     if (0 && (hello != NULL))
       GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL);
@@ -127,12 +108,11 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer,
 
 
 static void
-run (void *cls, char *const *args, const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls, 
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   size_t i;
 
-  cfg = c;
   h = GNUNET_PEERINFO_connect (cfg);
   GNUNET_assert (h != NULL);
   for (i = 0; i < NUM_REQUESTS; i++)
@@ -145,73 +125,19 @@ run (void *cls, char *const *args, const char *cfgfile,
   }
 }
 
-static int
-check ()
-{
-  int ok = 0;
-
-  char *const argv[] = { "perf-peerinfo-api",
-    "-c",
-    "test_peerinfo_api_data.conf",
-#if DEBUG_PEERINFO
-    "-L", "DEBUG",
-#else
-    "-L", "ERROR",
-#endif
-    NULL
-  };
-#if START_SERVICE
-  struct GNUNET_OS_Process *proc;
-
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-  proc =
-      GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo",
-                               "gnunet-service-peerinfo",
-#if DEBUG_PEERINFO
-                               "-L", "DEBUG",
-#else
-                               "-L", "ERROR",
-#endif
-                               "-c", "test_peerinfo_api_data.conf", NULL);
-#endif
-  GNUNET_assert (NULL != proc);
-  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
-                      "perf-peerinfo-api", "nohelp", options, &run, &ok);
-  FPRINTF (stderr, "Received %u/%u calls before timeout\n", numpeers,
-           NUM_REQUESTS * NUM_REQUESTS / 2);
-  GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s");
-#if START_SERVICE
-  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
-  {
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-    ok = 1;
-  }
-  GNUNET_OS_process_wait (proc);
-  GNUNET_OS_process_close (proc);
-  proc = NULL;
-
-#endif
-  return ok;
-}
-
 
 int
 main (int argc, char *argv[])
 {
-  int ret = 0;
-
-  GNUNET_log_setup ("perf_peerinfo_api",
-#if DEBUG_PEERINFO
-                    "DEBUG",
-#else
-                    "ERROR",
-#endif
-                    NULL);
-  ret = check ();
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo");
-  return ret;
+  if (0 != GNUNET_TESTING_service_run ("perf-gnunet-peerinfo",
+                                      "peerinfo",
+                                      "test_peerinfo_api_data.conf",
+                                      &run, NULL))
+    return 1;
+  FPRINTF (stderr, "Received %u/%u calls before timeout\n", numpeers,
+          NUM_REQUESTS * NUM_REQUESTS / 2);
+  GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s");
+  return 0;
 }
 
 /* end of perf_peerinfo_api.c */