using new function + additional safety checks
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 1 Sep 2011 09:24:44 +0000 (09:24 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 1 Sep 2011 09:24:44 +0000 (09:24 +0000)
src/transport/test_transport_api_reliability.c

index 09d23b78987100f93e4e2d28e4dc445b00c632ab..f0c9d9db8f02683bfa45bc4f6cc45b937df559fd 100644 (file)
@@ -38,7 +38,7 @@
 #include "transport.h"
 #include "transport-testing.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
 
 #define VERBOSE_ARM GNUNET_NO
 
  */
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500)
 
+static char *test_source;
+
+static char *test_plugin;
+
+static char *test_name;
+
 static int ok;
 
 static GNUNET_SCHEDULER_TaskIdentifier die_task;
@@ -82,9 +88,6 @@ struct TestMessage
   uint32_t num;
 };
 
-static char *test_name;
-static char *test_plugin;
-
 static int msg_scheduled;
 static int msg_sent;
 static int msg_recv_expected;
@@ -374,13 +377,22 @@ run (void *cls, char *const *args, const char *cfgfile,
                                             &notify_connect, &notify_disconnect,
                                             NULL);
 
+  if ((p1 == NULL) || (p2 == NULL))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
+    if (die_task != GNUNET_SCHEDULER_NO_TASK)
+      GNUNET_SCHEDULER_cancel (die_task);
+    die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
+    return;
+  }
+
   GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
 }
 
 static int
 check ()
 {
-  static char * argv[] = { "SDSD",
+  static char *argv[] = { "test_transport",
     "-c",
     "test_transport_api_data.conf",
 #if VERBOSE
@@ -396,9 +408,8 @@ check ()
   setTransportOptions ("test_transport_api_data.conf");
 #endif
   ok = 1;
-  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
-                      test_name, "nohelp", options, &run,
-                      &ok);
+  GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name,
+                      "nohelp", options, &run, &ok);
 
   return ok;
 }
@@ -408,10 +419,11 @@ main (int argc, char *argv[])
 {
   int ret;
   int nat_res;
-  //char * test_exec;
-
-  GNUNET_TRANSPORT_TESTING_get_test_sourcename (__FILE__, &test_name);
 
+  GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source);
+  GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source,
+                                                 &test_plugin);
+  GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name);
 
   GNUNET_log_setup (test_name,
 #if VERBOSE
@@ -421,10 +433,8 @@ main (int argc, char *argv[])
 #endif
                     NULL);
 
-  GNUNET_TRANSPORT_TESTING_get_test_plugin (argv[0], test_name, &test_plugin);
-
-  if ((strstr (argv[0], "tcp_nat") != NULL) ||
-      (strstr (argv[0], "udp_nat") != NULL))
+  if ((strcmp (test_plugin, "tcp_nat") == 0) ||
+      (strcmp (test_plugin, "udp_nat") == 0))
   {
     nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server");
     if (GNUNET_NO == nat_res)
@@ -441,7 +451,6 @@ main (int argc, char *argv[])
     }
   }
 
-
   GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1);
   GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2);
 
@@ -450,8 +459,9 @@ main (int argc, char *argv[])
   GNUNET_free (cfg_file_p1);
   GNUNET_free (cfg_file_p2);
 
-  GNUNET_free (test_name);
+  GNUNET_free (test_source);
   GNUNET_free (test_plugin);
+  GNUNET_free (test_name);
 
   return ret;
 }