diff options
Diffstat (limited to 'src/testbed/testbed_api_test.c')
-rw-r--r-- | src/testbed/testbed_api_test.c | 111 |
1 files changed, 102 insertions, 9 deletions
diff --git a/src/testbed/testbed_api_test.c b/src/testbed/testbed_api_test.c index 38e189b..af91cec 100644 --- a/src/testbed/testbed_api_test.c +++ b/src/testbed/testbed_api_test.c @@ -22,11 +22,66 @@ * @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; + + /** + * 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; +}; + + +/** + * 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; + + GNUNET_TESTBED_run (NULL, config, rc->num_peers, rc->event_mask, rc->cc, + rc->cc_cls, rc->test_master, rc->test_master_cls); +} /** @@ -49,19 +104,57 @@ * @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'. + * @return GNUNET_SYSERR on error, GNUNET_OK on success */ -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) +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, + 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; + int ret; + 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; + 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 */ |