-fixing #2442
authorSree Harsha Totakura <totakura@in.tum.de>
Wed, 20 Jun 2012 14:43:29 +0000 (14:43 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Wed, 20 Jun 2012 14:43:29 +0000 (14:43 +0000)
src/include/gnunet_testing_lib-new.h
src/testing/gnunet-testing-run-service.c
src/testing/test_testing_servicestartup.c
src/testing/testing.c

index 7daa4ee7f1467ed0bf240fe8901c6683f7a6d35d..fc26eefa03beb2810cd3fffbf94e2e3817750412 100644 (file)
@@ -183,7 +183,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
  * @param id identifier for the daemon, will be set
  */
 void
-GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
+GNUNET_TESTING_peer_get_identity (const struct GNUNET_TESTING_Peer *peer,
                                  struct GNUNET_PeerIdentity *id);
 
 
@@ -224,22 +224,11 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer);
  * 
  * @param cls closure
  * @param cfg configuration of the peer that was started
- */
-typedef void (*GNUNET_TESTING_TestMain)(void *cls,
-                                       const struct GNUNET_CONFIGURATION_Handle *cfg);
-
-
-/**
- * Signature of the 'main' function for a (single-peer) testcase that
- * is run using 'GNUNET_TESTING_system_run_restartable'.
- * 
- * @param cls closure
- * @param cfg configuration of the peer that was started
  * @param peer identity of the peer that was created
  */
-typedef void (*GNUNET_TESTING_RestartableTestMain)(void *cls,
-                                                  const struct GNUNET_CONFIGURATION_Handle *cfg,
-                                                  const struct GNUNET_TESTING_Peer *peer);
+typedef void (*GNUNET_TESTING_TestMain)(void *cls,
+                                       const struct GNUNET_CONFIGURATION_Handle *cfg,
+                                       struct GNUNET_TESTING_Peer *peer);
 
 
 /**
@@ -294,25 +283,6 @@ GNUNET_TESTING_service_run (const char *testdir,
                            void *tm_cls);
 
 
-/**
- * See GNUNET_TESTING_service_run.
- * The only difference is that we handle the GNUNET_TESTING_Peer to
- * the RestartableTestMain, so that the peer can be destroyed and re-created
- * to simulate failure in tests.
- *
- * FIXME: change 'GNUNET_TESTING_TestMain' to have the 'restartable' signature
- * and remove this extra function (in some sense, make this the primary one,
- * but keep the old name).
- */
-int
-GNUNET_TESTING_service_run_restartable (const char *testdir,
-                           const char *service_name,
-                           const char *cfgfilename,
-                           GNUNET_TESTING_RestartableTestMain tm,
-                           void *tm_cls);
-
-
-
 /**
  * Sometimes we use the binary name to determine which specific
  * test to run.  In those cases, the string after the last "_"
index 72415e606c2cc56740191d00e0ad5cb1c2f81a7d..cbd4763c5048a594466fd4b4557887751051fd41 100644 (file)
@@ -143,9 +143,9 @@ stdin_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  */
 static void
 testing_main (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
-              const struct GNUNET_TESTING_Peer *peer)
+              struct GNUNET_TESTING_Peer *peer)
 {
-  my_peer = (struct GNUNET_TESTING_Peer *) peer;
+  my_peer = peer;
   if (NULL == (tmpfilename = GNUNET_DISK_mktemp ("gnunet-testing")))
   {
     GNUNET_break (0);
@@ -193,8 +193,8 @@ main (int argc, char *const *argv)
   if (GNUNET_SYSERR ==
       GNUNET_GETOPT_run("gnunet-testing-run-service", options, argc, argv))
     return 1;
-  ret = GNUNET_TESTING_service_run_restartable ("gnunet_service_test", srv_name,
-                                               cfg_name, &testing_main, NULL);
+  ret = GNUNET_TESTING_service_run ("gnunet_service_test", srv_name,
+                                   cfg_name, &testing_main, NULL);
   if (0 != ret)
   {
     printf ("error\n");
index 236e8478978c67fd58185196ac0508ae9c41dd27..0a69892b60d1dc5dddd51b190c46268a7ad596d9 100644 (file)
@@ -45,7 +45,8 @@ static int test_success;
  * @param cfg the configuration with which the current testing service is run
  */
 static void
-test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
+test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+         struct GNUNET_TESTING_Peer *peer)
 {
   GNUNET_assert (NULL == cls);
   GNUNET_assert (NULL != cfg);
index 3e6cbbb0ed9aec1a038a21a1b6553e022d95e821..6d22c68cea48a07aeeda4a6694751ea51bd96a81 100644 (file)
@@ -132,6 +132,10 @@ struct GNUNET_TESTING_System
  */
 struct GNUNET_TESTING_Peer
 {
+  /**
+   * The TESTING system associated with this peer
+   */
+  struct GNUNET_TESTING_System *system;
 
   /**
    * Path to the configuration file for this peer.
@@ -151,6 +155,11 @@ struct GNUNET_TESTING_Peer
    * peer/service is currently not running.
    */
   struct GNUNET_OS_Process *main_process;
+
+  /**
+   * The keynumber of this peer's hostkey
+   */
+  uint32_t key_number;
 };
 
 
@@ -795,6 +804,8 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
   peer = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Peer));
   peer->cfgfile = config_filename; /* Free in peer_destroy */
   peer->main_binary = GNUNET_strdup ("gnunet-service-arm");
+  peer->system = system;
+  peer->key_number = key_number;
   return peer;
 }
 
