aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-06-17 02:23:24 +0000
committerChristian Grothoff <christian@grothoff.org>2009-06-17 02:23:24 +0000
commit4ac29e4a039e4f403a03f3bfb959c1bef4501846 (patch)
tree46ab02de49a3449c06e2eb1ba44e4f1755b4be8d /src
parent20945e0603fd6817a87165a9b471654130cb6d67 (diff)
downloadgnunet-4ac29e4a039e4f403a03f3bfb959c1bef4501846.tar.gz
gnunet-4ac29e4a039e4f403a03f3bfb959c1bef4501846.zip
towards compiling tests
Diffstat (limited to 'src')
-rw-r--r--src/datastore/Makefile.am1
-rw-r--r--src/datastore/perf_datastore_api.c217
-rw-r--r--src/datastore/test_datastore_api.c423
-rw-r--r--src/datastore/test_datastore_api_data.conf22
4 files changed, 351 insertions, 312 deletions
diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am
index 3fdf181d0..1ad59099c 100644
--- a/src/datastore/Makefile.am
+++ b/src/datastore/Makefile.am
@@ -81,3 +81,4 @@ perf_datastore_api_iterators_LDADD = \
81 $(top_builddir)/src/util/libgnunetutil.la 81 $(top_builddir)/src/util/libgnunetutil.la
82 82
83 83
84EXTRA_DIST = test_datastore_api_data.conf
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 5001ff2a6..7b3b6cfff 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -18,8 +18,8 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/* 20/*
21 * @file applications/sqstore_sqlite/sqlitetest2.c 21 * @file datastore/perf_datastore_api.c
22 * @brief Test for the sqstore implementations. 22 * @brief performance measurement for the datastore implementation
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * 24 *
25 * This testcase inserts a bunch of (variable size) data and then deletes 25 * This testcase inserts a bunch of (variable size) data and then deletes
@@ -42,12 +42,11 @@
42 */ 42 */
43 43
44#include "platform.h" 44#include "platform.h"
45#include "gnunet_util.h" 45#include "gnunet_util_lib.h"
46#include "gnunet_protocols.h" 46#include "gnunet_protocols.h"
47#include "gnunet_sqstore_service.h" 47#include "gnunet_datastore_service.h"
48#include "core.h"
49 48
50#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0) 49static struct GNUNET_DATASTORE_Handle *datastore;
51 50
52/** 51/**
53 * Target datastore size (in bytes). 52 * Target datastore size (in bytes).
@@ -110,7 +109,7 @@
110 * permission to the respective directory in order 109 * permission to the respective directory in order
111 * to obtain all of the performance information. 110 * to obtain all of the performance information.
112 */ 111 */
113#define DB_NAME "/tmp/gnunet-sqlite-sqstore-test/data/fs/" 112#define DB_NAME "/tmp/gnunet-datastore-test/data/fs/"
114 113
115static unsigned long long stored_bytes; 114static unsigned long long stored_bytes;
116 115
@@ -118,93 +117,81 @@ static unsigned long long stored_entries;
118 117
119static unsigned long long stored_ops; 118static unsigned long long stored_ops;
120 119
121static GNUNET_CronTime start_time; 120static struct GNUNET_TIME_Absolute start_time;
122 121
123static int 122static int
124putValue (GNUNET_SQstore_ServiceAPI * api, int i, int k) 123putValue (int i, int k)
125{ 124{
126 GNUNET_DatastoreValue *value;
127 size_t size; 125 size_t size;
128 static GNUNET_HashCode key; 126 static GNUNET_HashCode key;
129 static int ic; 127 static int ic;
128 static char data[65536];
130 129
131 /* most content is 32k */ 130 /* most content is 32k */
132 size = sizeof (GNUNET_DatastoreValue) + 32 * 1024; 131 size = 32 * 1024;
133 if (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ 132 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
134 size = 133 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
135 sizeof (GNUNET_DatastoreValue) +
136 GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 32 * 1024);
137 size = size - (size & 7); /* always multiple of 8 */ 134 size = size - (size & 7); /* always multiple of 8 */
138 135
139 /* generate random key */ 136 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
140 GNUNET_hash (&key, sizeof (GNUNET_HashCode), &key); 137 memset (data, i, size);
141 value = GNUNET_malloc (size);
142 value->size = htonl (size);
143 value->type = htonl (i);
144 value->priority =
145 htonl (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 100));
146 value->anonymity_level = htonl (i);
147 value->expiration_time =
148 GNUNET_htonll (GNUNET_get_time () +
149 GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 1000));
150 memset (&value[1], i, size - sizeof (GNUNET_DatastoreValue));
151 if (i > 255) 138 if (i > 255)
152 memset (&value[1], i - 255, (size - sizeof (GNUNET_DatastoreValue)) / 2); 139 memset (data, i - 255, size / 2);
153 ((char *) &value[1])[0] = k; 140 data[0] = k;
154 if (GNUNET_OK != api->put (&key, value)) 141 GNUNET_DATASTORE_put (datastore,
155 { 142 0,
156 GNUNET_free (value); 143 &key,
157 fprintf (stderr, "E"); 144 size,
158 return GNUNET_SYSERR; 145 data,
159 } 146 i,
147 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100),
148 i,
149 GNUNET_TIME_relative_to_absolute
150 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
151 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
152 NULL, NULL);
160 ic++; 153 ic++;
161#if REPORT_ID 154#if REPORT_ID
162 if (ic % REP_FREQ == 0) 155 if (ic % REP_FREQ == 0)
163 fprintf (stderr, "I"); 156 fprintf (stderr, "I");
164#endif 157#endif
165 stored_bytes += ntohl (value->size); 158 stored_bytes += size;
166 stored_ops++; 159 stored_ops++;
167 stored_entries++; 160 stored_entries++;
168 GNUNET_free (value);
169 return GNUNET_OK; 161 return GNUNET_OK;
170} 162}
171 163
172static int 164
173iterateDelete (const GNUNET_HashCode * key, 165static void
174 const GNUNET_DatastoreValue * val, void *cls, 166iterate_delete (void *cls,
175 unsigned long long uid) 167 const GNUNET_HashCode * key,
168 uint32_t size,
169 const void *data,
170 uint32_t type,
171 uint32_t priority,
172 uint32_t anonymity,
173 struct GNUNET_TIME_Absolute
174 expiration, uint64_t uid)
176{ 175{
177 GNUNET_SQstore_ServiceAPI *api = cls; 176 GNUNET_DATASTORE_remove (datastore, key, size, data, NULL, NULL);
178 static int dc;
179
180 if (api->getSize () < MAX_SIZE)
181 return GNUNET_SYSERR;
182 if (GNUNET_shutdown_test () == GNUNET_YES)
183 return GNUNET_SYSERR;
184 dc++;
185#if REPORT_ID
186 if (dc % REP_FREQ == 0)
187 fprintf (stderr, "D");
188#endif
189 stored_bytes -= ntohl (val->size);
190 stored_entries--;
191 return GNUNET_NO;
192} 177}
193 178
194/** 179
195 * Add testcode here! 180
196 */ 181static void
197static int 182run (void *cls,
198test (GNUNET_SQstore_ServiceAPI * api) 183 struct GNUNET_SCHEDULER_Handle *sched,
184 char *const *args,
185 const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
199{ 186{
200 int i;
201 int j; 187 int j;
202 unsigned long long size; 188 unsigned long long size;
203 int have_file; 189 int have_file;
204 struct stat sbuf; 190 struct stat sbuf;
191 int i;
205 192
193 datastore = GNUNET_DATASTORE_connect (cfg, sched);
206 have_file = 0 == stat (DB_NAME, &sbuf); 194 have_file = 0 == stat (DB_NAME, &sbuf);
207
208 for (i = 0; i < ITERATIONS; i++) 195 for (i = 0; i < ITERATIONS; i++)
209 { 196 {
210#if REPORT_ID 197#if REPORT_ID
@@ -212,18 +199,11 @@ test (GNUNET_SQstore_ServiceAPI * api)
212#endif 199#endif
213 /* insert data equivalent to 1/10th of MAX_SIZE */ 200 /* insert data equivalent to 1/10th of MAX_SIZE */
214 for (j = 0; j < PUT_10; j++) 201 for (j = 0; j < PUT_10; j++)
215 { 202 GNUNET_assert (GNUNET_OK == putValue (j, i));
216 ASSERT (GNUNET_OK == putValue (api, j, i));
217 if (GNUNET_shutdown_test () == GNUNET_YES)
218 break;
219 }
220 203
221 /* trim down below MAX_SIZE again */ 204 /* trim down below MAX_SIZE again */
222 if ((i % 2) == 0) 205 if ((i % 2) == 0)
223 api->iterateLowPriority (0, &iterateDelete, api); 206 GNUNET_DATASTORE_get_random (datastore, &iterate_delete, NULL);
224 else
225 api->iterateExpirationTime (0, &iterateDelete, api);
226
227 size = 0; 207 size = 0;
228 if (have_file) 208 if (have_file)
229 GNUNET_disk_file_size (NULL, DB_NAME, &size, GNUNET_NO); 209 GNUNET_disk_file_size (NULL, DB_NAME, &size, GNUNET_NO);
@@ -231,8 +211,8 @@ test (GNUNET_SQstore_ServiceAPI * api)
231#if REPORT_ID 211#if REPORT_ID
232 "\n" 212 "\n"
233#endif 213#endif
234 "Useful %llu, API %llu, disk %llu (%.2f%%) / %lluk ops / %llu ops/s\n", stored_bytes / 1024, /* used size in k */ 214 "Useful %llu, disk %llu (%.2f%%) / %lluk ops / %llu ops/s\n",
235 api->getSize () / 1024, /* API-reported size in k */ 215 stored_bytes / 1024, /* used size in k */
236 size / 1024, /* disk size in kb */ 216 size / 1024, /* disk size in kb */
237 (100.0 * size / stored_bytes) - 100, /* overhead */ 217 (100.0 * size / stored_bytes) - 100, /* overhead */
238 (stored_ops * 2 - stored_entries) / 1024, /* total operations (in k) */ 218 (stored_ops * 2 - stored_entries) / 1024, /* total operations (in k) */
@@ -240,45 +220,68 @@ test (GNUNET_SQstore_ServiceAPI * api)
240 if (GNUNET_shutdown_test () == GNUNET_YES) 220 if (GNUNET_shutdown_test () == GNUNET_YES)
241 break; 221 break;
242 } 222 }
243 api->drop ();
244 return GNUNET_OK;
245 223
246FAILURE: 224 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
247 api->drop (); 225}
248 return GNUNET_SYSERR; 226
227
228static int
229check ()
230{
231 int ok = 1 + 2 + 4 + 8;
232 pid_t pid;
233 char *const argv[] = { "perf-datastore-api",
234 "-c",
235 "test_datastore_api_data.conf",
236#if VERBOSE
237 "-L", "DEBUG",
238#endif
239 NULL
240 };
241 struct GNUNET_GETOPT_CommandLineOption options[] = {
242 GNUNET_GETOPT_OPTION_END
243 };
244 pid = GNUNET_OS_start_process ("gnunet-service-datastore",
245 "gnunet-service-datastore",
246#if VERBOSE
247 "-L", "DEBUG",
248#endif
249 "-c", "perf_datastore_api_data.conf", NULL);
250 sleep (1);
251 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
252 argv, "perf-datastore-api", "nohelp",
253 options, &run, &ok);
254 if (0 != PLIBC_KILL (pid, SIGTERM))
255 {
256 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
257 ok = 1;
258 }
259 GNUNET_OS_process_wait(pid);
260 if (ok != 0)
261 fprintf (stderr, "Missed some testcases: %u\n", ok);
262 return ok;
249} 263}
250 264
265
251int 266int
252main (int argc, char *argv[]) 267main (int argc, char *argv[])
253{ 268{
254 GNUNET_SQstore_ServiceAPI *api; 269 int ret;
255 int ok;
256 struct GNUNET_GC_Configuration *cfg;
257 struct GNUNET_CronManager *cron;
258 270
259 cfg = GNUNET_GC_create (); 271 GNUNET_log_setup ("perf-datastore-api",
260 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) 272#if VERBOSE
261 { 273 "DEBUG",
262 GNUNET_GC_free (cfg); 274#else
263 return -1; 275 "WARNING",
264 } 276#endif
265 cron = GNUNET_cron_create (NULL); 277 NULL);
266 GNUNET_CORE_init (NULL, cfg, cron, NULL); 278 ret = check ();
267 api = GNUNET_CORE_request_service ("sqstore"); 279
268 if (api != NULL) 280 return ret;
269 {
270 start_time = GNUNET_get_time ();
271 ok = test (api);
272 GNUNET_CORE_release_service (api);
273 }
274 else
275 ok = GNUNET_SYSERR;
276 GNUNET_CORE_done ();
277 GNUNET_cron_destroy (cron);
278 GNUNET_GC_free (cfg);
279 if (ok == GNUNET_SYSERR)
280 return 1;
281 return 0;
282} 281}
283 282
284/* end of mysqltest2.c */ 283
284
285
286
287/* end of perf_datastore_api.c */
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index d9f3c0459..0b08cfe8f 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing authors) 3 (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,273 +21,286 @@
21 * @file datastore/test_datastore_api.c 21 * @file datastore/test_datastore_api.c
22 * @brief Test for the datastore implementation. 22 * @brief Test for the datastore implementation.
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 *
25 * TODO:
26 * - test multiple values under same key
27 * - test "update"
28 * - test storage reservations
24 */ 29 */
25 30
26#include "platform.h" 31#include "platform.h"
27#include "gnunet_util.h" 32#include "gnunet_util_lib.h"
28#include "gnunet_protocols.h" 33#include "gnunet_protocols.h"
29#include "gnunet_sqstore_service.h" 34#include "gnunet_datastore_service.h"
30#include "core.h"
31 35
32#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0) 36static struct GNUNET_DATASTORE_Handle *datastore;
33 37
34static GNUNET_CronTime now; 38static struct GNUNET_TIME_Absolute now;
35 39
36static GNUNET_DatastoreValue * 40
37initValue (int i) 41static size_t
42get_size (int i)
38{ 43{
39 GNUNET_DatastoreValue *value; 44 return 8 * i;
40
41 value = GNUNET_malloc (sizeof (GNUNET_DatastoreValue) + 8 * i);
42 value->size = htonl (sizeof (GNUNET_DatastoreValue) + 8 * i);
43 value->type = htonl (i);
44 value->priority = htonl (i + 1);
45 value->anonymity_level = htonl (i);
46 value->expiration_time = GNUNET_htonll (now - i * GNUNET_CRON_SECONDS);
47 memset (&value[1], i, 8 * i);
48 return value;
49} 45}
50 46
51static int 47
52checkValue (const GNUNET_HashCode * key, 48static const void *
53 const GNUNET_DatastoreValue * val, void *closure, 49get_data (int i)
54 unsigned long long uid)
55{ 50{
56 int i; 51 static char buf[60000];
57 int ret; 52 memset (buf, i, 8 * i);
58 GNUNET_DatastoreValue *value; 53 return buf;
59
60 i = *(int *) closure;
61 value = initValue (i);
62 if ((value->size == val->size) &&
63 (0 == memcmp (val, value, ntohl (val->size))))
64 ret = GNUNET_OK;
65 else
66 {
67 /*
68 printf("Wanted: %u, %llu; got %u, %llu - %d\n",
69 ntohl(value->size), GNUNET_ntohll(value->expiration_time),
70 ntohl(val->size), GNUNET_ntohll(val->expiration_time),
71 memcmp(val, value, ntohl(val->size))); */
72 ret = GNUNET_SYSERR;
73 }
74 GNUNET_free (value);
75 return ret;
76} 54}
77 55
56
78static int 57static int
79iterateUp (const GNUNET_HashCode * key, const GNUNET_DatastoreValue * val, 58get_type(int i)
80 int *closure, unsigned long long uid)
81{ 59{
82 int ret; 60 return i;
61}
83 62
84 ret = checkValue (key, val, closure, uid); 63
85 (*closure) += 2; 64static int
86 return ret; 65get_priority (int i)
66{
67 return i+1;
87} 68}
88 69
70
89static int 71static int
90iterateDown (const GNUNET_HashCode * key, 72get_anonymity(int i)
91 const GNUNET_DatastoreValue * val, int *closure,
92 unsigned long long uid)
93{ 73{
94 int ret; 74 return i;
75}
95 76
96 (*closure) -= 2; 77
97 ret = checkValue (key, val, closure, uid); 78static struct GNUNET_TIME_Absolute
98 return ret; 79get_expiration (int i)
80{
81 struct GNUNET_TIME_Absolute av;
82
83 av.value = now.value - i * 1000;
84 return av;
99} 85}
100 86
101static int 87
102iterateDelete (const GNUNET_HashCode * key, 88static void
103 const GNUNET_DatastoreValue * val, void *closure, 89check_success (void *cls,
104 unsigned long long uid) 90 int success,
91 const char *msg)
105{ 92{
106 return GNUNET_NO; 93 GNUNET_assert (GNUNET_OK == success);
107} 94}
108 95
109static int 96
110iteratePriority (const GNUNET_HashCode * key, 97static void
111 const GNUNET_DatastoreValue * val, 98check_failure (void *cls,
112 GNUNET_SQstore_ServiceAPI * api, unsigned long long uid) 99 int success,
100 const char *msg)
113{ 101{
114 api->update (uid, 4, 0); 102 GNUNET_assert (GNUNET_OK != success);
115 return GNUNET_OK; 103 GNUNET_assert (NULL != msg);
116} 104}
117 105
118static int 106
119priorityCheck (const GNUNET_HashCode * key, 107static void
120 const GNUNET_DatastoreValue * val, int *closure, 108check_value (void *cls,
121 unsigned long long uid) 109 const GNUNET_HashCode * key,
110 uint32_t size,
111 const void *data,
112 uint32_t type,
113 uint32_t priority,
114 uint32_t anonymity,
115 struct GNUNET_TIME_Absolute
116 expiration, uint64_t uid)
122{ 117{
123 int id; 118 int *iptr = cls;
124 119 int i;
125 id = (*closure); 120
126 if (id + 1 == ntohl (val->priority)) 121 if (key == NULL)
127 return GNUNET_OK; 122 return;
128 fprintf (stderr, 123 i = *iptr;
129 "Wrong priority, wanted %u got %u\n", id + 1, 124 GNUNET_assert (size == get_size (i));
130 ntohl (val->priority)); 125 GNUNET_assert (0 == memcmp (data, get_data(i), size));
131 return GNUNET_SYSERR; 126 GNUNET_assert (type == get_type (i));
127 GNUNET_assert (priority == get_priority (i));
128 GNUNET_assert (anonymity == get_anonymity(i));
129 GNUNET_assert (expiration.value == get_expiration(i).value);
132} 130}
133 131
134static int 132
135multipleCheck (const GNUNET_HashCode * key, 133static void
136 const GNUNET_DatastoreValue * val, 134delete_value (void *cls,
137 GNUNET_DatastoreValue ** last, unsigned long long uid) 135 const GNUNET_HashCode * key,
136 uint32_t size,
137 const void *data,
138 uint32_t type,
139 uint32_t priority,
140 uint32_t anonymity,
141 struct GNUNET_TIME_Absolute
142 expiration, uint64_t uid)
138{ 143{
139 if (*last != NULL) 144 if (key == NULL)
140 { 145 return;
141 if (((*last)->size == val->size) && 146 GNUNET_DATASTORE_remove (datastore,
142 (0 == memcmp (*last, val, ntohl (val->size)))) 147 key,
143 return GNUNET_SYSERR; /* duplicate! */ 148 size,
144 GNUNET_free (*last); 149 data,
145 } 150 &check_success,
146 *last = GNUNET_malloc (ntohl (val->size)); 151 NULL);
147 memcpy (*last, val, ntohl (val->size)); 152 ((int*)key)[0]++;
148 return GNUNET_OK; 153 GNUNET_DATASTORE_remove (datastore,
154 key,
155 size,
156 data,
157 &check_failure,
158 NULL);
149} 159}
150 160
151 161
152/** 162
153 * Add testcode here! 163static void
154 */ 164check_nothing (void *cls,
155static int 165 const GNUNET_HashCode * key,
156test (GNUNET_SQstore_ServiceAPI * api) 166 uint32_t size,
167 const void *data,
168 uint32_t type,
169 uint32_t priority,
170 uint32_t anonymity,
171 struct GNUNET_TIME_Absolute
172 expiration, uint64_t uid)
173{
174 GNUNET_assert (key == NULL);
175}
176
177
178
179static void
180run (void *cls,
181 struct GNUNET_SCHEDULER_Handle *sched,
182 char *const *args,
183 const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
157{ 184{
158 GNUNET_DatastoreValue *value;
159 GNUNET_HashCode key; 185 GNUNET_HashCode key;
160 unsigned long long oldSize;
161 int i; 186 int i;
187 int *iptr;
162 188
163 now = 1000000; 189 datastore = GNUNET_DATASTORE_connect (cfg, sched);
164 oldSize = api->getSize (); 190 now.value = 1000000;
165 for (i = 0; i < 256; i++) 191 for (i = 0; i < 256; i++)
166 { 192 {
167 value = initValue (i);
168 memset (&key, 256 - i, sizeof (GNUNET_HashCode)); 193 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
169 ASSERT (GNUNET_OK == api->put (&key, value)); 194 GNUNET_DATASTORE_put (datastore,
170 GNUNET_free (value); 195 0,
196 &key,
197 get_size (i),
198 get_data (i),
199 get_type (i),
200 get_priority (i),
201 get_anonymity (i),
202 get_expiration (i),
203 &check_success,
204 NULL);
171 } 205 }
172 ASSERT (oldSize < api->getSize ());
173 for (i = 255; i >= 0; i--) 206 for (i = 255; i >= 0; i--)
174 { 207 {
175 memset (&key, 256 - i, sizeof (GNUNET_HashCode)); 208 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
176 ASSERT (1 == api->get (&key, NULL, i, &checkValue, (void *) &i)); 209 iptr = GNUNET_malloc(sizeof(int));
210 *iptr = i;
211 GNUNET_DATASTORE_get (datastore,
212 &key,
213 get_type (i),
214 &check_value,
215 iptr);
177 } 216 }
178 ASSERT (256 ==
179 api->iterateLowPriority (GNUNET_ECRS_BLOCKTYPE_ANY, NULL, NULL));
180 ASSERT (256 ==
181 api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY, NULL, NULL));
182 for (i = 255; i >= 0; i--) 217 for (i = 255; i >= 0; i--)
183 { 218 {
184 memset (&key, 256 - i, sizeof (GNUNET_HashCode)); 219 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
185 ASSERT (1 == api->get (&key, NULL, i, &checkValue, (void *) &i)); 220 iptr = GNUNET_malloc(sizeof(int));
221 *iptr = i;
222 GNUNET_DATASTORE_get (datastore,
223 &key,
224 get_type (i),
225 &delete_value,
226 iptr);
186 } 227 }
187 228 for (i = 255; i >= 0; i--)
188 oldSize = api->getSize ();
189 for (i = 255; i >= 0; i -= 2)
190 { 229 {
191 memset (&key, 256 - i, sizeof (GNUNET_HashCode)); 230 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
192 value = initValue (i); 231 iptr = GNUNET_malloc(sizeof(int));
193 if (1 != api->get (&key, NULL, 0, &iterateDelete, NULL)) 232 *iptr = i;
194 { 233 GNUNET_DATASTORE_get (datastore,
195 GNUNET_free (value); 234 &key,
196 ASSERT (0); 235 get_type (i),
197 } 236 &check_nothing,
198 GNUNET_free (value); 237 iptr);
199 } 238 }
200 ASSERT (oldSize > api->getSize ()); 239 /* check reservations */
201 i = 0; 240
202 ASSERT (128 == api->iterateLowPriority (GNUNET_ECRS_BLOCKTYPE_ANY, 241 /* check update */
203 (GNUNET_DatastoreValueIterator) &
204 iterateUp, &i));
205 ASSERT (256 == i);
206 ASSERT (128 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
207 (GNUNET_DatastoreValueIterator) &
208 iterateDown, &i));
209 ASSERT (0 == i);
210 ASSERT (128 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
211 (GNUNET_DatastoreValueIterator) &
212 iterateDelete, api));
213 i = 0;
214 ASSERT (0 ==
215 api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
216 (GNUNET_DatastoreValueIterator) &
217 iterateDown, &i));
218 i = 42;
219 value = initValue (i);
220 memset (&key, 256 - i, sizeof (GNUNET_HashCode));
221 api->put (&key, value);
222 ASSERT (1 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
223 (GNUNET_DatastoreValueIterator) &
224 priorityCheck, &i));
225 ASSERT (1 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
226 (GNUNET_DatastoreValueIterator) &
227 priorityCheck, &i));
228 ASSERT (1 ==
229 api->iterateAllNow ((GNUNET_DatastoreValueIterator) &
230 iteratePriority, api));
231 i += 4;
232 ASSERT (1 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY,
233 (GNUNET_DatastoreValueIterator) &
234 priorityCheck, &i));
235 GNUNET_free (value);
236 242
237 /* test multiple results */ 243 /* test multiple results */
238 value = initValue (i + 1); 244
239 api->put (&key, value); 245 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
240 GNUNET_free (value); 246}
241 247
242 value = NULL; 248
243 ASSERT (2 == api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY, 249
244 (GNUNET_DatastoreValueIterator) & 250static int
245 multipleCheck, &value)); 251check ()
246 GNUNET_free (value); 252{
247 ASSERT (2 == 253 int ok = 1 + 2 + 4 + 8;
248 api->iterateAllNow ((GNUNET_DatastoreValueIterator) & iterateDelete, 254 pid_t pid;
249 api)); 255 char *const argv[] = { "test-datastore-api",
250 ASSERT (0 == 256 "-c",
251 api->iterateExpirationTime (GNUNET_ECRS_BLOCKTYPE_ANY, NULL, NULL)); 257 "test_datastore_api_data.conf",
252 api->drop (); 258#if VERBOSE
253 259 "-L", "DEBUG",
254 return GNUNET_OK; 260#endif
255 261 NULL
256FAILURE: 262 };
257 api->drop (); 263 struct GNUNET_GETOPT_CommandLineOption options[] = {
258 return GNUNET_SYSERR; 264 GNUNET_GETOPT_OPTION_END
265 };
266 pid = GNUNET_OS_start_process ("gnunet-service-datastore",
267 "gnunet-service-datastore",
268#if VERBOSE
269 "-L", "DEBUG",
270#endif
271 "-c", "test_datastore_api_data.conf", NULL);
272 sleep (1);
273 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
274 argv, "test-datastore-api", "nohelp",
275 options, &run, &ok);
276 if (0 != PLIBC_KILL (pid, SIGTERM))
277 {
278 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
279 ok = 1;
280 }
281 GNUNET_OS_process_wait(pid);
282 if (ok != 0)
283 fprintf (stderr, "Missed some testcases: %u\n", ok);
284 return ok;
259} 285}
260 286
261int 287int
262main (int argc, char *argv[]) 288main (int argc, char *argv[])
263{ 289{
264 GNUNET_SQstore_ServiceAPI *api; 290 int ret;
265 int ok;
266 struct GNUNET_GC_Configuration *cfg;
267 struct GNUNET_CronManager *cron;
268 291
269 cfg = GNUNET_GC_create (); 292 GNUNET_log_setup ("test-datastore-api",
270 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) 293#if VERBOSE
271 { 294 "DEBUG",
272 GNUNET_GC_free (cfg); 295#else
273 return -1; 296 "WARNING",
274 } 297#endif
275 cron = GNUNET_cron_create (NULL); 298 NULL);
276 GNUNET_CORE_init (NULL, cfg, cron, NULL); 299 ret = check ();
277 api = GNUNET_CORE_request_service ("sqstore"); 300
278 if (api != NULL) 301 return ret;
279 {
280 ok = test (api);
281 GNUNET_CORE_release_service (api);
282 }
283 else
284 ok = GNUNET_SYSERR;
285 GNUNET_CORE_done ();
286 GNUNET_cron_destroy (cron);
287 GNUNET_GC_free (cfg);
288 if (ok == GNUNET_SYSERR)
289 return 1;
290 return 0;
291} 302}
292 303
304
305
293/* end of test_datastore_api.c */ 306/* end of test_datastore_api.c */
diff --git a/src/datastore/test_datastore_api_data.conf b/src/datastore/test_datastore_api_data.conf
new file mode 100644
index 000000000..9a419f4d1
--- /dev/null
+++ b/src/datastore/test_datastore_api_data.conf
@@ -0,0 +1,22 @@
1[PATHS]
2SERVICEHOME = /tmp/test-gnunetd-datastore/
3
4[datastore]
5PORT = 22654
6HOSTNAME = localhost
7HOME = $SERVICEHOME
8CONFIG = $DEFAULTCONFIG
9BINARY = gnunet-service-datastore
10ACCEPT_FROM = 127.0.0.1;
11ACCEPT_FROM6 = ::1;
12ALLOW_SHUTDOWN = YES
13QUOTA = 1000000
14BLOOMFILTER = $SERVICEHOME/fs/bloomfilter
15# USERNAME =
16# MAXBUF =
17# TIMEOUT =
18# DISABLEV6 =
19# BINDTO =
20# REJECT_FROM =
21# REJECT_FROM6 =
22# PREFIX =