diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-17 14:59:10 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-17 14:59:10 +0000 |
commit | eb3f4006fc74ef71296e53d83b1d4b6990b639d1 (patch) | |
tree | 39704da526a6107925ebec9684d6a1e7d65f6e4e /src/testbed/test_testbed_api_hosts.c | |
parent | 90b5375e31986484f5007ec62c57f455bb8178dc (diff) | |
download | gnunet-eb3f4006fc74ef71296e53d83b1d4b6990b639d1.tar.gz gnunet-eb3f4006fc74ef71296e53d83b1d4b6990b639d1.zip |
helper integration to GNUNET_TESTBED_host_run_()
todo: add controller start callback
with the configuration with which the controller is started
Diffstat (limited to 'src/testbed/test_testbed_api_hosts.c')
-rw-r--r-- | src/testbed/test_testbed_api_hosts.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/testbed/test_testbed_api_hosts.c b/src/testbed/test_testbed_api_hosts.c index 340e2491a..add3a1e02 100644 --- a/src/testbed/test_testbed_api_hosts.c +++ b/src/testbed/test_testbed_api_hosts.c | |||
@@ -43,6 +43,15 @@ static struct GNUNET_TESTBED_Host *host; | |||
43 | */ | 43 | */ |
44 | static struct GNUNET_TESTBED_HelperHandle *helper_handle; | 44 | static struct GNUNET_TESTBED_HelperHandle *helper_handle; |
45 | 45 | ||
46 | /** | ||
47 | * Global test status | ||
48 | */ | ||
49 | static int status; | ||
50 | |||
51 | /** | ||
52 | * Shutdown task identifier | ||
53 | */ | ||
54 | GNUNET_SCHEDULER_TaskIdentifier shutdown_id; | ||
46 | 55 | ||
47 | /** | 56 | /** |
48 | * The shutdown task | 57 | * The shutdown task |
@@ -59,6 +68,24 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
59 | 68 | ||
60 | 69 | ||
61 | /** | 70 | /** |
71 | * Callback that will be called when the helper process dies. This is not called | ||
72 | * when the helper process is stoped using GNUNET_HELPER_stop() | ||
73 | * | ||
74 | * @param cls the closure from GNUNET_HELPER_start() | ||
75 | * @param h the handle representing the helper process. This handle is invalid | ||
76 | * in this callback. It is only presented for reference. No operations | ||
77 | * can be performed using it. | ||
78 | */ | ||
79 | static void | ||
80 | exp_cb (void *cls, const struct GNUNET_HELPER_Handle *h) | ||
81 | { | ||
82 | status = GNUNET_SYSERR; | ||
83 | GNUNET_SCHEDULER_cancel (shutdown_id); | ||
84 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
85 | } | ||
86 | |||
87 | |||
88 | /** | ||
62 | * Main run function. | 89 | * Main run function. |
63 | * | 90 | * |
64 | * @param cls NULL | 91 | * @param cls NULL |
@@ -70,9 +97,6 @@ static void | |||
70 | run (void *cls, char *const *args, const char *cfgfile, | 97 | run (void *cls, char *const *args, const char *cfgfile, |
71 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 98 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
72 | { | 99 | { |
73 | char *const binary_args[] = {"gnunet-service-testbed", | ||
74 | NULL}; | ||
75 | |||
76 | host = GNUNET_TESTBED_host_create ("localhost", NULL, 0); | 100 | host = GNUNET_TESTBED_host_create ("localhost", NULL, 0); |
77 | GNUNET_assert (NULL != host); | 101 | GNUNET_assert (NULL != host); |
78 | GNUNET_assert (0 != GNUNET_TESTBED_host_get_id_ (host)); | 102 | GNUNET_assert (0 != GNUNET_TESTBED_host_get_id_ (host)); |
@@ -81,16 +105,15 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
81 | GNUNET_assert (NULL != host); | 105 | GNUNET_assert (NULL != host); |
82 | GNUNET_assert (0 == GNUNET_TESTBED_host_get_id_ (host)); | 106 | GNUNET_assert (0 == GNUNET_TESTBED_host_get_id_ (host)); |
83 | GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0)); | 107 | GNUNET_assert (host == GNUNET_TESTBED_host_lookup_by_id_ (0)); |
84 | helper_handle = GNUNET_TESTBED_host_run_ (host, binary_args); | 108 | helper_handle = GNUNET_TESTBED_host_run_ ("127.0.0.1", host, cfg, &exp_cb, NULL); |
85 | GNUNET_assert (NULL != helper_handle); | 109 | GNUNET_assert (NULL != helper_handle); |
86 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), &do_shutdown, NULL); | 110 | shutdown_id = |
111 | GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (2), &do_shutdown, NULL); | ||
87 | } | 112 | } |
88 | 113 | ||
89 | 114 | ||
90 | int main (int argc, char **argv) | 115 | int main (int argc, char **argv) |
91 | { | 116 | { |
92 | int ret; | ||
93 | |||
94 | char *const argv2[] = { "test_testbed_api_hosts", | 117 | char *const argv2[] = { "test_testbed_api_hosts", |
95 | "-c", "test_testbed_api.conf", | 118 | "-c", "test_testbed_api.conf", |
96 | NULL | 119 | NULL |
@@ -99,8 +122,11 @@ int main (int argc, char **argv) | |||
99 | GNUNET_GETOPT_OPTION_END | 122 | GNUNET_GETOPT_OPTION_END |
100 | }; | 123 | }; |
101 | 124 | ||
102 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 125 | status = GNUNET_YES; |
103 | "test_testbed_api_hosts", "nohelp", options, &run, NULL); | 126 | if (GNUNET_OK != |
104 | 127 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | |
105 | return GNUNET_OK == ret ? 0 : 1; | 128 | "test_testbed_api_hosts", "nohelp", |
129 | options, &run, NULL)) | ||
130 | return 1; | ||
131 | return (GNUNET_OK == status) ? 0 : 1; | ||
106 | } | 132 | } |