diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-06-19 08:04:04 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-06-19 08:04:04 +0000 |
commit | 03cd34c33f455c8e87136b1c469f092837aa7948 (patch) | |
tree | 0dcef8748aacde127dca3ea0285f450e6eb36971 /src/ats | |
parent | ebd2cf0e07c0dca2cc81282e8d7d1eb2a9dcffb0 (diff) | |
download | gnunet-03cd34c33f455c8e87136b1c469f092837aa7948.tar.gz gnunet-03cd34c33f455c8e87136b1c469f092837aa7948.zip |
new test deleting a session using the plugin_env_session_end way (addr=NULL,addr_length=0) + session
this fails atm and is a bug
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/Makefile.am | 7 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_destroy_session.c | 240 |
2 files changed, 247 insertions, 0 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index b8c35ab9e..889650bca 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -69,6 +69,7 @@ check_PROGRAMS = \ | |||
69 | test_ats_api_scheduling_add_address \ | 69 | test_ats_api_scheduling_add_address \ |
70 | test_ats_api_scheduling \ | 70 | test_ats_api_scheduling \ |
71 | test_ats_api_scheduling_destroy_address \ | 71 | test_ats_api_scheduling_destroy_address \ |
72 | test_ats_api_scheduling_destroy_session \ | ||
72 | test_ats_api_reset_backoff \ | 73 | test_ats_api_reset_backoff \ |
73 | $(GN_MLP_TEST) \ | 74 | $(GN_MLP_TEST) \ |
74 | $(GN_MLP_TEST_AVG) \ | 75 | $(GN_MLP_TEST_AVG) \ |
@@ -130,6 +131,12 @@ test_ats_api_scheduling_destroy_address_LDADD = \ | |||
130 | $(top_builddir)/src/util/libgnunetutil.la \ | 131 | $(top_builddir)/src/util/libgnunetutil.la \ |
131 | $(top_builddir)/src/ats/libgnunetats.la | 132 | $(top_builddir)/src/ats/libgnunetats.la |
132 | 133 | ||
134 | test_ats_api_scheduling_destroy_session_SOURCES = \ | ||
135 | test_ats_api_scheduling_destroy_session.c | ||
136 | test_ats_api_scheduling_destroy_session_LDADD = \ | ||
137 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
138 | $(top_builddir)/src/ats/libgnunetats.la | ||
139 | |||
133 | #test_ats_api_scheduling_get_type_SOURCES = \ | 140 | #test_ats_api_scheduling_get_type_SOURCES = \ |
134 | # test_ats_api_scheduling_get_type.c | 141 | # test_ats_api_scheduling_get_type.c |
135 | #test_ats_api_scheduling_get_type_LDADD = \ | 142 | #test_ats_api_scheduling_get_type_LDADD = \ |
diff --git a/src/ats/test_ats_api_scheduling_destroy_session.c b/src/ats/test_ats_api_scheduling_destroy_session.c new file mode 100644 index 000000000..7d223a71e --- /dev/null +++ b/src/ats/test_ats_api_scheduling_destroy_session.c | |||
@@ -0,0 +1,240 @@ | |||
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_destroy_session.c | ||
22 | * @brief test destroying sessions with unknown address (address NULL, length 0) | ||
23 | * in automatic transport selection scheduling API | ||
24 | * @author Christian Grothoff | ||
25 | * @author Matthias Wachs | ||
26 | * | ||
27 | */ | ||
28 | #include "platform.h" | ||
29 | #include "gnunet_ats_service.h" | ||
30 | #include "ats.h" | ||
31 | |||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
33 | |||
34 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
35 | |||
36 | static struct GNUNET_ATS_SchedulingHandle *ats; | ||
37 | |||
38 | struct GNUNET_OS_Process *arm_proc; | ||
39 | |||
40 | |||
41 | |||
42 | static int ret; | ||
43 | static int stage; | ||
44 | |||
45 | struct Address | ||
46 | { | ||
47 | char *plugin; | ||
48 | size_t plugin_len; | ||
49 | |||
50 | void *addr; | ||
51 | size_t addr_len; | ||
52 | |||
53 | struct GNUNET_ATS_Information *ats; | ||
54 | int ats_count; | ||
55 | |||
56 | void *session; | ||
57 | }; | ||
58 | |||
59 | struct PeerContext | ||
60 | { | ||
61 | struct GNUNET_PeerIdentity id; | ||
62 | |||
63 | struct Address *addr; | ||
64 | }; | ||
65 | |||
66 | struct Address test_addr; | ||
67 | struct PeerContext p; | ||
68 | struct GNUNET_ATS_Information atsi; | ||
69 | struct GNUNET_HELLO_Address hello_address; | ||
70 | |||
71 | static void | ||
72 | stop_arm () | ||
73 | { | ||
74 | if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM)) | ||
75 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
76 | GNUNET_OS_process_wait (arm_proc); | ||
77 | GNUNET_OS_process_destroy (arm_proc); | ||
78 | arm_proc = NULL; | ||
79 | } | ||
80 | |||
81 | |||
82 | static void | ||
83 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
84 | { | ||
85 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
86 | if (ats != NULL) | ||
87 | GNUNET_ATS_scheduling_done (ats); | ||
88 | |||
89 | ret = GNUNET_SYSERR; | ||
90 | |||
91 | stop_arm (); | ||
92 | } | ||
93 | |||
94 | |||
95 | static void | ||
96 | end () | ||
97 | { | ||
98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
99 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
100 | { | ||
101 | GNUNET_SCHEDULER_cancel (die_task); | ||
102 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
103 | } | ||
104 | |||
105 | GNUNET_ATS_scheduling_done (ats); | ||
106 | |||
107 | if (2 == stage) | ||
108 | ret = 0; | ||
109 | else | ||
110 | { | ||
111 | GNUNET_break (0); | ||
112 | ret = 1; | ||
113 | } | ||
114 | |||
115 | stop_arm (); | ||
116 | } | ||
117 | |||
118 | |||
119 | static void | ||
120 | address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | ||
121 | struct Session *session, | ||
122 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
123 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
124 | const struct GNUNET_ATS_Information *atsi, | ||
125 | uint32_t ats_count) | ||
126 | { | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage %u: ATS suggests address `%s' session %p\n", | ||
128 | stage, GNUNET_i2s (&address->peer), session); | ||
129 | GNUNET_ATS_reset_backoff(ats, &address->peer); | ||
130 | |||
131 | GNUNET_assert (0 == | ||
132 | memcmp (&address->peer, &p.id, | ||
133 | sizeof (struct GNUNET_PeerIdentity))); | ||
134 | GNUNET_assert (0 == strcmp (address->transport_name, test_addr.plugin)); | ||
135 | GNUNET_assert (address->address_length == test_addr.addr_len); | ||
136 | GNUNET_assert (0 == | ||
137 | memcmp (address->address, test_addr.plugin, | ||
138 | address->address_length)); | ||
139 | GNUNET_assert (test_addr.session == session); | ||
140 | |||
141 | if (0 == stage) | ||
142 | { | ||
143 | /* Delete session without the address */ | ||
144 | struct GNUNET_HELLO_Address hello_address_2; | ||
145 | hello_address_2.peer = p.id; | ||
146 | hello_address_2.transport_name = test_addr.plugin; | ||
147 | hello_address_2.address = NULL; | ||
148 | hello_address_2.address_length = 0; | ||
149 | |||
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
151 | "Stage %u: Destroying address for peer `%s' address %p length %u session %p\n", | ||
152 | stage, | ||
153 | GNUNET_i2s (&hello_address_2.peer), | ||
154 | hello_address_2.address, | ||
155 | hello_address_2.address_length, | ||
156 | session); | ||
157 | |||
158 | GNUNET_ATS_address_destroyed (ats, &hello_address_2, test_addr.session); | ||
159 | test_addr.session = NULL; | ||
160 | GNUNET_ATS_suggest_address (ats, &p.id); | ||
161 | } | ||
162 | if (1 == stage) | ||
163 | { | ||
164 | /* End */ | ||
165 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
166 | } | ||
167 | stage++; | ||
168 | } | ||
169 | |||
170 | void | ||
171 | start_arm (const char *cfgname) | ||
172 | { | ||
173 | arm_proc = | ||
174 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
175 | "gnunet-service-arm", | ||
176 | "-c", cfgname, NULL); | ||
177 | } | ||
178 | |||
179 | static void | ||
180 | check (void *cls, char *const *args, const char *cfgfile, | ||
181 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
182 | { | ||
183 | ret = GNUNET_SYSERR; | ||
184 | |||
185 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
186 | start_arm (cfgfile); | ||
187 | |||
188 | ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
189 | |||
190 | if (ats == NULL) | ||
191 | { | ||
192 | ret = GNUNET_SYSERR; | ||
193 | end (); | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | /* set up peer */ | ||
198 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, | ||
199 | &p.id.hashPubKey); | ||
200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
201 | GNUNET_i2s (&p.id)); | ||
202 | |||
203 | test_addr.plugin = "test"; | ||
204 | test_addr.session = &test_addr; | ||
205 | test_addr.addr = GNUNET_strdup ("test"); | ||
206 | test_addr.addr_len = 4; | ||
207 | |||
208 | /* Adding address with session */ | ||
209 | hello_address.peer = p.id; | ||
210 | hello_address.transport_name = test_addr.plugin; | ||
211 | hello_address.address = test_addr.addr; | ||
212 | hello_address.address_length = test_addr.addr_len; | ||
213 | GNUNET_ATS_address_add (ats, &hello_address, test_addr.session, NULL, 0); | ||
214 | |||
215 | GNUNET_ATS_suggest_address (ats, &p.id); | ||
216 | } | ||
217 | |||
218 | int | ||
219 | main (int argc, char *argv[]) | ||
220 | { | ||
221 | static char *const argv2[] = { "test_ats_api_scheduling_destroy_session", | ||
222 | "-c", | ||
223 | "test_ats_api.conf", | ||
224 | "-L", "WARNING", | ||
225 | NULL | ||
226 | }; | ||
227 | |||
228 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
229 | GNUNET_GETOPT_OPTION_END | ||
230 | }; | ||
231 | |||
232 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
233 | "test_ats_api_scheduling_destroy_session", "nohelp", options, &check, | ||
234 | NULL); | ||
235 | |||
236 | |||
237 | return ret; | ||
238 | } | ||
239 | |||
240 | /* end of file test_ats_api_scheduling_destroy_session.c */ | ||