diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-14 17:34:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-14 17:34:48 +0000 |
commit | b1055e6385d821fa7d328f2b4d63209a41e6167d (patch) | |
tree | 694368f1ab9ff916d05356563516a544c61334ae /src/fs/test_fs_download_persistence.c | |
parent | c44b94ee1f25110f259688c221d8ffcb42cd5aa5 (diff) | |
download | gnunet-b1055e6385d821fa7d328f2b4d63209a41e6167d.tar.gz gnunet-b1055e6385d821fa7d328f2b4d63209a41e6167d.zip |
-cleaning up fs-download testcases
Diffstat (limited to 'src/fs/test_fs_download_persistence.c')
-rw-r--r-- | src/fs/test_fs_download_persistence.c | 115 |
1 files changed, 22 insertions, 93 deletions
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c index ba776dd03..bb3bc84c9 100644 --- a/src/fs/test_fs_download_persistence.c +++ b/src/fs/test_fs_download_persistence.c | |||
@@ -27,12 +27,9 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_arm_service.h" | 29 | #include "gnunet_arm_service.h" |
30 | #include "gnunet_testing_lib-new.h" | ||
30 | #include "gnunet_fs_service.h" | 31 | #include "gnunet_fs_service.h" |
31 | 32 | ||
32 | #define VERBOSE GNUNET_NO | ||
33 | |||
34 | #define START_ARM GNUNET_YES | ||
35 | |||
36 | /** | 33 | /** |
37 | * File-size we use for testing. | 34 | * File-size we use for testing. |
38 | */ | 35 | */ |
@@ -48,15 +45,6 @@ | |||
48 | */ | 45 | */ |
49 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 46 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
50 | 47 | ||
51 | struct PeerContext | ||
52 | { | ||
53 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
54 | #if START_ARM | ||
55 | struct GNUNET_OS_Process *arm_proc; | ||
56 | #endif | ||
57 | }; | ||
58 | |||
59 | static struct PeerContext p1; | ||
60 | 48 | ||
61 | static struct GNUNET_TIME_Absolute start; | 49 | static struct GNUNET_TIME_Absolute start; |
62 | 50 | ||
@@ -74,6 +62,7 @@ static char *fn; | |||
74 | 62 | ||
75 | static int err; | 63 | static int err; |
76 | 64 | ||
65 | |||
77 | static void | 66 | static void |
78 | timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 67 | timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
79 | { | 68 | { |
@@ -92,6 +81,7 @@ timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
92 | err = 1; | 81 | err = 1; |
93 | } | 82 | } |
94 | 83 | ||
84 | |||
95 | static void | 85 | static void |
96 | abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 86 | abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
97 | { | 87 | { |
@@ -166,14 +156,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
166 | switch (event->status) | 156 | switch (event->status) |
167 | { | 157 | { |
168 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 158 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
169 | #if VERBOSE | 159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
170 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 160 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
171 | (unsigned long long) event->value.publish.completed, | 161 | (unsigned long long) event->value.publish.completed, |
172 | (unsigned long long) event->value.publish.size, | 162 | (unsigned long long) event->value.publish.size, |
173 | event->value.publish.specifics.progress.depth, | 163 | event->value.publish.specifics.progress.depth, |
174 | (unsigned long long) event->value.publish.specifics. | 164 | (unsigned long long) event->value.publish.specifics. |
175 | progress.offset); | 165 | progress.offset); |
176 | #endif | ||
177 | break; | 166 | break; |
178 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 167 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
179 | printf ("Publishing complete, %llu kbps.\n", | 168 | printf ("Publishing complete, %llu kbps.\n", |
@@ -201,14 +190,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
201 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 190 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
202 | consider_restart (event->status); | 191 | consider_restart (event->status); |
203 | GNUNET_assert (download == event->value.download.dc); | 192 | GNUNET_assert (download == event->value.download.dc); |
204 | #if VERBOSE | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
205 | printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n", | 194 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", |
206 | (unsigned long long) event->value.download.completed, | 195 | (unsigned long long) event->value.download.completed, |
207 | (unsigned long long) event->value.download.size, | 196 | (unsigned long long) event->value.download.size, |
208 | event->value.download.specifics.progress.depth, | 197 | event->value.download.specifics.progress.depth, |
209 | (unsigned long long) event->value.download.specifics. | 198 | (unsigned long long) event->value.download.specifics. |
210 | progress.offset); | 199 | progress.offset); |
211 | #endif | ||
212 | break; | 200 | break; |
213 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 201 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
214 | FPRINTF (stderr, "Error publishing file: %s\n", | 202 | FPRINTF (stderr, "Error publishing file: %s\n", |
@@ -290,44 +278,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
290 | 278 | ||
291 | 279 | ||
292 | static void | 280 | static void |
293 | setup_peer (struct PeerContext *p, const char *cfgname) | 281 | run (void *cls, |
294 | { | ||
295 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
296 | #if START_ARM | ||
297 | p->arm_proc = | ||
298 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
299 | "gnunet-service-arm", | ||
300 | #if VERBOSE | ||
301 | "-L", "DEBUG", | ||
302 | #endif | ||
303 | "-c", cfgname, NULL); | ||
304 | #endif | ||
305 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
306 | } | ||
307 | |||
308 | |||
309 | static void | ||
310 | stop_arm (struct PeerContext *p) | ||
311 | { | ||
312 | #if START_ARM | ||
313 | if (NULL != p->arm_proc) | ||
314 | { | ||
315 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
316 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
317 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | ||
318 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | ||
320 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
321 | GNUNET_OS_process_destroy (p->arm_proc); | ||
322 | p->arm_proc = NULL; | ||
323 | } | ||
324 | #endif | ||
325 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
326 | } | ||
327 | |||
328 | |||
329 | static void | ||
330 | run (void *cls, char *const *args, const char *cfgfile, | ||
331 | const struct GNUNET_CONFIGURATION_Handle *c) | 282 | const struct GNUNET_CONFIGURATION_Handle *c) |
332 | { | 283 | { |
333 | const char *keywords[] = { | 284 | const char *keywords[] = { |
@@ -342,7 +293,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
342 | struct GNUNET_FS_BlockOptions bo; | 293 | struct GNUNET_FS_BlockOptions bo; |
343 | 294 | ||
344 | cfg = c; | 295 | cfg = c; |
345 | setup_peer (&p1, "test_fs_download_data.conf"); | ||
346 | fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL, | 296 | fs = GNUNET_FS_start (cfg, "test-fs-download-persistence", &progress_cb, NULL, |
347 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); | 297 | GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); |
348 | GNUNET_assert (NULL != fs); | 298 | GNUNET_assert (NULL != fs); |
@@ -374,31 +324,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
374 | int | 324 | int |
375 | main (int argc, char *argv[]) | 325 | main (int argc, char *argv[]) |
376 | { | 326 | { |
377 | char *const argvx[] = { | 327 | if (0 != GNUNET_TESTING_peer_run ("test-fs-download-persistence", |
378 | "test-fs-download-persistence", | 328 | "test_fs_download_data.conf", |
379 | "-c", | 329 | &run, NULL)) |
380 | "test_fs_download_data.conf", | 330 | return 1; |
381 | #if VERBOSE | ||
382 | "-L", "DEBUG", | ||
383 | #endif | ||
384 | NULL | ||
385 | }; | ||
386 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
387 | GNUNET_GETOPT_OPTION_END | ||
388 | }; | ||
389 | GNUNET_log_setup ("test_fs_download_persistence", | ||
390 | #if VERBOSE | ||
391 | "DEBUG", | ||
392 | #else | ||
393 | "WARNING", | ||
394 | #endif | ||
395 | NULL); | ||
396 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); | ||
397 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | ||
398 | "test-fs-download-persistence", "nohelp", options, &run, | ||
399 | NULL); | ||
400 | stop_arm (&p1); | ||
401 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); | ||
402 | return err; | 331 | return err; |
403 | } | 332 | } |
404 | 333 | ||