stuff
[oweals/gnunet.git] / src / transport / perf_transport_ats.c
index eaec70c7bdf6a39954a34dec5f35766541022899..3f8950a8a173569b1184010b75e4f697fc8c84a9 100644 (file)
      Boston, MA 02111-1307, USA.
 */
 /**
- * @file testing/per_transport_ats.c
+ * @file transport/perf_transport_ats.c
  * @brief testcase for ats functionality
  */
 #include "platform.h"
 #include "gnunet_time_lib.h"
 #include "gauger.h"
-#if HAVE_LIBGLPK
 #include <glpk.h>
-#endif
 
 #define VERBOSE GNUNET_NO
 
 #define EXECS 5
 
+static int ret = 0;
 
-#if HAVE_LIBGLPK
 static int executions = EXECS;
 static uint64_t exec_time[EXECS];
 
@@ -47,12 +45,12 @@ static glp_prob * prob;
 static struct GNUNET_TIME_Absolute start;
 static struct GNUNET_TIME_Absolute end;
 
-
-void solve_mlp(int presolve)
+static void 
+solve_mlp(int presolve)
 {
   int result, solution;
-
   glp_iocp opt_mlp;
+
   glp_init_iocp(&opt_mlp);
   opt_mlp.msg_lev = GLP_MSG_OFF;
   opt_mlp.presolve = GLP_OFF;
@@ -62,9 +60,11 @@ void solve_mlp(int presolve)
   GNUNET_assert ((solution == 5) && (result==0));
 }
 
-void solve_lp(int presolve)
+static void
+solve_lp(int presolve)
 {
-  int result, solution;
+  int result;
+  int solution;
 
   glp_smcp opt_lp;
   glp_init_smcp(&opt_lp);
@@ -78,8 +78,10 @@ void solve_lp(int presolve)
   GNUNET_assert ((solution == 5) && (result==0));
 }
 
+#if 0
 /* Modify quality constraint */
-void modify_qm(int start, int length, int values_to_change)
+static void 
+modify_qm(int start, int length, int values_to_change)
 {
   //int * ind = GNUNET_malloc (length * sizeof (int));
   //double *val = GNUNET_malloc (length * sizeof (double));
@@ -97,20 +99,29 @@ void modify_qm(int start, int length, int values_to_change)
     {
             printf("%i = %f \n", ind[c2], val[c2]);
     }
-
     c++;
   }
   //glp_set_mat_row(prob, start, length, ind, val);
 }
+#endif
 
 
 
-void bench_simplex_optimization(char * file, int executions)
+static void 
+bench_simplex_optimization(char * file, int executions)
 {
   int c;
+  int res;
 
   prob = glp_create_prob();
-  glp_read_lp(prob, NULL, file);
+  res = glp_read_lp(prob, NULL, file);
+  if (res != 0)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Problem file `%s' not found\n",  file);
+    ret = 1;
+    return;
+  }
 
   solve_lp(GNUNET_YES);
 
@@ -131,12 +142,21 @@ void bench_simplex_optimization(char * file, int executions)
 }
 
 
-void bench_simplex_no_optimization(char * file, int executions)
+static void
+bench_simplex_no_optimization(char * file, int executions)
 {
   int c;
+  int res;
 
   prob = glp_create_prob();
-  glp_read_lp(prob, NULL, file);
+  res = glp_read_lp(prob, NULL, file);
+  if (res != 0)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Problem file `%s' not found\n",  file);
+    ret = 1;
+    return;
+  }
 
   for (c=0; c<executions;c++)
   {
@@ -155,13 +175,21 @@ void bench_simplex_no_optimization(char * file, int executions)
   glp_delete_prob(prob);
 }
 
-void bench_mlp_no_optimization(char * file, int executions)
+static void
+bench_mlp_no_optimization(char * file, int executions)
 {
   int c;
+  int res;
 
   prob = glp_create_prob();
-  glp_read_lp(prob, NULL, file);
-
+  res = glp_read_lp(prob, NULL, file);
+  if (res != 0)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Problem file `%s' not found\n",  file);
+    ret = 1;
+    return;
+  }
   for (c=0; c<executions;c++)
   {
       start = GNUNET_TIME_absolute_get();
@@ -181,11 +209,21 @@ void bench_mlp_no_optimization(char * file, int executions)
 }
 
 
-void bench_mlp_with_optimization(char * file, int executions, int changes)
+static void 
+bench_mlp_with_optimization(char * file, int executions, int changes)
 {
   int c;
+  int res;
+
   prob = glp_create_prob();
-  glp_read_lp(prob, NULL, file);
+  res = glp_read_lp(prob, NULL, file);
+  if (res != 0)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Problem file `%s' not found\n",  file);
+    ret = 1;
+    return;
+  }
 
   solve_lp(GNUNET_YES);
 
@@ -232,11 +270,11 @@ void modify_cr (int start, int length, int count)
   //glp_set_mat_row(prob, start, length, ind, val);
 }
 #endif
-#endif
+
 
 int main (int argc, char *argv[])
 {
-  int ret = 0;
+
   GNUNET_log_setup ("perf-transport-ats",
 #if VERBOSE
                     "DEBUG",
@@ -244,19 +282,10 @@ int main (int argc, char *argv[])
                     "INFO",
 #endif
                     NULL);
-
-#if !HAVE_LIBGLPK
-       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed, exiting testcase\n");
-       return 0;
-#else
-#if 0
-#endif
   int nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND);
   if (nullfd < 0)
     return GNUNET_SYSERR;
-  /* set stdin/stdout to /dev/null */
-  //stdi
-  if (/*(dup2 (nullfd, 0) < 0) || */(dup2 (nullfd, 1) < 0))
+  if (dup2 (nullfd, 1) < 0)
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
     (void) CLOSE (nullfd);
@@ -271,37 +300,38 @@ int main (int argc, char *argv[])
   bench_mlp_no_optimization (file, executions);
   bench_mlp_with_optimization (file, executions, 0);
 
+  if (ret != 0)
+    return ret;
+
   // -> 400 addresses
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
       "Simplex, no optimization, average per address: %f\n",
       ((double) sim_no_opt_avg / EXECS) / 400);
   GAUGER ("TRANSPORT","GLPK simplex  no optimization",
       ((double) sim_no_opt_avg  / EXECS) / 400, "ms/address");
 
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
       "Simplex, with optimization, average per address: %f\n",
       ((double) sim_with_opt_avg / EXECS) / 400);
   GAUGER ("TRANSPORT",
       "GLPK simplex, 100 peers 400 addresses with optimization",
       ((double) sim_with_opt_avg  / EXECS) / 400, "ms/address");
 
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
       "MLP no optimization average per address: %f\n",
       ((double) mlp_no_opt_avg  / EXECS) / 400);
   GAUGER ("TRANSPORT","GLPK MLP 100 peers 400 addresses no optimization",
       ((double) mlp_no_opt_avg  / EXECS) / 400, "ms/address");
 
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
       "MLP optimization average per address: %f\n",
       ((double) mlp_with_opt_avg/ EXECS) / 400);
   GAUGER ("TRANSPORT",
       "GLPK MLP 100 peers 400 addresses with optimization",
       ((double) mlp_with_opt_avg  / EXECS) / 400, "ms/address");
-
-#endif
   (void) CLOSE (nullfd);
   return ret;
 }
 
-/* end of per_transport_ats.c*/
+/* end of perf_transport_ats.c*/