From 0b9510a7354279a4f85c13ce204474404daa470a Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 5 Dec 2012 13:04:50 +0000 Subject: [PATCH] - init test --- src/ats/Makefile.am | 11 +++ src/ats/test_ats_api_scheduling_init.c | 123 +++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 src/ats/test_ats_api_scheduling_init.c diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index bd6d6def2..74aa0c5f1 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -58,6 +58,7 @@ gnunet_service_ats_DEPENDENCIES = \ libgnunetats.la check_PROGRAMS = \ + test_ats_api_scheduling_init \ test_ats_api_scheduling_add_address \ test_ats_api_scheduling \ test_ats_api_scheduling_destroy_address \ @@ -100,6 +101,16 @@ perf_ats_mlp_LDADD = \ $(top_builddir)/src/statistics/libgnunetstatistics.la endif + +test_ats_api_scheduling_init_SOURCES = \ + test_ats_api_scheduling_init.c +test_ats_api_scheduling_init_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/testing/libgnunettesting.la \ + $(top_builddir)/src/ats/libgnunetats.la + + + test_ats_api_scheduling_SOURCES = \ test_ats_api_scheduling.c test_ats_api_scheduling_LDADD = \ diff --git a/src/ats/test_ats_api_scheduling_init.c b/src/ats/test_ats_api_scheduling_init.c new file mode 100644 index 000000000..aef11804b --- /dev/null +++ b/src/ats/test_ats_api_scheduling_init.c @@ -0,0 +1,123 @@ +/* + This file is part of GNUnet. + (C) 2010,2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file ats/test_ats_api_scheduling.c + * @brief test automatic transport selection scheduling API init/shutdown + * @author Christian Grothoff + * @author Matthias Wachs + * + */ +#include "platform.h" +#include "gnunet_ats_service.h" +#include "gnunet_testing_lib-new.h" +#include "ats.h" + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) +#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) + +static GNUNET_SCHEDULER_TaskIdentifier die_task; +static GNUNET_SCHEDULER_TaskIdentifier wait_task; + +static struct GNUNET_ATS_SchedulingHandle *ats; + +static int ret; + +static void +end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + die_task = GNUNET_SCHEDULER_NO_TASK; + if (ats != NULL) + { + GNUNET_ATS_scheduling_done (ats); + ats = NULL; + } + ret = 1; +} + +static void +end_badly_now () +{ + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); +} + +static void +delay (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown ATS\n"); + GNUNET_ATS_scheduling_done (ats); + ats = NULL; + if (die_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; + } + ret = 0; +} + +static void +address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, + struct Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) +{ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received address without asking for it!\n"); + end_badly_now (); +} + + +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + ret = 1; + die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing ATS\n"); + ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); + if (ats == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to initialize ATS\n"); + end_badly_now (); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for %llu sec\n", (long long unsigned int) DELAY.rel_value); + wait_task = GNUNET_SCHEDULER_add_delayed (DELAY, &delay, NULL); +} + + +int +main (int argc, char *argv[]) +{ + if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling", + "test_ats_api.conf", + &run, NULL)) + return 1; + return ret; +} + +/* end of file test_ats_api_scheduling.c */ -- 2.25.1