aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_datastore_api_management.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/datastore/test_datastore_api_management.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/datastore/test_datastore_api_management.c')
-rw-r--r--src/datastore/test_datastore_api_management.c309
1 files changed, 142 insertions, 167 deletions
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index ca1df2cf9..b2146a915 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -47,7 +47,7 @@ static struct GNUNET_TIME_Absolute now;
47 47
48static int ok; 48static int ok;
49 49
50static const char* plugin_name; 50static const char *plugin_name;
51 51
52static size_t 52static size_t
53get_size (int i) 53get_size (int i)
@@ -59,34 +59,35 @@ get_size (int i)
59static const void * 59static const void *
60get_data (int i) 60get_data (int i)
61{ 61{
62 static char buf[60000]; 62 static char buf[60000];
63
63 memset (buf, i, 8 + 8 * (i % 256)); 64 memset (buf, i, 8 + 8 * (i % 256));
64 return buf; 65 return buf;
65} 66}
66 67
67 68
68static int 69static int
69get_type(int i) 70get_type (int i)
70{ 71{
71 return 1; 72 return 1;
72} 73}
73 74
74 75
75static int 76static int
76get_priority (int i) 77get_priority (int i)
77{ 78{
78 return i+1; 79 return i + 1;
79} 80}
80 81
81 82
82static int 83static int
83get_anonymity(int i) 84get_anonymity (int i)
84{ 85{
85 return i; 86 return i;
86} 87}
87 88
88 89
89static struct GNUNET_TIME_Absolute 90static struct GNUNET_TIME_Absolute
90get_expiration (int i) 91get_expiration (int i)
91{ 92{
92 struct GNUNET_TIME_Absolute av; 93 struct GNUNET_TIME_Absolute av;
@@ -96,12 +97,12 @@ get_expiration (int i)
96} 97}
97 98
98enum RunPhase 99enum RunPhase
99 { 100{
100 RP_PUT, 101 RP_PUT,
101 RP_GET, 102 RP_GET,
102 RP_DONE, 103 RP_DONE,
103 RP_GET_FAIL 104 RP_GET_FAIL
104 }; 105};
105 106
106 107
107struct CpsRunContext 108struct CpsRunContext
@@ -117,77 +118,70 @@ struct CpsRunContext
117 118
118 119
119static void 120static void
120run_continuation (void *cls, 121run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
121 const struct GNUNET_SCHEDULER_TaskContext *tc);
122 122
123 123
124static void 124static void
125check_success (void *cls, 125check_success (void *cls, int success, const char *msg)
126 int success,
127 const char *msg)
128{ 126{
129 struct CpsRunContext *crc = cls; 127 struct CpsRunContext *crc = cls;
128
130 if (GNUNET_OK != success) 129 if (GNUNET_OK != success)
131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", msg);
132 "%s\n", msg);
133 GNUNET_assert (GNUNET_OK == success); 131 GNUNET_assert (GNUNET_OK == success);
134 GNUNET_free_non_null (crc->data); 132 GNUNET_free_non_null (crc->data);
135 crc->data = NULL; 133 crc->data = NULL;
136 GNUNET_SCHEDULER_add_continuation (&run_continuation, 134 GNUNET_SCHEDULER_add_continuation (&run_continuation,
137 crc, 135 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
138 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
139} 136}
140 137
141 138
142static void 139static void
143check_value (void *cls, 140check_value (void *cls,
144 const GNUNET_HashCode * key, 141 const GNUNET_HashCode * key,
145 size_t size, 142 size_t size,
146 const void *data, 143 const void *data,
147 enum GNUNET_BLOCK_Type type, 144 enum GNUNET_BLOCK_Type type,
148 uint32_t priority, 145 uint32_t priority,
149 uint32_t anonymity, 146 uint32_t anonymity,
150 struct GNUNET_TIME_Absolute expiration, 147 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
151 uint64_t uid)
152{ 148{
153 struct CpsRunContext *crc = cls; 149 struct CpsRunContext *crc = cls;
154 int i; 150 int i;
155 151
156 if (NULL == key) 152 if (NULL == key)
157 { 153 {
158 crc->phase = RP_GET_FAIL; 154 crc->phase = RP_GET_FAIL;
159 GNUNET_SCHEDULER_add_continuation (&run_continuation, 155 GNUNET_SCHEDULER_add_continuation (&run_continuation,
160 crc, 156 crc,
161 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 157 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
162 return; 158 return;
163 } 159 }
164 i = crc->i; 160 i = crc->i;
165 GNUNET_assert (size == get_size (i)); 161 GNUNET_assert (size == get_size (i));
166 GNUNET_assert (0 == memcmp (data, get_data(i), size)); 162 GNUNET_assert (0 == memcmp (data, get_data (i), size));
167 GNUNET_assert (type == get_type (i)); 163 GNUNET_assert (type == get_type (i));
168 GNUNET_assert (priority == get_priority (i)); 164 GNUNET_assert (priority == get_priority (i));
169 GNUNET_assert (anonymity == get_anonymity(i)); 165 GNUNET_assert (anonymity == get_anonymity (i));
170 GNUNET_assert (expiration.abs_value == get_expiration(i).abs_value); 166 GNUNET_assert (expiration.abs_value == get_expiration (i).abs_value);
171 crc->offset++; 167 crc->offset++;
172 crc->i--; 168 crc->i--;
173 if (crc->i == 0) 169 if (crc->i == 0)
174 crc->phase = RP_DONE; 170 crc->phase = RP_DONE;
175 GNUNET_SCHEDULER_add_continuation (&run_continuation, 171 GNUNET_SCHEDULER_add_continuation (&run_continuation,
176 crc, 172 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
177 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
178} 173}
179 174
180 175
181static void 176static void
182check_nothing (void *cls, 177check_nothing (void *cls,
183 const GNUNET_HashCode * key, 178 const GNUNET_HashCode * key,
184 size_t size, 179 size_t size,
185 const void *data, 180 const void *data,
186 enum GNUNET_BLOCK_Type type, 181 enum GNUNET_BLOCK_Type type,
187 uint32_t priority, 182 uint32_t priority,
188 uint32_t anonymity, 183 uint32_t anonymity,
189 struct GNUNET_TIME_Absolute 184 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
190 expiration, uint64_t uid)
191{ 185{
192 struct CpsRunContext *crc = cls; 186 struct CpsRunContext *crc = cls;
193 187
@@ -195,143 +189,125 @@ check_nothing (void *cls,
195 if (0 == --crc->i) 189 if (0 == --crc->i)
196 crc->phase = RP_DONE; 190 crc->phase = RP_DONE;
197 GNUNET_SCHEDULER_add_continuation (&run_continuation, 191 GNUNET_SCHEDULER_add_continuation (&run_continuation,
198 crc, 192 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
199 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
200} 193}
201 194
202 195
203static void 196static void
204run_continuation (void *cls, 197run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
205 const struct GNUNET_SCHEDULER_TaskContext *tc)
206{ 198{
207 struct CpsRunContext *crc = cls; 199 struct CpsRunContext *crc = cls;
200
208 ok = (int) crc->phase; 201 ok = (int) crc->phase;
209 switch (crc->phase) 202 switch (crc->phase)
210 { 203 {
211 case RP_PUT: 204 case RP_PUT:
212#if VERBOSE 205#if VERBOSE
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "Executing `%s' number %u\n", 207 "Executing `%s' number %u\n", "PUT", crc->i);
215 "PUT",
216 crc->i);
217#endif 208#endif
218 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 209 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
219 GNUNET_DATASTORE_put (datastore, 210 GNUNET_DATASTORE_put (datastore,
220 0, 211 0,
221 &crc->key, 212 &crc->key,
222 get_size (crc->i), 213 get_size (crc->i),
223 get_data (crc->i), 214 get_data (crc->i),
224 get_type (crc->i), 215 get_type (crc->i),
225 get_priority (crc->i), 216 get_priority (crc->i),
226 get_anonymity (crc->i), 217 get_anonymity (crc->i),
227 0, 218 0,
228 get_expiration (crc->i), 219 get_expiration (crc->i),
229 1, 1, TIMEOUT, 220 1, 1, TIMEOUT, &check_success, crc);
230 &check_success, 221 crc->i++;
231 crc); 222 if (crc->i == ITERATIONS)
232 crc->i++; 223 {
233 if (crc->i == ITERATIONS) 224 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
234 { 225 "Sleeping to give datastore time to clean up\n");
235 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 226 sleep (1);
236 "Sleeping to give datastore time to clean up\n"); 227 crc->phase = RP_GET;
237 sleep (1); 228 crc->i--;
238 crc->phase = RP_GET; 229 }
239 crc->i--; 230 break;
240 } 231 case RP_GET:
241 break;
242 case RP_GET:
243#if VERBOSE 232#if VERBOSE
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245 "Executing `%s' number %u\n", 234 "Executing `%s' number %u\n", "GET", crc->i);
246 "GET",
247 crc->i);
248#endif 235#endif
249 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 236 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
250 GNUNET_DATASTORE_get_key (datastore, 237 GNUNET_DATASTORE_get_key (datastore,
251 crc->offset++, 238 crc->offset++,
252 &crc->key, 239 &crc->key,
253 get_type (crc->i), 240 get_type (crc->i),
254 1, 1, TIMEOUT, 241 1, 1, TIMEOUT, &check_value, crc);
255 &check_value, 242 break;
256 crc); 243 case RP_GET_FAIL:
257 break;
258 case RP_GET_FAIL:
259#if VERBOSE 244#if VERBOSE
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Executing `%s' number %u\n", 246 "Executing `%s' number %u\n", "GET(f)", crc->i);
262 "GET(f)",
263 crc->i);
264#endif 247#endif
265 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 248 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
266 GNUNET_DATASTORE_get_key (datastore, 249 GNUNET_DATASTORE_get_key (datastore,
267 crc->offset++, 250 crc->offset++,
268 &crc->key, 251 &crc->key,
269 get_type (crc->i), 252 get_type (crc->i),
270 1, 1, TIMEOUT, 253 1, 1, TIMEOUT, &check_nothing, crc);
271 &check_nothing, 254 break;
272 crc); 255 case RP_DONE:
273 break; 256 GNUNET_assert (0 == crc->i);
274 case RP_DONE:
275 GNUNET_assert (0 == crc->i);
276#if VERBOSE 257#if VERBOSE
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
278 "Finished, disconnecting\n");
279#endif 259#endif
280 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); 260 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
281 GNUNET_free (crc); 261 GNUNET_free (crc);
282 ok = 0; 262 ok = 0;
283 } 263 }
284} 264}
285 265
286 266
287static void 267static void
288run_tests (void *cls, 268run_tests (void *cls, int success, const char *msg)
289 int success,
290 const char *msg)
291{ 269{
292 struct CpsRunContext *crc = cls; 270 struct CpsRunContext *crc = cls;
293 271
294 if (success != GNUNET_YES) 272 if (success != GNUNET_YES)
295 { 273 {
296 fprintf (stderr, 274 fprintf (stderr,
297 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.", 275 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
298 msg); 276 msg);
299 GNUNET_free (crc); 277 GNUNET_free (crc);
300 return; 278 return;
301 } 279 }
302 GNUNET_SCHEDULER_add_continuation (&run_continuation, 280 GNUNET_SCHEDULER_add_continuation (&run_continuation,
303 crc, 281 crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
304 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
305} 282}
306 283
307 284
308static void 285static void
309run (void *cls, 286run (void *cls,
310 char *const *args, 287 char *const *args,
311 const char *cfgfile, 288 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
312 const struct GNUNET_CONFIGURATION_Handle *cfg)
313{ 289{
314 struct CpsRunContext *crc; 290 struct CpsRunContext *crc;
315 static GNUNET_HashCode zkey; 291 static GNUNET_HashCode zkey;
316 292
317 crc = GNUNET_malloc(sizeof(struct CpsRunContext)); 293 crc = GNUNET_malloc (sizeof (struct CpsRunContext));
318 crc->cfg = cfg; 294 crc->cfg = cfg;
319 crc->phase = RP_PUT; 295 crc->phase = RP_PUT;
320 now = GNUNET_TIME_absolute_get (); 296 now = GNUNET_TIME_absolute_get ();
321 datastore = GNUNET_DATASTORE_connect (cfg); 297 datastore = GNUNET_DATASTORE_connect (cfg);
322 if (NULL == 298 if (NULL ==
323 GNUNET_DATASTORE_put (datastore, 0, 299 GNUNET_DATASTORE_put (datastore, 0,
324 &zkey, 4, "TEST", 300 &zkey, 4, "TEST",
325 GNUNET_BLOCK_TYPE_TEST, 301 GNUNET_BLOCK_TYPE_TEST,
326 0, 0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS), 302 0, 0, 0,
327 0, 1, GNUNET_TIME_UNIT_MINUTES, 303 GNUNET_TIME_relative_to_absolute
328 &run_tests, crc)) 304 (GNUNET_TIME_UNIT_SECONDS), 0, 1,
329 { 305 GNUNET_TIME_UNIT_MINUTES, &run_tests, crc))
330 fprintf (stderr, 306 {
331 "Test 'put' operation failed.\n"); 307 fprintf (stderr, "Test 'put' operation failed.\n");
332 GNUNET_free (crc); 308 GNUNET_free (crc);
333 ok = 1; 309 ok = 1;
334 } 310 }
335} 311}
336 312
337 313
@@ -341,7 +317,8 @@ check ()
341{ 317{
342 struct GNUNET_OS_Process *proc; 318 struct GNUNET_OS_Process *proc;
343 char cfg_name[128]; 319 char cfg_name[128];
344 char *const argv[] = { 320
321 char *const argv[] = {
345 "test-datastore-api-management", 322 "test-datastore-api-management",
346 "-c", 323 "-c",
347 cfg_name, 324 cfg_name,
@@ -354,25 +331,24 @@ check ()
354 GNUNET_GETOPT_OPTION_END 331 GNUNET_GETOPT_OPTION_END
355 }; 332 };
356 GNUNET_snprintf (cfg_name, 333 GNUNET_snprintf (cfg_name,
357 sizeof (cfg_name), 334 sizeof (cfg_name),
358 "test_datastore_api_data_%s.conf", 335 "test_datastore_api_data_%s.conf", plugin_name);
359 plugin_name);
360 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 336 proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
361 "gnunet-service-arm", 337 "gnunet-service-arm",
362#if VERBOSE 338#if VERBOSE
363 "-L", "DEBUG", 339 "-L", "DEBUG",
364#endif 340#endif
365 "-c", cfg_name, NULL); 341 "-c", cfg_name, NULL);
366 GNUNET_assert (NULL != proc); 342 GNUNET_assert (NULL != proc);
367 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 343 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
368 argv, "test-datastore-api-management", "nohelp", 344 argv, "test-datastore-api-management", "nohelp",
369 options, &run, NULL); 345 options, &run, NULL);
370 sleep (1); /* give datastore chance to process 'DROP' request */ 346 sleep (1); /* give datastore chance to process 'DROP' request */
371 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 347 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
372 { 348 {
373 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 349 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
374 ok = 1; 350 ok = 1;
375 } 351 }
376 GNUNET_OS_process_wait (proc); 352 GNUNET_OS_process_wait (proc);
377 GNUNET_OS_process_close (proc); 353 GNUNET_OS_process_close (proc);
378 proc = NULL; 354 proc = NULL;
@@ -385,24 +361,23 @@ int
385main (int argc, char *argv[]) 361main (int argc, char *argv[])
386{ 362{
387 int ret; 363 int ret;
388 364
389 char *pos; 365 char *pos;
390 char dir_name[128]; 366 char dir_name[128];
391 367
392 sleep (1); 368 sleep (1);
393 /* determine name of plugin to use */ 369 /* determine name of plugin to use */
394 plugin_name = argv[0]; 370 plugin_name = argv[0];
395 while (NULL != (pos = strstr(plugin_name, "_"))) 371 while (NULL != (pos = strstr (plugin_name, "_")))
396 plugin_name = pos+1; 372 plugin_name = pos + 1;
397 if (NULL != (pos = strstr(plugin_name, "."))) 373 if (NULL != (pos = strstr (plugin_name, ".")))
398 pos[0] = 0; 374 pos[0] = 0;
399 else 375 else
400 pos = (char *) plugin_name; 376 pos = (char *) plugin_name;
401 377
402 GNUNET_snprintf (dir_name, 378 GNUNET_snprintf (dir_name,
403 sizeof (dir_name), 379 sizeof (dir_name),
404 "/tmp/test-gnunet-datastore-%s", 380 "/tmp/test-gnunet-datastore-%s", plugin_name);
405 plugin_name);
406 GNUNET_DISK_directory_remove (dir_name); 381 GNUNET_DISK_directory_remove (dir_name);
407 GNUNET_log_setup ("test-datastore-api-management", 382 GNUNET_log_setup ("test-datastore-api-management",
408#if VERBOSE 383#if VERBOSE