@@ -806,11 +817,12 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
  * @param id identifier for the daemon, will be set
  */
 void
-GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
+GNUNET_TESTING_peer_get_identity (const struct GNUNET_TESTING_Peer *peer,
                                  struct GNUNET_PeerIdentity *id)
 {
-  GNUNET_assert (0); // FIXME-SREE.
-  // *id = peer->id;
+  GNUNET_CRYPTO_rsa_key_free (GNUNET_TESTING_hostkey_get (peer->system,
+                                                         peer->key_number,
+                                                         id));
 }
 
 
@@ -931,33 +943,11 @@ struct ServiceContext
    * Callback to signal service startup
    */
   GNUNET_TESTING_TestMain tm;
-
-  /**
-   * Closure for the above callback
-   */
-  void *tm_cls;
-};
-
-
-/**
- * Structure for holding service data
- */
-struct RestartableServiceContext
-{
-  /**
-   * The configuration of the peer in which the service is run
-   */
-  const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-  /**
-   * Callback to signal service startup
-   */
-  GNUNET_TESTING_RestartableTestMain tm;
-
+  
   /**
    * The peer in which the service is run.
    */
-  const struct GNUNET_TESTING_Peer *peer;
+  struct GNUNET_TESTING_Peer *peer;
 
   /**
    * Closure for the above callback
@@ -978,22 +968,6 @@ service_run_main (void *cls,
 {
   struct ServiceContext *sc = cls;
 
-  sc->tm (sc->tm_cls, sc->cfg);
-}
-
-
-/**
- * Callback to be called when SCHEDULER has been started
- *
- * @param cls the ServiceContext
- * @param tc the TaskContext
- */
-static void
-service_run_restartable_main (void *cls,
-                 const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct RestartableServiceContext *sc = cls;
-
   sc->tm (sc->tm_cls, sc->cfg, sc->peer);
 }
 
@@ -1066,77 +1040,8 @@ GNUNET_TESTING_service_run (const char *testdir,
   sc.cfg = cfg;
   sc.tm = tm;
   sc.tm_cls = tm_cls;
-  GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
-  if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer))
-  {
-    GNUNET_TESTING_peer_destroy (peer);
-    GNUNET_CONFIGURATION_destroy (cfg);
-    GNUNET_TESTING_system_destroy (system, GNUNET_YES);
-    return 1;
-  }
-  GNUNET_TESTING_peer_destroy (peer);
-  GNUNET_CONFIGURATION_destroy (cfg);
-  GNUNET_TESTING_system_destroy (system, GNUNET_YES);
-  return 0;
-}
-
-
-
-/**
- * See GNUNET_TESTING_service_run.
- * The only difference is that we handle the GNUNET_TESTING_Peer to
- * the RestartableTestMain, so that the peer can be destroyed and re-created
- * to simulate failure in tests.
- */
-int
-GNUNET_TESTING_service_run_restartable (const char *testdir,
-                           const char *service_name,
-                           const char *cfgfilename,
-                           GNUNET_TESTING_RestartableTestMain tm,
-                           void *tm_cls)
-{
-  struct RestartableServiceContext sc;
-  struct GNUNET_TESTING_System *system;
-  struct GNUNET_TESTING_Peer *peer;
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-
-  GNUNET_log_setup (testdir,
-                    "WARNING",
-                    NULL);
-  system = GNUNET_TESTING_system_create (testdir, "127.0.0.1");
-  if (NULL == system)
-    return 1;
-  cfg = GNUNET_CONFIGURATION_create ();
-  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename))
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-        _("Failed to load configuration from %s\n"), cfgfilename);
-    GNUNET_CONFIGURATION_destroy (cfg);
-    GNUNET_TESTING_system_destroy (system, GNUNET_YES);
-    return 1;
-  }
-  peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL);
-  if (NULL == peer)
-  {
-    GNUNET_CONFIGURATION_destroy (cfg);
-    hostkeys_unload (system);
-    GNUNET_TESTING_system_destroy (system, GNUNET_YES);
-    return 1;
-  }
-  GNUNET_free (peer->main_binary);
-  GNUNET_asprintf (&peer->main_binary, "gnunet-service-%s", service_name);
-  if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
-  {
-    GNUNET_TESTING_peer_destroy (peer);
-    GNUNET_CONFIGURATION_destroy (cfg);
-    GNUNET_TESTING_system_destroy (system, GNUNET_YES);
-    return 1;
-  }
-  sc.cfg = cfg;
-  sc.tm = tm;
-  sc.tm_cls = tm_cls;
   sc.peer = peer;
-  GNUNET_SCHEDULER_run (&service_run_restartable_main, &sc); /* Scheduler loop */
+  GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */
   if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer))
   {
     GNUNET_TESTING_peer_destroy (peer);