aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-24 12:39:39 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-24 12:39:39 +0000
commite48b37b7041f4bad25a5d23a32be278f1801e1b3 (patch)
treeee0cb1245712fda0cf869b87ab36f421df4c8ba3 /src/testbed
parentefa8d0fd1dc4df1fd291d60dbe71c0b861af1e3e (diff)
downloadgnunet-e48b37b7041f4bad25a5d23a32be278f1801e1b3.tar.gz
gnunet-e48b37b7041f4bad25a5d23a32be278f1801e1b3.zip
testcases for peer get information
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/test_testbed_api.c66
-rw-r--r--src/testbed/testbed_api.c15
-rw-r--r--src/testbed/testbed_api_peers.c6
-rw-r--r--src/testbed/testbed_api_peers.h17
4 files changed, 91 insertions, 13 deletions
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c
index 3bb45f730..ba026cb65 100644
--- a/src/testbed/test_testbed_api.c
+++ b/src/testbed/test_testbed_api.c
@@ -94,6 +94,32 @@ static int result;
94 94
95 95
96/** 96/**
97 * Enumeration of sub testcases
98 */
99enum Test
100 {
101 /**
102 * Test cases which are not covered by the below ones
103 */
104 OTHER,
105
106 /**
107 * Test where we get a peer config from controller
108 */
109 PEER_GETCONFIG,
110
111 /**
112 * Test where we get a peer's identity from controller
113 */
114 PEER_DESTROY,
115 };
116
117/**
118 * Testing status
119 */
120static enum Test sub_test;
121
122/**
97 * Shutdown nicely 123 * Shutdown nicely
98 * 124 *
99 * @param cls NULL 125 * @param cls NULL
@@ -102,6 +128,7 @@ static int result;
102static void 128static void
103do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) 129do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
104{ 130{
131 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n");
105 if (GNUNET_SCHEDULER_NO_TASK != abort_task) 132 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
106 GNUNET_SCHEDULER_cancel (abort_task); 133 GNUNET_SCHEDULER_cancel (abort_task);
107 if (NULL != reg_handle) 134 if (NULL != reg_handle)
@@ -143,12 +170,32 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
143 switch (event->type) 170 switch (event->type)
144 { 171 {
145 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 172 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
146 GNUNET_assert (event->details.operation_finished.operation == operation); 173 switch(sub_test)
147 GNUNET_assert (NULL == event->details.operation_finished.op_cls); 174 {
148 GNUNET_assert (NULL == event->details.operation_finished.emsg); 175 case PEER_GETCONFIG:
149 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == 176 GNUNET_assert (event->details.operation_finished.operation == operation);
150 event->details.operation_finished.pit); 177 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
151 GNUNET_assert (NULL == event->details.operation_finished.op_result.generic); 178 GNUNET_assert (NULL == event->details.operation_finished.emsg);
179 GNUNET_assert (GNUNET_TESTBED_PIT_CONFIGURATION ==
180 event->details.operation_finished.pit);
181 GNUNET_assert (NULL != event->details.operation_finished.op_result.cfg);
182 sub_test = PEER_DESTROY;
183 operation = GNUNET_TESTBED_peer_destroy (peer);
184 break;
185 case PEER_DESTROY:
186 GNUNET_assert (event->details.operation_finished.operation == operation);
187 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
188 GNUNET_assert (NULL == event->details.operation_finished.emsg);
189 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC ==
190 event->details.operation_finished.pit);
191 GNUNET_assert (NULL ==
192 event->details.operation_finished.op_result.generic);
193 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
194 break;
195 case OTHER:
196 GNUNET_assert (0);
197 break;
198 }
152 break; 199 break;
153 case GNUNET_TESTBED_ET_PEER_START: 200 case GNUNET_TESTBED_ET_PEER_START:
154 GNUNET_assert (event->details.peer_start.host == host); 201 GNUNET_assert (event->details.peer_start.host == host);
@@ -157,8 +204,11 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
157 break; 204 break;
158 case GNUNET_TESTBED_ET_PEER_STOP: 205 case GNUNET_TESTBED_ET_PEER_STOP:
159 GNUNET_assert (event->details.peer_stop.peer == peer); 206 GNUNET_assert (event->details.peer_stop.peer == peer);
160 result = GNUNET_YES; 207 result = GNUNET_YES;
161 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 208 sub_test = PEER_GETCONFIG;
209 operation =
210 GNUNET_TESTBED_peer_get_information (peer,
211 GNUNET_TESTBED_PIT_CONFIGURATION);
162 break; 212 break;
163 default: 213 default:
164 GNUNET_assert (0); /* We should never reach this state */ 214 GNUNET_assert (0); /* We should never reach this state */
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 175c08404..6fce5adde 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -410,6 +410,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
410{ 410{
411 struct GNUNET_TESTBED_Operation *op; 411 struct GNUNET_TESTBED_Operation *op;
412 struct GNUNET_TESTBED_Peer *peer; 412 struct GNUNET_TESTBED_Peer *peer;
413 struct PeerInfoData *data;
413 struct GNUNET_TESTBED_EventInformation info; 414 struct GNUNET_TESTBED_EventInformation info;
414 uint64_t op_id; 415 uint64_t op_id;
415 416
@@ -424,12 +425,15 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
424 LOG_DEBUG ("Operation not found"); 425 LOG_DEBUG ("Operation not found");
425 return GNUNET_YES; 426 return GNUNET_YES;
426 } 427 }
427 peer = op->data; 428 data = op->data;
429 GNUNET_assert (NULL != data);
430 peer = data->peer;
428 GNUNET_assert (NULL != peer); 431 GNUNET_assert (NULL != peer);
429 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); 432 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
430 if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) 433 if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
431 { 434 {
432 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); 435 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
436 GNUNET_free (data);
433 GNUNET_free (op); 437 GNUNET_free (op);
434 return GNUNET_YES; 438 return GNUNET_YES;
435 } 439 }
@@ -437,8 +441,8 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
437 info.details.operation_finished.operation = op; 441 info.details.operation_finished.operation = op;
438 info.details.operation_finished.op_cls = NULL; 442 info.details.operation_finished.op_cls = NULL;
439 info.details.operation_finished.emsg = NULL; 443 info.details.operation_finished.emsg = NULL;
440 info.details.operation_finished.pit = op->operation_id; 444 info.details.operation_finished.pit = data->pit;
441 switch (op->operation_id) 445 switch (data->pit)
442 { 446 {
443 case GNUNET_TESTBED_PIT_IDENTITY: 447 case GNUNET_TESTBED_PIT_IDENTITY:
444 { 448 {
@@ -467,7 +471,9 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
467 cfg = GNUNET_CONFIGURATION_create (); 471 cfg = GNUNET_CONFIGURATION_create ();
468 GNUNET_assert (GNUNET_OK == 472 GNUNET_assert (GNUNET_OK ==
469 GNUNET_CONFIGURATION_deserialize (cfg, config, 473 GNUNET_CONFIGURATION_deserialize (cfg, config,
470 (size_t) config_size, GNUNET_NO)); 474 (size_t) config_size,
475 GNUNET_NO));
476 GNUNET_free (config);
471 info.details.operation_finished.op_result.cfg = cfg; 477 info.details.operation_finished.op_result.cfg = cfg;
472 } 478 }
473 break; 479 break;
@@ -477,6 +483,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
477 } 483 }
478 c->cc (c->cc_cls, &info); 484 c->cc (c->cc_cls, &info);
479 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); 485 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
486 GNUNET_free (data);
480 GNUNET_free (op); 487 GNUNET_free (op);
481 return GNUNET_YES; 488 return GNUNET_YES;
482} 489}
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index a1a8a76a3..c2bf2107f 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -242,12 +242,16 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
242{ 242{
243 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; 243 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
244 struct GNUNET_TESTBED_Operation *op; 244 struct GNUNET_TESTBED_Operation *op;
245 struct PeerInfoData *data;
245 246
246 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit); 247 GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit);
248 data = GNUNET_malloc (sizeof (struct PeerInfoData));
249 data->peer = peer;
250 data->pit = pit;
247 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 251 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
248 op->type = OP_PEER_INFO; 252 op->type = OP_PEER_INFO;
249 op->operation_id = peer->controller->operation_counter++; 253 op->operation_id = peer->controller->operation_counter++;
250 op->data = peer; 254 op->data = data;
251 msg = GNUNET_malloc (sizeof (struct 255 msg = GNUNET_malloc (sizeof (struct
252 GNUNET_TESTBED_PeerGetConfigurationMessage)); 256 GNUNET_TESTBED_PeerGetConfigurationMessage));
253 msg->header.size = htons 257 msg->header.size = htons
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index 83d2d890f..5b0a23c64 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -116,6 +116,23 @@ struct PeerDestroyData
116 116
117 117
118/** 118/**
119 * Data for the OperationType OP_PEER_INFO
120 */
121struct PeerInfoData
122{
123 /**
124 * The peer whose information has been requested
125 */
126 struct GNUNET_TESTBED_Peer *peer;
127
128 /**
129 * The type of peer information requested
130 */
131 enum GNUNET_TESTBED_PeerInformationType pit;
132};
133
134
135/**
119 * Create the given peer at the specified host using the given 136 * Create the given peer at the specified host using the given
120 * controller. If the given controller is not running on the target 137 * controller. If the given controller is not running on the target
121 * host, it should find or create a controller at the target host and 138 * host, it should find or create a controller at the target host and