diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-08-03 09:06:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-08-03 09:06:44 +0000 |
commit | c77ee3b95455fc2974edebc8e02db5d30be87d22 (patch) | |
tree | 29fe839ecd58d321f786c789b778911bc94bba0d /src/datastore/perf_datastore_api.c | |
parent | 89c5d0047e261ed7e5fabb2e771123f1707e4670 (diff) | |
download | gnunet-c77ee3b95455fc2974edebc8e02db5d30be87d22.tar.gz gnunet-c77ee3b95455fc2974edebc8e02db5d30be87d22.zip |
-cleaning up test logic, modernizing calls, improving test documentation
Diffstat (limited to 'src/datastore/perf_datastore_api.c')
-rw-r--r-- | src/datastore/perf_datastore_api.c | 329 |
1 files changed, 263 insertions, 66 deletions
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 09b530dbd..082b583c6 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2004, 2005, 2006, 2007, 2009, 2011 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2004, 2005, 2006, 2007, 2009, 2011, 2015 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 |
@@ -31,7 +31,6 @@ | |||
31 | * strategy uses the "random" iterator. Priorities and expiration | 31 | * strategy uses the "random" iterator. Priorities and expiration |
32 | * dates are set using a pseudo-random value within a realistic range. | 32 | * dates are set using a pseudo-random value within a realistic range. |
33 | */ | 33 | */ |
34 | |||
35 | #include "platform.h" | 34 | #include "platform.h" |
36 | #include "gnunet_util_lib.h" | 35 | #include "gnunet_util_lib.h" |
37 | #include "gnunet_protocols.h" | 36 | #include "gnunet_protocols.h" |
@@ -50,13 +49,13 @@ | |||
50 | #define MAX_SIZE 1024LL * 1024 * 4 | 49 | #define MAX_SIZE 1024LL * 1024 * 4 |
51 | 50 | ||
52 | /** | 51 | /** |
53 | * Report progress outside of major reports? Should probably be GNUNET_YES if | 52 | * Report progress outside of major reports? Should probably be #GNUNET_YES if |
54 | * size is > 16 MB. | 53 | * size is > 16 MB. |
55 | */ | 54 | */ |
56 | #define REPORT_ID GNUNET_YES | 55 | #define REPORT_ID GNUNET_YES |
57 | 56 | ||
58 | /** | 57 | /** |
59 | * Number of put operations equivalent to 1/3rd of MAX_SIZE | 58 | * Number of put operations equivalent to 1/3rd of #MAX_SIZE |
60 | */ | 59 | */ |
61 | #define PUT_10 MAX_SIZE / 32 / 1024 / 3 | 60 | #define PUT_10 MAX_SIZE / 32 / 1024 / 3 |
62 | 61 | ||
@@ -68,55 +67,146 @@ | |||
68 | #define ITERATIONS 8 | 67 | #define ITERATIONS 8 |
69 | 68 | ||
70 | 69 | ||
70 | /** | ||
71 | * Number of bytes stored in the datastore in total. | ||
72 | */ | ||
71 | static unsigned long long stored_bytes; | 73 | static unsigned long long stored_bytes; |
72 | 74 | ||
75 | /** | ||
76 | * Number of entries stored in the datastore in total. | ||
77 | */ | ||
73 | static unsigned long long stored_entries; | 78 | static unsigned long long stored_entries; |
74 | 79 | ||
80 | /** | ||
81 | * Number of database operations performed. Inserting | ||
82 | * counts as one operation, deleting as two (as deletion | ||
83 | * requires selecting a value for deletion first). | ||
84 | */ | ||
75 | static unsigned long long stored_ops; | 85 | static unsigned long long stored_ops; |
76 | 86 | ||
87 | /** | ||
88 | * Start time of the benchmark. | ||
89 | */ | ||
77 | static struct GNUNET_TIME_Absolute start_time; | 90 | static struct GNUNET_TIME_Absolute start_time; |
78 | 91 | ||
92 | /** | ||
93 | * Database backend we use. | ||
94 | */ | ||
79 | static const char *plugin_name; | 95 | static const char *plugin_name; |
80 | 96 | ||
97 | /** | ||
98 | * Handle to the datastore. | ||
99 | */ | ||
81 | static struct GNUNET_DATASTORE_Handle *datastore; | 100 | static struct GNUNET_DATASTORE_Handle *datastore; |
82 | 101 | ||
102 | /** | ||
103 | * Value we return from #main(). | ||
104 | */ | ||
83 | static int ok; | 105 | static int ok; |
84 | 106 | ||
85 | 107 | /** | |
108 | * Which phase of the process are we in? | ||
109 | */ | ||
86 | enum RunPhase | 110 | enum RunPhase |
87 | { | 111 | { |
112 | /** | ||
113 | * We are done (shutting down normally). | ||
114 | */ | ||
88 | RP_DONE = 0, | 115 | RP_DONE = 0, |
116 | |||
117 | /** | ||
118 | * We are adding new entries to the datastore. | ||
119 | */ | ||
89 | RP_PUT, | 120 | RP_PUT, |
121 | |||
122 | /** | ||
123 | * We are deleting entries from the datastore. | ||
124 | */ | ||
90 | RP_CUT, | 125 | RP_CUT, |
126 | |||
127 | /** | ||
128 | * We are generating a report. | ||
129 | */ | ||
91 | RP_REPORT, | 130 | RP_REPORT, |
131 | |||
132 | /** | ||
133 | * Execution failed with some kind of error. | ||
134 | */ | ||
92 | RP_ERROR | 135 | RP_ERROR |
93 | }; | 136 | }; |
94 | 137 | ||
95 | 138 | ||
139 | /** | ||
140 | * Closure we give to all of the functions executing the | ||
141 | * benchmark. Could right now be global, but this allows | ||
142 | * us to theoretically run multiple clients "in parallel". | ||
143 | */ | ||
96 | struct CpsRunContext | 144 | struct CpsRunContext |
97 | { | 145 | { |
98 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 146 | /** |
147 | * Execution phase we are in. | ||
148 | */ | ||
99 | enum RunPhase phase; | 149 | enum RunPhase phase; |
100 | int j; | 150 | |
101 | unsigned long long size; | 151 | /** |
102 | int i; | 152 | * Size of the value we are currently storing (during #RP_PUT). |
153 | */ | ||
154 | size_t size; | ||
155 | |||
156 | /** | ||
157 | * Current iteration counter, we are done with the benchmark | ||
158 | * once it hits #ITERATIONS. | ||
159 | */ | ||
160 | unsigned int i; | ||
161 | |||
162 | /** | ||
163 | * Counts the number of items put in the current phase. | ||
164 | * Once it hits #PUT_10, we progress tot he #RP_CUT phase | ||
165 | * or are done if @e i reaches #ITERATIONS. | ||
166 | */ | ||
167 | unsigned int j; | ||
103 | }; | 168 | }; |
104 | 169 | ||
105 | 170 | ||
171 | /** | ||
172 | * Main state machine. Executes the next step of the benchmark | ||
173 | * depending on the current state. | ||
174 | * | ||
175 | * @param cls the `struct CpsRunContext` | ||
176 | * @param tc scheduler context (unused) | ||
177 | */ | ||
106 | static void | 178 | static void |
107 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 179 | run_continuation (void *cls, |
180 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
108 | 181 | ||
109 | 182 | ||
183 | /** | ||
184 | * Continuation called to notify client about result of the insertion | ||
185 | * operation. Checks for errors, updates our iteration counters and | ||
186 | * continues execution with #run_continuation(). | ||
187 | * | ||
188 | * @param cls the `struct CpsRunContext` | ||
189 | * @param success #GNUNET_SYSERR on failure | ||
190 | * @param min_expiration minimum expiration time required for content to be stored | ||
191 | * by the datacache at this time, zero for unknown | ||
192 | * @param msg NULL on success, otherwise an error message | ||
193 | */ | ||
110 | static void | 194 | static void |
111 | check_success (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) | 195 | check_success (void *cls, |
196 | int success, | ||
197 | struct GNUNET_TIME_Absolute min_expiration, | ||
198 | const char *msg) | ||
112 | { | 199 | { |
113 | struct CpsRunContext *crc = cls; | 200 | struct CpsRunContext *crc = cls; |
114 | 201 | ||
115 | if (GNUNET_OK != success) | 202 | if (GNUNET_OK != success) |
116 | { | 203 | { |
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Check success failed: `%s'\n", msg); | 204 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
205 | "Check success failed: `%s'\n", | ||
206 | msg); | ||
118 | crc->phase = RP_ERROR; | 207 | crc->phase = RP_ERROR; |
119 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 208 | GNUNET_SCHEDULER_add_now (&run_continuation, |
209 | crc); | ||
120 | return; | 210 | return; |
121 | } | 211 | } |
122 | #if REPORT_ID | 212 | #if REPORT_ID |
@@ -135,45 +225,72 @@ check_success (void *cls, int success, struct GNUNET_TIME_Absolute min_expiratio | |||
135 | else | 225 | else |
136 | crc->phase = RP_CUT; | 226 | crc->phase = RP_CUT; |
137 | } | 227 | } |
138 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 228 | GNUNET_SCHEDULER_add_now (&run_continuation, |
139 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 229 | crc); |
140 | } | 230 | } |
141 | 231 | ||
142 | 232 | ||
143 | /** | 233 | /** |
144 | * Continuation called to notify client about result of the | 234 | * Continuation called to notify client about result of the |
145 | * operation. | 235 | * deletion operation. Checks for errors and continues |
236 | * execution with #run_continuation(). | ||
146 | * | 237 | * |
147 | * @param cls closure | 238 | * @param cls the `struct CpsRunContext` |
148 | * @param success GNUNET_SYSERR on failure | 239 | * @param success #GNUNET_SYSERR on failure |
149 | * @param min_expiration minimum expiration time required for content to be stored | 240 | * @param min_expiration minimum expiration time required for content to be stored |
150 | * by the datacache at this time, zero for unknown | 241 | * by the datacache at this time, zero for unknown |
151 | * @param msg NULL on success, otherwise an error message | 242 | * @param msg NULL on success, otherwise an error message |
152 | */ | 243 | */ |
153 | static void | 244 | static void |
154 | remove_next (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) | 245 | remove_next (void *cls, |
246 | int success, | ||
247 | struct GNUNET_TIME_Absolute min_expiration, | ||
248 | const char *msg) | ||
155 | { | 249 | { |
156 | struct CpsRunContext *crc = cls; | 250 | struct CpsRunContext *crc = cls; |
157 | 251 | ||
158 | if (GNUNET_OK != success) | 252 | if (GNUNET_OK != success) |
159 | { | 253 | { |
160 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "remove_next failed: `%s'\n", msg); | 254 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
255 | "remove_next failed: `%s'\n", | ||
256 | msg); | ||
161 | crc->phase = RP_ERROR; | 257 | crc->phase = RP_ERROR; |
162 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 258 | GNUNET_SCHEDULER_add_now (&run_continuation, |
259 | crc); | ||
163 | return; | 260 | return; |
164 | } | 261 | } |
165 | #if REPORT_ID | 262 | #if REPORT_ID |
166 | FPRINTF (stderr, "%s", "D"); | 263 | FPRINTF (stderr, "%s", "D"); |
167 | #endif | 264 | #endif |
168 | GNUNET_assert (GNUNET_OK == success); | 265 | GNUNET_assert (GNUNET_OK == success); |
169 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); | 266 | GNUNET_SCHEDULER_add_now (&run_continuation, |
267 | crc); | ||
170 | } | 268 | } |
171 | 269 | ||
172 | 270 | ||
271 | /** | ||
272 | * We have selected a value for deletion, trigger removal. | ||
273 | * | ||
274 | * @param cls the `struct CpsRunContext` | ||
275 | * @param key key for the content | ||
276 | * @param size number of bytes in data | ||
277 | * @param data content stored | ||
278 | * @param type type of the content | ||
279 | * @param priority priority of the content | ||
280 | * @param anonymity anonymity-level for the content | ||
281 | * @param expiration expiration time for the content | ||
282 | * @param uid unique identifier for the datum; | ||
283 | * maybe 0 if no unique identifier is available | ||
284 | */ | ||
173 | static void | 285 | static void |
174 | delete_value (void *cls, const struct GNUNET_HashCode * key, size_t size, | 286 | delete_value (void *cls, |
175 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, | 287 | const struct GNUNET_HashCode *key, |
176 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, | 288 | size_t size, |
289 | const void *data, | ||
290 | enum GNUNET_BLOCK_Type type, | ||
291 | uint32_t priority, | ||
292 | uint32_t anonymity, | ||
293 | struct GNUNET_TIME_Absolute expiration, | ||
177 | uint64_t uid) | 294 | uint64_t uid) |
178 | { | 295 | { |
179 | struct CpsRunContext *crc = cls; | 296 | struct CpsRunContext *crc = cls; |
@@ -186,56 +303,86 @@ delete_value (void *cls, const struct GNUNET_HashCode * key, size_t size, | |||
186 | if (stored_bytes < MAX_SIZE) | 303 | if (stored_bytes < MAX_SIZE) |
187 | crc->phase = RP_PUT; | 304 | crc->phase = RP_PUT; |
188 | GNUNET_assert (NULL != | 305 | GNUNET_assert (NULL != |
189 | GNUNET_DATASTORE_remove (datastore, key, size, data, 1, 1, | 306 | GNUNET_DATASTORE_remove (datastore, |
190 | TIMEOUT, &remove_next, crc)); | 307 | key, |
308 | size, | ||
309 | data, 1, 1, | ||
310 | TIMEOUT, | ||
311 | &remove_next, crc)); | ||
191 | } | 312 | } |
192 | 313 | ||
193 | 314 | ||
315 | /** | ||
316 | * Main state machine. Executes the next step of the benchmark | ||
317 | * depending on the current state. | ||
318 | * | ||
319 | * @param cls the `struct CpsRunContext` | ||
320 | * @param tc scheduler context (unused) | ||
321 | */ | ||
194 | static void | 322 | static void |
195 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 323 | run_continuation (void *cls, |
324 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
196 | { | 325 | { |
197 | struct CpsRunContext *crc = cls; | 326 | struct CpsRunContext *crc = cls; |
198 | size_t size; | 327 | size_t size; |
199 | static struct GNUNET_HashCode key; | 328 | static struct GNUNET_HashCode key; |
200 | static char data[65536]; | 329 | static char data[65536]; |
201 | int i; | ||
202 | int k; | ||
203 | char gstr[128]; | 330 | char gstr[128]; |
204 | 331 | ||
205 | ok = (int) crc->phase; | 332 | ok = (int) crc->phase; |
206 | switch (crc->phase) | 333 | switch (crc->phase) |
207 | { | 334 | { |
208 | case RP_PUT: | 335 | case RP_PUT: |
209 | memset (&key, 256 - crc->i, sizeof (struct GNUNET_HashCode)); | 336 | memset (&key, |
210 | i = crc->j; | 337 | 256 - crc->i, |
211 | k = crc->i; | 338 | sizeof (struct GNUNET_HashCode)); |
212 | /* most content is 32k */ | 339 | /* most content is 32k */ |
213 | size = 32 * 1024; | 340 | size = 32 * 1024; |
214 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ | 341 | if (0 == |
215 | size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); | 342 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
343 | 16)) /* but some of it is less! */ | ||
344 | size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
345 | 32 * 1024); | ||
216 | crc->size = size = size - (size & 7); /* always multiple of 8 */ | 346 | crc->size = size = size - (size & 7); /* always multiple of 8 */ |
217 | GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &key); | 347 | GNUNET_CRYPTO_hash (&key, |
218 | memset (data, i, size); | 348 | sizeof (struct GNUNET_HashCode), |
219 | if (i > 255) | 349 | &key); |
220 | memset (data, i - 255, size / 2); | 350 | memset (data, |
221 | data[0] = k; | 351 | (int) crc->j, |
352 | size); | ||
353 | if (crc->j > 255) | ||
354 | memset (data, | ||
355 | (int) (crc->j - 255), | ||
356 | size / 2); | ||
357 | data[0] = crc->i; | ||
222 | GNUNET_assert (NULL != | 358 | GNUNET_assert (NULL != |
223 | GNUNET_DATASTORE_put (datastore, 0, &key, size, data, i + 1, | 359 | GNUNET_DATASTORE_put (datastore, |
360 | 0, | ||
361 | &key, | ||
362 | size, | ||
363 | data, | ||
364 | crc->j + 1, | ||
224 | GNUNET_CRYPTO_random_u32 | 365 | GNUNET_CRYPTO_random_u32 |
225 | (GNUNET_CRYPTO_QUALITY_WEAK, 100), i, | 366 | (GNUNET_CRYPTO_QUALITY_WEAK, 100), |
367 | crc->j, | ||
226 | 0, | 368 | 0, |
227 | GNUNET_TIME_relative_to_absolute | 369 | GNUNET_TIME_relative_to_absolute |
228 | (GNUNET_TIME_relative_multiply | 370 | (GNUNET_TIME_relative_multiply |
229 | (GNUNET_TIME_UNIT_SECONDS, | 371 | (GNUNET_TIME_UNIT_SECONDS, |
230 | GNUNET_CRYPTO_random_u32 | 372 | GNUNET_CRYPTO_random_u32 |
231 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), | 373 | (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), |
232 | 1, 1, TIMEOUT, &check_success, crc)); | 374 | 1, |
375 | 1, | ||
376 | TIMEOUT, | ||
377 | &check_success, crc)); | ||
233 | break; | 378 | break; |
234 | case RP_CUT: | 379 | case RP_CUT: |
235 | /* trim down below MAX_SIZE again */ | 380 | /* trim down below MAX_SIZE again */ |
236 | GNUNET_assert (NULL != | 381 | GNUNET_assert (NULL != |
237 | GNUNET_DATASTORE_get_for_replication (datastore, 1, 1, | 382 | GNUNET_DATASTORE_get_for_replication (datastore, |
238 | TIMEOUT, &delete_value, | 383 | 1, 1, |
384 | TIMEOUT, | ||
385 | &delete_value, | ||
239 | crc)); | 386 | crc)); |
240 | break; | 387 | break; |
241 | case RP_REPORT: | 388 | case RP_REPORT: |
@@ -243,23 +390,30 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
243 | #if REPORT_ID | 390 | #if REPORT_ID |
244 | "\n" | 391 | "\n" |
245 | #endif | 392 | #endif |
246 | "Stored %llu kB / %lluk ops / %llu ops/s\n", stored_bytes / 1024, /* used size in k */ | 393 | "Stored %llu kB / %lluk ops / %llu ops/s\n", |
394 | stored_bytes / 1024, /* used size in k */ | ||
247 | stored_ops / 1024, /* total operations (in k) */ | 395 | stored_ops / 1024, /* total operations (in k) */ |
248 | 1000LL * 1000LL * stored_ops / (1 + | 396 | 1000LL * 1000LL * stored_ops / (1 + |
249 | GNUNET_TIME_absolute_get_duration | 397 | GNUNET_TIME_absolute_get_duration |
250 | (start_time).rel_value_us)); | 398 | (start_time).rel_value_us)); |
251 | crc->phase = RP_PUT; | 399 | crc->phase = RP_PUT; |
252 | crc->j = 0; | 400 | crc->j = 0; |
253 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 401 | GNUNET_SCHEDULER_add_now (&run_continuation, |
254 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 402 | crc); |
255 | break; | 403 | break; |
256 | case RP_DONE: | 404 | case RP_DONE: |
257 | GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name); | 405 | GNUNET_snprintf (gstr, |
406 | sizeof (gstr), | ||
407 | "DATASTORE-%s", | ||
408 | plugin_name); | ||
258 | if ((crc->i == ITERATIONS) && (stored_ops > 0)) | 409 | if ((crc->i == ITERATIONS) && (stored_ops > 0)) |
259 | GAUGER (gstr, "PUT operation duration", | 410 | GAUGER (gstr, |
411 | "PUT operation duration", | ||
260 | GNUNET_TIME_absolute_get_duration (start_time).rel_value_us / 1000LL / | 412 | GNUNET_TIME_absolute_get_duration (start_time).rel_value_us / 1000LL / |
261 | stored_ops, "ms/operation"); | 413 | stored_ops, |
262 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 414 | "ms/operation"); |
415 | GNUNET_DATASTORE_disconnect (datastore, | ||
416 | GNUNET_YES); | ||
263 | GNUNET_free (crc); | 417 | GNUNET_free (crc); |
264 | ok = 0; | 418 | ok = 0; |
265 | break; | 419 | break; |
@@ -274,8 +428,23 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
274 | } | 428 | } |
275 | 429 | ||
276 | 430 | ||
431 | /** | ||
432 | * Function called with the result of the initial PUT operation. If | ||
433 | * the PUT succeeded, we start the actual benchmark loop, otherwise we | ||
434 | * bail out with an error. | ||
435 | * | ||
436 | * | ||
437 | * @param cls closure | ||
438 | * @param success #GNUNET_SYSERR on failure | ||
439 | * @param min_expiration minimum expiration time required for content to be stored | ||
440 | * by the datacache at this time, zero for unknown | ||
441 | * @param msg NULL on success, otherwise an error message | ||
442 | */ | ||
277 | static void | 443 | static void |
278 | run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) | 444 | run_tests (void *cls, |
445 | int success, | ||
446 | struct GNUNET_TIME_Absolute min_expiration, | ||
447 | const char *msg) | ||
279 | { | 448 | { |
280 | struct CpsRunContext *crc = cls; | 449 | struct CpsRunContext *crc = cls; |
281 | 450 | ||
@@ -284,15 +453,25 @@ run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, c | |||
284 | FPRINTF (stderr, | 453 | FPRINTF (stderr, |
285 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 454 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
286 | msg); | 455 | msg); |
287 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 456 | GNUNET_DATASTORE_disconnect (datastore, |
457 | GNUNET_YES); | ||
288 | GNUNET_free (crc); | 458 | GNUNET_free (crc); |
289 | return; | 459 | return; |
290 | } | 460 | } |
291 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 461 | GNUNET_SCHEDULER_add_now (&run_continuation, |
292 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 462 | crc); |
293 | } | 463 | } |
294 | 464 | ||
295 | 465 | ||
466 | /** | ||
467 | * Beginning of the actual execution of the benchmark. | ||
468 | * Performs a first test operation (PUT) to verify that | ||
469 | * the plugin works at all. | ||
470 | * | ||
471 | * @param cls NULL | ||
472 | * @param cfg configuration to use | ||
473 | * @param peer peer handle (unused) | ||
474 | */ | ||
296 | static void | 475 | static void |
297 | run (void *cls, | 476 | run (void *cls, |
298 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 477 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -304,30 +483,48 @@ run (void *cls, | |||
304 | datastore = GNUNET_DATASTORE_connect (cfg); | 483 | datastore = GNUNET_DATASTORE_connect (cfg); |
305 | start_time = GNUNET_TIME_absolute_get (); | 484 | start_time = GNUNET_TIME_absolute_get (); |
306 | crc = GNUNET_new (struct CpsRunContext); | 485 | crc = GNUNET_new (struct CpsRunContext); |
307 | crc->cfg = cfg; | ||
308 | crc->phase = RP_PUT; | 486 | crc->phase = RP_PUT; |
309 | if (NULL == | 487 | if (NULL == |
310 | GNUNET_DATASTORE_put (datastore, 0, &zkey, 4, "TEST", | 488 | GNUNET_DATASTORE_put (datastore, |
311 | GNUNET_BLOCK_TYPE_TEST, 0, 0, 0, | 489 | 0, |
312 | GNUNET_TIME_relative_to_absolute | 490 | &zkey, |
313 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, | 491 | 4, "TEST", |
314 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) | 492 | GNUNET_BLOCK_TYPE_TEST, |
493 | 0, 0, 0, | ||
494 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS), | ||
495 | 0, 1, | ||
496 | GNUNET_TIME_UNIT_MINUTES, | ||
497 | &run_tests, crc)) | ||
315 | { | 498 | { |
316 | FPRINTF (stderr, "%s", "Test 'put' operation failed.\n"); | 499 | FPRINTF (stderr, |
500 | "%s", | ||
501 | "Test 'put' operation failed.\n"); | ||
317 | ok = 1; | 502 | ok = 1; |
318 | GNUNET_free (crc); | 503 | GNUNET_free (crc); |
319 | } | 504 | } |
320 | } | 505 | } |
321 | 506 | ||
322 | 507 | ||
508 | /** | ||
509 | * Entry point into the test. Determines which configuration / plugin | ||
510 | * we are running with based on the name of the binary and starts | ||
511 | * the peer. | ||
512 | * | ||
513 | * @param argc should be 1 | ||
514 | * @param argv used to determine plugin / configuration name. | ||
515 | * @return 0 on success | ||
516 | */ | ||
323 | int | 517 | int |
324 | main (int argc, char *argv[]) | 518 | main (int argc, |
519 | char *argv[]) | ||
325 | { | 520 | { |
326 | char cfg_name[128]; | 521 | char cfg_name[128]; |
327 | 522 | ||
328 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 523 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
329 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), | 524 | GNUNET_snprintf (cfg_name, |
330 | "test_datastore_api_data_%s.conf", plugin_name); | 525 | sizeof (cfg_name), |
526 | "test_datastore_api_data_%s.conf", | ||
527 | plugin_name); | ||
331 | if (0 != | 528 | if (0 != |
332 | GNUNET_TESTING_peer_run ("perf-gnunet-datastore", | 529 | GNUNET_TESTING_peer_run ("perf-gnunet-datastore", |
333 | cfg_name, | 530 | cfg_name, |