aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_plugin_datastore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-10 11:18:59 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-10 11:18:59 +0000
commit5d2bfbd4a69f87c99083fc60954c884af69258f4 (patch)
tree9fb3f83ca4e8f5bc2d8d770086882ff1ab27a56c /src/datastore/test_plugin_datastore.c
parent00abe8aad5a33c716a02e20cc8257f055edca869 (diff)
downloadgnunet-5d2bfbd4a69f87c99083fc60954c884af69258f4.tar.gz
gnunet-5d2bfbd4a69f87c99083fc60954c884af69258f4.zip
-using testing in datastore tests
Diffstat (limited to 'src/datastore/test_plugin_datastore.c')
-rw-r--r--src/datastore/test_plugin_datastore.c71
1 files changed, 23 insertions, 48 deletions
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c
index 16fe40ceb..de9e7c2ab 100644
--- a/src/datastore/test_plugin_datastore.c
+++ b/src/datastore/test_plugin_datastore.c
@@ -28,8 +28,6 @@
28#include "gnunet_protocols.h" 28#include "gnunet_protocols.h"
29#include "gnunet_datastore_plugin.h" 29#include "gnunet_datastore_plugin.h"
30 30
31#define VERBOSE GNUNET_NO
32
33/** 31/**
34 * Number of put operations to perform. 32 * Number of put operations to perform.
35 */ 33 */
@@ -117,10 +115,9 @@ put_value (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k)
117 value[0] = k; 115 value[0] = k;
118 msg = NULL; 116 msg = NULL;
119 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); 117 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
120#if VERBOSE 118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 FPRINTF (stderr, "putting type %u, anon %u under key %s\n", i + 1, i, 119 "putting type %u, anon %u under key %s\n", i + 1, i,
122 GNUNET_h2s (&key)); 120 GNUNET_h2s (&key));
123#endif
124 if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ , 121 if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ ,
125 prio, i /* anonymity */ , 122 prio, i /* anonymity */ ,
126 0 /* replication */ , 123 0 /* replication */ ,
@@ -159,12 +156,10 @@ iterate_one_shot (void *cls, const GNUNET_HashCode * key, uint32_t size,
159 GNUNET_assert (key != NULL); 156 GNUNET_assert (key != NULL);
160 guid = uid; 157 guid = uid;
161 crc->phase++; 158 crc->phase++;
162#if VERBOSE 159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 FPRINTF (stderr, 160 "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n",
164 "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n", 161 type, priority, size, (unsigned long long) expiration.abs_value,
165 type, priority, size, (unsigned long long) expiration.abs_value, 162 GNUNET_h2s (key));
166 GNUNET_h2s (key));
167#endif
168 GNUNET_SCHEDULER_add_now (&test, crc); 163 GNUNET_SCHEDULER_add_now (&test, crc);
169 return GNUNET_OK; 164 return GNUNET_OK;
170} 165}
@@ -229,9 +224,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test aborted.\n"); 224 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test aborted.\n");
230 crc->phase = RP_ERROR; 225 crc->phase = RP_ERROR;
231 } 226 }
232#if VERBOSE 227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 FPRINTF (stderr, "In phase %d, iteration %u\n", crc->phase, crc->cnt); 228 "In phase %d, iteration %u\n", crc->phase, crc->cnt);
234#endif
235 switch (crc->phase) 229 switch (crc->phase)
236 { 230 {
237 case RP_ERROR: 231 case RP_ERROR:
@@ -355,42 +349,23 @@ run (void *cls, char *const *args, const char *cfgfile,
355} 349}
356 350
357 351
358static int 352
359check () 353int
354main (int argc, char *argv[])
360{ 355{
356 char *pos;
357 char dir_name[128];
361 char cfg_name[128]; 358 char cfg_name[128];
362 359 char *const xargv[] = {
363 char *const argv[] = {
364 "test-plugin-datastore", 360 "test-plugin-datastore",
365 "-c", 361 "-c",
366 cfg_name, 362 cfg_name,
367#if VERBOSE
368 "-L", "DEBUG",
369#endif
370 NULL 363 NULL
371 }; 364 };
372 struct GNUNET_GETOPT_CommandLineOption options[] = { 365 static struct GNUNET_GETOPT_CommandLineOption options[] = {
373 GNUNET_GETOPT_OPTION_END 366 GNUNET_GETOPT_OPTION_END
374 }; 367 };
375 368
376 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
377 "test_plugin_datastore_data_%s.conf", plugin_name);
378 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
379 "test-plugin-datastore", "nohelp", options, &run, NULL);
380 if (ok != 0)
381 FPRINTF (stderr, "Missed some testcases: %u\n", ok);
382 return ok;
383}
384
385
386int
387main (int argc, char *argv[])
388{
389 int ret;
390 char *pos;
391 char dir_name[128];
392
393 sleep (1);
394 /* determine name of plugin to use */ 369 /* determine name of plugin to use */
395 plugin_name = argv[0]; 370 plugin_name = argv[0];
396 while (NULL != (pos = strstr (plugin_name, "_"))) 371 while (NULL != (pos = strstr (plugin_name, "_")))
@@ -404,18 +379,18 @@ main (int argc, char *argv[])
404 "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); 379 "/tmp/test-gnunet-datastore-plugin-%s", plugin_name);
405 GNUNET_DISK_directory_remove (dir_name); 380 GNUNET_DISK_directory_remove (dir_name);
406 GNUNET_log_setup ("test-plugin-datastore", 381 GNUNET_log_setup ("test-plugin-datastore",
407#if VERBOSE
408 "DEBUG",
409#else
410 "WARNING", 382 "WARNING",
411#endif
412 NULL); 383 NULL);
413 ret = check (); 384 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
385 "test_plugin_datastore_data_%s.conf", plugin_name);
386 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
387 "test-plugin-datastore", "nohelp", options, &run, NULL);
388 if (ok != 0)
389 FPRINTF (stderr, "Missed some testcases: %u\n", ok);
414 if (pos != plugin_name) 390 if (pos != plugin_name)
415 pos[0] = '.'; 391 pos[0] = '.';
416 GNUNET_DISK_directory_remove (dir_name); 392 GNUNET_DISK_directory_remove (dir_name);
417 393 return ok;
418 return ret;
419} 394}
420 395
421/* end of test_plugin_datastore.c */ 396/* end of test_plugin_datastore.c */