-svn ignore
[oweals/gnunet.git] / src / arm / test_arm_api.c
index 7fab89ca7956124896ccbbee9bbf5cd43c583e3f..086cfc25850da8376167d5111b7d2c0293d3a1f0 100644 (file)
@@ -1,10 +1,10 @@
 /*
      This file is part of GNUnet.
 /*
      This file is part of GNUnet.
-     (C) 2009 Christian Grothoff (and other contributing authors)
+     (C) 2009, 2011 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
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
+     by the Free Software Foundation; either version 3, or (at your
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
 
 #define START_ARM GNUNET_YES
 
 
 #define START_ARM GNUNET_YES
 
-#define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50)
+#define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1500)
 
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
 
 
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
 
-static struct GNUNET_SCHEDULER_Handle *sched;
-
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 static struct GNUNET_ARM_Handle *arm;
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 static struct GNUNET_ARM_Handle *arm;
@@ -47,18 +45,20 @@ static struct GNUNET_ARM_Handle *arm;
 static int ok = 1;
 
 static void
 static int ok = 1;
 
 static void
-arm_stopped (void *cls, int success)
+arm_stopped (void *cls,  enum GNUNET_ARM_ProcessStatus success)
 {
 {
-  if (success != GNUNET_NO)
-    ok = 1;
-  else
+  GNUNET_break (success == GNUNET_ARM_PROCESS_DOWN);
+  if (success != GNUNET_ARM_PROCESS_DOWN)
+    ok = 3;
+  else if (ok == 1)
     ok = 0;
 }
 
     ok = 0;
 }
 
+
 static void
 static void
-arm_notify_stop (void *cls, int success)
+arm_notify_stop (void *cls, enum GNUNET_ARM_ProcessStatus success)
 {
 {
-  GNUNET_assert (success == GNUNET_NO);
+  GNUNET_break (success == GNUNET_ARM_PROCESS_DOWN);
 #if START_ARM
   GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
 #endif
 #if START_ARM
   GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
 #endif
@@ -70,43 +70,58 @@ dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 {
   if (addr == NULL)
     {
 {
   if (addr == NULL)
     {
-      GNUNET_assert (ok == 0);
-      GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, NULL);
+      if (ok != 0)
+       {
+         GNUNET_break (0);
+         ok = 2;
+       }
+      GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop,
+                              NULL);
       return;
     }
       return;
     }
-  GNUNET_assert (addr != NULL);
+  GNUNET_break (addr != NULL);
   ok = 0;
 }
 
 
 static void
   ok = 0;
 }
 
 
 static void
-resolver_notify (void *cls, int success)
+resolver_notify (void *cls, enum GNUNET_ARM_ProcessStatus success)
 {
 {
-  GNUNET_assert (success == GNUNET_YES);
-  GNUNET_RESOLVER_ip_get (sched,
-                          cfg,
-                          "localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
+  if (success != GNUNET_ARM_PROCESS_STARTING)
+    {
+      GNUNET_break (0);
+      ok = 2;
+#if START_ARM
+      GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+#endif
+      return;
+    }
+  GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL);
 }
 
 
 static void
 }
 
 
 static void
-arm_notify (void *cls, int success)
+arm_notify (void *cls, enum GNUNET_ARM_ProcessStatus success)
 {
 {
-  GNUNET_assert (success == GNUNET_YES);
-  GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify, NULL);
+  if (success != GNUNET_ARM_PROCESS_STARTING)
+    {
+      GNUNET_break (0);
+      ok = 2;
+#if START_ARM
+      GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
+#endif
+    }
+  GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify,
+                           NULL);
 }
 
 
 static void
 }
 
 
 static void
-task (void *cls,
-      struct GNUNET_SCHEDULER_Handle *s,
-      char *const *args,
-      const char *cfgfile,
+task (void *cls, char *const *args, const char *cfgfile,
       const struct GNUNET_CONFIGURATION_Handle *c)
 {
   cfg = c;
       const struct GNUNET_CONFIGURATION_Handle *c)
 {
   cfg = c;
-  sched = s;
-  arm = GNUNET_ARM_connect (cfg, sched, NULL);
+  arm = GNUNET_ARM_connect (cfg, NULL);
 #if START_ARM
   GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL);
 #else
 #if START_ARM
   GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL);
 #else
@@ -131,10 +146,9 @@ check ()
     GNUNET_GETOPT_OPTION_END
   };
   GNUNET_assert (GNUNET_OK ==
     GNUNET_GETOPT_OPTION_END
   };
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-                                     argv,
-                                     "test-arm-api",
-                                     "nohelp", options, &task, NULL));
+                GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
+                                    argv, "test-arm-api", "nohelp", options,
+                                    &task, NULL));
   return ok;
 }
 
   return ok;
 }
 
@@ -146,11 +160,11 @@ main (int argc, char *argv[])
 
   GNUNET_log_setup ("test-arm-api",
 #if VERBOSE
 
   GNUNET_log_setup ("test-arm-api",
 #if VERBOSE
-                    "DEBUG",
+                   "DEBUG",
 #else
 #else
-                    "WARNING",
+                   "WARNING",
 #endif
 #endif
-                    NULL);
+                   NULL);
   ret = check ();
 
   return ret;
   ret = check ();
 
   return ret;