aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_plugin_datastore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/test_plugin_datastore.c')
-rw-r--r--src/datastore/test_plugin_datastore.c324
1 files changed, 143 insertions, 181 deletions
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c
index 6ac2d7a6e..15cca61f1 100644
--- a/src/datastore/test_plugin_datastore.c
+++ b/src/datastore/test_plugin_datastore.c
@@ -46,22 +46,22 @@ static const char *plugin_name;
46static int ok; 46static int ok;
47 47
48enum RunPhase 48enum RunPhase
49 { 49{
50 RP_ERROR = 0, 50 RP_ERROR = 0,
51 RP_PUT, 51 RP_PUT,
52 RP_GET, 52 RP_GET,
53 RP_UPDATE, 53 RP_UPDATE,
54 RP_ITER_ZERO, 54 RP_ITER_ZERO,
55 RP_REPL_GET, 55 RP_REPL_GET,
56 RP_EXPI_GET, 56 RP_EXPI_GET,
57 RP_DROP 57 RP_DROP
58 }; 58};
59 59
60 60
61struct CpsRunContext 61struct CpsRunContext
62{ 62{
63 const struct GNUNET_CONFIGURATION_Handle *cfg; 63 const struct GNUNET_CONFIGURATION_Handle *cfg;
64 struct GNUNET_DATASTORE_PluginFunctions * api; 64 struct GNUNET_DATASTORE_PluginFunctions *api;
65 enum RunPhase phase; 65 enum RunPhase phase;
66 unsigned int cnt; 66 unsigned int cnt;
67 unsigned int i; 67 unsigned int i;
@@ -78,27 +78,23 @@ struct CpsRunContext
78 * 0 for "reset to empty" 78 * 0 for "reset to empty"
79 */ 79 */
80static void 80static void
81disk_utilization_change_cb (void *cls, 81disk_utilization_change_cb (void *cls, int delta)
82 int delta)
83{ 82{
84 /* do nothing */ 83 /* do nothing */
85} 84}
86 85
87 86
88static void 87static void
89gen_key (int i, 88gen_key (int i, GNUNET_HashCode * key)
90 GNUNET_HashCode *key)
91{ 89{
92 memset (key, 0, sizeof (GNUNET_HashCode)); 90 memset (key, 0, sizeof (GNUNET_HashCode));
93 key->bits[0] = (unsigned int) i; 91 key->bits[0] = (unsigned int) i;
94 GNUNET_CRYPTO_hash (key, sizeof (GNUNET_HashCode), key); 92 GNUNET_CRYPTO_hash (key, sizeof (GNUNET_HashCode), key);
95} 93}
96 94
97 95
98static void 96static void
99put_value (struct GNUNET_DATASTORE_PluginFunctions * api, 97put_value (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k)
100 int i,
101 int k)
102{ 98{
103 char value[65536]; 99 char value[65536];
104 size_t size; 100 size_t size;
@@ -109,7 +105,7 @@ put_value (struct GNUNET_DATASTORE_PluginFunctions * api,
109 /* most content is 32k */ 105 /* most content is 32k */
110 size = 32 * 1024; 106 size = 32 * 1024;
111 107
112 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ 108 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
113 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); 109 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
114 size = size - (size & 7); /* always multiple of 8 */ 110 size = size - (size & 7); /* always multiple of 8 */
115 111
@@ -122,37 +118,31 @@ put_value (struct GNUNET_DATASTORE_PluginFunctions * api,
122 msg = NULL; 118 msg = NULL;
123 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); 119 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
124#if VERBOSE 120#if VERBOSE
125 fprintf (stderr, 121 fprintf (stderr,
126 "putting type %u, anon %u under key %s\n", 122 "putting type %u, anon %u under key %s\n",
127 i+1, i, GNUNET_h2s (&key)); 123 i + 1, i, GNUNET_h2s (&key));
128#endif 124#endif
129 if (GNUNET_OK != api->put (api->cls, 125 if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ ,
130 &key, 126 prio, i /* anonymity */ ,
131 size, 127 0 /* replication */ ,
132 value, 128 GNUNET_TIME_relative_to_absolute
133 i + 1 /* type */, 129 (GNUNET_TIME_relative_multiply
134 prio, 130 (GNUNET_TIME_UNIT_MILLISECONDS,
135 i /* anonymity */, 131 60 * 60 * 60 * 1000 +
136 0 /* replication */, 132 GNUNET_CRYPTO_random_u32
137 GNUNET_TIME_relative_to_absolute 133 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), &msg))
138 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 134 {
139 60 * 60 * 60 * 1000 + 135 fprintf (stderr, "ERROR: `%s'\n", msg);
140 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 136 GNUNET_free_non_null (msg);
141 &msg)) 137 return;
142 { 138 }
143 fprintf (stderr, "ERROR: `%s'\n", msg);
144 GNUNET_free_non_null (msg);
145 return;
146 }
147 stored_bytes += size; 139 stored_bytes += size;
148 stored_ops++; 140 stored_ops++;
149 stored_entries++; 141 stored_entries++;
150} 142}
151 143
152 144
153static void 145static void test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
154test (void *cls,
155 const struct GNUNET_SCHEDULER_TaskContext *tc);
156 146
157 147
158static uint64_t guid; 148static uint64_t guid;
@@ -160,28 +150,25 @@ static uint64_t guid;
160 150
161static int 151static int
162iterate_one_shot (void *cls, 152iterate_one_shot (void *cls,
163 const GNUNET_HashCode * key, 153 const GNUNET_HashCode * key,
164 uint32_t size, 154 uint32_t size,
165 const void *data, 155 const void *data,
166 enum GNUNET_BLOCK_Type type, 156 enum GNUNET_BLOCK_Type type,
167 uint32_t priority, 157 uint32_t priority,
168 uint32_t anonymity, 158 uint32_t anonymity,
169 struct GNUNET_TIME_Absolute 159 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
170 expiration,
171 uint64_t uid)
172{ 160{
173 struct CpsRunContext *crc = cls; 161 struct CpsRunContext *crc = cls;
174 162
175 GNUNET_assert (key != NULL); 163 GNUNET_assert (key != NULL);
176 guid = uid; 164 guid = uid;
177 crc->phase++; 165 crc->phase++;
178#if VERBOSE 166#if VERBOSE
179 fprintf (stderr, 167 fprintf (stderr,
180 "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n", 168 "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n",
181 type, priority, size, 169 type, priority, size,
182 (unsigned long long) expiration.abs_value, 170 (unsigned long long) expiration.abs_value, GNUNET_h2s (key));
183 GNUNET_h2s (key)); 171#endif
184#endif
185 GNUNET_SCHEDULER_add_now (&test, crc); 172 GNUNET_SCHEDULER_add_now (&test, crc);
186 return GNUNET_OK; 173 return GNUNET_OK;
187} 174}
@@ -195,8 +182,8 @@ iterate_one_shot (void *cls,
195 * @param cfg configuration to use 182 * @param cfg configuration to use
196 */ 183 */
197static void 184static void
198unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api, 185unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
199 const struct GNUNET_CONFIGURATION_Handle *cfg) 186 const struct GNUNET_CONFIGURATION_Handle *cfg)
200{ 187{
201 char *name; 188 char *name;
202 char *libname; 189 char *libname;
@@ -204,13 +191,12 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
204 if (GNUNET_OK != 191 if (GNUNET_OK !=
205 GNUNET_CONFIGURATION_get_value_string (cfg, 192 GNUNET_CONFIGURATION_get_value_string (cfg,
206 "DATASTORE", "DATABASE", &name)) 193 "DATASTORE", "DATABASE", &name))
207 { 194 {
208 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
209 _("No `%s' specified for `%s' in configuration!\n"), 196 _("No `%s' specified for `%s' in configuration!\n"),
210 "DATABASE", 197 "DATABASE", "DATASTORE");
211 "DATASTORE"); 198 return;
212 return; 199 }
213 }
214 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 200 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
215 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); 201 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
216 GNUNET_free (libname); 202 GNUNET_free (libname);
@@ -224,8 +210,7 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions * api,
224 * the transport and core. 210 * the transport and core.
225 */ 211 */
226static void 212static void
227cleaning_task (void *cls, 213cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
228 const struct GNUNET_SCHEDULER_TaskContext *tc)
229{ 214{
230 struct CpsRunContext *crc = cls; 215 struct CpsRunContext *crc = cls;
231 216
@@ -235,9 +220,8 @@ cleaning_task (void *cls,
235 220
236 221
237static void 222static void
238test (void *cls, 223test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
239 const struct GNUNET_SCHEDULER_TaskContext *tc) 224{
240{
241 struct CpsRunContext *crc = cls; 225 struct CpsRunContext *crc = cls;
242 int j; 226 int j;
243 unsigned long long os; 227 unsigned long long os;
@@ -245,91 +229,76 @@ test (void *cls,
245 GNUNET_HashCode key; 229 GNUNET_HashCode key;
246 230
247 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 231 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
248 { 232 {
249 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 233 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test aborted.\n");
250 "Test aborted.\n"); 234 crc->phase = RP_ERROR;
251 crc->phase = RP_ERROR; 235 }
252 }
253#if VERBOSE 236#if VERBOSE
254 fprintf (stderr, "In phase %d, iteration %u\n", 237 fprintf (stderr, "In phase %d, iteration %u\n", crc->phase, crc->cnt);
255 crc->phase,
256 crc->cnt);
257#endif 238#endif
258 switch (crc->phase) 239 switch (crc->phase)
240 {
241 case RP_ERROR:
242 ok = 1;
243 GNUNET_break (0);
244 crc->api->drop (crc->api->cls);
245 GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
246 break;
247 case RP_PUT:
248 os = 0;
249 for (j = 0; j < PUT_10; j++)
259 { 250 {
260 case RP_ERROR: 251 put_value (crc->api, j, crc->i);
261 ok = 1; 252 cs = crc->api->estimate_size (crc->api->cls);
262 GNUNET_break (0); 253 GNUNET_assert (os <= cs);
263 crc->api->drop (crc->api->cls); 254 os = cs;
264 GNUNET_SCHEDULER_add_now (&cleaning_task, crc); 255 }
265 break; 256 crc->phase++;
266 case RP_PUT: 257 GNUNET_SCHEDULER_add_now (&test, crc);
267 os = 0; 258 break;
268 for (j=0;j<PUT_10;j++) 259 case RP_GET:
269 { 260 if (crc->cnt == 1)
270 put_value (crc->api, j, crc->i); 261 {
271 cs = crc->api->estimate_size (crc->api->cls); 262 crc->cnt = 0;
272 GNUNET_assert (os <= cs);
273 os = cs;
274 }
275 crc->phase++; 263 crc->phase++;
276 GNUNET_SCHEDULER_add_now (&test, crc); 264 GNUNET_SCHEDULER_add_now (&test, crc);
277 break; 265 break;
278 case RP_GET: 266 }
279 if (crc->cnt == 1) 267 gen_key (5, &key);
280 { 268 crc->api->get_key (crc->api->cls,
281 crc->cnt = 0; 269 crc->offset++,
282 crc->phase++; 270 &key, NULL,
283 GNUNET_SCHEDULER_add_now (&test, crc); 271 GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc);
284 break; 272 break;
285 } 273 case RP_UPDATE:
286 gen_key (5, &key); 274 GNUNET_assert (GNUNET_OK ==
287 crc->api->get_key (crc->api->cls, 275 crc->api->update (crc->api->cls,
288 crc->offset++, 276 guid, 1, GNUNET_TIME_UNIT_ZERO_ABS, NULL));
289 &key, NULL, 277 crc->phase++;
290 GNUNET_BLOCK_TYPE_ANY, 278 GNUNET_SCHEDULER_add_now (&test, crc);
291 &iterate_one_shot, 279 break;
292 crc); 280
293 break; 281 case RP_ITER_ZERO:
294 case RP_UPDATE: 282 if (crc->cnt == 1)
295 GNUNET_assert (GNUNET_OK == 283 {
296 crc->api->update (crc->api->cls, 284 crc->cnt = 0;
297 guid, 1,
298 GNUNET_TIME_UNIT_ZERO_ABS,
299 NULL));
300 crc->phase++; 285 crc->phase++;
301 GNUNET_SCHEDULER_add_now (&test, crc); 286 GNUNET_SCHEDULER_add_now (&test, crc);
302 break; 287 break;
303
304 case RP_ITER_ZERO:
305 if (crc->cnt == 1)
306 {
307 crc->cnt = 0;
308 crc->phase++;
309 GNUNET_SCHEDULER_add_now (&test, crc);
310 break;
311 }
312 crc->api->get_zero_anonymity (crc->api->cls,
313 0,
314 1,
315 &iterate_one_shot,
316 crc);
317 break;
318 case RP_REPL_GET:
319 crc->api->get_replication (crc->api->cls,
320 &iterate_one_shot,
321 crc);
322 break;
323 case RP_EXPI_GET:
324 crc->api->get_expiration (crc->api->cls,
325 &iterate_one_shot,
326 crc);
327 break;
328 case RP_DROP:
329 crc->api->drop (crc->api->cls);
330 GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
331 break;
332 } 288 }
289 crc->api->get_zero_anonymity (crc->api->cls, 0, 1, &iterate_one_shot, crc);
290 break;
291 case RP_REPL_GET:
292 crc->api->get_replication (crc->api->cls, &iterate_one_shot, crc);
293 break;
294 case RP_EXPI_GET:
295 crc->api->get_expiration (crc->api->cls, &iterate_one_shot, crc);
296 break;
297 case RP_DROP:
298 crc->api->drop (crc->api->cls);
299 GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
300 break;
301 }
333} 302}
334 303
335 304
@@ -340,20 +309,19 @@ static struct GNUNET_DATASTORE_PluginFunctions *
340load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) 309load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
341{ 310{
342 static struct GNUNET_DATASTORE_PluginEnvironment env; 311 static struct GNUNET_DATASTORE_PluginEnvironment env;
343 struct GNUNET_DATASTORE_PluginFunctions * ret; 312 struct GNUNET_DATASTORE_PluginFunctions *ret;
344 char *name; 313 char *name;
345 char *libname; 314 char *libname;
346 315
347 if (GNUNET_OK != 316 if (GNUNET_OK !=
348 GNUNET_CONFIGURATION_get_value_string (cfg, 317 GNUNET_CONFIGURATION_get_value_string (cfg,
349 "DATASTORE", "DATABASE", &name)) 318 "DATASTORE", "DATABASE", &name))
350 { 319 {
351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 320 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
352 _("No `%s' specified for `%s' in configuration!\n"), 321 _("No `%s' specified for `%s' in configuration!\n"),
353 "DATABASE", 322 "DATABASE", "DATASTORE");
354 "DATASTORE"); 323 return NULL;
355 return NULL; 324 }
356 }
357 env.cfg = cfg; 325 env.cfg = cfg;
358 env.duc = &disk_utilization_change_cb; 326 env.duc = &disk_utilization_change_cb;
359 env.cls = NULL; 327 env.cls = NULL;
@@ -361,12 +329,10 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
361 _("Loading `%s' datastore plugin\n"), name); 329 _("Loading `%s' datastore plugin\n"), name);
362 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 330 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
363 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) 331 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
364 { 332 {
365 fprintf (stderr, 333 fprintf (stderr, "Failed to load plugin `%s'!\n", name);
366 "Failed to load plugin `%s'!\n", 334 return NULL;
367 name); 335 }
368 return NULL;
369 }
370 GNUNET_free (libname); 336 GNUNET_free (libname);
371 GNUNET_free (name); 337 GNUNET_free (name);
372 return ret; 338 return ret;
@@ -376,20 +342,19 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
376static void 342static void
377run (void *cls, 343run (void *cls,
378 char *const *args, 344 char *const *args,
379 const char *cfgfile, 345 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
380 const struct GNUNET_CONFIGURATION_Handle *c)
381{ 346{
382 struct GNUNET_DATASTORE_PluginFunctions *api; 347 struct GNUNET_DATASTORE_PluginFunctions *api;
383 struct CpsRunContext *crc; 348 struct CpsRunContext *crc;
384 349
385 api = load_plugin (c); 350 api = load_plugin (c);
386 if (api == NULL) 351 if (api == NULL)
387 { 352 {
388 fprintf (stderr, 353 fprintf (stderr,
389 "Could not initialize plugin, assuming database not configured. Test not run!\n"); 354 "Could not initialize plugin, assuming database not configured. Test not run!\n");
390 return; 355 return;
391 } 356 }
392 crc = GNUNET_malloc(sizeof(struct CpsRunContext)); 357 crc = GNUNET_malloc (sizeof (struct CpsRunContext));
393 crc->api = api; 358 crc->api = api;
394 crc->cfg = c; 359 crc->cfg = c;
395 crc->phase = RP_PUT; 360 crc->phase = RP_PUT;
@@ -401,7 +366,8 @@ static int
401check () 366check ()
402{ 367{
403 char cfg_name[128]; 368 char cfg_name[128];
404 char *const argv[] = { 369
370 char *const argv[] = {
405 "test-plugin-datastore", 371 "test-plugin-datastore",
406 "-c", 372 "-c",
407 cfg_name, 373 cfg_name,
@@ -415,9 +381,8 @@ check ()
415 }; 381 };
416 382
417 GNUNET_snprintf (cfg_name, 383 GNUNET_snprintf (cfg_name,
418 sizeof (cfg_name), 384 sizeof (cfg_name),
419 "test_plugin_datastore_data_%s.conf", 385 "test_plugin_datastore_data_%s.conf", plugin_name);
420 plugin_name);
421 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 386 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
422 argv, "test-plugin-datastore", "nohelp", 387 argv, "test-plugin-datastore", "nohelp",
423 options, &run, NULL); 388 options, &run, NULL);
@@ -437,17 +402,16 @@ main (int argc, char *argv[])
437 sleep (1); 402 sleep (1);
438 /* determine name of plugin to use */ 403 /* determine name of plugin to use */
439 plugin_name = argv[0]; 404 plugin_name = argv[0];
440 while (NULL != (pos = strstr(plugin_name, "_"))) 405 while (NULL != (pos = strstr (plugin_name, "_")))
441 plugin_name = pos+1; 406 plugin_name = pos + 1;
442 if (NULL != (pos = strstr(plugin_name, "."))) 407 if (NULL != (pos = strstr (plugin_name, ".")))
443 pos[0] = 0; 408 pos[0] = 0;
444 else 409 else
445 pos = (char *) plugin_name; 410 pos = (char *) plugin_name;
446 411
447 GNUNET_snprintf (dir_name, 412 GNUNET_snprintf (dir_name,
448 sizeof (dir_name), 413 sizeof (dir_name),
449 "/tmp/test-gnunet-datastore-plugin-%s", 414 "/tmp/test-gnunet-datastore-plugin-%s", plugin_name);
450 plugin_name);
451 GNUNET_DISK_directory_remove (dir_name); 415 GNUNET_DISK_directory_remove (dir_name);
452 GNUNET_log_setup ("test-plugin-datastore", 416 GNUNET_log_setup ("test-plugin-datastore",
453#if VERBOSE 417#if VERBOSE
@@ -465,5 +429,3 @@ main (int argc, char *argv[])
465} 429}
466 430
467/* end of test_plugin_datastore.c */ 431/* end of test_plugin_datastore.c */
468
469