diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-10 11:18:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-10 11:18:59 +0000 |
commit | 5d2bfbd4a69f87c99083fc60954c884af69258f4 (patch) | |
tree | 9fb3f83ca4e8f5bc2d8d770086882ff1ab27a56c /src/datastore/perf_datastore_api.c | |
parent | 00abe8aad5a33c716a02e20cc8257f055edca869 (diff) | |
download | gnunet-5d2bfbd4a69f87c99083fc60954c884af69258f4.tar.gz gnunet-5d2bfbd4a69f87c99083fc60954c884af69258f4.zip |
-using testing in datastore tests
Diffstat (limited to 'src/datastore/perf_datastore_api.c')
-rw-r--r-- | src/datastore/perf_datastore_api.c | 95 |
1 files changed, 18 insertions, 77 deletions
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index cdbd6ae9c..e236b6235 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c | |||
@@ -36,19 +36,14 @@ | |||
36 | #include "gnunet_util_lib.h" | 36 | #include "gnunet_util_lib.h" |
37 | #include "gnunet_protocols.h" | 37 | #include "gnunet_protocols.h" |
38 | #include "gnunet_datastore_service.h" | 38 | #include "gnunet_datastore_service.h" |
39 | #include "gnunet_testing_lib-new.h" | ||
39 | #include <gauger.h> | 40 | #include <gauger.h> |
40 | 41 | ||
41 | #define VERBOSE GNUNET_NO | ||
42 | |||
43 | /** | 42 | /** |
44 | * How long until we give up on transmitting the message? | 43 | * How long until we give up on transmitting the message? |
45 | */ | 44 | */ |
46 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
47 | 46 | ||
48 | static const char *plugin_name; | ||
49 | |||
50 | static struct GNUNET_DATASTORE_Handle *datastore; | ||
51 | |||
52 | /** | 47 | /** |
53 | * Target datastore size (in bytes). | 48 | * Target datastore size (in bytes). |
54 | */ | 49 | */ |
@@ -81,8 +76,13 @@ static unsigned long long stored_ops; | |||
81 | 76 | ||
82 | static struct GNUNET_TIME_Absolute start_time; | 77 | static struct GNUNET_TIME_Absolute start_time; |
83 | 78 | ||
79 | static const char *plugin_name; | ||
80 | |||
81 | static struct GNUNET_DATASTORE_Handle *datastore; | ||
82 | |||
84 | static int ok; | 83 | static int ok; |
85 | 84 | ||
85 | |||
86 | enum RunPhase | 86 | enum RunPhase |
87 | { | 87 | { |
88 | RP_DONE = 0, | 88 | RP_DONE = 0, |
@@ -103,13 +103,10 @@ struct CpsRunContext | |||
103 | }; | 103 | }; |
104 | 104 | ||
105 | 105 | ||
106 | |||
107 | static void | 106 | static void |
108 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 107 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
109 | 108 | ||
110 | 109 | ||
111 | |||
112 | |||
113 | static void | 110 | static void |
114 | check_success (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) | 111 | check_success (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) |
115 | { | 112 | { |
@@ -297,7 +294,7 @@ run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, c | |||
297 | 294 | ||
298 | 295 | ||
299 | static void | 296 | static void |
300 | run (void *cls, char *const *args, const char *cfgfile, | 297 | run (void *cls, |
301 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 298 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
302 | { | 299 | { |
303 | struct CpsRunContext *crc; | 300 | struct CpsRunContext *crc; |
@@ -322,85 +319,29 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
322 | } | 319 | } |
323 | 320 | ||
324 | 321 | ||
325 | static int | ||
326 | check () | ||
327 | { | ||
328 | struct GNUNET_OS_Process *proc; | ||
329 | char cfg_name[128]; | ||
330 | |||
331 | char *const argv[] = { | ||
332 | "perf-datastore-api", | ||
333 | "-c", | ||
334 | cfg_name, | ||
335 | #if VERBOSE | ||
336 | "-L", "DEBUG", | ||
337 | #endif | ||
338 | NULL | ||
339 | }; | ||
340 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
341 | GNUNET_GETOPT_OPTION_END | ||
342 | }; | ||
343 | |||
344 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), | ||
345 | "test_datastore_api_data_%s.conf", plugin_name); | ||
346 | proc = | ||
347 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
348 | "gnunet-service-arm", | ||
349 | #if VERBOSE | ||
350 | "-L", "DEBUG", | ||
351 | #endif | ||
352 | "-c", cfg_name, NULL); | ||
353 | GNUNET_assert (NULL != proc); | ||
354 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, | ||
355 | "perf-datastore-api", "nohelp", options, &run, NULL); | ||
356 | sleep (1); /* give datastore chance to process 'DROP' */ | ||
357 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | ||
358 | { | ||
359 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
360 | ok = 1; | ||
361 | } | ||
362 | GNUNET_OS_process_wait (proc); | ||
363 | GNUNET_OS_process_destroy (proc); | ||
364 | proc = NULL; | ||
365 | return ok; | ||
366 | } | ||
367 | |||
368 | |||
369 | int | 322 | int |
370 | main (int argc, char *argv[]) | 323 | main (int argc, char *argv[]) |
371 | { | 324 | { |
372 | int ret; | ||
373 | char *pos; | 325 | char *pos; |
374 | char dir_name[128]; | 326 | char cfg_name[128]; |
375 | 327 | ||
376 | sleep (1); | ||
377 | /* determine name of plugin to use */ | 328 | /* determine name of plugin to use */ |
378 | plugin_name = argv[0]; | 329 | plugin_name = argv[0]; |
379 | while (NULL != (pos = strstr (plugin_name, "_"))) | 330 | while (NULL != (pos = strstr (plugin_name, "_"))) |
380 | plugin_name = pos + 1; | 331 | plugin_name = pos + 1; |
381 | if (NULL != (pos = strstr (plugin_name, "."))) | 332 | if (NULL != (pos = strstr (plugin_name, "."))) |
382 | pos[0] = 0; | 333 | pos[0] = '\0'; |
383 | else | 334 | else |
384 | pos = (char *) plugin_name; | 335 | pos = (char *) plugin_name; |
385 | 336 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), | |
386 | GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s", | 337 | "test_datastore_api_data_%s.conf", plugin_name); |
387 | plugin_name); | 338 | if (0 != |
388 | GNUNET_DISK_directory_remove (dir_name); | 339 | GNUNET_TESTING_peer_run ("perf-gnunet-datastore", |
389 | GNUNET_log_setup ("perf-datastore-api", | 340 | cfg_name, |
390 | #if VERBOSE | 341 | &run, |
391 | "DEBUG", | 342 | NULL)) |
392 | #else | 343 | return 1; |
393 | "WARNING", | 344 | return ok; |
394 | #endif | ||
395 | NULL); | ||
396 | ret = check (); | ||
397 | if (pos != plugin_name) | ||
398 | pos[0] = '.'; | ||
399 | #if REPORT_ID | ||
400 | FPRINTF (stderr, "%s", "\n"); | ||
401 | #endif | ||
402 | GNUNET_DISK_directory_remove (dir_name); | ||
403 | return ret; | ||
404 | } | 345 | } |
405 | 346 | ||
406 | /* end of perf_datastore_api.c */ | 347 | /* end of perf_datastore_api.c */ |