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 | |
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')
-rw-r--r-- | src/datastore/datastore_api.c | 6 | ||||
-rw-r--r-- | src/datastore/perf_datastore_api.c | 329 | ||||
-rw-r--r-- | src/datastore/test_datastore_api.c | 233 | ||||
-rw-r--r-- | src/datastore/test_datastore_api_management.c | 15 |
4 files changed, 451 insertions, 132 deletions
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index f11647d92..d7e933fc6 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c | |||
@@ -308,16 +308,14 @@ transmit_drop (void *cls, size_t size, void *buf) | |||
308 | { | 308 | { |
309 | LOG (GNUNET_ERROR_TYPE_WARNING, | 309 | LOG (GNUNET_ERROR_TYPE_WARNING, |
310 | _("Failed to transmit request to drop database.\n")); | 310 | _("Failed to transmit request to drop database.\n")); |
311 | GNUNET_SCHEDULER_add_continuation (&disconnect_after_drop, h, | 311 | GNUNET_SCHEDULER_add_now (&disconnect_after_drop, h); |
312 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
313 | return 0; | 312 | return 0; |
314 | } | 313 | } |
315 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 314 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); |
316 | hdr = buf; | 315 | hdr = buf; |
317 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); | 316 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); |
318 | hdr->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DROP); | 317 | hdr->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DROP); |
319 | GNUNET_SCHEDULER_add_continuation (&disconnect_after_drop, h, | 318 | GNUNET_SCHEDULER_add_now (&disconnect_after_drop, h); |
320 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
321 | return sizeof (struct GNUNET_MessageHeader); | 319 | return sizeof (struct GNUNET_MessageHeader); |
322 | } | 320 | } |
323 | 321 | ||
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, |
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index a29e01a1e..36e637845 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 | Copyright (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2004, 2005, 2006, 2007, 2009, 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 |
@@ -40,10 +40,16 @@ | |||
40 | 40 | ||
41 | #define ITERATIONS 256 | 41 | #define ITERATIONS 256 |
42 | 42 | ||
43 | /** | ||
44 | * Handle to the datastore. | ||
45 | */ | ||
43 | static struct GNUNET_DATASTORE_Handle *datastore; | 46 | static struct GNUNET_DATASTORE_Handle *datastore; |
44 | 47 | ||
45 | static struct GNUNET_TIME_Absolute now; | 48 | static struct GNUNET_TIME_Absolute now; |
46 | 49 | ||
50 | /** | ||
51 | * Value we return from #main(). | ||
52 | */ | ||
47 | static int ok; | 53 | static int ok; |
48 | 54 | ||
49 | /** | 55 | /** |
@@ -51,6 +57,7 @@ static int ok; | |||
51 | */ | 57 | */ |
52 | static const char *plugin_name; | 58 | static const char *plugin_name; |
53 | 59 | ||
60 | |||
54 | static size_t | 61 | static size_t |
55 | get_size (int i) | 62 | get_size (int i) |
56 | { | 63 | { |
@@ -98,9 +105,20 @@ get_expiration (int i) | |||
98 | return av; | 105 | return av; |
99 | } | 106 | } |
100 | 107 | ||
108 | |||
109 | /** | ||
110 | * Which phase of the process are we in? | ||
111 | */ | ||
101 | enum RunPhase | 112 | enum RunPhase |
102 | { | 113 | { |
114 | /** | ||
115 | * We are done (shutting down normally). | ||
116 | */ | ||
103 | RP_DONE = 0, | 117 | RP_DONE = 0, |
118 | |||
119 | /** | ||
120 | * We are adding new entries to the datastore. | ||
121 | */ | ||
104 | RP_PUT = 1, | 122 | RP_PUT = 1, |
105 | RP_GET = 2, | 123 | RP_GET = 2, |
106 | RP_DEL = 3, | 124 | RP_DEL = 3, |
@@ -113,29 +131,61 @@ enum RunPhase | |||
113 | RP_GET_MULTIPLE_NEXT = 10, | 131 | RP_GET_MULTIPLE_NEXT = 10, |
114 | RP_UPDATE = 11, | 132 | RP_UPDATE = 11, |
115 | RP_UPDATE_VALIDATE = 12, | 133 | RP_UPDATE_VALIDATE = 12, |
134 | |||
135 | /** | ||
136 | * Execution failed with some kind of error. | ||
137 | */ | ||
116 | RP_ERROR | 138 | RP_ERROR |
117 | }; | 139 | }; |
118 | 140 | ||
119 | 141 | ||
142 | /** | ||
143 | * Closure we give to all of the functions executing the | ||
144 | * benchmark. Could right now be global, but this allows | ||
145 | * us to theoretically run multiple clients "in parallel". | ||
146 | */ | ||
120 | struct CpsRunContext | 147 | struct CpsRunContext |
121 | { | 148 | { |
149 | /** | ||
150 | * Execution phase we are in. | ||
151 | */ | ||
152 | enum RunPhase phase; | ||
153 | |||
122 | struct GNUNET_HashCode key; | 154 | struct GNUNET_HashCode key; |
123 | int i; | 155 | int i; |
124 | int rid; | 156 | int rid; |
125 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
126 | void *data; | 157 | void *data; |
127 | size_t size; | 158 | size_t size; |
128 | enum RunPhase phase; | 159 | |
129 | uint64_t uid; | 160 | uint64_t uid; |
130 | uint64_t offset; | 161 | uint64_t offset; |
131 | uint64_t first_uid; | 162 | uint64_t first_uid; |
132 | }; | 163 | }; |
133 | 164 | ||
134 | 165 | ||
166 | /** | ||
167 | * Main state machine. Executes the next step of the test | ||
168 | * depending on the current state. | ||
169 | * | ||
170 | * @param cls the `struct CpsRunContext` | ||
171 | * @param tc scheduler context (unused) | ||
172 | */ | ||
135 | static void | 173 | static void |
136 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 174 | run_continuation (void *cls, |
175 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
137 | 176 | ||
138 | 177 | ||
178 | /** | ||
179 | * Continuation called to notify client about result of an | ||
180 | * operation. Checks for errors, updates our iteration counters and | ||
181 | * continues execution with #run_continuation(). | ||
182 | * | ||
183 | * @param cls the `struct CpsRunContext` | ||
184 | * @param success #GNUNET_SYSERR on failure | ||
185 | * @param min_expiration minimum expiration time required for content to be stored | ||
186 | * by the datacache at this time, zero for unknown | ||
187 | * @param msg NULL on success, otherwise an error message | ||
188 | */ | ||
139 | static void | 189 | static void |
140 | check_success (void *cls, | 190 | check_success (void *cls, |
141 | int success, | 191 | int success, |
@@ -147,14 +197,15 @@ check_success (void *cls, | |||
147 | if (GNUNET_OK != success) | 197 | if (GNUNET_OK != success) |
148 | { | 198 | { |
149 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 199 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
150 | "Operation %d/%d not successfull: `%s'\n", crc->phase, crc->i, | 200 | "Operation %d/%d not successfull: `%s'\n", |
201 | crc->phase, | ||
202 | crc->i, | ||
151 | msg); | 203 | msg); |
152 | crc->phase = RP_ERROR; | 204 | crc->phase = RP_ERROR; |
153 | } | 205 | } |
154 | GNUNET_free_non_null (crc->data); | 206 | GNUNET_free_non_null (crc->data); |
155 | crc->data = NULL; | 207 | crc->data = NULL; |
156 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 208 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
157 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
158 | } | 209 | } |
159 | 210 | ||
160 | 211 | ||
@@ -172,8 +223,8 @@ get_reserved (void *cls, | |||
172 | msg); | 223 | msg); |
173 | GNUNET_assert (0 < success); | 224 | GNUNET_assert (0 < success); |
174 | crc->rid = success; | 225 | crc->rid = success; |
175 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 226 | GNUNET_SCHEDULER_add_now (&run_continuation, |
176 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 227 | crc); |
177 | } | 228 | } |
178 | 229 | ||
179 | 230 | ||
@@ -199,8 +250,8 @@ check_value (void *cls, | |||
199 | crc->phase, | 250 | crc->phase, |
200 | crc->i); | 251 | crc->i); |
201 | crc->phase = RP_ERROR; | 252 | crc->phase = RP_ERROR; |
202 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 253 | GNUNET_SCHEDULER_add_now (&run_continuation, |
203 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 254 | crc); |
204 | return; | 255 | return; |
205 | } | 256 | } |
206 | #if 0 | 257 | #if 0 |
@@ -225,8 +276,8 @@ check_value (void *cls, | |||
225 | crc->phase = RP_DEL; | 276 | crc->phase = RP_DEL; |
226 | crc->i = ITERATIONS; | 277 | crc->i = ITERATIONS; |
227 | } | 278 | } |
228 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 279 | GNUNET_SCHEDULER_add_now (&run_continuation, |
229 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 280 | crc); |
230 | } | 281 | } |
231 | 282 | ||
232 | 283 | ||
@@ -250,15 +301,20 @@ delete_value (void *cls, | |||
250 | crc->data = GNUNET_malloc (size); | 301 | crc->data = GNUNET_malloc (size); |
251 | memcpy (crc->data, data, size); | 302 | memcpy (crc->data, data, size); |
252 | crc->phase = RP_DO_DEL; | 303 | crc->phase = RP_DO_DEL; |
253 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 304 | GNUNET_SCHEDULER_add_now (&run_continuation, |
254 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 305 | crc); |
255 | } | 306 | } |
256 | 307 | ||
257 | 308 | ||
258 | static void | 309 | static void |
259 | check_nothing (void *cls, const struct GNUNET_HashCode * key, size_t size, | 310 | check_nothing (void *cls, |
260 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, | 311 | const struct GNUNET_HashCode *key, |
261 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, | 312 | size_t size, |
313 | const void *data, | ||
314 | enum GNUNET_BLOCK_Type type, | ||
315 | uint32_t priority, | ||
316 | uint32_t anonymity, | ||
317 | struct GNUNET_TIME_Absolute expiration, | ||
262 | uint64_t uid) | 318 | uint64_t uid) |
263 | { | 319 | { |
264 | struct CpsRunContext *crc = cls; | 320 | struct CpsRunContext *crc = cls; |
@@ -266,8 +322,8 @@ check_nothing (void *cls, const struct GNUNET_HashCode * key, size_t size, | |||
266 | GNUNET_assert (key == NULL); | 322 | GNUNET_assert (key == NULL); |
267 | if (crc->i == 0) | 323 | if (crc->i == 0) |
268 | crc->phase = RP_RESERVE; | 324 | crc->phase = RP_RESERVE; |
269 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 325 | GNUNET_SCHEDULER_add_now (&run_continuation, |
270 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 326 | crc); |
271 | } | 327 | } |
272 | 328 | ||
273 | 329 | ||
@@ -303,8 +359,7 @@ check_multiple (void *cls, | |||
303 | } | 359 | } |
304 | if (priority == get_priority (42)) | 360 | if (priority == get_priority (42)) |
305 | crc->uid = uid; | 361 | crc->uid = uid; |
306 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 362 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
307 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
308 | } | 363 | } |
309 | 364 | ||
310 | 365 | ||
@@ -330,11 +385,17 @@ check_update (void *cls, | |||
330 | GNUNET_assert (size == get_size (43)); | 385 | GNUNET_assert (size == get_size (43)); |
331 | crc->offset++; | 386 | crc->offset++; |
332 | } | 387 | } |
333 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 388 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
334 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
335 | } | 389 | } |
336 | 390 | ||
337 | 391 | ||
392 | /** | ||
393 | * Main state machine. Executes the next step of the test | ||
394 | * depending on the current state. | ||
395 | * | ||
396 | * @param cls the `struct CpsRunContext` | ||
397 | * @param tc scheduler context (unused) | ||
398 | */ | ||
338 | static void | 399 | static void |
339 | run_continuation (void *cls, | 400 | run_continuation (void *cls, |
340 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 401 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -430,43 +491,68 @@ run_continuation (void *cls, | |||
430 | break; | 491 | break; |
431 | case RP_PUT_MULTIPLE_NEXT: | 492 | case RP_PUT_MULTIPLE_NEXT: |
432 | crc->phase = RP_GET_MULTIPLE; | 493 | crc->phase = RP_GET_MULTIPLE; |
433 | GNUNET_DATASTORE_put (datastore, crc->rid, &crc->key, get_size (43), | 494 | GNUNET_DATASTORE_put (datastore, crc->rid, |
434 | get_data (43), get_type (42), get_priority (43), | 495 | &crc->key, |
435 | get_anonymity (43), 0, get_expiration (43), 1, 1, | 496 | get_size (43), |
436 | TIMEOUT, &check_success, crc); | 497 | get_data (43), |
498 | get_type (42), | ||
499 | get_priority (43), | ||
500 | get_anonymity (43), | ||
501 | 0, | ||
502 | get_expiration (43), | ||
503 | 1, 1, | ||
504 | TIMEOUT, | ||
505 | &check_success, crc); | ||
437 | break; | 506 | break; |
438 | case RP_GET_MULTIPLE: | 507 | case RP_GET_MULTIPLE: |
439 | GNUNET_assert (NULL != | 508 | GNUNET_assert (NULL != |
440 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, | 509 | GNUNET_DATASTORE_get_key (datastore, |
441 | get_type (42), 1, 1, TIMEOUT, | 510 | crc->offset, |
511 | &crc->key, | ||
512 | get_type (42), 1, 1, | ||
513 | TIMEOUT, | ||
442 | &check_multiple, crc)); | 514 | &check_multiple, crc)); |
443 | break; | 515 | break; |
444 | case RP_GET_MULTIPLE_NEXT: | 516 | case RP_GET_MULTIPLE_NEXT: |
445 | GNUNET_assert (NULL != | 517 | GNUNET_assert (NULL != |
446 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, | 518 | GNUNET_DATASTORE_get_key (datastore, |
447 | get_type (42), 1, 1, TIMEOUT, | 519 | crc->offset, |
520 | &crc->key, | ||
521 | get_type (42), | ||
522 | 1, 1, | ||
523 | TIMEOUT, | ||
448 | &check_multiple, crc)); | 524 | &check_multiple, crc)); |
449 | break; | 525 | break; |
450 | case RP_UPDATE: | 526 | case RP_UPDATE: |
451 | GNUNET_assert (crc->uid > 0); | 527 | GNUNET_assert (crc->uid > 0); |
452 | crc->phase = RP_UPDATE_VALIDATE; | 528 | crc->phase = RP_UPDATE_VALIDATE; |
453 | GNUNET_DATASTORE_update (datastore, crc->uid, 100, get_expiration (42), 1, | 529 | GNUNET_DATASTORE_update (datastore, |
454 | 1, TIMEOUT, &check_success, crc); | 530 | crc->uid, 100, |
531 | get_expiration (42), 1, | ||
532 | 1, TIMEOUT, | ||
533 | &check_success, crc); | ||
455 | break; | 534 | break; |
456 | case RP_UPDATE_VALIDATE: | 535 | case RP_UPDATE_VALIDATE: |
457 | GNUNET_assert (NULL != | 536 | GNUNET_assert (NULL != |
458 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, | 537 | GNUNET_DATASTORE_get_key (datastore, |
459 | get_type (42), 1, 1, TIMEOUT, | 538 | crc->offset, |
539 | &crc->key, | ||
540 | get_type (42), | ||
541 | 1, 1, | ||
542 | TIMEOUT, | ||
460 | &check_update, crc)); | 543 | &check_update, crc)); |
461 | break; | 544 | break; |
462 | case RP_DONE: | 545 | case RP_DONE: |
463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n"); | 546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
464 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 547 | "Finished, disconnecting\n"); |
548 | GNUNET_DATASTORE_disconnect (datastore, | ||
549 | GNUNET_YES); | ||
465 | GNUNET_free (crc); | 550 | GNUNET_free (crc); |
466 | ok = 0; | 551 | ok = 0; |
467 | break; | 552 | break; |
468 | case RP_ERROR: | 553 | case RP_ERROR: |
469 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 554 | GNUNET_DATASTORE_disconnect (datastore, |
555 | GNUNET_YES); | ||
470 | GNUNET_free (crc); | 556 | GNUNET_free (crc); |
471 | ok = 43; | 557 | ok = 43; |
472 | break; | 558 | break; |
@@ -474,6 +560,18 @@ run_continuation (void *cls, | |||
474 | } | 560 | } |
475 | 561 | ||
476 | 562 | ||
563 | /** | ||
564 | * Function called with the result of the initial PUT operation. If | ||
565 | * the PUT succeeded, we start the actual benchmark loop, otherwise we | ||
566 | * bail out with an error. | ||
567 | * | ||
568 | * | ||
569 | * @param cls closure | ||
570 | * @param success #GNUNET_SYSERR on failure | ||
571 | * @param min_expiration minimum expiration time required for content to be stored | ||
572 | * by the datacache at this time, zero for unknown | ||
573 | * @param msg NULL on success, otherwise an error message | ||
574 | */ | ||
477 | static void | 575 | static void |
478 | run_tests (void *cls, | 576 | run_tests (void *cls, |
479 | int32_t success, | 577 | int32_t success, |
@@ -485,20 +583,22 @@ run_tests (void *cls, | |||
485 | switch (success) | 583 | switch (success) |
486 | { | 584 | { |
487 | case GNUNET_YES: | 585 | case GNUNET_YES: |
488 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 586 | GNUNET_SCHEDULER_add_now (&run_continuation, |
489 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 587 | crc); |
490 | return; | 588 | return; |
491 | case GNUNET_NO: | 589 | case GNUNET_NO: |
492 | FPRINTF (stderr, | 590 | FPRINTF (stderr, |
493 | "%s", "Test 'put' operation failed, key already exists (!?)\n"); | 591 | "%s", "Test 'put' operation failed, key already exists (!?)\n"); |
494 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 592 | GNUNET_DATASTORE_disconnect (datastore, |
593 | GNUNET_YES); | ||
495 | GNUNET_free (crc); | 594 | GNUNET_free (crc); |
496 | return; | 595 | return; |
497 | case GNUNET_SYSERR: | 596 | case GNUNET_SYSERR: |
498 | FPRINTF (stderr, | 597 | FPRINTF (stderr, |
499 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", | 598 | "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", |
500 | msg); | 599 | msg); |
501 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 600 | GNUNET_DATASTORE_disconnect (datastore, |
601 | GNUNET_YES); | ||
502 | GNUNET_free (crc); | 602 | GNUNET_free (crc); |
503 | return; | 603 | return; |
504 | default: | 604 | default: |
@@ -507,6 +607,15 @@ run_tests (void *cls, | |||
507 | } | 607 | } |
508 | 608 | ||
509 | 609 | ||
610 | /** | ||
611 | * Beginning of the actual execution of the benchmark. | ||
612 | * Performs a first test operation (PUT) to verify that | ||
613 | * the plugin works at all. | ||
614 | * | ||
615 | * @param cls NULL | ||
616 | * @param cfg configuration to use | ||
617 | * @param peer peer handle (unused) | ||
618 | */ | ||
510 | static void | 619 | static void |
511 | run (void *cls, | 620 | run (void *cls, |
512 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 621 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -516,32 +625,52 @@ run (void *cls, | |||
516 | static struct GNUNET_HashCode zkey; | 625 | static struct GNUNET_HashCode zkey; |
517 | 626 | ||
518 | crc = GNUNET_new (struct CpsRunContext); | 627 | crc = GNUNET_new (struct CpsRunContext); |
519 | crc->cfg = cfg; | ||
520 | crc->phase = RP_PUT; | 628 | crc->phase = RP_PUT; |
521 | now = GNUNET_TIME_absolute_get (); | 629 | now = GNUNET_TIME_absolute_get (); |
522 | datastore = GNUNET_DATASTORE_connect (cfg); | 630 | datastore = GNUNET_DATASTORE_connect (cfg); |
523 | if (NULL == | 631 | if (NULL == |
524 | GNUNET_DATASTORE_put (datastore, 0, &zkey, 4, "TEST", | 632 | GNUNET_DATASTORE_put (datastore, |
525 | GNUNET_BLOCK_TYPE_TEST, 0, 0, 0, | 633 | 0, |
634 | &zkey, | ||
635 | 4, | ||
636 | "TEST", | ||
637 | GNUNET_BLOCK_TYPE_TEST, | ||
638 | 0, 0, 0, | ||
526 | GNUNET_TIME_relative_to_absolute | 639 | GNUNET_TIME_relative_to_absolute |
527 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, | 640 | (GNUNET_TIME_UNIT_SECONDS), |
528 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) | 641 | 0, 1, |
642 | GNUNET_TIME_UNIT_MINUTES, | ||
643 | &run_tests, crc)) | ||
529 | { | 644 | { |
530 | FPRINTF (stderr, "%s", "Test 'put' operation failed.\n"); | 645 | FPRINTF (stderr, |
646 | "%s", | ||
647 | "Test 'put' operation failed.\n"); | ||
531 | ok = 1; | 648 | ok = 1; |
532 | GNUNET_free (crc); | 649 | GNUNET_free (crc); |
533 | } | 650 | } |
534 | } | 651 | } |
535 | 652 | ||
536 | 653 | ||
654 | /** | ||
655 | * Entry point into the test. Determines which configuration / plugin | ||
656 | * we are running with based on the name of the binary and starts | ||
657 | * the peer. | ||
658 | * | ||
659 | * @param argc should be 1 | ||
660 | * @param argv used to determine plugin / configuration name. | ||
661 | * @return 0 on success | ||
662 | */ | ||
537 | int | 663 | int |
538 | main (int argc, char *argv[]) | 664 | main (int argc, |
665 | char *argv[]) | ||
539 | { | 666 | { |
540 | char cfg_name[128]; | 667 | char cfg_name[128]; |
541 | 668 | ||
542 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | 669 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); |
543 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), | 670 | GNUNET_snprintf (cfg_name, |
544 | "test_datastore_api_data_%s.conf", plugin_name); | 671 | sizeof (cfg_name), |
672 | "test_datastore_api_data_%s.conf", | ||
673 | plugin_name); | ||
545 | if (0 != | 674 | if (0 != |
546 | GNUNET_TESTING_peer_run ("test-gnunet-datastore", | 675 | GNUNET_TESTING_peer_run ("test-gnunet-datastore", |
547 | cfg_name, | 676 | cfg_name, |
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index e46f094f4..4b888d468 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c | |||
@@ -132,8 +132,7 @@ check_success (void *cls, int success, struct GNUNET_TIME_Absolute min_expiratio | |||
132 | GNUNET_assert (GNUNET_OK == success); | 132 | GNUNET_assert (GNUNET_OK == success); |
133 | GNUNET_free_non_null (crc->data); | 133 | GNUNET_free_non_null (crc->data); |
134 | crc->data = NULL; | 134 | crc->data = NULL; |
135 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 135 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
136 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
137 | } | 136 | } |
138 | 137 | ||
139 | 138 | ||
@@ -149,8 +148,7 @@ check_value (void *cls, const struct GNUNET_HashCode * key, size_t size, | |||
149 | if (NULL == key) | 148 | if (NULL == key) |
150 | { | 149 | { |
151 | crc->phase = RP_GET_FAIL; | 150 | crc->phase = RP_GET_FAIL; |
152 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 151 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
153 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
154 | return; | 152 | return; |
155 | } | 153 | } |
156 | i = crc->i; | 154 | i = crc->i; |
@@ -164,8 +162,7 @@ check_value (void *cls, const struct GNUNET_HashCode * key, size_t size, | |||
164 | crc->i--; | 162 | crc->i--; |
165 | if (crc->i == 0) | 163 | if (crc->i == 0) |
166 | crc->phase = RP_DONE; | 164 | crc->phase = RP_DONE; |
167 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 165 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
168 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
169 | } | 166 | } |
170 | 167 | ||
171 | 168 | ||
@@ -180,8 +177,7 @@ check_nothing (void *cls, const struct GNUNET_HashCode * key, size_t size, | |||
180 | GNUNET_assert (key == NULL); | 177 | GNUNET_assert (key == NULL); |
181 | if (0 == --crc->i) | 178 | if (0 == --crc->i) |
182 | crc->phase = RP_DONE; | 179 | crc->phase = RP_DONE; |
183 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 180 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
184 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
185 | } | 181 | } |
186 | 182 | ||
187 | 183 | ||
@@ -252,8 +248,7 @@ run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, c | |||
252 | GNUNET_free (crc); | 248 | GNUNET_free (crc); |
253 | return; | 249 | return; |
254 | } | 250 | } |
255 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, | 251 | GNUNET_SCHEDULER_add_now (&run_continuation, crc); |
256 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
257 | } | 252 | } |
258 | 253 | ||
259 | 254 | ||