aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-12-05 13:04:50 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-12-05 13:04:50 +0000
commit0b9510a7354279a4f85c13ce204474404daa470a (patch)
tree60525957f272c11e89f32d3d599648c997477e60
parent4f3d082005c620fd99f53a8152c37f2589028ba0 (diff)
downloadgnunet-0b9510a7354279a4f85c13ce204474404daa470a.tar.gz
gnunet-0b9510a7354279a4f85c13ce204474404daa470a.zip
- init test
-rw-r--r--src/ats/Makefile.am11
-rw-r--r--src/ats/test_ats_api_scheduling_init.c123
2 files changed, 134 insertions, 0 deletions
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 = \
58 libgnunetats.la 58 libgnunetats.la
59 59
60check_PROGRAMS = \ 60check_PROGRAMS = \
61 test_ats_api_scheduling_init \
61 test_ats_api_scheduling_add_address \ 62 test_ats_api_scheduling_add_address \
62 test_ats_api_scheduling \ 63 test_ats_api_scheduling \
63 test_ats_api_scheduling_destroy_address \ 64 test_ats_api_scheduling_destroy_address \
@@ -100,6 +101,16 @@ perf_ats_mlp_LDADD = \
100 $(top_builddir)/src/statistics/libgnunetstatistics.la 101 $(top_builddir)/src/statistics/libgnunetstatistics.la
101endif 102endif
102 103
104
105test_ats_api_scheduling_init_SOURCES = \
106 test_ats_api_scheduling_init.c
107test_ats_api_scheduling_init_LDADD = \
108 $(top_builddir)/src/util/libgnunetutil.la \
109 $(top_builddir)/src/testing/libgnunettesting.la \
110 $(top_builddir)/src/ats/libgnunetats.la
111
112
113
103test_ats_api_scheduling_SOURCES = \ 114test_ats_api_scheduling_SOURCES = \
104 test_ats_api_scheduling.c 115 test_ats_api_scheduling.c
105test_ats_api_scheduling_LDADD = \ 116test_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 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20/**
21 * @file ats/test_ats_api_scheduling.c
22 * @brief test automatic transport selection scheduling API init/shutdown
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25 *
26 */
27#include "platform.h"
28#include "gnunet_ats_service.h"
29#include "gnunet_testing_lib-new.h"
30#include "ats.h"
31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
33#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
34
35static GNUNET_SCHEDULER_TaskIdentifier die_task;
36static GNUNET_SCHEDULER_TaskIdentifier wait_task;
37
38static struct GNUNET_ATS_SchedulingHandle *ats;
39
40static int ret;
41
42static void
43end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
44{
45 die_task = GNUNET_SCHEDULER_NO_TASK;
46 if (ats != NULL)
47 {
48 GNUNET_ATS_scheduling_done (ats);
49 ats = NULL;
50 }
51 ret = 1;
52}
53
54static void
55end_badly_now ()
56{
57 if (die_task != GNUNET_SCHEDULER_NO_TASK)
58 {
59 GNUNET_SCHEDULER_cancel (die_task);
60 die_task = GNUNET_SCHEDULER_NO_TASK;
61 }
62 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
63}
64
65static void
66delay (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67{
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown ATS\n");
69 GNUNET_ATS_scheduling_done (ats);
70 ats = NULL;
71 if (die_task != GNUNET_SCHEDULER_NO_TASK)
72 {
73 GNUNET_SCHEDULER_cancel (die_task);
74 die_task = GNUNET_SCHEDULER_NO_TASK;
75 }
76 ret = 0;
77}
78
79static void
80address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
81 struct Session *session,
82 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
83 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
84 const struct GNUNET_ATS_Information *ats,
85 uint32_t ats_count)
86{
87 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received address without asking for it!\n");
88 end_badly_now ();
89}
90
91
92static void
93run (void *cls,
94 const struct GNUNET_CONFIGURATION_Handle *cfg,
95 struct GNUNET_TESTING_Peer *peer)
96{
97 ret = 1;
98 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
99
100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing ATS\n");
101 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
102 if (ats == NULL)
103 {
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to initialize ATS\n");
105 end_badly_now ();
106 return;
107 }
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Waiting for %llu sec\n", (long long unsigned int) DELAY.rel_value);
109 wait_task = GNUNET_SCHEDULER_add_delayed (DELAY, &delay, NULL);
110}
111
112
113int
114main (int argc, char *argv[])
115{
116 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling",
117 "test_ats_api.conf",
118 &run, NULL))
119 return 1;
120 return ret;
121}
122
123/* end of file test_ats_api_scheduling.c */