* Closure for the above callback
*/
void *cc_cls;
-
+
/**
* event mask for the controller callback
*/
* 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.
*
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);
}
* @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)
{
GNUNET_GETOPT_OPTION_END
};
struct TestRunContext *rc;
+ int ret;
argv2[0] = GNUNET_strdup (testname);
argv2[2] = GNUNET_strdup (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 */