diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-18 12:23:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-18 12:23:42 +0000 |
commit | 58e7d98695853ef182f7f7a4c70fefc834aed8ae (patch) | |
tree | 1242466260ffea001b40cb8ededf4d81ab0e2941 /src/ats | |
parent | 16ca3ecb37b3989e5dfde6ba688618c576cdf691 (diff) | |
download | gnunet-58e7d98695853ef182f7f7a4c70fefc834aed8ae.tar.gz gnunet-58e7d98695853ef182f7f7a4c70fefc834aed8ae.zip |
-test cleanup
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/test_ats_api_scheduling_destroy_address.c | 137 |
1 files changed, 82 insertions, 55 deletions
diff --git a/src/ats/test_ats_api_scheduling_destroy_address.c b/src/ats/test_ats_api_scheduling_destroy_address.c index 5cc2094c2..a286ab8a4 100644 --- a/src/ats/test_ats_api_scheduling_destroy_address.c +++ b/src/ats/test_ats_api_scheduling_destroy_address.c | |||
@@ -33,12 +33,12 @@ | |||
33 | /** | 33 | /** |
34 | * Timeout task | 34 | * Timeout task |
35 | */ | 35 | */ |
36 | static struct GNUNET_SCHEDULER_Task * die_task; | 36 | static struct GNUNET_SCHEDULER_Task *die_task; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Statistics handle | 39 | * Statistics handle |
40 | */ | 40 | */ |
41 | struct GNUNET_STATISTICS_Handle *stats; | 41 | static struct GNUNET_STATISTICS_Handle *stats; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Scheduling handle | 44 | * Scheduling handle |
@@ -63,7 +63,7 @@ static struct PeerContext p; | |||
63 | /** | 63 | /** |
64 | * HELLO address | 64 | * HELLO address |
65 | */ | 65 | */ |
66 | struct GNUNET_HELLO_Address test_hello_address; | 66 | static struct GNUNET_HELLO_Address test_hello_address; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Session | 69 | * Session |
@@ -73,40 +73,18 @@ static void *test_session; | |||
73 | /** | 73 | /** |
74 | * Test ats info | 74 | * Test ats info |
75 | */ | 75 | */ |
76 | struct GNUNET_ATS_Information test_ats_info[2]; | 76 | static struct GNUNET_ATS_Information test_ats_info[2]; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Test ats count | 79 | * Test ats count |
80 | */ | 80 | */ |
81 | uint32_t test_ats_count; | 81 | static uint32_t test_ats_count; |
82 | 82 | ||
83 | 83 | ||
84 | static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
85 | |||
86 | static int | 84 | static int |
87 | stat_cb(void *cls, const char *subsystem, | 85 | stat_cb (void *cls, const char *subsystem, |
88 | const char *name, uint64_t value, | 86 | const char *name, uint64_t value, |
89 | int is_persistent) | 87 | int is_persistent); |
90 | { | ||
91 | static int initial_ats_stat_cb = GNUNET_YES; | ||
92 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
93 | subsystem,name, value); | ||
94 | |||
95 | if ((0 == value) && (initial_ats_stat_cb == GNUNET_NO)) | ||
96 | { | ||
97 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
98 | } | ||
99 | if ((0 == value) && (initial_ats_stat_cb == GNUNET_YES)) | ||
100 | { | ||
101 | initial_ats_stat_cb = GNUNET_NO; | ||
102 | } | ||
103 | if (1 == value) | ||
104 | { | ||
105 | GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address, test_session); | ||
106 | } | ||
107 | |||
108 | return GNUNET_OK; | ||
109 | } | ||
110 | 88 | ||
111 | 89 | ||
112 | static void | 90 | static void |
@@ -114,38 +92,71 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
114 | { | 92 | { |
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | 93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); |
116 | 94 | ||
117 | if (die_task != NULL) | 95 | if (NULL != die_task) |
118 | { | 96 | { |
119 | GNUNET_SCHEDULER_cancel (die_task); | 97 | GNUNET_SCHEDULER_cancel (die_task); |
120 | die_task = NULL; | 98 | die_task = NULL; |
121 | } | 99 | } |
122 | |||
123 | if (NULL != sched_ats) | 100 | if (NULL != sched_ats) |
124 | { | 101 | { |
125 | GNUNET_ATS_scheduling_done (sched_ats); | 102 | GNUNET_ATS_scheduling_done (sched_ats); |
126 | sched_ats = NULL; | 103 | sched_ats = NULL; |
127 | } | 104 | } |
128 | 105 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", | |
129 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | 106 | &stat_cb, NULL); |
130 | if (NULL != stats) | 107 | if (NULL != stats) |
131 | { | 108 | { |
132 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 109 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
133 | stats = NULL; | 110 | stats = NULL; |
134 | } | 111 | } |
135 | |||
136 | free_test_address (&test_addr); | 112 | free_test_address (&test_addr); |
137 | |||
138 | ret = 0; | 113 | ret = 0; |
139 | } | 114 | } |
140 | 115 | ||
116 | |||
117 | static int | ||
118 | stat_cb (void *cls, const char *subsystem, | ||
119 | const char *name, uint64_t value, | ||
120 | int is_persistent) | ||
121 | { | ||
122 | static int initial_ats_stat_cb = GNUNET_YES; | ||
123 | |||
124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
125 | "ATS statistics: `%s' `%s' %llu\n", | ||
126 | subsystem, | ||
127 | name, | ||
128 | value); | ||
129 | |||
130 | if ((0 == value) && (initial_ats_stat_cb == GNUNET_NO)) | ||
131 | { | ||
132 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
133 | } | ||
134 | if ((0 == value) && (initial_ats_stat_cb == GNUNET_YES)) | ||
135 | { | ||
136 | initial_ats_stat_cb = GNUNET_NO; | ||
137 | } | ||
138 | if (1 == value) | ||
139 | { | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
141 | "Statistics observed address added, now destroying address\n"); | ||
142 | GNUNET_ATS_address_destroyed (sched_ats, | ||
143 | &test_hello_address, | ||
144 | test_session); | ||
145 | } | ||
146 | return GNUNET_OK; | ||
147 | } | ||
148 | |||
149 | |||
141 | static void | 150 | static void |
142 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 151 | end_badly (void *cls, |
152 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
143 | { | 153 | { |
144 | die_task = NULL; | 154 | die_task = NULL; |
145 | end ( NULL, NULL); | 155 | end ( NULL, NULL); |
146 | ret = GNUNET_SYSERR; | 156 | ret = GNUNET_SYSERR; |
147 | } | 157 | } |
148 | 158 | ||
159 | |||
149 | static void | 160 | static void |
150 | address_suggest_cb (void *cls, | 161 | address_suggest_cb (void *cls, |
151 | const struct GNUNET_PeerIdentity *peer, | 162 | const struct GNUNET_PeerIdentity *peer, |
@@ -156,24 +167,29 @@ address_suggest_cb (void *cls, | |||
156 | const struct GNUNET_ATS_Information *atsi, | 167 | const struct GNUNET_ATS_Information *atsi, |
157 | uint32_t ats_count) | 168 | uint32_t ats_count) |
158 | { | 169 | { |
159 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | 170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
160 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 171 | "Did not expect suggestion callback!\n"); |
161 | return; | 172 | GNUNET_SCHEDULER_shutdown (); |
162 | } | 173 | } |
163 | 174 | ||
175 | |||
164 | static void | 176 | static void |
165 | got_initial_value (void *cls, int success) | 177 | got_initial_value (void *cls, |
178 | int success) | ||
166 | { | 179 | { |
167 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 180 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
168 | 181 | ||
169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); | 182 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
183 | "Statistics running, now adding address\n"); | ||
170 | 184 | ||
171 | /* Connect to ATS scheduling */ | 185 | /* Connect to ATS scheduling */ |
172 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | 186 | sched_ats = GNUNET_ATS_scheduling_init (cfg, |
173 | if (sched_ats == NULL) | 187 | &address_suggest_cb, NULL); |
188 | if (NULL == sched_ats) | ||
174 | { | 189 | { |
175 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | 190 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
176 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 191 | "Could not connect to ATS scheduling!\n"); |
192 | GNUNET_SCHEDULER_shutdown (); | ||
177 | return; | 193 | return; |
178 | } | 194 | } |
179 | 195 | ||
@@ -188,19 +204,28 @@ got_initial_value (void *cls, int success) | |||
188 | 204 | ||
189 | /* Adding address without session */ | 205 | /* Adding address without session */ |
190 | test_session = NULL; | 206 | test_session = NULL; |
191 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | 207 | create_test_address (&test_addr, |
208 | "test", test_session, | ||
209 | "test", strlen ("test") + 1); | ||
192 | test_hello_address.peer = p.id; | 210 | test_hello_address.peer = p.id; |
193 | test_hello_address.transport_name = test_addr.plugin; | 211 | test_hello_address.transport_name = test_addr.plugin; |
194 | test_hello_address.address = test_addr.addr; | 212 | test_hello_address.address = test_addr.addr; |
195 | test_hello_address.address_length = test_addr.addr_len; | 213 | test_hello_address.address_length = test_addr.addr_len; |
196 | 214 | ||
197 | /* Adding address */ | 215 | /* Adding address */ |
198 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); | 216 | GNUNET_ATS_address_add (sched_ats, |
199 | 217 | &test_hello_address, | |
218 | test_session, | ||
219 | test_ats_info, | ||
220 | test_ats_count); | ||
200 | } | 221 | } |
201 | 222 | ||
223 | |||
202 | static int | 224 | static int |
203 | dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | 225 | dummy_stat (void *cls, |
226 | const char *subsystem, | ||
227 | const char *name, | ||
228 | uint64_t value, | ||
204 | int is_persistent) | 229 | int is_persistent) |
205 | { | 230 | { |
206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", | 231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", |
@@ -217,11 +242,13 @@ run (void *cls, | |||
217 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 242 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
218 | stats = GNUNET_STATISTICS_create ("ats", cfg); | 243 | stats = GNUNET_STATISTICS_create ("ats", cfg); |
219 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | 244 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); |
220 | 245 | GNUNET_STATISTICS_get (stats, | |
221 | 246 | "ats", | |
222 | GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, | 247 | "# addresses", |
223 | &got_initial_value, &dummy_stat, | 248 | TIMEOUT, |
224 | GNUNET_CONFIGURATION_dup (cfg)); | 249 | &got_initial_value, |
250 | &dummy_stat, | ||
251 | GNUNET_CONFIGURATION_dup (cfg)); | ||
225 | } | 252 | } |
226 | 253 | ||
227 | 254 | ||