diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-09 11:35:19 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-09 11:35:19 +0000 |
commit | fbb36b18c6d58e14a8fe1af922a72bb58fb6a4f7 (patch) | |
tree | b34c54be926c1f46967d3ef8c45ec15f475ba088 /src/testbed/test_testbed_api.c | |
parent | 0890551ed766641630b318db14f86a11802702bb (diff) | |
download | gnunet-fbb36b18c6d58e14a8fe1af922a72bb58fb6a4f7.tar.gz gnunet-fbb36b18c6d58e14a8fe1af922a72bb58fb6a4f7.zip |
-peer create bug fixes and test case
Diffstat (limited to 'src/testbed/test_testbed_api.c')
-rw-r--r-- | src/testbed/test_testbed_api.c | 99 |
1 files changed, 77 insertions, 22 deletions
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 612b30347..2ed3e1fa8 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c | |||
@@ -36,6 +36,11 @@ | |||
36 | #define LOG(kind,...) \ | 36 | #define LOG(kind,...) \ |
37 | GNUNET_log (kind, __VA_ARGS__) | 37 | GNUNET_log (kind, __VA_ARGS__) |
38 | 38 | ||
39 | /** | ||
40 | * Relative time seconds shorthand | ||
41 | */ | ||
42 | #define TIME_REL_SECS(sec) \ | ||
43 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | ||
39 | 44 | ||
40 | /** | 45 | /** |
41 | * Our localhost | 46 | * Our localhost |
@@ -45,7 +50,7 @@ static struct GNUNET_TESTBED_Host *host; | |||
45 | /** | 50 | /** |
46 | * The controller handle | 51 | * The controller handle |
47 | */ | 52 | */ |
48 | static struct GNUNET_TESTBED_Controller *c; | 53 | static struct GNUNET_TESTBED_Controller *controller; |
49 | 54 | ||
50 | /** | 55 | /** |
51 | * A neighbouring host | 56 | * A neighbouring host |
@@ -58,9 +63,29 @@ static struct GNUNET_TESTBED_Host *neighbour; | |||
58 | static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle; | 63 | static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle; |
59 | 64 | ||
60 | /** | 65 | /** |
66 | * Handle for a peer | ||
67 | */ | ||
68 | static struct GNUNET_TESTBED_Peer *peer; | ||
69 | |||
70 | /** | ||
71 | * Handle to configuration | ||
72 | */ | ||
73 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
74 | |||
75 | /** | ||
76 | * Handle to operation | ||
77 | */ | ||
78 | static struct GNUNET_TESTBED_Operation *operation; | ||
79 | |||
80 | /** | ||
61 | * Abort task identifier | 81 | * Abort task identifier |
62 | */ | 82 | */ |
63 | static GNUNET_SCHEDULER_TaskIdentifier abort_task_id; | 83 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; |
84 | |||
85 | /** | ||
86 | * Peer destroy task identifier | ||
87 | */ | ||
88 | static GNUNET_SCHEDULER_TaskIdentifier peer_destroy_task; | ||
64 | 89 | ||
65 | /** | 90 | /** |
66 | * The testing result | 91 | * The testing result |
@@ -77,11 +102,11 @@ static int result; | |||
77 | static void | 102 | static void |
78 | do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | 103 | do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) |
79 | { | 104 | { |
80 | if (GNUNET_SCHEDULER_NO_TASK != abort_task_id) | 105 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) |
81 | GNUNET_SCHEDULER_cancel (abort_task_id); | 106 | GNUNET_SCHEDULER_cancel (abort_task); |
82 | if (NULL != reg_handle) | 107 | if (NULL != reg_handle) |
83 | GNUNET_TESTBED_cancel_registration (reg_handle); | 108 | GNUNET_TESTBED_cancel_registration (reg_handle); |
84 | GNUNET_TESTBED_controller_disconnect (c); | 109 | GNUNET_TESTBED_controller_disconnect (controller); |
85 | GNUNET_TESTBED_host_destroy (neighbour); | 110 | GNUNET_TESTBED_host_destroy (neighbour); |
86 | GNUNET_TESTBED_host_destroy (host); | 111 | GNUNET_TESTBED_host_destroy (host); |
87 | } | 112 | } |
@@ -97,7 +122,9 @@ static void | |||
97 | do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | 122 | do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) |
98 | { | 123 | { |
99 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 124 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
100 | abort_task_id = GNUNET_SCHEDULER_NO_TASK; | 125 | abort_task = GNUNET_SCHEDULER_NO_TASK; |
126 | if (GNUNET_SCHEDULER_NO_TASK != peer_destroy_task) | ||
127 | GNUNET_SCHEDULER_cancel (peer_destroy_task); | ||
101 | do_shutdown (cls, tc); | 128 | do_shutdown (cls, tc); |
102 | } | 129 | } |
103 | 130 | ||
@@ -112,7 +139,31 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
112 | static void | 139 | static void |
113 | controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 140 | controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) |
114 | { | 141 | { |
115 | GNUNET_break (0); | 142 | GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); |
143 | GNUNET_assert (event->details.operation_finished.operation == operation); | ||
144 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | ||
145 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
146 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == | ||
147 | event->details.operation_finished.pit); | ||
148 | GNUNET_assert (NULL == event->details.operation_finished.op_result.generic); | ||
149 | result = GNUNET_YES; | ||
150 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
151 | } | ||
152 | |||
153 | |||
154 | /** | ||
155 | * Task for destroying the peer | ||
156 | * | ||
157 | * @param cls NULL | ||
158 | * @param tc the task context | ||
159 | */ | ||
160 | static void | ||
161 | do_peer_destroy (void *cls, | ||
162 | const const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
163 | { | ||
164 | peer_destroy_task = GNUNET_SCHEDULER_NO_TASK; | ||
165 | operation = GNUNET_TESTBED_peer_destroy (peer); | ||
166 | GNUNET_assert (NULL != operation); | ||
116 | } | 167 | } |
117 | 168 | ||
118 | 169 | ||
@@ -126,9 +177,11 @@ static void | |||
126 | registration_comp (void *cls, const char *emsg) | 177 | registration_comp (void *cls, const char *emsg) |
127 | { | 178 | { |
128 | GNUNET_assert (cls == neighbour); | 179 | GNUNET_assert (cls == neighbour); |
129 | reg_handle = NULL; | 180 | reg_handle = NULL; |
130 | result = GNUNET_YES; | 181 | peer = GNUNET_TESTBED_peer_create (controller, host, cfg); |
131 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 182 | GNUNET_assert (NULL != peer); |
183 | peer_destroy_task = | ||
184 | GNUNET_SCHEDULER_add_now (&do_peer_destroy, NULL); | ||
132 | } | 185 | } |
133 | 186 | ||
134 | 187 | ||
@@ -137,27 +190,29 @@ registration_comp (void *cls, const char *emsg) | |||
137 | */ | 190 | */ |
138 | static void | 191 | static void |
139 | run (void *cls, | 192 | run (void *cls, |
140 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 193 | const struct GNUNET_CONFIGURATION_Handle *config, |
141 | struct GNUNET_TESTING_Peer *peer) | 194 | struct GNUNET_TESTING_Peer *peer) |
142 | { | 195 | { |
143 | uint64_t event_mask; | 196 | uint64_t event_mask; |
144 | 197 | ||
198 | cfg = config; | ||
145 | host = GNUNET_TESTBED_host_create (NULL, NULL, 0); | 199 | host = GNUNET_TESTBED_host_create (NULL, NULL, 0); |
146 | GNUNET_assert (NULL != host); | 200 | GNUNET_assert (NULL != host); |
147 | event_mask ^= event_mask; /* NULL out */ | 201 | event_mask ^= event_mask; /* NULL out */ |
148 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); | 202 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START); |
149 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); | 203 | event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP); |
150 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); | 204 | event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT); |
151 | c = GNUNET_TESTBED_controller_connect (cfg, host, event_mask, | 205 | event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
152 | &controller_cb, NULL); | 206 | controller = GNUNET_TESTBED_controller_connect (config, host, event_mask, |
153 | GNUNET_assert (NULL != c); | 207 | &controller_cb, NULL); |
208 | GNUNET_assert (NULL != controller); | ||
154 | neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, 0); | 209 | neighbour = GNUNET_TESTBED_host_create ("localhost", NULL, 0); |
155 | GNUNET_assert (NULL != neighbour); | 210 | GNUNET_assert (NULL != neighbour); |
156 | reg_handle = | 211 | reg_handle = |
157 | GNUNET_TESTBED_register_host (c, neighbour, ®istration_comp, neighbour); | 212 | GNUNET_TESTBED_register_host (controller, neighbour, ®istration_comp, |
158 | GNUNET_assert (NULL != reg_handle); | 213 | neighbour); |
159 | 214 | GNUNET_assert (NULL != reg_handle); | |
160 | abort_task_id = GNUNET_SCHEDULER_add_delayed | 215 | abort_task = GNUNET_SCHEDULER_add_delayed |
161 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30), &do_abort, NULL); | 216 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30), &do_abort, NULL); |
162 | } | 217 | } |
163 | 218 | ||
@@ -168,10 +223,10 @@ run (void *cls, | |||
168 | int main (int argc, char **argv) | 223 | int main (int argc, char **argv) |
169 | { | 224 | { |
170 | result = GNUNET_SYSERR; | 225 | result = GNUNET_SYSERR; |
171 | if (0 != GNUNET_TESTING_service_run ("test_testbed_api", | 226 | if (0 != GNUNET_TESTING_peer_run ("test_testbed_api", |
172 | "testbed", | 227 | // "arm", |
173 | "test_testbed_api.conf", | 228 | "test_testbed_api.conf", |
174 | &run, NULL)) | 229 | &run, NULL)) |
175 | return 1; | 230 | return 1; |
176 | else return (GNUNET_OK == result) ? 0 : 1; | 231 | else return (GNUNET_OK == result) ? 0 : 1; |
177 | } | 232 | } |