[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23546 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23546 - gnunet/src/testbed |
Date: |
Fri, 31 Aug 2012 18:24:14 +0200 |
Author: harsha
Date: 2012-08-31 18:24:14 +0200 (Fri, 31 Aug 2012)
New Revision: 23546
Modified:
gnunet/src/testbed/testbed_api_test.c
Log:
implemented GNUNET_TESTBED_test_run
Modified: gnunet/src/testbed/testbed_api_test.c
===================================================================
--- gnunet/src/testbed/testbed_api_test.c 2012-08-31 16:23:53 UTC (rev
23545)
+++ gnunet/src/testbed/testbed_api_test.c 2012-08-31 16:24:14 UTC (rev
23546)
@@ -22,14 +22,101 @@
* @file testbed/testbed_api_test.c
* @brief high-level test function
* @author Christian Grothoff
+ * @author Sree Harsha Totakura
*/
#include "platform.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;
+
+ /**
+ * 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 (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
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *config)
+{
+ struct TestRunContext *rc = cls;
+
+ GNUNET_TESTBED_run (NULL, config, rc->num_peers, 0, &controller_event_cb,
+ rc, &master_task, rc);
+}
+
+
+/**
* Convenience method for running a "simple" test on the local system
* with a single call from 'main'. Underlay and overlay topology are
* configured using the "UNDERLAY" and "OVERLAY" options in the
@@ -58,7 +145,30 @@
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);
+ 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 = rc->num_peers;
+ (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]);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23546 - gnunet/src/testbed,
gnunet <=