aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_datastore_api_management.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_datastore_api_management.c
parent00abe8aad5a33c716a02e20cc8257f055edca869 (diff)
downloadgnunet-5d2bfbd4a69f87c99083fc60954c884af69258f4.tar.gz
gnunet-5d2bfbd4a69f87c99083fc60954c884af69258f4.zip
-using testing in datastore tests
Diffstat (limited to 'src/datastore/test_datastore_api_management.c')
-rw-r--r--src/datastore/test_datastore_api_management.c131
1 files changed, 34 insertions, 97 deletions
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index bb3898e08..9b5fb4e6f 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -22,13 +22,12 @@
22 * @brief Test for the space management functions of the datastore implementation. 22 * @brief Test for the space management functions of the datastore implementation.
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25
26#include "platform.h" 25#include "platform.h"
27#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
28#include "gnunet_protocols.h" 27#include "gnunet_protocols.h"
29#include "gnunet_datastore_service.h" 28#include "gnunet_datastore_service.h"
29#include "gnunet_testing_lib-new.h"
30 30
31#define VERBOSE GNUNET_NO
32 31
33/** 32/**
34 * How long until we give up on transmitting the message? 33 * How long until we give up on transmitting the message?
@@ -41,6 +40,27 @@
41 */ 40 */
42#define ITERATIONS 5000 41#define ITERATIONS 5000
43 42
43enum RunPhase
44{
45 RP_PUT,
46 RP_GET,
47 RP_DONE,
48 RP_GET_FAIL
49};
50
51
52struct CpsRunContext
53{
54 GNUNET_HashCode key;
55 int i;
56 int found;
57 const struct GNUNET_CONFIGURATION_Handle *cfg;
58 void *data;
59 enum RunPhase phase;
60 uint64_t offset;
61};
62
63
44static struct GNUNET_DATASTORE_Handle *datastore; 64static struct GNUNET_DATASTORE_Handle *datastore;
45 65
46static struct GNUNET_TIME_Absolute now; 66static struct GNUNET_TIME_Absolute now;
@@ -49,6 +69,7 @@ static int ok;
49 69
50static const char *plugin_name; 70static const char *plugin_name;
51 71
72
52static size_t 73static size_t
53get_size (int i) 74get_size (int i)
54{ 75{
@@ -96,26 +117,6 @@ get_expiration (int i)
96 return av; 117 return av;
97} 118}
98 119
99enum RunPhase
100{
101 RP_PUT,
102 RP_GET,
103 RP_DONE,
104 RP_GET_FAIL
105};
106
107
108struct CpsRunContext
109{
110 GNUNET_HashCode key;
111 int i;
112 int found;
113 const struct GNUNET_CONFIGURATION_Handle *cfg;
114 void *data;
115 enum RunPhase phase;
116 uint64_t offset;
117};
118
119 120
120static void 121static void
121run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 122run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
@@ -193,10 +194,8 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
193 switch (crc->phase) 194 switch (crc->phase)
194 { 195 {
195 case RP_PUT: 196 case RP_PUT:
196#if VERBOSE
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT", 197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT",
198 crc->i); 198 crc->i);
199#endif
200 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 199 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
201 GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i), 200 GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i),
202 get_data (crc->i), get_type (crc->i), 201 get_data (crc->i), get_type (crc->i),
@@ -214,20 +213,16 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
214 } 213 }
215 break; 214 break;
216 case RP_GET: 215 case RP_GET:
217#if VERBOSE
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET", 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
219 crc->i); 217 crc->i);
220#endif
221 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 218 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
222 GNUNET_DATASTORE_get_key (datastore, crc->offset++, &crc->key, 219 GNUNET_DATASTORE_get_key (datastore, crc->offset++, &crc->key,
223 get_type (crc->i), 1, 1, TIMEOUT, &check_value, 220 get_type (crc->i), 1, 1, TIMEOUT, &check_value,
224 crc); 221 crc);
225 break; 222 break;
226 case RP_GET_FAIL: 223 case RP_GET_FAIL:
227#if VERBOSE
228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)", 224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)",
229 crc->i); 225 crc->i);
230#endif
231 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 226 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
232 GNUNET_DATASTORE_get_key (datastore, crc->offset++, &crc->key, 227 GNUNET_DATASTORE_get_key (datastore, crc->offset++, &crc->key,
233 get_type (crc->i), 1, 1, TIMEOUT, &check_nothing, 228 get_type (crc->i), 1, 1, TIMEOUT, &check_nothing,
@@ -235,9 +230,7 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
235 break; 230 break;
236 case RP_DONE: 231 case RP_DONE:
237 GNUNET_assert (0 == crc->i); 232 GNUNET_assert (0 == crc->i);
238#if VERBOSE
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n"); 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
240#endif
241 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); 234 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
242 GNUNET_free (crc); 235 GNUNET_free (crc);
243 ok = 0; 236 ok = 0;
@@ -265,7 +258,7 @@ run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, c
265 258
266 259
267static void 260static void
268run (void *cls, char *const *args, const char *cfgfile, 261run (void *cls,
269 const struct GNUNET_CONFIGURATION_Handle *cfg) 262 const struct GNUNET_CONFIGURATION_Handle *cfg)
270{ 263{
271 struct CpsRunContext *crc; 264 struct CpsRunContext *crc;
@@ -290,61 +283,12 @@ run (void *cls, char *const *args, const char *cfgfile,
290} 283}
291 284
292 285
293
294static int
295check ()
296{
297 struct GNUNET_OS_Process *proc;
298 char cfg_name[128];
299
300 char *const argv[] = {
301 "test-datastore-api-management",
302 "-c",
303 cfg_name,
304#if VERBOSE
305 "-L", "DEBUG",
306#endif
307 NULL
308 };
309 struct GNUNET_GETOPT_CommandLineOption options[] = {
310 GNUNET_GETOPT_OPTION_END
311 };
312 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
313 "test_datastore_api_data_%s.conf", plugin_name);
314 proc =
315 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
316 "gnunet-service-arm",
317#if VERBOSE
318 "-L", "DEBUG",
319#endif
320 "-c", cfg_name, NULL);
321 GNUNET_assert (NULL != proc);
322 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
323 "test-datastore-api-management", "nohelp", options, &run,
324 NULL);
325 sleep (1); /* give datastore chance to process 'DROP' request */
326 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
327 {
328 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
329 ok = 1;
330 }
331 GNUNET_OS_process_wait (proc);
332 GNUNET_OS_process_destroy (proc);
333 proc = NULL;
334 if (ok != 0)
335 FPRINTF (stderr, "Missed some testcases: %u\n", ok);
336 return ok;
337}
338
339int 286int
340main (int argc, char *argv[]) 287main (int argc, char *argv[])
341{ 288{
342 int ret;
343
344 char *pos; 289 char *pos;
345 char dir_name[128]; 290 char cfg_name[128];
346 291
347 sleep (1);
348 /* determine name of plugin to use */ 292 /* determine name of plugin to use */
349 plugin_name = argv[0]; 293 plugin_name = argv[0];
350 while (NULL != (pos = strstr (plugin_name, "_"))) 294 while (NULL != (pos = strstr (plugin_name, "_")))
@@ -353,22 +297,15 @@ main (int argc, char *argv[])
353 pos[0] = 0; 297 pos[0] = 0;
354 else 298 else
355 pos = (char *) plugin_name; 299 pos = (char *) plugin_name;
356 300 GNUNET_snprintf (cfg_name, sizeof (cfg_name),
357 GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s", 301 "test_datastore_api_data_%s.conf", plugin_name);
358 plugin_name); 302 if (0 !=
359 GNUNET_DISK_directory_remove (dir_name); 303 GNUNET_TESTING_peer_run ("test-gnunet-datastore-management",
360 GNUNET_log_setup ("test-datastore-api-management", 304 cfg_name,
361#if VERBOSE 305 &run,
362 "DEBUG", 306 NULL))
363#else 307 return 1;
364 "WARNING", 308 return ok;
365#endif
366 NULL);
367 ret = check ();
368 if (pos != plugin_name)
369 pos[0] = '.';
370 GNUNET_DISK_directory_remove (dir_name);
371 return ret;
372} 309}
373 310
374/* end of test_datastore_api_management.c */ 311/* end of test_datastore_api_management.c */