*/
/**
- * @file testing/new_testing_api_test.c
+ * @file testbed/testbed_api_test.c
* @brief high-level test function
* @author Christian Grothoff
+ * @author Sree Harsha Totakura
*/
#include "platform.h"
-#include "gnunet_testing_service.h"
+#include "gnunet_testbed_service.h"
+/**
+ * Context information for test run
+ */
+struct TestRunContext
+{
+ /**
+ * Test master callback
+ */
+ GNUNET_TESTBED_TestMaster test_master;
+
+ /**
+ * Closure for test master
+ */
+ void *test_master_cls;
+
+ /**
+ * The controller event callback
+ */
+ GNUNET_TESTBED_ControllerCallback cc;
+
+ /**
+ * Closure for the above callback
+ */
+ void *cc_cls;
+
+ /**
+ * event mask for the controller callback
+ */
+ uint64_t event_mask;
+
+ /**
+ * 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 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);
+}
/**
* @param cfg_filename configuration filename to use
* (for testbed, controller and peers)
* @param num_peers number of peers to start
+ * @param event_mask bit mask with set of events to call 'cc' for;
+ * or-ed values of "1LL" shifted by the
+ * respective 'enum GNUNET_TESTBED_EventType'
+ * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
+ * @param cc controller callback to invoke on events; This callback is called
+ * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
+ * set in the event_mask as this is the only way get access to the
+ * handle of each peer
+ * @param cc_cls closure for cc
* @param test_master task to run once the test is ready
* @param test_master_cls closure for 'task'.
*/
void
-GNUNET_TESTBED_test_run (const char *testname,
- const char *cfg_filename,
- unsigned int num_peers,
- GNUNET_TESTBED_TestMaster test_master,
- void *test_master_cls)
+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,
+ GNUNET_TESTBED_TestMaster test_master,
+ void *test_master_cls)
{
- GNUNET_break (0);
-}
-
+ char *argv2[] = {
+ NULL,
+ "-c",
+ NULL,
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ struct TestRunContext *rc;
+ argv2[0] = GNUNET_strdup (testname);
+ argv2[2] = GNUNET_strdup (cfg_filename);
+ GNUNET_assert (NULL != test_master);
+ GNUNET_assert (num_peers > 0);
+ rc = GNUNET_malloc (sizeof (struct TestRunContext) +
+ (num_peers * sizeof (struct GNUNET_TESTBED_Peer *)));
+ rc->test_master = test_master;
+ rc->test_master_cls = test_master_cls;
+ rc->num_peers = num_peers;
+ 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);
+ GNUNET_free (rc);
+ GNUNET_free (argv2[0]);
+ GNUNET_free (argv2[2]);
+}
-/* end of new_testing_api_test.c */
+/* end of testbed_api_test.c */