aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_datastore_api_management.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/datastore/test_datastore_api_management.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/datastore/test_datastore_api_management.c')
-rw-r--r--src/datastore/test_datastore_api_management.c381
1 files changed, 193 insertions, 188 deletions
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index e7599999f..e6bacaf6e 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -33,7 +33,7 @@
33/** 33/**
34 * How long until we give up on transmitting the message? 34 * How long until we give up on transmitting the message?
35 */ 35 */
36#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) 36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
37 37
38/** 38/**
39 * Number of iterations to run; must be large enough 39 * Number of iterations to run; must be large enough
@@ -41,7 +41,8 @@
41 */ 41 */
42#define ITERATIONS 5000 42#define ITERATIONS 5000
43 43
44enum RunPhase { 44enum RunPhase
45{
45 RP_PUT, 46 RP_PUT,
46 RP_GET, 47 RP_GET,
47 RP_DONE, 48 RP_DONE,
@@ -49,7 +50,8 @@ enum RunPhase {
49}; 50};
50 51
51 52
52struct CpsRunContext { 53struct CpsRunContext
54{
53 struct GNUNET_HashCode key; 55 struct GNUNET_HashCode key;
54 int i; 56 int i;
55 int found; 57 int found;
@@ -69,45 +71,45 @@ static const char *plugin_name;
69 71
70 72
71static size_t 73static size_t
72get_size(int i) 74get_size (int i)
73{ 75{
74 return 8 + 8 * (i % 256); 76 return 8 + 8 * (i % 256);
75} 77}
76 78
77 79
78static const void * 80static const void *
79get_data(int i) 81get_data (int i)
80{ 82{
81 static char buf[60000]; 83 static char buf[60000];
82 84
83 memset(buf, i, 8 + 8 * (i % 256)); 85 memset (buf, i, 8 + 8 * (i % 256));
84 return buf; 86 return buf;
85} 87}
86 88
87 89
88static int 90static int
89get_type(int i) 91get_type (int i)
90{ 92{
91 return 1; 93 return 1;
92} 94}
93 95
94 96
95static int 97static int
96get_priority(int i) 98get_priority (int i)
97{ 99{
98 return i + 1; 100 return i + 1;
99} 101}
100 102
101 103
102static int 104static int
103get_anonymity(int i) 105get_anonymity (int i)
104{ 106{
105 return i; 107 return i;
106} 108}
107 109
108 110
109static struct GNUNET_TIME_Absolute 111static struct GNUNET_TIME_Absolute
110get_expiration(int i) 112get_expiration (int i)
111{ 113{
112 struct GNUNET_TIME_Absolute av; 114 struct GNUNET_TIME_Absolute av;
113 115
@@ -117,204 +119,207 @@ get_expiration(int i)
117 119
118 120
119static void 121static void
120run_continuation(void *cls); 122run_continuation (void *cls);
121 123
122 124
123static void 125static void
124check_success(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) 126check_success (void *cls, int success, struct GNUNET_TIME_Absolute
127 min_expiration, const char *msg)
125{ 128{
126 struct CpsRunContext *crc = cls; 129 struct CpsRunContext *crc = cls;
127 130
128 if (GNUNET_OK != success) 131 if (GNUNET_OK != success)
129 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", msg); 132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", msg);
130 GNUNET_assert(GNUNET_OK == success); 133 GNUNET_assert (GNUNET_OK == success);
131 GNUNET_free_non_null(crc->data); 134 GNUNET_free_non_null (crc->data);
132 crc->data = NULL; 135 crc->data = NULL;
133 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 136 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
134} 137}
135 138
136 139
137static void 140static void
138check_value(void *cls, 141check_value (void *cls,
139 const struct GNUNET_HashCode *key, 142 const struct GNUNET_HashCode *key,
140 size_t size, 143 size_t size,
141 const void *data, 144 const void *data,
142 enum GNUNET_BLOCK_Type type, 145 enum GNUNET_BLOCK_Type type,
143 uint32_t priority, 146 uint32_t priority,
144 uint32_t anonymity, 147 uint32_t anonymity,
145 uint32_t replication, 148 uint32_t replication,
146 struct GNUNET_TIME_Absolute expiration, 149 struct GNUNET_TIME_Absolute expiration,
147 uint64_t uid) 150 uint64_t uid)
148{ 151{
149 struct CpsRunContext *crc = cls; 152 struct CpsRunContext *crc = cls;
150 int i; 153 int i;
151 154
152 if (NULL == key) 155 if (NULL == key)
153 { 156 {
154 crc->phase = RP_GET_FAIL; 157 crc->phase = RP_GET_FAIL;
155 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 158 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
156 return; 159 return;
157 } 160 }
158 i = crc->i; 161 i = crc->i;
159 GNUNET_assert(size == get_size(i)); 162 GNUNET_assert (size == get_size (i));
160 GNUNET_assert(0 == memcmp(data, get_data(i), size)); 163 GNUNET_assert (0 == memcmp (data, get_data (i), size));
161 GNUNET_assert(type == get_type(i)); 164 GNUNET_assert (type == get_type (i));
162 GNUNET_assert(priority == get_priority(i)); 165 GNUNET_assert (priority == get_priority (i));
163 GNUNET_assert(anonymity == get_anonymity(i)); 166 GNUNET_assert (anonymity == get_anonymity (i));
164 GNUNET_assert(expiration.abs_value_us == get_expiration(i).abs_value_us); 167 GNUNET_assert (expiration.abs_value_us == get_expiration (i).abs_value_us);
165 crc->i--; 168 crc->i--;
166 if (crc->i == 0) 169 if (crc->i == 0)
167 crc->phase = RP_DONE; 170 crc->phase = RP_DONE;
168 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 171 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
169} 172}
170 173
171 174
172static void 175static void
173check_nothing(void *cls, 176check_nothing (void *cls,
174 const struct GNUNET_HashCode *key, 177 const struct GNUNET_HashCode *key,
175 size_t size, 178 size_t size,
176 const void *data, 179 const void *data,
177 enum GNUNET_BLOCK_Type type, 180 enum GNUNET_BLOCK_Type type,
178 uint32_t priority, 181 uint32_t priority,
179 uint32_t anonymity, 182 uint32_t anonymity,
180 uint32_t replication, 183 uint32_t replication,
181 struct GNUNET_TIME_Absolute expiration, 184 struct GNUNET_TIME_Absolute expiration,
182 uint64_t uid) 185 uint64_t uid)
183{ 186{
184 struct CpsRunContext *crc = cls; 187 struct CpsRunContext *crc = cls;
185 188
186 GNUNET_assert(key == NULL); 189 GNUNET_assert (key == NULL);
187 if (0 == --crc->i) 190 if (0 == --crc->i)
188 crc->phase = RP_DONE; 191 crc->phase = RP_DONE;
189 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 192 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
190} 193}
191 194
192 195
193static void 196static void
194run_continuation(void *cls) 197run_continuation (void *cls)
195{ 198{
196 struct CpsRunContext *crc = cls; 199 struct CpsRunContext *crc = cls;
197 200
198 ok = (int)crc->phase; 201 ok = (int) crc->phase;
199 switch (crc->phase) 202 switch (crc->phase)
203 {
204 case RP_PUT:
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT",
206 crc->i);
207 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
208 GNUNET_DATASTORE_put (datastore,
209 0,
210 &crc->key,
211 get_size (crc->i),
212 get_data (crc->i),
213 get_type (crc->i),
214 get_priority (crc->i),
215 get_anonymity (crc->i),
216 0,
217 get_expiration (crc->i),
218 1,
219 1,
220 &check_success, crc);
221 crc->i++;
222 if (crc->i == ITERATIONS)
200 { 223 {
201 case RP_PUT: 224 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
202 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT", 225 "Sleeping to give datastore time to clean up\n");
203 crc->i); 226 sleep (1);
204 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); 227 crc->phase = RP_GET;
205 GNUNET_DATASTORE_put(datastore, 228 crc->i--;
206 0,
207 &crc->key,
208 get_size(crc->i),
209 get_data(crc->i),
210 get_type(crc->i),
211 get_priority(crc->i),
212 get_anonymity(crc->i),
213 0,
214 get_expiration(crc->i),
215 1,
216 1,
217 &check_success, crc);
218 crc->i++;
219 if (crc->i == ITERATIONS)
220 {
221 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
222 "Sleeping to give datastore time to clean up\n");
223 sleep(1);
224 crc->phase = RP_GET;
225 crc->i--;
226 }
227 break;
228
229 case RP_GET:
230 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
231 crc->i);
232 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key);
233 GNUNET_DATASTORE_get_key(datastore,
234 0,
235 false,
236 &crc->key,
237 get_type(crc->i),
238 1,
239 1,
240 &check_value,
241 crc);
242 break;
243
244 case RP_GET_FAIL:
245 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)",
246 crc->i);
247 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key);
248 GNUNET_DATASTORE_get_key(datastore,
249 0,
250 false,
251 &crc->key,
252 get_type(crc->i),
253 1,
254 1,
255 &check_nothing,
256 crc);
257 break;
258
259 case RP_DONE:
260 GNUNET_assert(0 == crc->i);
261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
262 GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES);
263 GNUNET_free(crc);
264 ok = 0;
265 } 229 }
230 break;
231
232 case RP_GET:
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
234 crc->i);
235 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
236 GNUNET_DATASTORE_get_key (datastore,
237 0,
238 false,
239 &crc->key,
240 get_type (crc->i),
241 1,
242 1,
243 &check_value,
244 crc);
245 break;
246
247 case RP_GET_FAIL:
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)",
249 crc->i);
250 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
251 GNUNET_DATASTORE_get_key (datastore,
252 0,
253 false,
254 &crc->key,
255 get_type (crc->i),
256 1,
257 1,
258 &check_nothing,
259 crc);
260 break;
261
262 case RP_DONE:
263 GNUNET_assert (0 == crc->i);
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
265 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
266 GNUNET_free (crc);
267 ok = 0;
268 }
266} 269}
267 270
268 271
269static void 272static void
270run_tests(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) 273run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration,
274 const char *msg)
271{ 275{
272 struct CpsRunContext *crc = cls; 276 struct CpsRunContext *crc = cls;
273 277
274 if (success != GNUNET_YES) 278 if (success != GNUNET_YES)
275 { 279 {
276 fprintf(stderr, 280 fprintf (stderr,
277 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 281 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
278 msg); 282 msg);
279 GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES); 283 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
280 GNUNET_free(crc); 284 GNUNET_free (crc);
281 return; 285 return;
282 } 286 }
283 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 287 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
284} 288}
285 289
286 290
287static void 291static void
288run(void *cls, 292run (void *cls,
289 const struct GNUNET_CONFIGURATION_Handle *cfg, 293 const struct GNUNET_CONFIGURATION_Handle *cfg,
290 struct GNUNET_TESTING_Peer *peer) 294 struct GNUNET_TESTING_Peer *peer)
291{ 295{
292 struct CpsRunContext *crc; 296 struct CpsRunContext *crc;
293 static struct GNUNET_HashCode zkey; 297 static struct GNUNET_HashCode zkey;
294 298
295 crc = GNUNET_new(struct CpsRunContext); 299 crc = GNUNET_new (struct CpsRunContext);
296 crc->cfg = cfg; 300 crc->cfg = cfg;
297 crc->phase = RP_PUT; 301 crc->phase = RP_PUT;
298 now = GNUNET_TIME_absolute_get(); 302 now = GNUNET_TIME_absolute_get ();
299 datastore = GNUNET_DATASTORE_connect(cfg); 303 datastore = GNUNET_DATASTORE_connect (cfg);
300 if (NULL == 304 if (NULL ==
301 GNUNET_DATASTORE_put(datastore, 305 GNUNET_DATASTORE_put (datastore,
302 0, 306 0,
303 &zkey, 307 &zkey,
304 4, 308 4,
305 "TEST", 309 "TEST",
306 GNUNET_BLOCK_TYPE_TEST, 310 GNUNET_BLOCK_TYPE_TEST,
307 0, 0, 0, 311 0, 0, 0,
308 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_SECONDS), 312 GNUNET_TIME_relative_to_absolute (
309 0, 313 GNUNET_TIME_UNIT_SECONDS),
310 1, 314 0,
311 &run_tests, 315 1,
312 crc)) 316 &run_tests,
313 { 317 crc))
314 fprintf(stderr, "%s", "Test 'put' operation failed.\n"); 318 {
315 GNUNET_free(crc); 319 fprintf (stderr, "%s", "Test 'put' operation failed.\n");
316 ok = 1; 320 GNUNET_free (crc);
317 } 321 ok = 1;
322 }
318} 323}
319 324
320 325
@@ -325,8 +330,8 @@ run(void *cls,
325 * @param delta change in utilization 330 * @param delta change in utilization
326 */ 331 */
327static void 332static void
328ignore_payload_cb(void *cls, 333ignore_payload_cb (void *cls,
329 int delta) 334 int delta)
330{ 335{
331 /* do nothing */ 336 /* do nothing */
332} 337}
@@ -336,65 +341,65 @@ ignore_payload_cb(void *cls,
336 * check if plugin is actually working 341 * check if plugin is actually working
337 */ 342 */
338static int 343static int
339test_plugin(const char *cfg_name) 344test_plugin (const char *cfg_name)
340{ 345{
341 char libname[PATH_MAX]; 346 char libname[PATH_MAX];
342 struct GNUNET_CONFIGURATION_Handle *cfg; 347 struct GNUNET_CONFIGURATION_Handle *cfg;
343 struct GNUNET_DATASTORE_PluginFunctions *api; 348 struct GNUNET_DATASTORE_PluginFunctions *api;
344 struct GNUNET_DATASTORE_PluginEnvironment env; 349 struct GNUNET_DATASTORE_PluginEnvironment env;
345 350
346 cfg = GNUNET_CONFIGURATION_create(); 351 cfg = GNUNET_CONFIGURATION_create ();
347 if (GNUNET_OK != 352 if (GNUNET_OK !=
348 GNUNET_CONFIGURATION_load(cfg, 353 GNUNET_CONFIGURATION_load (cfg,
349 cfg_name)) 354 cfg_name))
350 { 355 {
351 GNUNET_CONFIGURATION_destroy(cfg); 356 GNUNET_CONFIGURATION_destroy (cfg);
352 fprintf(stderr, 357 fprintf (stderr,
353 "Failed to load configuration %s\n", 358 "Failed to load configuration %s\n",
354 cfg_name); 359 cfg_name);
355 return 1; 360 return 1;
356 } 361 }
357 memset(&env, 0, sizeof(env)); 362 memset (&env, 0, sizeof(env));
358 env.cfg = cfg; 363 env.cfg = cfg;
359 env.duc = &ignore_payload_cb; 364 env.duc = &ignore_payload_cb;
360 GNUNET_snprintf(libname, 365 GNUNET_snprintf (libname,
361 sizeof(libname), 366 sizeof(libname),
362 "libgnunet_plugin_datastore_%s", 367 "libgnunet_plugin_datastore_%s",
363 plugin_name); 368 plugin_name);
364 api = GNUNET_PLUGIN_load(libname, &env); 369 api = GNUNET_PLUGIN_load (libname, &env);
365 if (NULL == api) 370 if (NULL == api)
366 { 371 {
367 GNUNET_CONFIGURATION_destroy(cfg); 372 GNUNET_CONFIGURATION_destroy (cfg);
368 fprintf(stderr, 373 fprintf (stderr,
369 "Failed to load plugin `%s'\n", 374 "Failed to load plugin `%s'\n",
370 libname); 375 libname);
371 return 77; 376 return 77;
372 } 377 }
373 GNUNET_PLUGIN_unload(libname, api); 378 GNUNET_PLUGIN_unload (libname, api);
374 GNUNET_CONFIGURATION_destroy(cfg); 379 GNUNET_CONFIGURATION_destroy (cfg);
375 return 0; 380 return 0;
376} 381}
377 382
378 383
379int 384int
380main(int argc, char *argv[]) 385main (int argc, char *argv[])
381{ 386{
382 char cfg_name[PATH_MAX]; 387 char cfg_name[PATH_MAX];
383 int ret; 388 int ret;
384 389
385 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); 390 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
386 GNUNET_snprintf(cfg_name, 391 GNUNET_snprintf (cfg_name,
387 sizeof(cfg_name), 392 sizeof(cfg_name),
388 "test_datastore_api_data_%s.conf", 393 "test_datastore_api_data_%s.conf",
389 plugin_name); 394 plugin_name);
390 ret = test_plugin(cfg_name); 395 ret = test_plugin (cfg_name);
391 if (0 != ret) 396 if (0 != ret)
392 return ret; 397 return ret;
393 if (0 != 398 if (0 !=
394 GNUNET_TESTING_peer_run("test-gnunet-datastore-management", 399 GNUNET_TESTING_peer_run ("test-gnunet-datastore-management",
395 cfg_name, 400 cfg_name,
396 &run, 401 &run,
397 NULL)) 402 NULL))
398 return 1; 403 return 1;
399 return ok; 404 return ok;
400} 405}