From: Christian Grothoff Date: Tue, 19 Jul 2011 11:59:34 +0000 (+0000) Subject: run glpk code and tests only if gplk installed, fewer ifdefs X-Git-Tag: initial-import-from-subversion-38251~17727 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=50e7453045035b43f2a412e21f0cca2a5fd62b84;p=oweals%2Fgnunet.git run glpk code and tests only if gplk installed, fewer ifdefs --- diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 51f8447ee..4121206c7 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -21,6 +21,14 @@ endif if HAVE_LIBGLPK TRANSPORT_ATS_SRC = gnunet-service-transport_ats.c + TEST_TRANSPORT_ATS = \ + test_transport_ats \ + test_transport_ats_multiple_peers + GN_GLPK = -lglpk +if HAVE_BENCHMARKS + ATS_TRANSPORT_BENCHMARKS = \ + perf_transport_ats +endif endif if USE_COVERAGE @@ -139,10 +147,6 @@ gnunet_transport_LDADD = \ gnunet_transport_DEPENDENCIES = \ libgnunettransportnew.la -if HAVE_LIBGLPK - GN_GLPK = -lglpk -endif - gnunet_service_transport_SOURCES = \ gnunet-service-transport.c $(TRANSPORT_ATS_SRC) gnunet_service_transport_LDADD = \ @@ -246,15 +250,10 @@ libgnunet_plugin_transport_https_la_CFLAGS = \ libgnunet_plugin_transport_https_la_CPPFLAGS = \ @LIBCURL_CPPFLAGS@ -if HAVE_BENCHMARKS - TRANSPORT_BENCHMARKS = \ - perf_transport_ats -endif check_PROGRAMS = \ - test_transport_ats \ - test_transport_ats_multiple_peers \ - $(TRANSPORT_BENCHMARKS) \ + $(TEST_TRANSPORT_ATS) \ + $(ATS_TRANSPORT_BENCHMARKS) \ test_transport_api_tcp \ test_transport_api_tcp_nat \ test_transport_api_udp \ @@ -285,8 +284,7 @@ check_PROGRAMS = \ if ENABLE_TEST_RUN TESTS = \ - test_transport_ats \ - test_transport_ats_multiple_peers \ + $(TEST_TRANSPORT_ATS) \ perf_transport_ats \ test_transport_api_tcp \ test_transport_api_tcp_nat \ @@ -327,7 +325,7 @@ test_transport_ats_LDADD = -lm \ $(GN_GLPK) test_transport_ats_multiple_peers_SOURCES = \ - test_transport_ats_multiple_peers.c + test_transport_ats_multiple_peers.c $(TRANSPORT_ATS_SRC) test_transport_ats_multiple_peers_LDADD = -lm \ $(top_builddir)/src/transport/libgnunettransportnew.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ @@ -337,7 +335,7 @@ test_transport_ats_multiple_peers_LDADD = -lm \ perf_transport_ats_SOURCES = \ perf_transport_ats.c perf_transport_ats_LDADD = \ - $(GN_GLPK) \ + -lglpk \ $(top_builddir)/src/util/libgnunetutil.la test_transport_api_tcp_SOURCES = \ diff --git a/src/transport/gnunet-service-transport_ats.h b/src/transport/gnunet-service-transport_ats.h index 997014e7a..0e4427dc6 100644 --- a/src/transport/gnunet-service-transport_ats.h +++ b/src/transport/gnunet-service-transport_ats.h @@ -19,7 +19,7 @@ */ /** - * @file transport/transport_ats.h + * @file transport/gnunet-service-transport_ats.h * @brief common internal definitions for transport service's ats code * @author Matthias Wachs */ @@ -512,4 +512,4 @@ ats_set_logging_options (struct ATS_Handle * ats, int log_problem); #endif -/* end of file transport_ats.h */ +/* end of file gnunet-service-transport_ats.h */ diff --git a/src/transport/perf_transport_ats.c b/src/transport/perf_transport_ats.c index 59e276d09..3f8950a8a 100644 --- a/src/transport/perf_transport_ats.c +++ b/src/transport/perf_transport_ats.c @@ -18,15 +18,13 @@ 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 -#endif #define VERBOSE GNUNET_NO @@ -34,7 +32,6 @@ static int ret = 0; -#if HAVE_LIBGLPK static int executions = EXECS; static uint64_t exec_time[EXECS]; @@ -48,7 +45,8 @@ 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; @@ -62,7 +60,8 @@ void solve_mlp(int presolve) GNUNET_assert ((solution == 5) && (result==0)); } -void solve_lp(int presolve) +static void +solve_lp(int presolve) { int result; int solution; @@ -79,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)); @@ -102,10 +103,12 @@ void modify_qm(int start, int length, int values_to_change) } //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; @@ -139,7 +142,8 @@ 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; @@ -171,7 +175,8 @@ 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; @@ -204,7 +209,8 @@ 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; @@ -264,7 +270,7 @@ 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[]) { @@ -276,12 +282,6 @@ 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 - int nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND); if (nullfd < 0) return GNUNET_SYSERR; @@ -330,10 +330,8 @@ int main (int argc, char *argv[]) "GLPK MLP 100 peers 400 addresses with optimization", ((double) mlp_with_opt_avg / EXECS) / 400, "ms/address"); (void) CLOSE (nullfd); - -#endif return ret; } -/* end of per_transport_ats.c*/ +/* end of perf_transport_ats.c*/ diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c index 57110d5e5..fe8b6e87b 100644 --- a/src/transport/test_transport_ats.c +++ b/src/transport/test_transport_ats.c @@ -29,9 +29,14 @@ #define VERBOSE GNUNET_YES static struct ATS_Handle * ats; + static struct GNUNET_CONFIGURATION_Handle * cfg; -void ats_result_cb () +static struct TransportConfiguration *tc; + + +static void +ats_result_cb () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS Result callback\n"); @@ -49,40 +54,11 @@ struct TransportConfiguration struct ATS_mechanism * m_tail; }; -struct TransportConfiguration *tc; - -/* -void create_topology (int c_peers, int c_mechanisms) -{ - int c; - peers = GNUNET_malloc ( c_peers * sizeof (struct ATS_peer)); - for (c=0 ; cmechanisms; (*m) = tc->m_head; (*c_m) = tc->mechanisms; - } -int run_ats (void) + +static +int run_ats () { int ret = 0; -#if HAVE_LIBGLPK ats_calculate_bandwidth_distribution (ats); -#endif GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); return ret; } -int init_ats (void) + +static int +init_ats () { int ret = 0; -#if HAVE_LIBGLPK ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION, create_ats_information, ats_result_cb); -#endif //GNUNET_assert (ats != NULL); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -120,49 +95,56 @@ int init_ats (void) } -int shutdown_ats (void) +static int +shutdown_ats () { int ret = 0; -#if HAVE_LIBGLPK ats_delete_problem (ats); ats_shutdown (ats); -#endif GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); return ret; } + /* To make compiler happy */ -void dummy(void) +void +dummy() { struct ATS_quality_metric * q = qm; q = NULL; struct ATS_ressource * r = ressources; r = NULL; + q++; + r++; } -void iterate_peer_values (void *cls, - const char *section, - const char *option, - const char *value) + +static void +iterate_peer_values (void *cls, + const char *section, + const char *option, + const char *value) { if (strcmp (option, "f") == 0) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value); } -void iterate_mech_values (void *cls, - const char *section, - const char *option, - const char *value) +static void +iterate_mech_values (void *cls, + const char *section, + const char *option, + const char *value) { if (strcmp (option, "f") == 0) GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value); } -void iterate_sections (void *cls, - const char *section) +static void +iterate_sections (void *cls, + const char *section) { struct TransportConfiguration * tc = cls; /* Peer definition */ @@ -183,22 +165,22 @@ void iterate_sections (void *cls, } } -void destroy_transport_configuration (char * filename) -{ - GNUNET_CONFIGURATION_destroy (cfg); -} - -struct TransportConfiguration * load_transport_configuration (char * filename) +static struct TransportConfiguration * +load_transport_configuration (char * filename) { struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration)); - cfg = GNUNET_CONFIGURATION_create(); - GNUNET_CONFIGURATION_load(cfg, filename); - GNUNET_CONFIGURATION_iterate_sections(cfg, iterate_sections, ret); + cfg = GNUNET_CONFIGURATION_create(); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_load(cfg, filename)); + GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret); + GNUNET_CONFIGURATION_destroy (cfg); + cfg = NULL; return ret; } + int main (int argc, char *argv[]) { @@ -211,29 +193,11 @@ main (int argc, char *argv[]) "INFO", #endif NULL); -#if !HAVE_LIBGLPK - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "HAVE_LIBGLPK not set, exiting testcase\n"); -#endif - -#if !HAVE_LIBGLPK - return ret; -#endif - - return 0; - tc = load_transport_configuration ("test.ats"); - - return ret; - - /* Testing */ ats = NULL; - ret += init_ats (); ret += run_ats (); ret += shutdown_ats (); - - /* Shutdown */ return ret; } diff --git a/src/transport/test_transport_ats_multiple_peers.c b/src/transport/test_transport_ats_multiple_peers.c index 3ba20455f..9d30a061d 100644 --- a/src/transport/test_transport_ats_multiple_peers.c +++ b/src/transport/test_transport_ats_multiple_peers.c @@ -25,8 +25,6 @@ #include "platform.h" #include "gnunet_util_lib.h" -#if HAVE_LIBGLPK - #include "gnunet_testing_lib.h" #include "gnunet_transport_service.h" #include "gauger.h" @@ -557,8 +555,10 @@ void dummy(void) { struct ATS_quality_metric * q = qm; q = NULL; + q++; struct ATS_ressource * r = ressources; r = NULL; + r++; } static size_t @@ -789,8 +789,6 @@ check () return ok; } -#endif - int main (int argc, char *argv[]) { @@ -804,11 +802,6 @@ main (int argc, char *argv[]) #endif NULL); -#if !HAVE_LIBGLPK - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "GLPK not installed, exiting testcase\n"); - return ret; -#else GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing"); machine_parsable = GNUNET_NO; peers = NUM_PEERS; @@ -848,7 +841,6 @@ main (int argc, char *argv[]) */ GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing"); return ret; -#endif } /* end of test_transport_ats_multiple_peers.c*/