aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-25 15:57:43 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-25 15:57:43 +0000
commit75ff303510da8123bc7794c9d6e8fda51b73a7db (patch)
tree910e6cb442e6efc57e23965fd27d0c9a863cf6d9
parent61b801d9949076ecac3f472b2fab58377a3d33a7 (diff)
downloadgnunet-75ff303510da8123bc7794c9d6e8fda51b73a7db.tar.gz
gnunet-75ff303510da8123bc7794c9d6e8fda51b73a7db.zip
-removing useless/dead/redundant tests, adjusting other tests to fit current API
-rw-r--r--src/ats/Makefile.am9
-rw-r--r--src/ats/gnunet-service-ats_addresses.c28
-rw-r--r--src/ats/test_ats_api_scheduling_add_address_duplicate.c75
-rw-r--r--src/ats/test_ats_api_scheduling_add_address_inbound.c27
-rw-r--r--src/ats/test_ats_api_scheduling_add_session.c34
-rw-r--r--src/ats/test_ats_api_scheduling_destroy_session.c246
-rw-r--r--src/ats/test_ats_solver_add_address_and_request.c37
7 files changed, 132 insertions, 324 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index abe61d37e..a165cebb7 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -117,7 +117,6 @@ TESTING_TESTS = \
117 test_ats_api_scheduling_add_address_inbound \ 117 test_ats_api_scheduling_add_address_inbound \
118 test_ats_api_scheduling_destroy_address \ 118 test_ats_api_scheduling_destroy_address \
119 test_ats_api_scheduling_add_session \ 119 test_ats_api_scheduling_add_session \
120 test_ats_api_scheduling_destroy_session \
121 test_ats_api_delayed_service_scheduling_add_address \ 120 test_ats_api_delayed_service_scheduling_add_address \
122 test_ats_api_performance_list_all_addresses \ 121 test_ats_api_performance_list_all_addresses \
123 test_ats_api_delayed_service_performance_list_all_addresses \ 122 test_ats_api_delayed_service_performance_list_all_addresses \
@@ -224,14 +223,6 @@ test_ats_api_scheduling_add_session_LDADD = \
224 libgnunetats.la \ 223 libgnunetats.la \
225 $(top_builddir)/src/statistics/libgnunetstatistics.la 224 $(top_builddir)/src/statistics/libgnunetstatistics.la
226 225
227test_ats_api_scheduling_destroy_session_SOURCES = \
228 test_ats_api_scheduling_destroy_session.c test_ats_api_common.c
229test_ats_api_scheduling_destroy_session_LDADD = \
230 $(top_builddir)/src/util/libgnunetutil.la \
231 $(top_builddir)/src/testing/libgnunettesting.la \
232 libgnunetats.la \
233 $(top_builddir)/src/statistics/libgnunetstatistics.la
234
235# performance API tests 226# performance API tests
236 227
237test_ats_api_performance_list_all_addresses_SOURCES = \ 228test_ats_api_performance_list_all_addresses_SOURCES = \
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index e30e86539..c2010e8d2 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -785,21 +785,25 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
785 uint32_t previous_session; 785 uint32_t previous_session;
786 int c1; 786 int c1;
787 787
788 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
789 "Received `%s' for peer `%s'\n", 789 "Received `%s' for peer `%s'\n",
790 "ADDRESS ADD", 790 "ADDRESS ADD",
791 GNUNET_i2s (peer)); 791 GNUNET_i2s (peer));
792
793 if (GNUNET_NO == running) 792 if (GNUNET_NO == running)
793 {
794 GNUNET_break (0);
794 return; 795 return;
795 796 }
796 GNUNET_assert(NULL != addresses); 797 new_address = create_address (peer,
797 798 plugin_name,
798 new_address = create_address (peer, plugin_name, 799 plugin_addr,
799 plugin_addr, plugin_addr_len, 800 plugin_addr_len,
800 local_address_info, session_id); 801 local_address_info,
802 session_id);
801 atsi_delta = NULL; 803 atsi_delta = NULL;
802 disassemble_ats_information (new_address, atsi, atsi_count, &atsi_delta, 804 disassemble_ats_information (new_address,
805 atsi, atsi_count,
806 &atsi_delta,
803 &atsi_delta_count); 807 &atsi_delta_count);
804 GNUNET_free_non_null (atsi_delta); 808 GNUNET_free_non_null (atsi_delta);
805 addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE); 809 addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE);
diff --git a/src/ats/test_ats_api_scheduling_add_address_duplicate.c b/src/ats/test_ats_api_scheduling_add_address_duplicate.c
index fc3890f6c..b0d02727f 100644
--- a/src/ats/test_ats_api_scheduling_add_address_duplicate.c
+++ b/src/ats/test_ats_api_scheduling_add_address_duplicate.c
@@ -39,7 +39,7 @@ static struct GNUNET_SCHEDULER_Task * wait_task;
39/** 39/**
40 * Statistics handle 40 * Statistics handle
41 */ 41 */
42struct GNUNET_STATISTICS_Handle *stats; 42static struct GNUNET_STATISTICS_Handle *stats;
43 43
44/** 44/**
45 * Scheduling handle 45 * Scheduling handle
@@ -64,7 +64,7 @@ static struct PeerContext p;
64/** 64/**
65 * HELLO address 65 * HELLO address
66 */ 66 */
67struct GNUNET_HELLO_Address test_hello_address; 67static struct GNUNET_HELLO_Address test_hello_address;
68 68
69/** 69/**
70 * Session 70 * Session
@@ -74,25 +74,30 @@ static void *test_session;
74/** 74/**
75 * Test ats info 75 * Test ats info
76 */ 76 */
77struct GNUNET_ATS_Information test_ats_info[2]; 77static struct GNUNET_ATS_Information test_ats_info[2];
78 78
79/** 79/**
80 * Test ats count 80 * Test ats count
81 */ 81 */
82uint32_t test_ats_count; 82static uint32_t test_ats_count;
83 83
84 84
85static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 85static void
86static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 86end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
87
88
89static void
90end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
91
87 92
88static int 93static int
89stat_cb(void *cls, const char *subsystem, 94stat_cb (void *cls, const char *subsystem,
90 const char *name, uint64_t value, 95 const char *name, uint64_t value,
91 int is_persistent) 96 int is_persistent)
92{ 97{
93 98 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
94 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", 99 "ATS statistics: `%s' `%s' %llu\n",
95 subsystem,name, value); 100 subsystem,name, value);
96 if (1 < value) 101 if (1 < value)
97 { 102 {
98 if (NULL != wait_task) 103 if (NULL != wait_task)
@@ -102,7 +107,8 @@ stat_cb(void *cls, const char *subsystem,
102 if (1 == value) 107 if (1 == value)
103 { 108 {
104 if (NULL == wait_task) 109 if (NULL == wait_task)
105 wait_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); 110 wait_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
111 &end, NULL);
106 } 112 }
107 return GNUNET_OK; 113 return GNUNET_OK;
108} 114}
@@ -111,15 +117,15 @@ stat_cb(void *cls, const char *subsystem,
111static void 117static void
112end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 118end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
113{ 119{
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Shutting down\n");
115 wait_task = NULL; 122 wait_task = NULL;
116 123
117 if (die_task != NULL) 124 if (NULL != die_task)
118 { 125 {
119 GNUNET_SCHEDULER_cancel (die_task); 126 GNUNET_SCHEDULER_cancel (die_task);
120 die_task = NULL; 127 die_task = NULL;
121 } 128 }
122
123 if (NULL != sched_ats) 129 if (NULL != sched_ats)
124 { 130 {
125 GNUNET_ATS_scheduling_done (sched_ats); 131 GNUNET_ATS_scheduling_done (sched_ats);
@@ -138,6 +144,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
138 ret = 0; 144 ret = 0;
139} 145}
140 146
147
141static void 148static void
142end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 149end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
143{ 150{
@@ -155,16 +162,21 @@ address_suggest_cb (void *cls,
155 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 162 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
156 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 163 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
157{ 164{
158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); 165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
166 "Did not expect suggestion callback!\n");
159 GNUNET_SCHEDULER_add_now (&end_badly, NULL); 167 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
160} 168}
161 169
162 170
163static int 171static int
164dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, 172dummy_stat (void *cls,
173 const char *subsystem,
174 const char *name,
175 uint64_t value,
165 int is_persistent) 176 int is_persistent)
166{ 177{
167 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", 178 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
179 "Got dummy stat %s%s:%s = %llu\n",
168 is_persistent ? "!" : " ", subsystem, name, value); 180 is_persistent ? "!" : " ", subsystem, name, value);
169 return GNUNET_OK; 181 return GNUNET_OK;
170} 182}
@@ -174,6 +186,7 @@ static void
174got_initial_value (void *cls, int success) 186got_initial_value (void *cls, int success)
175{ 187{
176 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 188 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
189 struct GNUNET_ATS_AddressRecord *ar;
177 190
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); 191 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n");
179 192
@@ -181,14 +194,16 @@ got_initial_value (void *cls, int success)
181 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); 194 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
182 if (sched_ats == NULL) 195 if (sched_ats == NULL)
183 { 196 {
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); 197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
198 "Could not connect to ATS scheduling!\n");
185 GNUNET_SCHEDULER_add_now (&end_badly, NULL); 199 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
186 return; 200 return;
187 } 201 }
188 202
189 /* Set up peer */ 203 /* Set up peer */
190 memset (&p.id, '1', sizeof (p.id)); 204 memset (&p.id, '1', sizeof (p.id));
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", 205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
206 "Created peer `%s'\n",
192 GNUNET_i2s_full(&p.id)); 207 GNUNET_i2s_full(&p.id));
193 208
194 /* Prepare ATS Information */ 209 /* Prepare ATS Information */
@@ -200,17 +215,25 @@ got_initial_value (void *cls, int success)
200 215
201 /* Adding address without session */ 216 /* Adding address without session */
202 test_session = NULL; 217 test_session = NULL;
203 create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); 218 create_test_address (&test_addr, "test",
219 test_session, "test",
220 strlen ("test") + 1);
204 test_hello_address.peer = p.id; 221 test_hello_address.peer = p.id;
205 test_hello_address.transport_name = test_addr.plugin; 222 test_hello_address.transport_name = test_addr.plugin;
206 test_hello_address.address = test_addr.addr; 223 test_hello_address.address = test_addr.addr;
207 test_hello_address.address_length = test_addr.addr_len; 224 test_hello_address.address_length = test_addr.addr_len;
208 225
209 /* Adding address */ 226 /* Adding address */
210 GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); 227 GNUNET_ATS_address_add (sched_ats,
228 &test_hello_address, test_session,
229 test_ats_info, test_ats_count);
211 /* Adding duplicate */ 230 /* Adding duplicate */
212 GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); 231 GNUNET_log_skip (1, GNUNET_NO);
213 232 ar = GNUNET_ATS_address_add (sched_ats,
233 &test_hello_address, test_session,
234 test_ats_info, test_ats_count);
235 GNUNET_log_skip (0, GNUNET_YES);
236 GNUNET_assert (NULL == ar);
214} 237}
215 238
216 239
@@ -222,8 +245,6 @@ run (void *cls,
222 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 245 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
223 stats = GNUNET_STATISTICS_create ("ats", cfg); 246 stats = GNUNET_STATISTICS_create ("ats", cfg);
224 GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); 247 GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL);
225
226
227 GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, 248 GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT,
228 &got_initial_value, &dummy_stat, 249 &got_initial_value, &dummy_stat,
229 GNUNET_CONFIGURATION_dup (cfg)); 250 GNUNET_CONFIGURATION_dup (cfg));
diff --git a/src/ats/test_ats_api_scheduling_add_address_inbound.c b/src/ats/test_ats_api_scheduling_add_address_inbound.c
index 3d0e5b2ca..7f9be45be 100644
--- a/src/ats/test_ats_api_scheduling_add_address_inbound.c
+++ b/src/ats/test_ats_api_scheduling_add_address_inbound.c
@@ -18,7 +18,7 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file ats/test_ats_api_scheduling_add_address.c 21 * @file ats/test_ats_api_scheduling_add_address_inbound.c
22 * @brief adding addresses with scheduling API 22 * @brief adding addresses with scheduling API
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * @author Matthias Wachs 24 * @author Matthias Wachs
@@ -131,6 +131,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
131 ret = 0; 131 ret = 0;
132} 132}
133 133
134
134static void 135static void
135end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 136end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
136{ 137{
@@ -148,7 +149,8 @@ address_suggest_cb (void *cls,
148 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 149 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
149 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 150 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
150{ 151{
151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); 152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
153 "Did not expect suggestion callback!\n");
152 GNUNET_SCHEDULER_add_now (&end_badly, NULL); 154 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
153} 155}
154 156
@@ -188,16 +190,25 @@ got_initial_value (void *cls, int success)
188 test_hello_address.address_length = 0; 190 test_hello_address.address_length = 0;
189 191
190 /* Adding address */ 192 /* Adding address */
191 GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count); 193 GNUNET_ATS_address_add (sched_ats,
192 GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count); 194 &test_hello_address, NULL,
195 test_ats_info, test_ats_count);
193} 196}
194 197
198
195static int 199static int
196dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, 200dummy_stat (void *cls,
201 const char *subsystem,
202 const char *name,
203 uint64_t value,
197 int is_persistent) 204 int is_persistent)
198{ 205{
199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", 206 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
200 is_persistent ? "!" : " ", subsystem, name, value); 207 "Got dummy stat %s%s:%s = %llu\n",
208 is_persistent ? "!" : " ",
209 subsystem,
210 name,
211 value);
201 return GNUNET_OK; 212 return GNUNET_OK;
202} 213}
203 214
@@ -229,4 +240,4 @@ main (int argc, char *argv[])
229 return ret; 240 return ret;
230} 241}
231 242
232/* end of file test_ats_api_scheduling_add_address.c */ 243/* end of file test_ats_api_scheduling_add_address_inbound.c */
diff --git a/src/ats/test_ats_api_scheduling_add_session.c b/src/ats/test_ats_api_scheduling_add_session.c
index 2aac84ee5..5a94f9ba5 100644
--- a/src/ats/test_ats_api_scheduling_add_session.c
+++ b/src/ats/test_ats_api_scheduling_add_session.c
@@ -79,6 +79,11 @@ static struct GNUNET_ATS_Information test_ats_info[2];
79 */ 79 */
80static uint32_t test_ats_count; 80static uint32_t test_ats_count;
81 81
82/**
83 * Address record we will modify with a session later.
84 */
85static struct GNUNET_ATS_AddressRecord *ar;
86
82 87
83static void 88static void
84end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 89end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -89,26 +94,30 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
89 94
90 95
91static int 96static int
92stat_cb(void *cls, const char *subsystem, 97stat_cb (void *cls, const char *subsystem,
93 const char *name, uint64_t value, 98 const char *name, uint64_t value,
94 int is_persistent) 99 int is_persistent)
95{ 100{
96 static int first_stat_cb = GNUNET_YES; 101 static int first_stat_cb = GNUNET_YES;
97 102
98 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", 103 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
99 subsystem,name, value); 104 "ATS statistics: `%s' `%s' %llu\n",
105 subsystem,name, value);
100 if ((GNUNET_YES == first_stat_cb) && (1 == value)) 106 if ((GNUNET_YES == first_stat_cb) && (1 == value))
101 { 107 {
102 GNUNET_ATS_address_add (sched_ats, &test_hello_address, (struct Session *) &test_session, test_ats_info, test_ats_count); 108 GNUNET_ATS_address_add_session (ar,
109 (struct Session *) &test_session);
103 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); 110 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
104 } 111 }
105 if ((GNUNET_NO == first_stat_cb) && (1 == value)) 112 if ((GNUNET_NO == first_stat_cb) && (1 == value))
106 { 113 {
107 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS updated existing address\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
115 "ATS updated existing address\n");
108 } 116 }
109 if (value > 1) 117 if (value > 1)
110 { 118 {
111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS did not update existing address, but added 2nd address!\n"); 119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 "ATS did not update existing address, but added 2nd address!\n");
112 GNUNET_SCHEDULER_add_now (&end_badly, NULL); 121 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
113 } 122 }
114 123
@@ -145,6 +154,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
145 ret = 0; 154 ret = 0;
146} 155}
147 156
157
148static void 158static void
149end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 159end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
150{ 160{
@@ -153,6 +163,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
153 ret = GNUNET_SYSERR; 163 ret = GNUNET_SYSERR;
154} 164}
155 165
166
156static void 167static void
157address_suggest_cb (void *cls, 168address_suggest_cb (void *cls,
158 const struct GNUNET_PeerIdentity *peer, 169 const struct GNUNET_PeerIdentity *peer,
@@ -187,7 +198,8 @@ run (void *cls,
187 198
188 /* Set up peer */ 199 /* Set up peer */
189 memset (&p.id, '1', sizeof (p.id)); 200 memset (&p.id, '1', sizeof (p.id));
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", 201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
202 "Created peer `%s'\n",
191 GNUNET_i2s_full(&p.id)); 203 GNUNET_i2s_full(&p.id));
192 204
193 /* Prepare ATS Information */ 205 /* Prepare ATS Information */
@@ -205,7 +217,9 @@ run (void *cls,
205 test_hello_address.address_length = test_addr.addr_len; 217 test_hello_address.address_length = test_addr.addr_len;
206 218
207 /* Adding address */ 219 /* Adding address */
208 GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count); 220 ar = GNUNET_ATS_address_add (sched_ats,
221 &test_hello_address, NULL,
222 test_ats_info, test_ats_count);
209} 223}
210 224
211 225
diff --git a/src/ats/test_ats_api_scheduling_destroy_session.c b/src/ats/test_ats_api_scheduling_destroy_session.c
deleted file mode 100644
index 2b46bdc88..000000000
--- a/src/ats/test_ats_api_scheduling_destroy_session.c
+++ /dev/null
@@ -1,246 +0,0 @@
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: first add an address with a session,
23 * request the address and compare, delete the session, request and
24 * compare again, delete whole address, request and wait for timeout,
25 * shutdown
26 * @author Christian Grothoff
27 * @author Matthias Wachs
28 *
29 */
30#include "platform.h"
31#include "gnunet_ats_service.h"
32#include "gnunet_testing_lib.h"
33#include "ats.h"
34#include "test_ats_api_common.h"
35
36/**
37 * Timeout task
38 */
39static struct GNUNET_SCHEDULER_Task * die_task;
40
41/**
42 * Statistics handle
43 */
44static struct GNUNET_STATISTICS_Handle *stats;
45
46/**
47 * Scheduling handle
48 */
49static struct GNUNET_ATS_SchedulingHandle *sched_ats;
50
51/**
52 * Return value
53 */
54static int ret;
55
56/**
57 * Test address
58 */
59static struct Test_Address test_addr;
60
61/**
62 * Test peer
63 */
64static struct PeerContext p;
65
66/**
67 * HELLO address
68 */
69static struct GNUNET_HELLO_Address test_hello_address;
70
71/**
72 * Session
73 */
74static void *test_session;
75
76/**
77 * Test ats info
78 */
79static struct GNUNET_ATS_Information test_ats_info[2];
80
81/**
82 * Test ats count
83 */
84static uint32_t test_ats_count;
85
86
87static void
88end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
89
90
91static void
92end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
93
94
95static int
96stat_cb(void *cls, const char *subsystem,
97 const char *name, uint64_t value,
98 int is_persistent)
99{
100 static int first_stat_cb = GNUNET_YES;
101
102 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n",
103 subsystem,name, value);
104 if ((GNUNET_YES == first_stat_cb) && (1 == value))
105 {
106 GNUNET_ATS_address_add (sched_ats, &test_hello_address, (struct Session *) &test_session, test_ats_info, test_ats_count);
107 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
108 }
109 if ((GNUNET_NO == first_stat_cb) && (1 == value))
110 {
111 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS updated existing address\n");
112 }
113 if (value > 1)
114 {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS did not update existing address, but added 2nd address!\n");
116 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
117 }
118
119 return GNUNET_OK;
120}
121
122
123static void
124end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
125{
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
127
128 if (die_task != NULL)
129 {
130 GNUNET_SCHEDULER_cancel (die_task);
131 die_task = NULL;
132 }
133
134 if (NULL != sched_ats)
135 {
136 GNUNET_ATS_scheduling_done (sched_ats);
137 sched_ats = NULL;
138 }
139
140 GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL);
141 if (NULL != stats)
142 {
143 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
144 stats = NULL;
145 }
146
147 free_test_address (&test_addr);
148
149 ret = 0;
150}
151
152static void
153end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
154{
155 die_task = NULL;
156 end ( NULL, NULL);
157 ret = GNUNET_SYSERR;
158}
159
160static void
161address_suggest_cb (void *cls,
162 const struct GNUNET_PeerIdentity *peer,
163 const struct GNUNET_HELLO_Address *address,
164 struct Session *session,
165 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
166 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
167{
168 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n");
169 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
170}
171
172static void
173got_initial_value (void *cls, int success)
174{
175 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
176
177 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n");
178
179 /* Connect to ATS scheduling */
180 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
181 if (sched_ats == NULL)
182 {
183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
184 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
185 return;
186 }
187
188 /* Set up peer */
189 memset (&p.id, '1', sizeof (p.id));
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 create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1);
199 test_hello_address.peer = p.id;
200 test_hello_address.transport_name = test_addr.plugin;
201 test_hello_address.address = test_addr.addr;
202 test_hello_address.address_length = test_addr.addr_len;
203
204 /* Adding address */
205 GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count);
206
207}
208
209static int
210dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
211 int is_persistent)
212{
213 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n",
214 is_persistent ? "!" : " ", subsystem, name, value);
215 return GNUNET_OK;
216}
217
218
219
220static void
221run (void *cls,
222 const struct GNUNET_CONFIGURATION_Handle *cfg,
223 struct GNUNET_TESTING_Peer *peer)
224{
225 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
226 stats = GNUNET_STATISTICS_create ("ats", cfg);
227 GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL);
228
229
230 GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT,
231 &got_initial_value, &dummy_stat,
232 GNUNET_CONFIGURATION_dup (cfg));
233}
234
235
236int
237main (int argc, char *argv[])
238{
239 ret = 0;
240 if (0 != GNUNET_TESTING_peer_run ("test-ats-api",
241 "test_ats_api.conf",
242 &run, NULL))
243 return 1;
244 return ret;
245}
246/* end of file test_ats_api_scheduling_destroy_session.c */
diff --git a/src/ats/test_ats_solver_add_address_and_request.c b/src/ats/test_ats_solver_add_address_and_request.c
index df7cdae70..a0965c915 100644
--- a/src/ats/test_ats_solver_add_address_and_request.c
+++ b/src/ats/test_ats_solver_add_address_and_request.c
@@ -38,7 +38,7 @@
38/** 38/**
39 * Timeout task 39 * Timeout task
40 */ 40 */
41static struct GNUNET_SCHEDULER_Task * die_task; 41static struct GNUNET_SCHEDULER_Task *die_task;
42 42
43/** 43/**
44 * Statistics handle 44 * Statistics handle
@@ -90,6 +90,7 @@ static int
90stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, 90stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value,
91 int is_persistent); 91 int is_persistent);
92 92
93
93static void 94static void
94end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 95end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
95{ 96{
@@ -127,6 +128,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
127 ret = GNUNET_SYSERR; 128 ret = GNUNET_SYSERR;
128} 129}
129 130
131
130static void 132static void
131address_suggest_cb (void *cls, 133address_suggest_cb (void *cls,
132 const struct GNUNET_PeerIdentity *peer, 134 const struct GNUNET_PeerIdentity *peer,
@@ -148,20 +150,27 @@ address_suggest_cb (void *cls,
148 150
149 151
150static int 152static int
151stat_cb(void *cls, const char *subsystem, 153stat_cb (void *cls, const char *subsystem,
152 const char *name, uint64_t value, 154 const char *name, uint64_t value,
153 int is_persistent) 155 int is_persistent)
154{ 156{
157 struct GNUNET_ATS_SuggestHandle *sh;
155 158
156 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", 159 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
157 subsystem,name, value); 160 "ATS statistics: `%s' `%s' %llu\n",
158 GNUNET_ATS_suggest_address (sched_ats, &p.id); 161 subsystem,
162 name,
163 value);
164 if (NULL == sh)
165 sh = GNUNET_ATS_suggest_address (sched_ats, &p.id);
159 return GNUNET_OK; 166 return GNUNET_OK;
160} 167}
161 168
169
162static void 170static void
163run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, 171run (void *cls,
164 struct GNUNET_TESTING_Peer *peer) 172 const struct GNUNET_CONFIGURATION_Handle *mycfg,
173 struct GNUNET_TESTING_Peer *peer)
165{ 174{
166 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 175 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
167 stats = GNUNET_STATISTICS_create ("ats", mycfg); 176 stats = GNUNET_STATISTICS_create ("ats", mycfg);
@@ -172,14 +181,16 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg,
172 sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); 181 sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL);
173 if (sched_ats == NULL) 182 if (sched_ats == NULL)
174 { 183 {
175 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); 184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
185 "Could not connect to ATS scheduling!\n");
176 GNUNET_SCHEDULER_add_now (&end_badly, NULL); 186 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
177 return; 187 return;
178 } 188 }
179 189
180 /* Set up peer */ 190 /* Set up peer */
181 memset (&p.id, '1', sizeof (p.id)); 191 memset (&p.id, '1', sizeof (p.id));
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", 192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
193 "Created peer `%s'\n",
183 GNUNET_i2s_full(&p.id)); 194 GNUNET_i2s_full(&p.id));
184 195
185 /* Prepare ATS Information */ 196 /* Prepare ATS Information */
@@ -198,7 +209,9 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg,
198 test_hello_address.address_length = test_addr.addr_len; 209 test_hello_address.address_length = test_addr.addr_len;
199 210
200 /* Adding address */ 211 /* Adding address */
201 GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count); 212 GNUNET_ATS_address_add (sched_ats,
213 &test_hello_address, NULL,
214 test_ats_info, test_ats_count);
202} 215}
203 216
204 217