diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-25 15:57:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-25 15:57:43 +0000 |
commit | 75ff303510da8123bc7794c9d6e8fda51b73a7db (patch) | |
tree | 910e6cb442e6efc57e23965fd27d0c9a863cf6d9 | |
parent | 61b801d9949076ecac3f472b2fab58377a3d33a7 (diff) | |
download | gnunet-75ff303510da8123bc7794c9d6e8fda51b73a7db.tar.gz gnunet-75ff303510da8123bc7794c9d6e8fda51b73a7db.zip |
-removing useless/dead/redundant tests, adjusting other tests to fit current API
-rw-r--r-- | src/ats/Makefile.am | 9 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 28 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_add_address_duplicate.c | 75 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_add_address_inbound.c | 27 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_add_session.c | 34 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_destroy_session.c | 246 | ||||
-rw-r--r-- | src/ats/test_ats_solver_add_address_and_request.c | 37 |
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 | ||
227 | test_ats_api_scheduling_destroy_session_SOURCES = \ | ||
228 | test_ats_api_scheduling_destroy_session.c test_ats_api_common.c | ||
229 | test_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 | ||
237 | test_ats_api_performance_list_all_addresses_SOURCES = \ | 228 | test_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 | */ |
42 | struct GNUNET_STATISTICS_Handle *stats; | 42 | static 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 | */ |
67 | struct GNUNET_HELLO_Address test_hello_address; | 67 | static 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 | */ |
77 | struct GNUNET_ATS_Information test_ats_info[2]; | 77 | static struct GNUNET_ATS_Information test_ats_info[2]; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Test ats count | 80 | * Test ats count |
81 | */ | 81 | */ |
82 | uint32_t test_ats_count; | 82 | static uint32_t test_ats_count; |
83 | 83 | ||
84 | 84 | ||
85 | static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 85 | static void |
86 | static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 86 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
87 | |||
88 | |||
89 | static void | ||
90 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
91 | |||
87 | 92 | ||
88 | static int | 93 | static int |
89 | stat_cb(void *cls, const char *subsystem, | 94 | stat_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, | |||
111 | static void | 117 | static void |
112 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 118 | end (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 | |||
141 | static void | 148 | static void |
142 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 149 | end_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 | ||
163 | static int | 171 | static int |
164 | dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | 172 | dummy_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 | |||
174 | got_initial_value (void *cls, int success) | 186 | got_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 | |||
134 | static void | 135 | static void |
135 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 136 | end_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 | |||
195 | static int | 199 | static int |
196 | dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | 200 | dummy_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 | */ |
80 | static uint32_t test_ats_count; | 80 | static uint32_t test_ats_count; |
81 | 81 | ||
82 | /** | ||
83 | * Address record we will modify with a session later. | ||
84 | */ | ||
85 | static struct GNUNET_ATS_AddressRecord *ar; | ||
86 | |||
82 | 87 | ||
83 | static void | 88 | static void |
84 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 89 | end (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 | ||
91 | static int | 96 | static int |
92 | stat_cb(void *cls, const char *subsystem, | 97 | stat_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 | |||
148 | static void | 158 | static void |
149 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 159 | end_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 | |||
156 | static void | 167 | static void |
157 | address_suggest_cb (void *cls, | 168 | address_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 | */ | ||
39 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
40 | |||
41 | /** | ||
42 | * Statistics handle | ||
43 | */ | ||
44 | static struct GNUNET_STATISTICS_Handle *stats; | ||
45 | |||
46 | /** | ||
47 | * Scheduling handle | ||
48 | */ | ||
49 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
50 | |||
51 | /** | ||
52 | * Return value | ||
53 | */ | ||
54 | static int ret; | ||
55 | |||
56 | /** | ||
57 | * Test address | ||
58 | */ | ||
59 | static struct Test_Address test_addr; | ||
60 | |||
61 | /** | ||
62 | * Test peer | ||
63 | */ | ||
64 | static struct PeerContext p; | ||
65 | |||
66 | /** | ||
67 | * HELLO address | ||
68 | */ | ||
69 | static struct GNUNET_HELLO_Address test_hello_address; | ||
70 | |||
71 | /** | ||
72 | * Session | ||
73 | */ | ||
74 | static void *test_session; | ||
75 | |||
76 | /** | ||
77 | * Test ats info | ||
78 | */ | ||
79 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
80 | |||
81 | /** | ||
82 | * Test ats count | ||
83 | */ | ||
84 | static uint32_t test_ats_count; | ||
85 | |||
86 | |||
87 | static void | ||
88 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
89 | |||
90 | |||
91 | static void | ||
92 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
93 | |||
94 | |||
95 | static int | ||
96 | stat_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 | |||
123 | static void | ||
124 | end (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 | |||
152 | static void | ||
153 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
154 | { | ||
155 | die_task = NULL; | ||
156 | end ( NULL, NULL); | ||
157 | ret = GNUNET_SYSERR; | ||
158 | } | ||
159 | |||
160 | static void | ||
161 | address_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 | |||
172 | static void | ||
173 | got_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 | |||
209 | static int | ||
210 | dummy_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 | |||
220 | static void | ||
221 | run (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 | |||
236 | int | ||
237 | main (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 | */ |
41 | static struct GNUNET_SCHEDULER_Task * die_task; | 41 | static struct GNUNET_SCHEDULER_Task *die_task; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Statistics handle | 44 | * Statistics handle |
@@ -90,6 +90,7 @@ static int | |||
90 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, | 90 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, |
91 | int is_persistent); | 91 | int is_persistent); |
92 | 92 | ||
93 | |||
93 | static void | 94 | static void |
94 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 95 | end (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 | |||
130 | static void | 132 | static void |
131 | address_suggest_cb (void *cls, | 133 | address_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 | ||
150 | static int | 152 | static int |
151 | stat_cb(void *cls, const char *subsystem, | 153 | stat_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 | |||
162 | static void | 170 | static void |
163 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | 171 | run (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 | ||