aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_datastore_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/test_datastore_api.c')
-rw-r--r--src/datastore/test_datastore_api.c718
1 files changed, 330 insertions, 388 deletions
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index f25ee08c2..39b7a1ae2 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -63,34 +63,35 @@ get_size (int i)
63static const void * 63static const void *
64get_data (int i) 64get_data (int i)
65{ 65{
66 static char buf[60000]; 66 static char buf[60000];
67
67 memset (buf, i, 8 * i); 68 memset (buf, i, 8 * i);
68 return buf; 69 return buf;
69} 70}
70 71
71 72
72static int 73static int
73get_type(int i) 74get_type (int i)
74{ 75{
75 return i+1; 76 return i + 1;
76} 77}
77 78
78 79
79static int 80static int
80get_priority (int i) 81get_priority (int i)
81{ 82{
82 return i+1; 83 return i + 1;
83} 84}
84 85
85 86
86static int 87static int
87get_anonymity(int i) 88get_anonymity (int i)
88{ 89{
89 return i; 90 return i;
90} 91}
91 92
92 93
93static struct GNUNET_TIME_Absolute 94static struct GNUNET_TIME_Absolute
94get_expiration (int i) 95get_expiration (int i)
95{ 96{
96 struct GNUNET_TIME_Absolute av; 97 struct GNUNET_TIME_Absolute av;
@@ -100,22 +101,22 @@ get_expiration (int i)
100} 101}
101 102
102enum RunPhase 103enum RunPhase
103 { 104{
104 RP_DONE = 0, 105 RP_DONE = 0,
105 RP_PUT = 1, 106 RP_PUT = 1,
106 RP_GET = 2, 107 RP_GET = 2,
107 RP_DEL = 3, 108 RP_DEL = 3,
108 RP_DO_DEL = 4, 109 RP_DO_DEL = 4,
109 RP_DELVALIDATE = 5, 110 RP_DELVALIDATE = 5,
110 RP_RESERVE = 6, 111 RP_RESERVE = 6,
111 RP_PUT_MULTIPLE = 7, 112 RP_PUT_MULTIPLE = 7,
112 RP_PUT_MULTIPLE_NEXT = 8, 113 RP_PUT_MULTIPLE_NEXT = 8,
113 RP_GET_MULTIPLE = 9, 114 RP_GET_MULTIPLE = 9,
114 RP_GET_MULTIPLE_NEXT = 10, 115 RP_GET_MULTIPLE_NEXT = 10,
115 RP_UPDATE = 11, 116 RP_UPDATE = 11,
116 RP_UPDATE_VALIDATE = 12, 117 RP_UPDATE_VALIDATE = 12,
117 RP_ERROR 118 RP_ERROR
118 }; 119};
119 120
120 121
121struct CpsRunContext 122struct CpsRunContext
@@ -134,62 +135,52 @@ struct CpsRunContext
134 135
135 136
136static void 137static void
137run_continuation (void *cls, 138run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
138 const struct GNUNET_SCHEDULER_TaskContext *tc);
139 139
140 140
141static void 141static void
142check_success (void *cls, 142check_success (void *cls, int success, const char *msg)
143 int success,
144 const char *msg)
145{ 143{
146 struct CpsRunContext *crc = cls; 144 struct CpsRunContext *crc = cls;
147 145
148 if (GNUNET_OK != success) 146 if (GNUNET_OK != success)
149 { 147 {
150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
151 "Operation %d/%d not successfull: `%s'\n", 149 "Operation %d/%d not successfull: `%s'\n",
152 crc->phase, 150 crc->phase, crc->i, msg);
153 crc->i, 151 crc->phase = RP_ERROR;
154 msg); 152 }
155 crc->phase = RP_ERROR;
156 }
157 GNUNET_free_non_null (crc->data); 153 GNUNET_free_non_null (crc->data);
158 crc->data = NULL; 154 crc->data = NULL;
159 GNUNET_SCHEDULER_add_continuation (&run_continuation, 155 GNUNET_SCHEDULER_add_continuation (&run_continuation,
160 crc, 156 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
161 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
162} 157}
163 158
164 159
165static void 160static void
166get_reserved (void *cls, 161get_reserved (void *cls, int success, const char *msg)
167 int success,
168 const char *msg)
169{ 162{
170 struct CpsRunContext *crc = cls; 163 struct CpsRunContext *crc = cls;
164
171 if (0 >= success) 165 if (0 >= success)
172 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
173 "Error obtaining reservation: `%s'\n", 167 "Error obtaining reservation: `%s'\n", msg);
174 msg);
175 GNUNET_assert (0 < success); 168 GNUNET_assert (0 < success);
176 crc->rid = success; 169 crc->rid = success;
177 GNUNET_SCHEDULER_add_continuation (&run_continuation, 170 GNUNET_SCHEDULER_add_continuation (&run_continuation,
178 crc, 171 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
179 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
180} 172}
181 173
182 174
183static void 175static void
184check_value (void *cls, 176check_value (void *cls,
185 const GNUNET_HashCode * key, 177 const GNUNET_HashCode * key,
186 size_t size, 178 size_t size,
187 const void *data, 179 const void *data,
188 enum GNUNET_BLOCK_Type type, 180 enum GNUNET_BLOCK_Type type,
189 uint32_t priority, 181 uint32_t priority,
190 uint32_t anonymity, 182 uint32_t anonymity,
191 struct GNUNET_TIME_Absolute expiration, 183 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
192 uint64_t uid)
193{ 184{
194 struct CpsRunContext *crc = cls; 185 struct CpsRunContext *crc = cls;
195 int i; 186 int i;
@@ -197,46 +188,42 @@ check_value (void *cls,
197 i = crc->i; 188 i = crc->i;
198#if 0 189#if 0
199 fprintf (stderr, 190 fprintf (stderr,
200 "Check value got `%s' of size %u, type %d, expire %llu\n", 191 "Check value got `%s' of size %u, type %d, expire %llu\n",
201 GNUNET_h2s (key), 192 GNUNET_h2s (key),
202 (unsigned int) size, 193 (unsigned int) size,
203 type, 194 type, (unsigned long long) expiration.abs_value);
204 (unsigned long long) expiration.abs_value);
205 fprintf (stderr, 195 fprintf (stderr,
206 "Check value iteration %d wants size %u, type %d, expire %llu\n", 196 "Check value iteration %d wants size %u, type %d, expire %llu\n",
207 i, 197 i,
208 (unsigned int) get_size (i), 198 (unsigned int) get_size (i),
209 get_type (i), 199 get_type (i), (unsigned long long) get_expiration (i).abs_value);
210 (unsigned long long) get_expiration(i).abs_value);
211#endif 200#endif
212 GNUNET_assert (size == get_size (i)); 201 GNUNET_assert (size == get_size (i));
213 GNUNET_assert (0 == memcmp (data, get_data(i), size)); 202 GNUNET_assert (0 == memcmp (data, get_data (i), size));
214 GNUNET_assert (type == get_type (i)); 203 GNUNET_assert (type == get_type (i));
215 GNUNET_assert (priority == get_priority (i)); 204 GNUNET_assert (priority == get_priority (i));
216 GNUNET_assert (anonymity == get_anonymity(i)); 205 GNUNET_assert (anonymity == get_anonymity (i));
217 GNUNET_assert (expiration.abs_value == get_expiration(i).abs_value); 206 GNUNET_assert (expiration.abs_value == get_expiration (i).abs_value);
218 crc->offset++; 207 crc->offset++;
219 if (crc->i == 0) 208 if (crc->i == 0)
220 { 209 {
221 crc->phase = RP_DEL; 210 crc->phase = RP_DEL;
222 crc->i = ITERATIONS; 211 crc->i = ITERATIONS;
223 } 212 }
224 GNUNET_SCHEDULER_add_continuation (&run_continuation, 213 GNUNET_SCHEDULER_add_continuation (&run_continuation,
225 crc, 214 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
226 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
227} 215}
228 216
229 217
230static void 218static void
231delete_value (void *cls, 219delete_value (void *cls,
232 const GNUNET_HashCode *key, 220 const GNUNET_HashCode * key,
233 size_t size, 221 size_t size,
234 const void *data, 222 const void *data,
235 enum GNUNET_BLOCK_Type type, 223 enum GNUNET_BLOCK_Type type,
236 uint32_t priority, 224 uint32_t priority,
237 uint32_t anonymity, 225 uint32_t anonymity,
238 struct GNUNET_TIME_Absolute 226 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
239 expiration, uint64_t uid)
240{ 227{
241 struct CpsRunContext *crc = cls; 228 struct CpsRunContext *crc = cls;
242 229
@@ -248,21 +235,19 @@ delete_value (void *cls,
248 memcpy (crc->data, data, size); 235 memcpy (crc->data, data, size);
249 crc->phase = RP_DO_DEL; 236 crc->phase = RP_DO_DEL;
250 GNUNET_SCHEDULER_add_continuation (&run_continuation, 237 GNUNET_SCHEDULER_add_continuation (&run_continuation,
251 crc, 238 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
252 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
253} 239}
254 240
255 241
256static void 242static void
257check_nothing (void *cls, 243check_nothing (void *cls,
258 const GNUNET_HashCode *key, 244 const GNUNET_HashCode * key,
259 size_t size, 245 size_t size,
260 const void *data, 246 const void *data,
261 enum GNUNET_BLOCK_Type type, 247 enum GNUNET_BLOCK_Type type,
262 uint32_t priority, 248 uint32_t priority,
263 uint32_t anonymity, 249 uint32_t anonymity,
264 struct GNUNET_TIME_Absolute 250 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
265 expiration, uint64_t uid)
266{ 251{
267 struct CpsRunContext *crc = cls; 252 struct CpsRunContext *crc = cls;
268 253
@@ -270,352 +255,310 @@ check_nothing (void *cls,
270 if (crc->i == 0) 255 if (crc->i == 0)
271 crc->phase = RP_RESERVE; 256 crc->phase = RP_RESERVE;
272 GNUNET_SCHEDULER_add_continuation (&run_continuation, 257 GNUNET_SCHEDULER_add_continuation (&run_continuation,
273 crc, 258 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
274 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
275} 259}
276 260
277 261
278static void 262static void
279check_multiple (void *cls, 263check_multiple (void *cls,
280 const GNUNET_HashCode * key, 264 const GNUNET_HashCode * key,
281 size_t size, 265 size_t size,
282 const void *data, 266 const void *data,
283 enum GNUNET_BLOCK_Type type, 267 enum GNUNET_BLOCK_Type type,
284 uint32_t priority, 268 uint32_t priority,
285 uint32_t anonymity, 269 uint32_t anonymity,
286 struct GNUNET_TIME_Absolute 270 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
287 expiration, uint64_t uid)
288{ 271{
289 struct CpsRunContext *crc = cls; 272 struct CpsRunContext *crc = cls;
290 273
291 GNUNET_assert (key != NULL); 274 GNUNET_assert (key != NULL);
292 switch (crc->phase) 275 switch (crc->phase)
293 { 276 {
294 case RP_GET_MULTIPLE: 277 case RP_GET_MULTIPLE:
295 crc->phase = RP_GET_MULTIPLE_NEXT; 278 crc->phase = RP_GET_MULTIPLE_NEXT;
296 crc->first_uid = uid; 279 crc->first_uid = uid;
297 crc->offset++; 280 crc->offset++;
298 break; 281 break;
299 case RP_GET_MULTIPLE_NEXT: 282 case RP_GET_MULTIPLE_NEXT:
300 GNUNET_assert (uid != crc->first_uid); 283 GNUNET_assert (uid != crc->first_uid);
301 crc->phase = RP_UPDATE; 284 crc->phase = RP_UPDATE;
302 break; 285 break;
303 default: 286 default:
304 GNUNET_break (0); 287 GNUNET_break (0);
305 crc->phase = RP_ERROR; 288 crc->phase = RP_ERROR;
306 break; 289 break;
307 } 290 }
308 if (priority == get_priority (42)) 291 if (priority == get_priority (42))
309 crc->uid = uid; 292 crc->uid = uid;
310 GNUNET_SCHEDULER_add_continuation (&run_continuation, 293 GNUNET_SCHEDULER_add_continuation (&run_continuation,
311 crc, 294 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
312 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
313} 295}
314 296
315 297
316static void 298static void
317check_update (void *cls, 299check_update (void *cls,
318 const GNUNET_HashCode * key, 300 const GNUNET_HashCode * key,
319 size_t size, 301 size_t size,
320 const void *data, 302 const void *data,
321 enum GNUNET_BLOCK_Type type, 303 enum GNUNET_BLOCK_Type type,
322 uint32_t priority, 304 uint32_t priority,
323 uint32_t anonymity, 305 uint32_t anonymity,
324 struct GNUNET_TIME_Absolute 306 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
325 expiration, uint64_t uid)
326{ 307{
327 struct CpsRunContext *crc = cls; 308 struct CpsRunContext *crc = cls;
328 309
329 GNUNET_assert (key != NULL); 310 GNUNET_assert (key != NULL);
330 if ( (anonymity == get_anonymity (42)) && 311 if ((anonymity == get_anonymity (42)) &&
331 (size == get_size (42)) && 312 (size == get_size (42)) && (priority == get_priority (42) + 100))
332 (priority == get_priority (42) + 100) ) 313 crc->phase = RP_DONE;
333 crc->phase = RP_DONE;
334 else 314 else
335 { 315 {
336 GNUNET_assert (size == get_size (43)); 316 GNUNET_assert (size == get_size (43));
337 crc->offset++; 317 crc->offset++;
338 } 318 }
339 GNUNET_SCHEDULER_add_continuation (&run_continuation, 319 GNUNET_SCHEDULER_add_continuation (&run_continuation,
340 crc, 320 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
341 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
342} 321}
343 322
344 323
345static void 324static void
346run_continuation (void *cls, 325run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
347 const struct GNUNET_SCHEDULER_TaskContext *tc)
348{ 326{
349 struct CpsRunContext *crc = cls; 327 struct CpsRunContext *crc = cls;
328
350 ok = (int) crc->phase; 329 ok = (int) crc->phase;
351#if VERBOSE 330#if VERBOSE
352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test in phase %u\n", crc->phase);
353 "Test in phase %u\n", crc->phase);
354#endif 332#endif
355 switch (crc->phase) 333 switch (crc->phase)
356 { 334 {
357 case RP_PUT: 335 case RP_PUT:
358#if VERBOSE 336#if VERBOSE
359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
360 "Executing `%s' number %u\n", 338 "Executing `%s' number %u\n", "PUT", crc->i);
361 "PUT",
362 crc->i);
363#endif 339#endif
364 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 340 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
365 GNUNET_DATASTORE_put (datastore, 341 GNUNET_DATASTORE_put (datastore,
366 0, 342 0,
367 &crc->key, 343 &crc->key,
368 get_size (crc->i), 344 get_size (crc->i),
369 get_data (crc->i), 345 get_data (crc->i),
370 get_type (crc->i), 346 get_type (crc->i),
371 get_priority (crc->i), 347 get_priority (crc->i),
372 get_anonymity (crc->i), 348 get_anonymity (crc->i),
373 0, 349 0,
374 get_expiration (crc->i), 350 get_expiration (crc->i),
375 1, 1, TIMEOUT, 351 1, 1, TIMEOUT, &check_success, crc);
376 &check_success, 352 crc->i++;
377 crc); 353 if (crc->i == ITERATIONS)
378 crc->i++; 354 crc->phase = RP_GET;
379 if (crc->i == ITERATIONS) 355 break;
380 crc->phase = RP_GET; 356 case RP_GET:
381 break; 357 crc->i--;
382 case RP_GET:
383 crc->i--;
384#if VERBOSE 358#if VERBOSE
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "Executing `%s' number %u\n", 360 "Executing `%s' number %u\n", "GET", crc->i);
387 "GET",
388 crc->i);
389#endif 361#endif
390 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 362 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
391 GNUNET_DATASTORE_get_key (datastore, 363 GNUNET_DATASTORE_get_key (datastore,
392 crc->offset, 364 crc->offset,
393 &crc->key, 365 &crc->key,
394 get_type (crc->i), 366 get_type (crc->i),
395 1, 1, TIMEOUT, 367 1, 1, TIMEOUT, &check_value, crc);
396 &check_value, 368 break;
397 crc); 369 case RP_DEL:
398 break; 370 crc->i--;
399 case RP_DEL:
400 crc->i--;
401#if VERBOSE 371#if VERBOSE
402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
403 "Executing `%s' number %u\n", 373 "Executing `%s' number %u\n", "DEL", crc->i);
404 "DEL",
405 crc->i);
406#endif 374#endif
407 crc->data = NULL; 375 crc->data = NULL;
408 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 376 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
409 GNUNET_assert (NULL != 377 GNUNET_assert (NULL !=
410 GNUNET_DATASTORE_get_key (datastore, 378 GNUNET_DATASTORE_get_key (datastore,
411 crc->offset, 379 crc->offset,
412 &crc->key, 380 &crc->key,
413 get_type (crc->i), 381 get_type (crc->i),
414 1, 1, TIMEOUT, 382 1, 1, TIMEOUT,
415 &delete_value, 383 &delete_value, crc));
416 crc)); 384 break;
417 break; 385 case RP_DO_DEL:
418 case RP_DO_DEL:
419#if VERBOSE 386#if VERBOSE
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421 "Executing `%s' number %u\n", 388 "Executing `%s' number %u\n", "DO_DEL", crc->i);
422 "DO_DEL",
423 crc->i);
424#endif 389#endif
425 if (crc->i == 0) 390 if (crc->i == 0)
426 { 391 {
427 crc->i = ITERATIONS; 392 crc->i = ITERATIONS;
428 crc->phase = RP_DELVALIDATE; 393 crc->phase = RP_DELVALIDATE;
429 } 394 }
430 else 395 else
431 { 396 {
432 crc->phase = RP_DEL; 397 crc->phase = RP_DEL;
433 } 398 }
434 GNUNET_assert (NULL != 399 GNUNET_assert (NULL !=
435 GNUNET_DATASTORE_remove (datastore, 400 GNUNET_DATASTORE_remove (datastore,
436 &crc->key, 401 &crc->key,
437 crc->size, 402 crc->size,
438 crc->data, 403 crc->data,
439 1, 1, TIMEOUT, 404 1, 1, TIMEOUT,
440 &check_success, 405 &check_success, crc));
441 crc)); 406 break;
442 break; 407 case RP_DELVALIDATE:
443 case RP_DELVALIDATE: 408 crc->i--;
444 crc->i--;
445#if VERBOSE 409#if VERBOSE
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "Executing `%s' number %u\n", 411 "Executing `%s' number %u\n", "DEL-VALIDATE", crc->i);
448 "DEL-VALIDATE",
449 crc->i);
450#endif 412#endif
451 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 413 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
452 GNUNET_assert (NULL != 414 GNUNET_assert (NULL !=
453 GNUNET_DATASTORE_get_key (datastore, 415 GNUNET_DATASTORE_get_key (datastore,
454 crc->offset, 416 crc->offset,
455 &crc->key, 417 &crc->key,
456 get_type (crc->i), 418 get_type (crc->i),
457 1, 1, TIMEOUT, 419 1, 1, TIMEOUT,
458 &check_nothing, 420 &check_nothing, crc));
459 crc)); 421 break;
460 break; 422 case RP_RESERVE:
461 case RP_RESERVE: 423 crc->phase = RP_PUT_MULTIPLE;
462 crc->phase = RP_PUT_MULTIPLE; 424 GNUNET_DATASTORE_reserve (datastore,
463 GNUNET_DATASTORE_reserve (datastore, 425 128 * 1024, 2, 1, 1, TIMEOUT, &get_reserved, crc);
464 128*1024, 426 break;
465 2, 427 case RP_PUT_MULTIPLE:
466 1, 1, TIMEOUT, 428 crc->phase = RP_PUT_MULTIPLE_NEXT;
467 &get_reserved, 429 GNUNET_DATASTORE_put (datastore,
468 crc); 430 crc->rid,
469 break; 431 &crc->key,
470 case RP_PUT_MULTIPLE: 432 get_size (42),
471 crc->phase = RP_PUT_MULTIPLE_NEXT; 433 get_data (42),
472 GNUNET_DATASTORE_put (datastore, 434 get_type (42),
473 crc->rid, 435 get_priority (42),
474 &crc->key, 436 get_anonymity (42),
475 get_size (42), 437 0,
476 get_data (42), 438 get_expiration (42),
477 get_type (42), 439 1, 1, TIMEOUT, &check_success, crc);
478 get_priority (42), 440 break;
479 get_anonymity (42), 441 case RP_PUT_MULTIPLE_NEXT:
480 0, 442 crc->phase = RP_GET_MULTIPLE;
481 get_expiration (42), 443 GNUNET_DATASTORE_put (datastore,
482 1, 1, TIMEOUT, 444 crc->rid,
483 &check_success, 445 &crc->key,
484 crc); 446 get_size (43),
485 break; 447 get_data (43),
486 case RP_PUT_MULTIPLE_NEXT: 448 get_type (42),
487 crc->phase = RP_GET_MULTIPLE; 449 get_priority (43),
488 GNUNET_DATASTORE_put (datastore, 450 get_anonymity (43),
489 crc->rid, 451 0,
490 &crc->key, 452 get_expiration (43),
491 get_size (43), 453 1, 1, TIMEOUT, &check_success, crc);
492 get_data (43), 454 break;
493 get_type (42), 455 case RP_GET_MULTIPLE:
494 get_priority (43), 456 GNUNET_assert (NULL !=
495 get_anonymity (43), 457 GNUNET_DATASTORE_get_key (datastore,
496 0, 458 crc->offset,
497 get_expiration (43), 459 &crc->key,
498 1, 1, TIMEOUT, 460 get_type (42),
499 &check_success, 461 1, 1, TIMEOUT,
500 crc); 462 &check_multiple, crc));
501 break; 463 break;
502 case RP_GET_MULTIPLE: 464 case RP_GET_MULTIPLE_NEXT:
503 GNUNET_assert (NULL != 465 GNUNET_assert (NULL !=
504 GNUNET_DATASTORE_get_key (datastore, 466 GNUNET_DATASTORE_get_key (datastore,
505 crc->offset, 467 crc->offset,
506 &crc->key, 468 &crc->key,
507 get_type (42), 469 get_type (42),
508 1, 1, TIMEOUT, 470 1, 1, TIMEOUT,
509 &check_multiple, 471 &check_multiple, crc));
510 crc)); 472 break;
511 break; 473 case RP_UPDATE:
512 case RP_GET_MULTIPLE_NEXT: 474 GNUNET_assert (crc->uid > 0);
513 GNUNET_assert (NULL != 475 crc->phase = RP_UPDATE_VALIDATE;
514 GNUNET_DATASTORE_get_key (datastore, 476 GNUNET_DATASTORE_update (datastore,
515 crc->offset, 477 crc->uid,
516 &crc->key, 478 100,
517 get_type (42), 479 get_expiration (42),
518 1, 1, TIMEOUT, 480 1, 1, TIMEOUT, &check_success, crc);
519 &check_multiple, 481 break;
520 crc)); 482 case RP_UPDATE_VALIDATE:
521 break; 483 GNUNET_assert (NULL !=
522 case RP_UPDATE: 484 GNUNET_DATASTORE_get_key (datastore,
523 GNUNET_assert (crc->uid > 0); 485 crc->offset,
524 crc->phase = RP_UPDATE_VALIDATE; 486 &crc->key,
525 GNUNET_DATASTORE_update (datastore, 487 get_type (42),
526 crc->uid, 488 1, 1, TIMEOUT,
527 100, 489 &check_update, crc));
528 get_expiration (42), 490 break;
529 1, 1, TIMEOUT, 491 case RP_DONE:
530 &check_success,
531 crc);
532 break;
533 case RP_UPDATE_VALIDATE:
534 GNUNET_assert (NULL !=
535 GNUNET_DATASTORE_get_key (datastore,
536 crc->offset,
537 &crc->key,
538 get_type (42),
539 1, 1, TIMEOUT,
540 &check_update,
541 crc));
542 break;
543 case RP_DONE:
544#if VERBOSE 492#if VERBOSE
545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
546 "Finished, disconnecting\n");
547#endif 494#endif
548 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); 495 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
549 GNUNET_free (crc); 496 GNUNET_free (crc);
550 ok = 0; 497 ok = 0;
551 break; 498 break;
552 case RP_ERROR: 499 case RP_ERROR:
553 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); 500 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
554 GNUNET_free (crc); 501 GNUNET_free (crc);
555 ok = 43; 502 ok = 43;
556 break; 503 break;
557 } 504 }
558} 505}
559 506
560 507
561static void 508static void
562run_tests (void *cls, 509run_tests (void *cls, int32_t success, const char *msg)
563 int32_t success,
564 const char *msg)
565{ 510{
566 struct CpsRunContext *crc = cls; 511 struct CpsRunContext *crc = cls;
567 512
568 switch (success) 513 switch (success)
569 { 514 {
570 case GNUNET_YES: 515 case GNUNET_YES:
571 GNUNET_SCHEDULER_add_continuation (&run_continuation, 516 GNUNET_SCHEDULER_add_continuation (&run_continuation,
572 crc, 517 crc,
573 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 518 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
574 return; 519 return;
575 case GNUNET_NO: 520 case GNUNET_NO:
576 fprintf (stderr, 521 fprintf (stderr, "Test 'put' operation failed, key already exists (!?)\n");
577 "Test 'put' operation failed, key already exists (!?)\n"); 522 GNUNET_free (crc);
578 GNUNET_free (crc); 523 return;
579 return; 524 case GNUNET_SYSERR:
580 case GNUNET_SYSERR: 525 fprintf (stderr,
581 fprintf (stderr, 526 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
582 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 527 msg);
583 msg); 528 GNUNET_free (crc);
584 GNUNET_free (crc); 529 return;
585 return; 530 default:
586 default: 531 GNUNET_assert (0);
587 GNUNET_assert (0); 532 }
588 }
589} 533}
590 534
591 535
592static void 536static void
593run (void *cls, 537run (void *cls,
594 char *const *args, 538 char *const *args,
595 const char *cfgfile, 539 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
596 const struct GNUNET_CONFIGURATION_Handle *cfg)
597{ 540{
598 struct CpsRunContext *crc; 541 struct CpsRunContext *crc;
599 static GNUNET_HashCode zkey; 542 static GNUNET_HashCode zkey;
600 543
601 crc = GNUNET_malloc(sizeof(struct CpsRunContext)); 544 crc = GNUNET_malloc (sizeof (struct CpsRunContext));
602 crc->cfg = cfg; 545 crc->cfg = cfg;
603 crc->phase = RP_PUT; 546 crc->phase = RP_PUT;
604 now = GNUNET_TIME_absolute_get (); 547 now = GNUNET_TIME_absolute_get ();
605 datastore = GNUNET_DATASTORE_connect (cfg); 548 datastore = GNUNET_DATASTORE_connect (cfg);
606 if (NULL == 549 if (NULL ==
607 GNUNET_DATASTORE_put (datastore, 0, 550 GNUNET_DATASTORE_put (datastore, 0,
608 &zkey, 4, "TEST", 551 &zkey, 4, "TEST",
609 GNUNET_BLOCK_TYPE_TEST, 552 GNUNET_BLOCK_TYPE_TEST,
610 0, 0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS), 553 0, 0, 0,
611 0, 1, GNUNET_TIME_UNIT_MINUTES, 554 GNUNET_TIME_relative_to_absolute
612 &run_tests, crc)) 555 (GNUNET_TIME_UNIT_SECONDS), 0, 1,
613 { 556 GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
614 fprintf (stderr, 557 {
615 "Test 'put' operation failed.\n"); 558 fprintf (stderr, "Test 'put' operation failed.\n");
616 ok = 1; 559 ok = 1;
617 GNUNET_free (crc); 560 GNUNET_free (crc);
618 } 561 }
619} 562}
620 563
621 564
@@ -623,6 +566,7 @@ static int
623check () 566check ()
624{ 567{
625 char cfg_name[128]; 568 char cfg_name[128];
569
626#if START_DATASTORE 570#if START_DATASTORE
627 struct GNUNET_OS_Process *proc; 571 struct GNUNET_OS_Process *proc;
628#endif 572#endif
@@ -639,28 +583,27 @@ check ()
639 GNUNET_GETOPT_OPTION_END 583 GNUNET_GETOPT_OPTION_END
640 }; 584 };
641 GNUNET_snprintf (cfg_name, 585 GNUNET_snprintf (cfg_name,
642 sizeof (cfg_name), 586 sizeof (cfg_name),
643 "test_datastore_api_data_%s.conf", 587 "test_datastore_api_data_%s.conf", plugin_name);
644 plugin_name);
645#if START_DATASTORE 588#if START_DATASTORE
646 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 589 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
647 "gnunet-service-arm", 590 "gnunet-service-arm",
648#if VERBOSE 591#if VERBOSE
649 "-L", "DEBUG", 592 "-L", "DEBUG",
650#endif 593#endif
651 "-c", cfg_name, NULL); 594 "-c", cfg_name, NULL);
652#endif 595#endif
653 GNUNET_assert (NULL != proc); 596 GNUNET_assert (NULL != proc);
654 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 597 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
655 argv, "test-datastore-api", "nohelp", 598 argv, "test-datastore-api", "nohelp",
656 options, &run, NULL); 599 options, &run, NULL);
657#if START_DATASTORE 600#if START_DATASTORE
658 sleep (1); /* give datastore chance to receive 'DROP' request */ 601 sleep (1); /* give datastore chance to receive 'DROP' request */
659 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 602 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
660 { 603 {
661 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 604 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
662 ok = 1; 605 ok = 1;
663 } 606 }
664 GNUNET_OS_process_wait (proc); 607 GNUNET_OS_process_wait (proc);
665 GNUNET_OS_process_close (proc); 608 GNUNET_OS_process_close (proc);
666 proc = NULL; 609 proc = NULL;
@@ -680,17 +623,16 @@ main (int argc, char *argv[])
680 sleep (1); 623 sleep (1);
681 /* determine name of plugin to use */ 624 /* determine name of plugin to use */
682 plugin_name = argv[0]; 625 plugin_name = argv[0];
683 while (NULL != (pos = strstr(plugin_name, "_"))) 626 while (NULL != (pos = strstr (plugin_name, "_")))
684 plugin_name = pos+1; 627 plugin_name = pos + 1;
685 if (NULL != (pos = strstr(plugin_name, "."))) 628 if (NULL != (pos = strstr (plugin_name, ".")))
686 pos[0] = 0; 629 pos[0] = 0;
687 else 630 else
688 pos = (char *) plugin_name; 631 pos = (char *) plugin_name;
689 632
690 GNUNET_snprintf (dir_name, 633 GNUNET_snprintf (dir_name,
691 sizeof (dir_name), 634 sizeof (dir_name),
692 "/tmp/test-gnunet-datastore-%s", 635 "/tmp/test-gnunet-datastore-%s", plugin_name);
693 plugin_name);
694 GNUNET_DISK_directory_remove (dir_name); 636 GNUNET_DISK_directory_remove (dir_name);
695 GNUNET_log_setup ("test-datastore-api", 637 GNUNET_log_setup ("test-datastore-api",
696#if VERBOSE 638#if VERBOSE