diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-09-26 11:33:37 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-09-26 11:33:37 +0000 |
commit | 1cc4422321ddec369d7ff8843ca4fbec8d61e68f (patch) | |
tree | 6038c34a50aba3456c0184f0b8d64eb04bc1aeef /src | |
parent | b718a4eeff0d33abbaf35633f8ab82d82842139c (diff) | |
download | gnunet-1cc4422321ddec369d7ff8843ca4fbec8d61e68f.tar.gz gnunet-1cc4422321ddec369d7ff8843ca4fbec8d61e68f.zip |
new solver specific test
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/Makefile.am | 10 | ||||
-rw-r--r-- | src/ats/test_ats_solver_add_address.c | 164 | ||||
-rw-r--r-- | src/ats/test_ats_solver_default.conf | 7 | ||||
-rw-r--r-- | src/ats/test_ats_solver_mlp.conf | 2 | ||||
-rw-r--r-- | src/ats/test_ats_solver_proportional.conf | 2 | ||||
-rw-r--r-- | src/ats/test_ats_solver_ril.conf | 2 |
6 files changed, 182 insertions, 5 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index b6032aede..8883baf87 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -224,7 +224,8 @@ test_ats_api_performance_monitor_initial_callback_LDADD = \ | |||
224 | 224 | ||
225 | # solver tests | 225 | # solver tests |
226 | test_ats_solver_add_address_proportional_SOURCES = \ | 226 | test_ats_solver_add_address_proportional_SOURCES = \ |
227 | test_ats_solver_add_address.c | 227 | test_ats_solver_add_address.c \ |
228 | test_ats_api_common.c test_ats_api_common.h | ||
228 | test_ats_solver_add_address_proportional_LDADD = \ | 229 | test_ats_solver_add_address_proportional_LDADD = \ |
229 | $(top_builddir)/src/util/libgnunetutil.la \ | 230 | $(top_builddir)/src/util/libgnunetutil.la \ |
230 | $(top_builddir)/src/testing/libgnunettesting.la \ | 231 | $(top_builddir)/src/testing/libgnunettesting.la \ |
@@ -234,7 +235,8 @@ test_ats_solver_add_address_proportional_LDADD = \ | |||
234 | 235 | ||
235 | if HAVE_LIBGLPK | 236 | if HAVE_LIBGLPK |
236 | test_ats_solver_add_address_mlp_SOURCES = \ | 237 | test_ats_solver_add_address_mlp_SOURCES = \ |
237 | test_ats_solver_add_address.c | 238 | test_ats_solver_add_address.c \ |
239 | test_ats_api_common.c test_ats_api_common.h | ||
238 | test_ats_solver_add_address_mlp_LDADD = \ | 240 | test_ats_solver_add_address_mlp_LDADD = \ |
239 | $(top_builddir)/src/util/libgnunetutil.la \ | 241 | $(top_builddir)/src/util/libgnunetutil.la \ |
240 | $(top_builddir)/src/testing/libgnunettesting.la \ | 242 | $(top_builddir)/src/testing/libgnunettesting.la \ |
@@ -244,7 +246,8 @@ test_ats_solver_add_address_mlp_LDADD = \ | |||
244 | endif | 246 | endif |
245 | 247 | ||
246 | test_ats_solver_add_address_ril_SOURCES = \ | 248 | test_ats_solver_add_address_ril_SOURCES = \ |
247 | test_ats_solver_add_address.c | 249 | test_ats_solver_add_address.c \ |
250 | test_ats_api_common.c test_ats_api_common.h | ||
248 | test_ats_solver_add_address_ril_LDADD = \ | 251 | test_ats_solver_add_address_ril_LDADD = \ |
249 | $(top_builddir)/src/util/libgnunetutil.la \ | 252 | $(top_builddir)/src/util/libgnunetutil.la \ |
250 | $(top_builddir)/src/testing/libgnunettesting.la \ | 253 | $(top_builddir)/src/testing/libgnunettesting.la \ |
@@ -375,6 +378,7 @@ EXTRA_DIST = \ | |||
375 | ats.h \ | 378 | ats.h \ |
376 | test_ats_api.conf \ | 379 | test_ats_api.conf \ |
377 | test_ats_mlp.conf \ | 380 | test_ats_mlp.conf \ |
381 | test_ats_solver_default.conf \ | ||
378 | test_ats_solver_proportional.conf \ | 382 | test_ats_solver_proportional.conf \ |
379 | test_ats_solver_mlp.conf \ | 383 | test_ats_solver_mlp.conf \ |
380 | test_ats_solver_ril.conf | 384 | test_ats_solver_ril.conf |
diff --git a/src/ats/test_ats_solver_add_address.c b/src/ats/test_ats_solver_add_address.c index 34d20398b..3dd88fd60 100644 --- a/src/ats/test_ats_solver_add_address.c +++ b/src/ats/test_ats_solver_add_address.c | |||
@@ -33,20 +33,180 @@ | |||
33 | #include "gnunet_util_lib.h" | 33 | #include "gnunet_util_lib.h" |
34 | #include "gnunet_testbed_service.h" | 34 | #include "gnunet_testbed_service.h" |
35 | #include "gnunet_ats_service.h" | 35 | #include "gnunet_ats_service.h" |
36 | #include "test_ats_api_common.h" | ||
36 | 37 | ||
37 | /** | 38 | /** |
38 | * Result | 39 | * Timeout task |
40 | */ | ||
41 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
42 | |||
43 | /** | ||
44 | * Statistics handle | ||
45 | */ | ||
46 | struct GNUNET_STATISTICS_Handle *stats; | ||
47 | |||
48 | /** | ||
49 | * Scheduling handle | ||
50 | */ | ||
51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
52 | |||
53 | /** | ||
54 | * Return value | ||
39 | */ | 55 | */ |
40 | static int ret; | 56 | static int ret; |
41 | 57 | ||
58 | /** | ||
59 | * Test address | ||
60 | */ | ||
61 | static struct Test_Address test_addr; | ||
62 | |||
63 | /** | ||
64 | * Test peer | ||
65 | */ | ||
66 | static struct PeerContext p; | ||
67 | |||
68 | /** | ||
69 | * HELLO address | ||
70 | */ | ||
71 | struct GNUNET_HELLO_Address test_hello_address; | ||
72 | |||
73 | /** | ||
74 | * Session | ||
75 | */ | ||
76 | static void *test_session; | ||
77 | |||
78 | /** | ||
79 | * Test ats info | ||
80 | */ | ||
81 | struct GNUNET_ATS_Information test_ats_info[2]; | ||
82 | |||
83 | /** | ||
84 | * Test ats count | ||
85 | */ | ||
86 | uint32_t test_ats_count; | ||
87 | |||
88 | |||
89 | static int | ||
90 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, | ||
91 | int is_persistent); | ||
92 | |||
93 | static void | ||
94 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
95 | { | ||
96 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
97 | |||
98 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
99 | { | ||
100 | GNUNET_SCHEDULER_cancel (die_task); | ||
101 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
102 | } | ||
103 | |||
104 | if (NULL != sched_ats) | ||
105 | { | ||
106 | GNUNET_ATS_scheduling_done (sched_ats); | ||
107 | sched_ats = NULL; | ||
108 | } | ||
109 | |||
110 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
111 | if (NULL != stats) | ||
112 | { | ||
113 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
114 | stats = NULL; | ||
115 | } | ||
116 | |||
117 | free_test_address (&test_addr); | ||
118 | |||
119 | ret = 0; | ||
120 | } | ||
121 | |||
122 | |||
123 | static void | ||
124 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
125 | { | ||
126 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
127 | end ( NULL, NULL); | ||
128 | ret = GNUNET_SYSERR; | ||
129 | } | ||
130 | |||
131 | static void | ||
132 | address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | ||
133 | struct Session *session, | ||
134 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
135 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
136 | const struct GNUNET_ATS_Information *atsi, | ||
137 | uint32_t ats_count) | ||
138 | { | ||
139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
140 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
141 | return; | ||
142 | } | ||
143 | |||
144 | |||
145 | static int | ||
146 | stat_cb(void *cls, const char *subsystem, | ||
147 | const char *name, uint64_t value, | ||
148 | int is_persistent) | ||
149 | { | ||
150 | |||
151 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
152 | subsystem,name, value); | ||
153 | if (1 == value) | ||
154 | { | ||
155 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
156 | } | ||
157 | return GNUNET_OK; | ||
158 | } | ||
42 | 159 | ||
43 | static void | 160 | static void |
44 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | 161 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, |
45 | struct GNUNET_TESTING_Peer *peer) | 162 | struct GNUNET_TESTING_Peer *peer) |
46 | { | 163 | { |
47 | ret = 0; | 164 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
165 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | ||
166 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
167 | |||
168 | |||
169 | /* Connect to ATS scheduling */ | ||
170 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | ||
171 | if (sched_ats == NULL) | ||
172 | { | ||
173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
174 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
175 | return; | ||
176 | } | ||
177 | |||
178 | /* Set up peer */ | ||
179 | if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p.id.hashPubKey)) | ||
180 | { | ||
181 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
182 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
183 | return; | ||
184 | } | ||
185 | GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p.id))); | ||
186 | |||
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
188 | GNUNET_i2s_full(&p.id)); | ||
189 | |||
190 | /* Prepare ATS Information */ | ||
191 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
192 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
193 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
194 | test_ats_info[1].value = htonl(1); | ||
195 | test_ats_count = 2; | ||
196 | |||
197 | /* Adding address without session */ | ||
198 | test_session = NULL; | ||
199 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
200 | test_hello_address.peer = p.id; | ||
201 | test_hello_address.transport_name = test_addr.plugin; | ||
202 | test_hello_address.address = test_addr.addr; | ||
203 | test_hello_address.address_length = test_addr.addr_len; | ||
204 | |||
205 | /* Adding address */ | ||
206 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); | ||
48 | } | 207 | } |
49 | 208 | ||
209 | |||
50 | int | 210 | int |
51 | main (int argc, char *argv[]) | 211 | main (int argc, char *argv[]) |
52 | { | 212 | { |
diff --git a/src/ats/test_ats_solver_default.conf b/src/ats/test_ats_solver_default.conf new file mode 100644 index 000000000..46187d163 --- /dev/null +++ b/src/ats/test_ats_solver_default.conf | |||
@@ -0,0 +1,7 @@ | |||
1 | [arm] | ||
2 | PORT = 12001 | ||
3 | DEFAULTSERVICES = ats | ||
4 | UNIXPATH = /tmp/test-ats-scheduling-arm.sock | ||
5 | |||
6 | [transport] | ||
7 | AUTOSTART = NO | ||
diff --git a/src/ats/test_ats_solver_mlp.conf b/src/ats/test_ats_solver_mlp.conf index a640e942d..64dadefbf 100644 --- a/src/ats/test_ats_solver_mlp.conf +++ b/src/ats/test_ats_solver_mlp.conf | |||
@@ -1,3 +1,5 @@ | |||
1 | @INLINE@ test_ats_solver_default.conf | ||
2 | |||
1 | [ats] | 3 | [ats] |
2 | #PREFIX = valgrind --leak-check=yes | 4 | #PREFIX = valgrind --leak-check=yes |
3 | MODE = MLP | 5 | MODE = MLP |
diff --git a/src/ats/test_ats_solver_proportional.conf b/src/ats/test_ats_solver_proportional.conf index 1b5914434..407dbcb1c 100644 --- a/src/ats/test_ats_solver_proportional.conf +++ b/src/ats/test_ats_solver_proportional.conf | |||
@@ -1,3 +1,5 @@ | |||
1 | @INLINE@ test_ats_solver_default.conf | ||
2 | |||
1 | [ats] | 3 | [ats] |
2 | #PREFIX = valgrind --leak-check=yes | 4 | #PREFIX = valgrind --leak-check=yes |
3 | MODE = PROPORTIONAL | 5 | MODE = PROPORTIONAL |
diff --git a/src/ats/test_ats_solver_ril.conf b/src/ats/test_ats_solver_ril.conf index b3f5d9b67..74421728e 100644 --- a/src/ats/test_ats_solver_ril.conf +++ b/src/ats/test_ats_solver_ril.conf | |||
@@ -1,3 +1,5 @@ | |||
1 | @INLINE@ test_ats_solver_default.conf | ||
2 | |||
1 | [ats] | 3 | [ats] |
2 | #PREFIX = valgrind --leak-check=yes | 4 | #PREFIX = valgrind --leak-check=yes |
3 | MODE = RIL | 5 | MODE = RIL |