diff options
Diffstat (limited to 'src/datastore/test_plugin_datastore.c')
-rw-r--r-- | src/datastore/test_plugin_datastore.c | 451 |
1 files changed, 228 insertions, 223 deletions
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c index 2b7bf9ae4..a260e1575 100644 --- a/src/datastore/test_plugin_datastore.c +++ b/src/datastore/test_plugin_datastore.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /* | 20 | /* |
21 | * @file test_plugin_datastore.c | 21 | * @file test_plugin_datastore.c |
22 | * @brief Test database plugin directly, calling each API function once | 22 | * @brief Test database plugin directly, calling each API function once |
@@ -44,8 +44,7 @@ static const char *plugin_name; | |||
44 | 44 | ||
45 | static int ok; | 45 | static int ok; |
46 | 46 | ||
47 | enum RunPhase | 47 | enum RunPhase { |
48 | { | ||
49 | RP_ERROR = 0, | 48 | RP_ERROR = 0, |
50 | RP_PUT, | 49 | RP_PUT, |
51 | RP_GET, | 50 | RP_GET, |
@@ -57,8 +56,7 @@ enum RunPhase | |||
57 | }; | 56 | }; |
58 | 57 | ||
59 | 58 | ||
60 | struct CpsRunContext | 59 | struct CpsRunContext { |
61 | { | ||
62 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 60 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
63 | struct GNUNET_DATASTORE_PluginFunctions *api; | 61 | struct GNUNET_DATASTORE_PluginFunctions *api; |
64 | enum RunPhase phase; | 62 | enum RunPhase phase; |
@@ -76,14 +74,14 @@ struct CpsRunContext | |||
76 | * 0 for "reset to empty" | 74 | * 0 for "reset to empty" |
77 | */ | 75 | */ |
78 | static void | 76 | static void |
79 | disk_utilization_change_cb (void *cls, int delta) | 77 | disk_utilization_change_cb(void *cls, int delta) |
80 | { | 78 | { |
81 | /* do nothing */ | 79 | /* do nothing */ |
82 | } | 80 | } |
83 | 81 | ||
84 | 82 | ||
85 | static void | 83 | static void |
86 | test (void *cls); | 84 | test(void *cls); |
87 | 85 | ||
88 | 86 | ||
89 | /** | 87 | /** |
@@ -96,47 +94,47 @@ test (void *cls); | |||
96 | * @param msg error message on error | 94 | * @param msg error message on error |
97 | */ | 95 | */ |
98 | static void | 96 | static void |
99 | put_continuation (void *cls, | 97 | put_continuation(void *cls, |
100 | const struct GNUNET_HashCode *key, | 98 | const struct GNUNET_HashCode *key, |
101 | uint32_t size, | 99 | uint32_t size, |
102 | int status, | 100 | int status, |
103 | const char *msg) | 101 | const char *msg) |
104 | { | 102 | { |
105 | struct CpsRunContext *crc = cls; | 103 | struct CpsRunContext *crc = cls; |
106 | static unsigned long long os; | 104 | static unsigned long long os; |
107 | unsigned long long cs; | 105 | unsigned long long cs; |
108 | 106 | ||
109 | if (GNUNET_OK != status) | 107 | if (GNUNET_OK != status) |
110 | { | 108 | { |
111 | fprintf (stderr, | 109 | fprintf(stderr, |
112 | "ERROR: `%s'\n", | 110 | "ERROR: `%s'\n", |
113 | msg); | 111 | msg); |
114 | } | 112 | } |
115 | else | 113 | else |
116 | { | 114 | { |
117 | crc->api->estimate_size (crc->api->cls, | 115 | crc->api->estimate_size(crc->api->cls, |
118 | &cs); | 116 | &cs); |
119 | GNUNET_assert (os <= cs); | 117 | GNUNET_assert(os <= cs); |
120 | os = cs; | 118 | os = cs; |
121 | stored_bytes += size; | 119 | stored_bytes += size; |
122 | stored_ops++; | 120 | stored_ops++; |
123 | stored_entries++; | 121 | stored_entries++; |
124 | } | 122 | } |
125 | GNUNET_SCHEDULER_add_now (&test, crc); | 123 | GNUNET_SCHEDULER_add_now(&test, crc); |
126 | } | 124 | } |
127 | 125 | ||
128 | 126 | ||
129 | static void | 127 | static void |
130 | gen_key (int i, struct GNUNET_HashCode * key) | 128 | gen_key(int i, struct GNUNET_HashCode * key) |
131 | { | 129 | { |
132 | memset (key, 0, sizeof (struct GNUNET_HashCode)); | 130 | memset(key, 0, sizeof(struct GNUNET_HashCode)); |
133 | key->bits[0] = (unsigned int) i; | 131 | key->bits[0] = (unsigned int)i; |
134 | GNUNET_CRYPTO_hash (key, sizeof (struct GNUNET_HashCode), key); | 132 | GNUNET_CRYPTO_hash(key, sizeof(struct GNUNET_HashCode), key); |
135 | } | 133 | } |
136 | 134 | ||
137 | 135 | ||
138 | static void | 136 | static void |
139 | do_put (struct CpsRunContext *crc) | 137 | do_put(struct CpsRunContext *crc) |
140 | { | 138 | { |
141 | char value[65536]; | 139 | char value[65536]; |
142 | size_t size; | 140 | size_t size; |
@@ -145,45 +143,45 @@ do_put (struct CpsRunContext *crc) | |||
145 | static int i; | 143 | static int i; |
146 | 144 | ||
147 | if (PUT_10 == i) | 145 | if (PUT_10 == i) |
148 | { | 146 | { |
149 | i = 0; | 147 | i = 0; |
150 | crc->phase++; | 148 | crc->phase++; |
151 | GNUNET_SCHEDULER_add_now (&test, crc); | 149 | GNUNET_SCHEDULER_add_now(&test, crc); |
152 | return; | 150 | return; |
153 | } | 151 | } |
154 | /* most content is 32k */ | 152 | /* most content is 32k */ |
155 | size = 32 * 1024; | 153 | size = 32 * 1024; |
156 | 154 | ||
157 | if (0 != i && GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ | 155 | if (0 != i && GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ |
158 | size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); | 156 | size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); |
159 | size = size - (size & 7); /* always multiple of 8 */ | 157 | size = size - (size & 7); /* always multiple of 8 */ |
160 | 158 | ||
161 | /* generate random key */ | 159 | /* generate random key */ |
162 | gen_key (i, &key); | 160 | gen_key(i, &key); |
163 | memset (value, i, size); | 161 | memset(value, i, size); |
164 | if (i > 255) | 162 | if (i > 255) |
165 | memset (value, i - 255, size / 2); | 163 | memset(value, i - 255, size / 2); |
166 | value[0] = crc->i; | 164 | value[0] = crc->i; |
167 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 165 | prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); |
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 166 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
169 | "putting type %u, anon %u under key %s\n", i + 1, i, | 167 | "putting type %u, anon %u under key %s\n", i + 1, i, |
170 | GNUNET_h2s (&key)); | 168 | GNUNET_h2s(&key)); |
171 | crc->api->put (crc->api->cls, | 169 | crc->api->put(crc->api->cls, |
172 | &key, | 170 | &key, |
173 | false /* absent */, | 171 | false /* absent */, |
174 | size, | 172 | size, |
175 | value, i + 1 /* type */ , | 173 | value, i + 1 /* type */, |
176 | prio, | 174 | prio, |
177 | i /* anonymity */ , | 175 | i /* anonymity */, |
178 | 0 /* replication */ , | 176 | 0 /* replication */, |
179 | GNUNET_TIME_relative_to_absolute | 177 | GNUNET_TIME_relative_to_absolute |
180 | (GNUNET_TIME_relative_multiply | 178 | (GNUNET_TIME_relative_multiply |
181 | (GNUNET_TIME_UNIT_MILLISECONDS, | 179 | (GNUNET_TIME_UNIT_MILLISECONDS, |
182 | 60 * 60 * 60 * 1000 + | 180 | 60 * 60 * 60 * 1000 + |
183 | GNUNET_CRYPTO_random_u32 | 181 | GNUNET_CRYPTO_random_u32 |
184 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), | 182 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), |
185 | put_continuation, | 183 | put_continuation, |
186 | crc); | 184 | crc); |
187 | i++; | 185 | i++; |
188 | } | 186 | } |
189 | 187 | ||
@@ -192,51 +190,51 @@ static uint64_t guid; | |||
192 | 190 | ||
193 | 191 | ||
194 | static int | 192 | static int |
195 | iterate_one_shot (void *cls, | 193 | iterate_one_shot(void *cls, |
196 | const struct GNUNET_HashCode *key, | 194 | const struct GNUNET_HashCode *key, |
197 | uint32_t size, | 195 | uint32_t size, |
198 | const void *data, | 196 | const void *data, |
199 | enum GNUNET_BLOCK_Type type, | 197 | enum GNUNET_BLOCK_Type type, |
200 | uint32_t priority, | 198 | uint32_t priority, |
201 | uint32_t anonymity, | 199 | uint32_t anonymity, |
202 | uint32_t replication, | 200 | uint32_t replication, |
203 | struct GNUNET_TIME_Absolute expiration, | 201 | struct GNUNET_TIME_Absolute expiration, |
204 | uint64_t uid) | 202 | uint64_t uid) |
205 | { | 203 | { |
206 | struct CpsRunContext *crc = cls; | 204 | struct CpsRunContext *crc = cls; |
207 | 205 | ||
208 | GNUNET_assert (NULL != key); | 206 | GNUNET_assert(NULL != key); |
209 | guid = uid; | 207 | guid = uid; |
210 | crc->phase++; | 208 | crc->phase++; |
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 209 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
212 | "Found result type=%u, priority=%u, size=%u, expire=%s, key %s\n", | 210 | "Found result type=%u, priority=%u, size=%u, expire=%s, key %s\n", |
213 | (unsigned int) type, | 211 | (unsigned int)type, |
214 | (unsigned int) priority, | 212 | (unsigned int)priority, |
215 | (unsigned int) size, | 213 | (unsigned int)size, |
216 | GNUNET_STRINGS_absolute_time_to_string (expiration), | 214 | GNUNET_STRINGS_absolute_time_to_string(expiration), |
217 | GNUNET_h2s (key)); | 215 | GNUNET_h2s(key)); |
218 | GNUNET_SCHEDULER_add_now (&test, | 216 | GNUNET_SCHEDULER_add_now(&test, |
219 | crc); | 217 | crc); |
220 | return GNUNET_OK; | 218 | return GNUNET_OK; |
221 | } | 219 | } |
222 | 220 | ||
223 | 221 | ||
224 | static void | 222 | static void |
225 | remove_continuation (void *cls, | 223 | remove_continuation(void *cls, |
226 | const struct GNUNET_HashCode *key, | 224 | const struct GNUNET_HashCode *key, |
227 | uint32_t size, | 225 | uint32_t size, |
228 | int status, | 226 | int status, |
229 | const char *msg) | 227 | const char *msg) |
230 | { | 228 | { |
231 | struct CpsRunContext *crc = cls; | 229 | struct CpsRunContext *crc = cls; |
232 | 230 | ||
233 | GNUNET_assert (NULL != key); | 231 | GNUNET_assert(NULL != key); |
234 | GNUNET_assert (32768 == size); | 232 | GNUNET_assert(32768 == size); |
235 | GNUNET_assert (GNUNET_OK == status); | 233 | GNUNET_assert(GNUNET_OK == status); |
236 | GNUNET_assert (NULL == msg); | 234 | GNUNET_assert(NULL == msg); |
237 | crc->phase++; | 235 | crc->phase++; |
238 | GNUNET_SCHEDULER_add_now (&test, | 236 | GNUNET_SCHEDULER_add_now(&test, |
239 | crc); | 237 | crc); |
240 | } | 238 | } |
241 | 239 | ||
242 | 240 | ||
@@ -248,28 +246,28 @@ remove_continuation (void *cls, | |||
248 | * @param cfg configuration to use | 246 | * @param cfg configuration to use |
249 | */ | 247 | */ |
250 | static void | 248 | static void |
251 | unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, | 249 | unload_plugin(struct GNUNET_DATASTORE_PluginFunctions *api, |
252 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 250 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
253 | { | 251 | { |
254 | char *name; | 252 | char *name; |
255 | char *libname; | 253 | char *libname; |
256 | 254 | ||
257 | if (GNUNET_OK != | 255 | if (GNUNET_OK != |
258 | GNUNET_CONFIGURATION_get_value_string (cfg, | 256 | GNUNET_CONFIGURATION_get_value_string(cfg, |
259 | "DATASTORE", | 257 | "DATASTORE", |
260 | "DATABASE", | 258 | "DATABASE", |
261 | &name)) | 259 | &name)) |
262 | { | 260 | { |
263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 261 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
264 | _("No `%s' specified for `%s' in configuration!\n"), | 262 | _("No `%s' specified for `%s' in configuration!\n"), |
265 | "DATABASE", | 263 | "DATABASE", |
266 | "DATASTORE"); | 264 | "DATASTORE"); |
267 | return; | 265 | return; |
268 | } | 266 | } |
269 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 267 | GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); |
270 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); | 268 | GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api)); |
271 | GNUNET_free (libname); | 269 | GNUNET_free(libname); |
272 | GNUNET_free (name); | 270 | GNUNET_free(name); |
273 | } | 271 | } |
274 | 272 | ||
275 | 273 | ||
@@ -279,92 +277,99 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, | |||
279 | * the transport and core. | 277 | * the transport and core. |
280 | */ | 278 | */ |
281 | static void | 279 | static void |
282 | cleaning_task (void *cls) | 280 | cleaning_task(void *cls) |
283 | { | 281 | { |
284 | struct CpsRunContext *crc = cls; | 282 | struct CpsRunContext *crc = cls; |
285 | 283 | ||
286 | unload_plugin (crc->api, crc->cfg); | 284 | unload_plugin(crc->api, crc->cfg); |
287 | GNUNET_free (crc); | 285 | GNUNET_free(crc); |
288 | } | 286 | } |
289 | 287 | ||
290 | 288 | ||
291 | static void | 289 | static void |
292 | test (void *cls) | 290 | test(void *cls) |
293 | { | 291 | { |
294 | struct CpsRunContext *crc = cls; | 292 | struct CpsRunContext *crc = cls; |
295 | struct GNUNET_HashCode key; | 293 | struct GNUNET_HashCode key; |
296 | 294 | ||
297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
298 | "In phase %d, iteration %u\n", crc->phase, crc->cnt); | 296 | "In phase %d, iteration %u\n", crc->phase, crc->cnt); |
299 | switch (crc->phase) | 297 | switch (crc->phase) |
300 | { | ||
301 | case RP_ERROR: | ||
302 | ok = 1; | ||
303 | GNUNET_break (0); | ||
304 | crc->api->drop (crc->api->cls); | ||
305 | GNUNET_SCHEDULER_add_now (&cleaning_task, crc); | ||
306 | break; | ||
307 | case RP_PUT: | ||
308 | do_put (crc); | ||
309 | break; | ||
310 | case RP_GET: | ||
311 | if (crc->cnt == 1) | ||
312 | { | 298 | { |
313 | crc->cnt = 0; | 299 | case RP_ERROR: |
314 | crc->phase++; | 300 | ok = 1; |
315 | GNUNET_SCHEDULER_add_now (&test, crc); | 301 | GNUNET_break(0); |
302 | crc->api->drop(crc->api->cls); | ||
303 | GNUNET_SCHEDULER_add_now(&cleaning_task, crc); | ||
316 | break; | 304 | break; |
317 | } | 305 | |
318 | gen_key (5, &key); | 306 | case RP_PUT: |
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 307 | do_put(crc); |
320 | "Looking for %s\n", | ||
321 | GNUNET_h2s (&key)); | ||
322 | crc->api->get_key (crc->api->cls, | ||
323 | 0, | ||
324 | false, | ||
325 | &key, | ||
326 | GNUNET_BLOCK_TYPE_ANY, | ||
327 | &iterate_one_shot, | ||
328 | crc); | ||
329 | break; | ||
330 | case RP_ITER_ZERO: | ||
331 | if (crc->cnt == 1) | ||
332 | { | ||
333 | crc->cnt = 0; | ||
334 | crc->phase++; | ||
335 | GNUNET_SCHEDULER_add_now (&test, crc); | ||
336 | break; | 308 | break; |
337 | } | 309 | |
338 | crc->api->get_zero_anonymity (crc->api->cls, 0, 1, &iterate_one_shot, crc); | 310 | case RP_GET: |
339 | break; | 311 | if (crc->cnt == 1) |
340 | case RP_REPL_GET: | 312 | { |
341 | crc->api->get_replication (crc->api->cls, &iterate_one_shot, crc); | 313 | crc->cnt = 0; |
342 | break; | 314 | crc->phase++; |
343 | case RP_EXPI_GET: | 315 | GNUNET_SCHEDULER_add_now(&test, crc); |
344 | crc->api->get_expiration (crc->api->cls, &iterate_one_shot, crc); | 316 | break; |
345 | break; | 317 | } |
346 | case RP_REMOVE: | 318 | gen_key(5, &key); |
319 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
320 | "Looking for %s\n", | ||
321 | GNUNET_h2s(&key)); | ||
322 | crc->api->get_key(crc->api->cls, | ||
323 | 0, | ||
324 | false, | ||
325 | &key, | ||
326 | GNUNET_BLOCK_TYPE_ANY, | ||
327 | &iterate_one_shot, | ||
328 | crc); | ||
329 | break; | ||
330 | |||
331 | case RP_ITER_ZERO: | ||
332 | if (crc->cnt == 1) | ||
333 | { | ||
334 | crc->cnt = 0; | ||
335 | crc->phase++; | ||
336 | GNUNET_SCHEDULER_add_now(&test, crc); | ||
337 | break; | ||
338 | } | ||
339 | crc->api->get_zero_anonymity(crc->api->cls, 0, 1, &iterate_one_shot, crc); | ||
340 | break; | ||
341 | |||
342 | case RP_REPL_GET: | ||
343 | crc->api->get_replication(crc->api->cls, &iterate_one_shot, crc); | ||
344 | break; | ||
345 | |||
346 | case RP_EXPI_GET: | ||
347 | crc->api->get_expiration(crc->api->cls, &iterate_one_shot, crc); | ||
348 | break; | ||
349 | |||
350 | case RP_REMOVE: | ||
347 | { | 351 | { |
348 | struct GNUNET_HashCode key; | 352 | struct GNUNET_HashCode key; |
349 | uint32_t size = 32768; | 353 | uint32_t size = 32768; |
350 | char value[size]; | 354 | char value[size]; |
351 | 355 | ||
352 | gen_key (0, &key); | 356 | gen_key(0, &key); |
353 | memset (value, 0, size); | 357 | memset(value, 0, size); |
354 | value[0] = crc->i; | 358 | value[0] = crc->i; |
355 | crc->api->remove_key (crc->api->cls, | 359 | crc->api->remove_key(crc->api->cls, |
356 | &key, | 360 | &key, |
357 | size, | 361 | size, |
358 | value, | 362 | value, |
359 | &remove_continuation, | 363 | &remove_continuation, |
360 | crc); | 364 | crc); |
365 | break; | ||
366 | } | ||
367 | |||
368 | case RP_DROP: | ||
369 | crc->api->drop(crc->api->cls); | ||
370 | GNUNET_SCHEDULER_add_now(&cleaning_task, crc); | ||
361 | break; | 371 | break; |
362 | } | 372 | } |
363 | case RP_DROP: | ||
364 | crc->api->drop (crc->api->cls); | ||
365 | GNUNET_SCHEDULER_add_now (&cleaning_task, crc); | ||
366 | break; | ||
367 | } | ||
368 | } | 373 | } |
369 | 374 | ||
370 | 375 | ||
@@ -372,7 +377,7 @@ test (void *cls) | |||
372 | * Load the datastore plugin. | 377 | * Load the datastore plugin. |
373 | */ | 378 | */ |
374 | static struct GNUNET_DATASTORE_PluginFunctions * | 379 | static struct GNUNET_DATASTORE_PluginFunctions * |
375 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | 380 | load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) |
376 | { | 381 | { |
377 | static struct GNUNET_DATASTORE_PluginEnvironment env; | 382 | static struct GNUNET_DATASTORE_PluginEnvironment env; |
378 | struct GNUNET_DATASTORE_PluginFunctions *ret; | 383 | struct GNUNET_DATASTORE_PluginFunctions *ret; |
@@ -380,61 +385,61 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
380 | char *libname; | 385 | char *libname; |
381 | 386 | ||
382 | if (GNUNET_OK != | 387 | if (GNUNET_OK != |
383 | GNUNET_CONFIGURATION_get_value_string (cfg, | 388 | GNUNET_CONFIGURATION_get_value_string(cfg, |
384 | "DATASTORE", | 389 | "DATASTORE", |
385 | "DATABASE", | 390 | "DATABASE", |
386 | &name)) | 391 | &name)) |
387 | { | 392 | { |
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 393 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
389 | _("No `%s' specified for `%s' in configuration!\n"), | 394 | _("No `%s' specified for `%s' in configuration!\n"), |
390 | "DATABASE", | 395 | "DATABASE", |
391 | "DATASTORE"); | 396 | "DATASTORE"); |
392 | return NULL; | 397 | return NULL; |
393 | } | 398 | } |
394 | env.cfg = cfg; | 399 | env.cfg = cfg; |
395 | env.duc = &disk_utilization_change_cb; | 400 | env.duc = &disk_utilization_change_cb; |
396 | env.cls = NULL; | 401 | env.cls = NULL; |
397 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), | 402 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), |
398 | name); | 403 | name); |
399 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 404 | GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); |
400 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) | 405 | if (NULL == (ret = GNUNET_PLUGIN_load(libname, &env))) |
401 | { | 406 | { |
402 | fprintf (stderr, "Failed to load plugin `%s'!\n", name); | 407 | fprintf(stderr, "Failed to load plugin `%s'!\n", name); |
403 | GNUNET_free (libname); | 408 | GNUNET_free(libname); |
404 | GNUNET_free (name); | 409 | GNUNET_free(name); |
405 | ok = 77; /* mark test as skipped */ | 410 | ok = 77; /* mark test as skipped */ |
406 | return NULL; | 411 | return NULL; |
407 | } | 412 | } |
408 | GNUNET_free (libname); | 413 | GNUNET_free(libname); |
409 | GNUNET_free (name); | 414 | GNUNET_free(name); |
410 | return ret; | 415 | return ret; |
411 | } | 416 | } |
412 | 417 | ||
413 | 418 | ||
414 | static void | 419 | static void |
415 | run (void *cls, char *const *args, const char *cfgfile, | 420 | run(void *cls, char *const *args, const char *cfgfile, |
416 | const struct GNUNET_CONFIGURATION_Handle *c) | 421 | const struct GNUNET_CONFIGURATION_Handle *c) |
417 | { | 422 | { |
418 | struct GNUNET_DATASTORE_PluginFunctions *api; | 423 | struct GNUNET_DATASTORE_PluginFunctions *api; |
419 | struct CpsRunContext *crc; | 424 | struct CpsRunContext *crc; |
420 | 425 | ||
421 | api = load_plugin (c); | 426 | api = load_plugin(c); |
422 | if (api == NULL) | 427 | if (api == NULL) |
423 | { | 428 | { |
424 | fprintf (stderr, | 429 | fprintf(stderr, |
425 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); | 430 | "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); |
426 | return; | 431 | return; |
427 | } | 432 | } |
428 | crc = GNUNET_new (struct CpsRunContext); | 433 | crc = GNUNET_new(struct CpsRunContext); |
429 | crc->api = api; | 434 | crc->api = api; |
430 | crc->cfg = c; | 435 | crc->cfg = c; |
431 | crc->phase = RP_PUT; | 436 | crc->phase = RP_PUT; |
432 | GNUNET_SCHEDULER_add_now (&test, crc); | 437 | GNUNET_SCHEDULER_add_now(&test, crc); |
433 | } | 438 | } |
434 | 439 | ||
435 | 440 | ||
436 | int | 441 | int |
437 | main (int argc, char *argv[]) | 442 | main(int argc, char *argv[]) |
438 | { | 443 | { |
439 | char dir_name[PATH_MAX]; | 444 | char dir_name[PATH_MAX]; |
440 | char cfg_name[PATH_MAX]; | 445 | char cfg_name[PATH_MAX]; |
@@ -449,20 +454,20 @@ main (int argc, char *argv[]) | |||
449 | }; | 454 | }; |
450 | 455 | ||
451 | /* determine name of plugin to use */ | 456 | /* determine name of plugin to use */ |
452 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 457 | plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); |
453 | GNUNET_snprintf (dir_name, sizeof (dir_name), | 458 | GNUNET_snprintf(dir_name, sizeof(dir_name), |
454 | "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); | 459 | "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); |
455 | GNUNET_DISK_directory_remove (dir_name); | 460 | GNUNET_DISK_directory_remove(dir_name); |
456 | GNUNET_log_setup ("test-plugin-datastore", | 461 | GNUNET_log_setup("test-plugin-datastore", |
457 | "WARNING", | 462 | "WARNING", |
458 | NULL); | 463 | NULL); |
459 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), | 464 | GNUNET_snprintf(cfg_name, sizeof(cfg_name), |
460 | "test_plugin_datastore_data_%s.conf", plugin_name); | 465 | "test_plugin_datastore_data_%s.conf", plugin_name); |
461 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | 466 | GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, xargv, |
462 | "test-plugin-datastore", "nohelp", options, &run, NULL); | 467 | "test-plugin-datastore", "nohelp", options, &run, NULL); |
463 | if ( (0 != ok) && (77 != ok) ) | 468 | if ((0 != ok) && (77 != ok)) |
464 | fprintf (stderr, "Missed some testcases: %u\n", ok); | 469 | fprintf(stderr, "Missed some testcases: %u\n", ok); |
465 | GNUNET_DISK_directory_remove (dir_name); | 470 | GNUNET_DISK_directory_remove(dir_name); |
466 | return ok; | 471 | return ok; |
467 | } | 472 | } |
468 | 473 | ||