Merge branch 'credentials' of git+ssh://gnunet.org/gnunet into credentials
[oweals/gnunet.git] / src / testbed / testbed_api_test.c
index 0a15b3db9070a6623aeec955ca128d89f186232f..e64e9fe2d84cc8ac0586dbd247c7579a128dd819 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2008--2012 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2008--2013 GNUnet e.V.
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
       You should have received a copy of the GNU General Public License
       along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
+      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+      Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -52,7 +52,7 @@ struct TestRunContext
    * Closure for the above callback
    */
   void *cc_cls;
-  
+
   /**
    * event mask for the controller callback
    */
@@ -62,77 +62,25 @@ struct TestRunContext
    * Number of peers to start
    */
   unsigned int num_peers;
-
-  /**
-   * counter for loading peers
-   */
-  unsigned int peer_cnt;
-
-  /**
-   * Followed by peers list
-   */
-  struct GNUNET_TESTBED_Peer *peers[0];
 };
 
 
-/**
- * Controller event callback
- *
- * @param cls NULL
- * @param event the controller event
- */
-static void
-controller_event_cb (void *cls,
-                     const struct GNUNET_TESTBED_EventInformation *event)
-{
-  struct TestRunContext *rc = cls;
-
-  if ((NULL != rc->cc) && (0 != (rc->event_mask & (1LL << event->type))))
-    rc->cc (rc->cc_cls, event);
-  if (rc->peer_cnt == rc->num_peers)
-    return;
-  GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type);
-  GNUNET_assert (NULL == rc->peers[rc->peer_cnt]);
-  GNUNET_assert (NULL != event->details.peer_start.peer);
-  rc->peers[rc->peer_cnt++] = event->details.peer_start.peer;
-}
-
-
-/**
- * Task to be executed when peers are ready
- *
- * @param cls NULL
- * @param tc the task context
- */
-static void
-master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct TestRunContext *rc = cls;
-
-  GNUNET_assert (rc->peer_cnt == rc->num_peers);
-  rc->test_master (rc->test_master_cls, rc->num_peers, rc->peers);
-}
-
-
 /**
  * Main run function.
  *
  * @param cls NULL
  * @param args arguments passed to GNUNET_PROGRAM_run
  * @param cfgfile the path to configuration file
- * @param cfg the configuration file handle
+ * @param config the configuration file handle
  */
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *config)
 {
   struct TestRunContext *rc = cls;
-  uint64_t event_mask;
-  
-  event_mask = rc->event_mask;
-  event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
-  GNUNET_TESTBED_run (NULL, config, rc->num_peers, event_mask,
-                      &controller_event_cb, rc, &master_task, rc);
+
+  GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask, rc->cc,
+                      rc->cc_cls, rc->test_master, rc->test_master_cls);
 }
 
 
@@ -167,13 +115,12 @@ run (void *cls, char *const *args, const char *cfgfile,
  * @param cc_cls closure for cc
  * @param test_master task to run once the test is ready
  * @param test_master_cls closure for 'task'.
+ * @return GNUNET_SYSERR on error, GNUNET_OK on success
  */
-void
+int
 GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename,
-                         unsigned int num_peers,
-                         uint64_t event_mask,
-                         GNUNET_TESTBED_ControllerCallback cc,
-                         void *cc_cls,
+                         unsigned int num_peers, uint64_t event_mask,
+                         GNUNET_TESTBED_ControllerCallback cc, void *cc_cls,
                          GNUNET_TESTBED_TestMaster test_master,
                          void *test_master_cls)
 {
@@ -187,6 +134,7 @@ GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename,
     GNUNET_GETOPT_OPTION_END
   };
   struct TestRunContext *rc;
+  int ret;
 
   argv2[0] = GNUNET_strdup (testname);
   argv2[2] = GNUNET_strdup (cfg_filename);
@@ -200,11 +148,13 @@ GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename,
   rc->event_mask = event_mask;
   rc->cc = cc;
   rc->cc_cls = cc_cls;
-  (void) GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
-                             testname, "nohelp", options, &run, rc);
+  ret =
+      GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
+                          testname, "nohelp", options, &run, rc);
   GNUNET_free (rc);
   GNUNET_free (argv2[0]);
   GNUNET_free (argv2[2]);
+  return ret;
 }
 
 /* end of testbed_api_test.c */