2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats/test_ats_api_scheduling_init.c
22 * @brief test automatic transport selection scheduling API init/shutdown
23 * @author Christian Grothoff
24 * @author Matthias Wachs
28 #include "gnunet_ats_service.h"
29 #include "gnunet_testing_lib.h"
32 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
33 #define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
35 static GNUNET_SCHEDULER_TaskIdentifier die_task;
36 static GNUNET_SCHEDULER_TaskIdentifier wait_task;
38 static struct GNUNET_ATS_SchedulingHandle *ats;
43 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
45 die_task = GNUNET_SCHEDULER_NO_TASK;
46 if (GNUNET_SCHEDULER_NO_TASK != wait_task)
48 GNUNET_SCHEDULER_cancel (wait_task);
49 wait_task = GNUNET_SCHEDULER_NO_TASK;
53 GNUNET_ATS_scheduling_done (ats);
62 if (die_task != GNUNET_SCHEDULER_NO_TASK)
64 GNUNET_SCHEDULER_cancel (die_task);
65 die_task = GNUNET_SCHEDULER_NO_TASK;
67 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
71 delay (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
73 static int v_delay = 5;
78 wait_task = GNUNET_SCHEDULER_NO_TASK;
79 wait_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &delay, NULL);
85 fprintf (stderr,"\n");
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown ATS\n");
87 GNUNET_ATS_scheduling_done (ats);
89 if (die_task != GNUNET_SCHEDULER_NO_TASK)
91 GNUNET_SCHEDULER_cancel (die_task);
92 die_task = GNUNET_SCHEDULER_NO_TASK;
98 address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
99 struct Session *session,
100 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
101 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
102 const struct GNUNET_ATS_Information *ats,
105 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received address without asking for it!\n");
112 const struct GNUNET_CONFIGURATION_Handle *cfg,
113 struct GNUNET_TESTING_Peer *peer)
116 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing ATS\n");
119 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to initialize ATS\n");
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for %llu sec\n", (long long unsigned int) DELAY.rel_value);
127 wait_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &delay, NULL);
132 main (int argc, char *argv[])
134 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling_init",
141 /* end of file test_ats_api_scheduling_init.c */