testcases for peer get information
authorSree Harsha Totakura <totakura@in.tum.de>
Tue, 24 Jul 2012 12:39:39 +0000 (12:39 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Tue, 24 Jul 2012 12:39:39 +0000 (12:39 +0000)
src/testbed/test_testbed_api.c
src/testbed/testbed_api.c
src/testbed/testbed_api_peers.c
src/testbed/testbed_api_peers.h

index 3bb45f73085679712fc0b0c2a5fa7adb9355efea..ba026cb652fc62fb8f13bb075f46a49924049e55 100644 (file)
@@ -93,6 +93,32 @@ static GNUNET_SCHEDULER_TaskIdentifier abort_task;
 static int result;
 
 
+/**
+ * Enumeration of sub testcases
+ */
+enum Test
+  {
+    /**
+     * Test cases which are not covered by the below ones
+     */
+    OTHER,
+
+    /**
+     * Test where we get a peer config from controller
+     */
+    PEER_GETCONFIG,
+
+    /**
+     * Test where we get a peer's identity from controller
+     */
+    PEER_DESTROY,
+  };
+
+/**
+ * Testing status
+ */
+static enum Test sub_test;
+
 /**
  * Shutdown nicely
  *
@@ -102,6 +128,7 @@ static int result;
 static void
 do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down...\n");
   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
     GNUNET_SCHEDULER_cancel (abort_task);
   if (NULL != reg_handle)
@@ -143,12 +170,32 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
   switch (event->type)
   {
   case GNUNET_TESTBED_ET_OPERATION_FINISHED:
-    GNUNET_assert (event->details.operation_finished.operation == operation);
-    GNUNET_assert (NULL == event->details.operation_finished.op_cls);
-    GNUNET_assert (NULL == event->details.operation_finished.emsg);
-    GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC ==
-                  event->details.operation_finished.pit);
-    GNUNET_assert (NULL == event->details.operation_finished.op_result.generic);
+    switch(sub_test)
+    {
+    case PEER_GETCONFIG:
+      GNUNET_assert (event->details.operation_finished.operation == operation);
+      GNUNET_assert (NULL == event->details.operation_finished.op_cls);
+      GNUNET_assert (NULL == event->details.operation_finished.emsg);
+      GNUNET_assert (GNUNET_TESTBED_PIT_CONFIGURATION ==
+                    event->details.operation_finished.pit);
+      GNUNET_assert (NULL != event->details.operation_finished.op_result.cfg);
+      sub_test = PEER_DESTROY;
+      operation = GNUNET_TESTBED_peer_destroy (peer);
+      break;
+    case PEER_DESTROY:
+      GNUNET_assert (event->details.operation_finished.operation == operation);
+      GNUNET_assert (NULL == event->details.operation_finished.op_cls);
+      GNUNET_assert (NULL == event->details.operation_finished.emsg);
+      GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC ==
+                    event->details.operation_finished.pit);
+      GNUNET_assert (NULL ==
+                    event->details.operation_finished.op_result.generic); 
+      GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+      break;
+    case OTHER:
+      GNUNET_assert (0);
+      break;
+    }    
     break;
   case GNUNET_TESTBED_ET_PEER_START:
     GNUNET_assert (event->details.peer_start.host == host);
@@ -157,8 +204,11 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
     break;
   case GNUNET_TESTBED_ET_PEER_STOP:
     GNUNET_assert (event->details.peer_stop.peer == peer);    
-    result = GNUNET_YES;  
-    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    result = GNUNET_YES;
+    sub_test = PEER_GETCONFIG;
+    operation = 
+      GNUNET_TESTBED_peer_get_information (peer,
+                                          GNUNET_TESTBED_PIT_CONFIGURATION);
     break;
   default:
     GNUNET_assert (0);         /* We should never reach this state */
index 175c0840465c25e87753b34ead65398d6b62c915..6fce5addecaa1f74dcb35a37370763939b675107 100644 (file)
@@ -410,6 +410,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
 {
   struct GNUNET_TESTBED_Operation *op;
   struct GNUNET_TESTBED_Peer *peer;
+  struct PeerInfoData *data;
   struct GNUNET_TESTBED_EventInformation info;
   uint64_t op_id;
   
@@ -424,12 +425,15 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
     LOG_DEBUG ("Operation not found");
     return GNUNET_YES;
   }
-  peer = op->data;  
+  data = op->data;
+  GNUNET_assert (NULL != data);
+  peer = data->peer;
   GNUNET_assert (NULL != peer);
   GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
   if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
   {
     GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
+    GNUNET_free (data);
     GNUNET_free (op);
     return GNUNET_YES;
   }
@@ -437,8 +441,8 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
   info.details.operation_finished.operation = op;
   info.details.operation_finished.op_cls = NULL;
   info.details.operation_finished.emsg = NULL;
-  info.details.operation_finished.pit = op->operation_id;
-  switch (op->operation_id)
+  info.details.operation_finished.pit = data->pit;
+  switch (data->pit)
   {
   case GNUNET_TESTBED_PIT_IDENTITY:
     {
@@ -467,7 +471,9 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
       cfg = GNUNET_CONFIGURATION_create ();
       GNUNET_assert (GNUNET_OK == 
                     GNUNET_CONFIGURATION_deserialize (cfg, config,
-                                                      (size_t) config_size, GNUNET_NO));
+                                                      (size_t) config_size,
+                                                      GNUNET_NO));
+      GNUNET_free (config);
       info.details.operation_finished.op_result.cfg = cfg;
     }
     break;
@@ -477,6 +483,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
   }
   c->cc (c->cc_cls, &info);
   GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
+  GNUNET_free (data);
   GNUNET_free (op);
   return GNUNET_YES;
 }
index a1a8a76a37767efabc08a5a23dac4dcc3b820fe7..c2bf2107f1f5e0fef9e9f6118e954e2357fadd15 100644 (file)
@@ -242,12 +242,16 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
 {
   struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
   struct GNUNET_TESTBED_Operation *op;
+  struct PeerInfoData *data;
   
   GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit);
+  data = GNUNET_malloc (sizeof (struct PeerInfoData));
+  data->peer = peer;
+  data->pit = pit;
   op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
   op->type = OP_PEER_INFO;
   op->operation_id = peer->controller->operation_counter++;
-  op->data = peer;
+  op->data = data;
   msg = GNUNET_malloc (sizeof (struct
                                GNUNET_TESTBED_PeerGetConfigurationMessage));
   msg->header.size = htons
index 83d2d890f6c1dc3fd22e3686b022b4bb19595878..5b0a23c64f0d04f169ce9bd9dfe33895773dfea5 100644 (file)
@@ -115,6 +115,23 @@ struct PeerDestroyData
 };
 
 
+/**
+ * Data for the OperationType OP_PEER_INFO
+ */
+struct PeerInfoData
+{
+  /**
+   * The peer whose information has been requested
+   */
+  struct GNUNET_TESTBED_Peer *peer;
+  
+  /**
+   * The type of peer information requested
+   */
+  enum GNUNET_TESTBED_PeerInformationType pit;
+};
+
+
 /**
  * Create the given peer at the specified host using the given
  * controller.  If the given controller is not running on the target