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 | |
parent | c44b94ee1f25110f259688c221d8ffcb42cd5aa5 (diff) | |
download | gnunet-b1055e6385d821fa7d328f2b4d63209a41e6167d.tar.gz gnunet-b1055e6385d821fa7d328f2b4d63209a41e6167d.zip |
-cleaning up fs-download testcases
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/Makefile.am | 3 | ||||
-rw-r--r-- | src/fs/test_fs_download.c | 146 | ||||
-rw-r--r-- | src/fs/test_fs_download_indexed.c | 114 | ||||
-rw-r--r-- | src/fs/test_fs_download_persistence.c | 115 | ||||
-rw-r--r-- | src/fs/test_fs_download_recursive.c | 375 |
5 files changed, 86 insertions, 667 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index c88427d83..2c5c545c2 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -274,18 +274,21 @@ test_fs_directory_LDADD = \ | |||
274 | test_fs_download_SOURCES = \ | 274 | test_fs_download_SOURCES = \ |
275 | test_fs_download.c | 275 | test_fs_download.c |
276 | test_fs_download_LDADD = \ | 276 | test_fs_download_LDADD = \ |
277 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
277 | $(top_builddir)/src/fs/libgnunetfs.la \ | 278 | $(top_builddir)/src/fs/libgnunetfs.la \ |
278 | $(top_builddir)/src/util/libgnunetutil.la | 279 | $(top_builddir)/src/util/libgnunetutil.la |
279 | 280 | ||
280 | test_fs_download_indexed_SOURCES = \ | 281 | test_fs_download_indexed_SOURCES = \ |
281 | test_fs_download_indexed.c | 282 | test_fs_download_indexed.c |
282 | test_fs_download_indexed_LDADD = \ | 283 | test_fs_download_indexed_LDADD = \ |
284 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
283 | $(top_builddir)/src/fs/libgnunetfs.la \ | 285 | $(top_builddir)/src/fs/libgnunetfs.la \ |
284 | $(top_builddir)/src/util/libgnunetutil.la | 286 | $(top_builddir)/src/util/libgnunetutil.la |
285 | 287 | ||
286 | test_fs_download_persistence_SOURCES = \ | 288 | test_fs_download_persistence_SOURCES = \ |
287 | test_fs_download_persistence.c | 289 | test_fs_download_persistence.c |
288 | test_fs_download_persistence_LDADD = \ | 290 | test_fs_download_persistence_LDADD = \ |
291 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
289 | $(top_builddir)/src/fs/libgnunetfs.la \ | 292 | $(top_builddir)/src/fs/libgnunetfs.la \ |
290 | $(top_builddir)/src/util/libgnunetutil.la | 293 | $(top_builddir)/src/util/libgnunetutil.la |
291 | 294 | ||
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 278197478..31be61903 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c | |||
@@ -28,12 +28,9 @@ | |||
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_fs_service.h" | 30 | #include "gnunet_fs_service.h" |
31 | #include "gnunet_testing_lib-new.h" | ||
31 | #include <gauger.h> | 32 | #include <gauger.h> |
32 | 33 | ||
33 | #define VERBOSE GNUNET_NO | ||
34 | |||
35 | #define START_ARM GNUNET_YES | ||
36 | |||
37 | /** | 34 | /** |
38 | * File-size we use for testing. | 35 | * File-size we use for testing. |
39 | */ | 36 | */ |
@@ -49,15 +46,6 @@ | |||
49 | */ | 46 | */ |
50 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 47 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
51 | 48 | ||
52 | struct PeerContext | ||
53 | { | ||
54 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
55 | #if START_ARM | ||
56 | struct GNUNET_OS_Process *arm_proc; | ||
57 | #endif | ||
58 | }; | ||
59 | |||
60 | static struct PeerContext p1; | ||
61 | 49 | ||
62 | static struct GNUNET_TIME_Absolute start; | 50 | static struct GNUNET_TIME_Absolute start; |
63 | 51 | ||
@@ -73,15 +61,16 @@ static char *fn; | |||
73 | 61 | ||
74 | static int err; | 62 | static int err; |
75 | 63 | ||
64 | |||
76 | static void | 65 | static void |
77 | timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 66 | timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
78 | { | 67 | { |
79 | if (download != NULL) | 68 | if (NULL != download) |
80 | { | 69 | { |
81 | GNUNET_FS_download_stop (download, GNUNET_YES); | 70 | GNUNET_FS_download_stop (download, GNUNET_YES); |
82 | download = NULL; | 71 | download = NULL; |
83 | } | 72 | } |
84 | else if (publish != NULL) | 73 | else if (NULL != publish) |
85 | { | 74 | { |
86 | GNUNET_FS_publish_stop (publish); | 75 | GNUNET_FS_publish_stop (publish); |
87 | publish = NULL; | 76 | publish = NULL; |
@@ -91,16 +80,18 @@ timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
91 | err = 1; | 80 | err = 1; |
92 | } | 81 | } |
93 | 82 | ||
83 | |||
94 | static void | 84 | static void |
95 | abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 85 | abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
96 | { | 86 | { |
97 | if (publish != NULL) | 87 | if (NULL != publish) |
98 | { | 88 | { |
99 | GNUNET_FS_publish_stop (publish); | 89 | GNUNET_FS_publish_stop (publish); |
100 | publish = NULL; | 90 | publish = NULL; |
101 | } | 91 | } |
102 | } | 92 | } |
103 | 93 | ||
94 | |||
104 | static void | 95 | static void |
105 | stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 96 | stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
106 | { | 97 | { |
@@ -108,12 +99,13 @@ stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
108 | fs = NULL; | 99 | fs = NULL; |
109 | } | 100 | } |
110 | 101 | ||
102 | |||
111 | static void | 103 | static void |
112 | abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 104 | abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
113 | { | 105 | { |
114 | uint64_t size; | 106 | uint64_t size; |
115 | 107 | ||
116 | if (download != NULL) | 108 | if (NULL != download) |
117 | { | 109 | { |
118 | GNUNET_FS_download_stop (download, GNUNET_YES); | 110 | GNUNET_FS_download_stop (download, GNUNET_YES); |
119 | download = NULL; | 111 | download = NULL; |
@@ -135,21 +127,21 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
135 | switch (event->status) | 127 | switch (event->status) |
136 | { | 128 | { |
137 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 129 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
138 | #if VERBOSE | 130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
139 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 131 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
140 | (unsigned long long) event->value.publish.completed, | 132 | (unsigned long long) event->value.publish.completed, |
141 | (unsigned long long) event->value.publish.size, | 133 | (unsigned long long) event->value.publish.size, |
142 | event->value.publish.specifics.progress.depth, | 134 | event->value.publish.specifics.progress.depth, |
143 | (unsigned long long) event->value.publish.specifics. | 135 | (unsigned long long) event->value.publish.specifics. |
144 | progress.offset); | 136 | progress.offset); |
145 | #endif | ||
146 | break; | 137 | break; |
147 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 138 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
148 | printf ("Publishing complete, %llu kb/s.\n", | 139 | fprintf (stdout, |
149 | (unsigned long long) (FILESIZE * 1000LL / | 140 | "Publishing complete, %llu kb/s.\n", |
150 | (1 + | 141 | (unsigned long long) (FILESIZE * 1000LL / |
151 | GNUNET_TIME_absolute_get_duration | 142 | (1 + |
152 | (start).rel_value) / 1024LL)); | 143 | GNUNET_TIME_absolute_get_duration |
144 | (start).rel_value) / 1024LL)); | ||
153 | GAUGER ("FS", "Publishing speed (insertion)", | 145 | GAUGER ("FS", "Publishing speed (insertion)", |
154 | (unsigned long long) (FILESIZE * 1000LL / | 146 | (unsigned long long) (FILESIZE * 1000LL / |
155 | (1 + | 147 | (1 + |
@@ -166,11 +158,12 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
166 | GNUNET_assert (download != NULL); | 158 | GNUNET_assert (download != NULL); |
167 | break; | 159 | break; |
168 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 160 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
169 | printf ("Download complete, %llu kb/s.\n", | 161 | fprintf (stdout, |
170 | (unsigned long long) (FILESIZE * 1000LL / | 162 | "Download complete, %llu kb/s.\n", |
171 | (1 + | 163 | (unsigned long long) (FILESIZE * 1000LL / |
172 | GNUNET_TIME_absolute_get_duration | 164 | (1 + |
173 | (start).rel_value) / 1024LL)); | 165 | GNUNET_TIME_absolute_get_duration |
166 | (start).rel_value) / 1024LL)); | ||
174 | GAUGER ("FS", "Local download speed (inserted)", | 167 | GAUGER ("FS", "Local download speed (inserted)", |
175 | (unsigned long long) (FILESIZE * 1000LL / | 168 | (unsigned long long) (FILESIZE * 1000LL / |
176 | (1 + | 169 | (1 + |
@@ -180,14 +173,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
180 | break; | 173 | break; |
181 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 174 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
182 | GNUNET_assert (download == event->value.download.dc); | 175 | GNUNET_assert (download == event->value.download.dc); |
183 | #if VERBOSE | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
184 | printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n", | 177 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", |
185 | (unsigned long long) event->value.download.completed, | 178 | (unsigned long long) event->value.download.completed, |
186 | (unsigned long long) event->value.download.size, | 179 | (unsigned long long) event->value.download.size, |
187 | event->value.download.specifics.progress.depth, | 180 | event->value.download.specifics.progress.depth, |
188 | (unsigned long long) event->value.download.specifics. | 181 | (unsigned long long) event->value.download.specifics. |
189 | progress.offset); | 182 | progress.offset); |
190 | #endif | ||
191 | break; | 183 | break; |
192 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 184 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
193 | FPRINTF (stderr, "Error publishing file: %s\n", | 185 | FPRINTF (stderr, "Error publishing file: %s\n", |
@@ -240,44 +232,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
240 | 232 | ||
241 | 233 | ||
242 | static void | 234 | static void |
243 | setup_peer (struct PeerContext *p, const char *cfgname) | 235 | run (void *cls, |
244 | { | ||
245 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
246 | #if START_ARM | ||
247 | p->arm_proc = | ||
248 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
249 | "gnunet-service-arm", | ||
250 | #if VERBOSE | ||
251 | "-L", "DEBUG", | ||
252 | #endif | ||
253 | "-c", cfgname, NULL); | ||
254 | #endif | ||
255 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
256 | } | ||
257 | |||
258 | |||
259 | static void | ||
260 | stop_arm (struct PeerContext *p) | ||
261 | { | ||
262 | #if START_ARM | ||
263 | if (NULL != p->arm_proc) | ||
264 | { | ||
265 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
266 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
267 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | ||
268 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | ||
270 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
271 | GNUNET_OS_process_destroy (p->arm_proc); | ||
272 | p->arm_proc = NULL; | ||
273 | } | ||
274 | #endif | ||
275 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
276 | } | ||
277 | |||
278 | |||
279 | static void | ||
280 | run (void *cls, char *const *args, const char *cfgfile, | ||
281 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 236 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
282 | { | 237 | { |
283 | const char *keywords[] = { | 238 | const char *keywords[] = { |
@@ -291,7 +246,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
291 | size_t i; | 246 | size_t i; |
292 | struct GNUNET_FS_BlockOptions bo; | 247 | struct GNUNET_FS_BlockOptions bo; |
293 | 248 | ||
294 | setup_peer (&p1, "test_fs_download_data.conf"); | ||
295 | fs = GNUNET_FS_start (cfg, "test-fs-download", &progress_cb, NULL, | 249 | fs = GNUNET_FS_start (cfg, "test-fs-download", &progress_cb, NULL, |
296 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 250 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
297 | GNUNET_assert (NULL != fs); | 251 | GNUNET_assert (NULL != fs); |
@@ -323,30 +277,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
323 | int | 277 | int |
324 | main (int argc, char *argv[]) | 278 | main (int argc, char *argv[]) |
325 | { | 279 | { |
326 | char *const argvx[] = { | 280 | if (0 != GNUNET_TESTING_peer_run ("test-fs-download", |
327 | "test-fs-download", | 281 | "test_fs_download_data.conf", |
328 | "-c", | 282 | &run, NULL)) |
329 | "test_fs_download_data.conf", | 283 | return 1; |
330 | #if VERBOSE | ||
331 | "-L", "DEBUG", | ||
332 | #endif | ||
333 | NULL | ||
334 | }; | ||
335 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
336 | GNUNET_GETOPT_OPTION_END | ||
337 | }; | ||
338 | |||
339 | GNUNET_log_setup ("test_fs_download", | ||
340 | #if VERBOSE | ||
341 | "DEBUG", | ||
342 | #else | ||
343 | "WARNING", | ||
344 | #endif | ||
345 | NULL); | ||
346 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | ||
347 | "test-fs-download", "nohelp", options, &run, NULL); | ||
348 | stop_arm (&p1); | ||
349 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); | ||
350 | return err; | 284 | return err; |
351 | } | 285 | } |
352 | 286 | ||
diff --git a/src/fs/test_fs_download_indexed.c b/src/fs/test_fs_download_indexed.c index d16aa97f1..eac683ab9 100644 --- a/src/fs/test_fs_download_indexed.c +++ b/src/fs/test_fs_download_indexed.c | |||
@@ -23,16 +23,13 @@ | |||
23 | * @brief simple testcase for downloading of indexed file | 23 | * @brief simple testcase for downloading of indexed file |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_arm_service.h" | 28 | #include "gnunet_arm_service.h" |
30 | #include "gnunet_fs_service.h" | 29 | #include "gnunet_fs_service.h" |
30 | #include "gnunet_testing_lib-new.h" | ||
31 | #include <gauger.h> | 31 | #include <gauger.h> |
32 | 32 | ||
33 | #define VERBOSE GNUNET_NO | ||
34 | |||
35 | #define START_ARM GNUNET_YES | ||
36 | 33 | ||
37 | /** | 34 | /** |
38 | * File-size we use for testing. | 35 | * File-size we use for testing. |
@@ -49,15 +46,6 @@ | |||
49 | */ | 46 | */ |
50 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 47 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
51 | 48 | ||
52 | struct PeerContext | ||
53 | { | ||
54 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
55 | #if START_ARM | ||
56 | struct GNUNET_OS_Process *arm_proc; | ||
57 | #endif | ||
58 | }; | ||
59 | |||
60 | static struct PeerContext p1; | ||
61 | 49 | ||
62 | static struct GNUNET_TIME_Absolute start; | 50 | static struct GNUNET_TIME_Absolute start; |
63 | 51 | ||
@@ -94,6 +82,7 @@ timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
94 | err = 1; | 82 | err = 1; |
95 | } | 83 | } |
96 | 84 | ||
85 | |||
97 | static void | 86 | static void |
98 | abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 87 | abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
99 | { | 88 | { |
@@ -140,14 +129,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
140 | switch (event->status) | 129 | switch (event->status) |
141 | { | 130 | { |
142 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 131 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
143 | #if VERBOSE | 132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
144 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 133 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
145 | (unsigned long long) event->value.publish.completed, | 134 | (unsigned long long) event->value.publish.completed, |
146 | (unsigned long long) event->value.publish.size, | 135 | (unsigned long long) event->value.publish.size, |
147 | event->value.publish.specifics.progress.depth, | 136 | event->value.publish.specifics.progress.depth, |
148 | (unsigned long long) event->value.publish.specifics. | 137 | (unsigned long long) event->value.publish.specifics. |
149 | progress.offset); | 138 | progress.offset); |
150 | #endif | ||
151 | break; | 139 | break; |
152 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 140 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
153 | printf ("Publishing complete, %llu kbps.\n", | 141 | printf ("Publishing complete, %llu kbps.\n", |
@@ -185,14 +173,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
185 | break; | 173 | break; |
186 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | 174 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: |
187 | GNUNET_assert (download == event->value.download.dc); | 175 | GNUNET_assert (download == event->value.download.dc); |
188 | #if VERBOSE | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
189 | printf ("Download is progressing (%llu/%llu at level %u off %llu)...\n", | 177 | "Download is progressing (%llu/%llu at level %u off %llu)...\n", |
190 | (unsigned long long) event->value.download.completed, | 178 | (unsigned long long) event->value.download.completed, |
191 | (unsigned long long) event->value.download.size, | 179 | (unsigned long long) event->value.download.size, |
192 | event->value.download.specifics.progress.depth, | 180 | event->value.download.specifics.progress.depth, |
193 | (unsigned long long) event->value.download.specifics. | 181 | (unsigned long long) event->value.download.specifics. |
194 | progress.offset); | 182 | progress.offset); |
195 | #endif | ||
196 | break; | 183 | break; |
197 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 184 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
198 | FPRINTF (stderr, "Error publishing file: %s\n", | 185 | FPRINTF (stderr, "Error publishing file: %s\n", |
@@ -245,41 +232,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
245 | 232 | ||
246 | 233 | ||
247 | static void | 234 | static void |
248 | setup_peer (struct PeerContext *p, const char *cfgname) | 235 | run (void *cls, |
249 | { | ||
250 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
251 | #if START_ARM | ||
252 | p->arm_proc = | ||
253 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
254 | "gnunet-service-arm", | ||
255 | "-c", cfgname, NULL); | ||
256 | #endif | ||
257 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
258 | } | ||
259 | |||
260 | |||
261 | static void | ||
262 | stop_arm (struct PeerContext *p) | ||
263 | { | ||
264 | #if START_ARM | ||
265 | if (NULL != p->arm_proc) | ||
266 | { | ||
267 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
268 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
269 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | ||
270 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | ||
272 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
273 | GNUNET_OS_process_destroy (p->arm_proc); | ||
274 | p->arm_proc = NULL; | ||
275 | } | ||
276 | #endif | ||
277 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
278 | } | ||
279 | |||
280 | |||
281 | static void | ||
282 | run (void *cls, char *const *args, const char *cfgfile, | ||
283 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 236 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
284 | { | 237 | { |
285 | const char *keywords[] = { | 238 | const char *keywords[] = { |
@@ -293,7 +246,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
293 | struct GNUNET_FS_BlockOptions bo; | 246 | struct GNUNET_FS_BlockOptions bo; |
294 | size_t i; | 247 | size_t i; |
295 | 248 | ||
296 | setup_peer (&p1, "test_fs_download_data.conf"); | ||
297 | fs = GNUNET_FS_start (cfg, "test-fs-download-indexed", &progress_cb, NULL, | 249 | fs = GNUNET_FS_start (cfg, "test-fs-download-indexed", &progress_cb, NULL, |
298 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 250 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
299 | GNUNET_assert (NULL != fs); | 251 | GNUNET_assert (NULL != fs); |
@@ -332,34 +284,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
332 | int | 284 | int |
333 | main (int argc, char *argv[]) | 285 | main (int argc, char *argv[]) |
334 | { | 286 | { |
335 | char *const argvx[] = { | 287 | if (0 != GNUNET_TESTING_peer_run ("test-fs-download-indexed", |
336 | "test-fs-download-indexed", | 288 | "test_fs_download_data.conf", |
337 | "-c", | 289 | &run, NULL)) |
338 | "test_fs_download_data.conf", | 290 | return 1; |
339 | NULL | ||
340 | }; | ||
341 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
342 | GNUNET_GETOPT_OPTION_END | ||
343 | }; | ||
344 | |||
345 | GNUNET_log_setup ("test_fs_download_indexed", | ||
346 | "WARNING", | ||
347 | NULL); | ||
348 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | ||
349 | "test-fs-download-indexed", "nohelp", options, &run, | ||
350 | NULL); | ||
351 | stop_arm (&p1); | ||
352 | if (fn1 != NULL) | ||
353 | { | ||
354 | GNUNET_DISK_directory_remove (fn1); | ||
355 | GNUNET_free (fn1); | ||
356 | } | ||
357 | if (fn != NULL) | ||
358 | { | ||
359 | GNUNET_DISK_directory_remove (fn); | ||
360 | GNUNET_free (fn); | ||
361 | } | ||
362 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); | ||
363 | return err; | 291 | return err; |
364 | } | 292 | } |
365 | 293 | ||
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 | ||
diff --git a/src/fs/test_fs_download_recursive.c b/src/fs/test_fs_download_recursive.c deleted file mode 100644 index bcbfe2b2a..000000000 --- a/src/fs/test_fs_download_recursive.c +++ /dev/null | |||
@@ -1,375 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2004, 2005, 2006, 2008 Christian Grothoff (and other contributing authors) | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file applications/fs/fsui/recursive_download_test.c | ||
23 | * @brief testcase for fsui recursive upload-download | ||
24 | * @author Christian Grothoff | ||
25 | * @author Heikki Lindholm | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util.h" | ||
30 | #include "gnunet_fsui_lib.h" | ||
31 | |||
32 | #define DEBUG_VERBOSE GNUNET_NO | ||
33 | |||
34 | #define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto FAILURE; } | ||
35 | |||
36 | #define FILESIZE (1024 * 1024 * 2) | ||
37 | /* depth-first directory tree d=dir f=file .=end of level*/ | ||
38 | #define DIRECTORY_TREE_SPEC "dddf.f.d" | ||
39 | |||
40 | static struct GNUNET_GE_Context *ectx; | ||
41 | |||
42 | static int download_done; | ||
43 | |||
44 | static char * | ||
45 | makeName (unsigned int i) | ||
46 | { | ||
47 | char *fn; | ||
48 | |||
49 | fn = GNUNET_malloc (strlen | ||
50 | ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + | ||
51 | 15); | ||
52 | GNUNET_snprintf (fn, | ||
53 | strlen ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") | ||
54 | + 15, "/tmp/gnunet-fsui-recursive_download_test/FSUITEST%u/", | ||
55 | i); | ||
56 | return fn; | ||
57 | } | ||
58 | |||
59 | static int | ||
60 | makeHierarchyHelper (const char *current, const char *tree, int index, | ||
61 | int check) | ||
62 | { | ||
63 | unsigned int fi, i; | ||
64 | int done; | ||
65 | char *s, *buf; | ||
66 | |||
67 | fi = 0; | ||
68 | done = 0; | ||
69 | while (!done && tree[index] != '\0') | ||
70 | { | ||
71 | s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14); | ||
72 | GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14, | ||
73 | "%s%s%u", current, DIR_SEPARATOR_STR, fi); | ||
74 | switch (tree[index++]) | ||
75 | { | ||
76 | case 'd': | ||
77 | if (check) | ||
78 | { | ||
79 | if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO) | ||
80 | { | ||
81 | index = -1; | ||
82 | done = 1; | ||
83 | } | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | GNUNET_disk_directory_create (NULL, s); | ||
88 | } | ||
89 | if (!done) | ||
90 | index = makeHierarchyHelper (s, tree, index, check); | ||
91 | break; | ||
92 | case 'f': | ||
93 | if (check) | ||
94 | { | ||
95 | /* TODO: compare file contents */ | ||
96 | if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO) | ||
97 | { | ||
98 | index = -1; | ||
99 | done = 1; | ||
100 | } | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | buf = GNUNET_malloc (FILESIZE); | ||
105 | for (i = 0; i < FILESIZE; i++) | ||
106 | buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256); | ||
107 | GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600"); | ||
108 | GNUNET_free (buf); | ||
109 | } | ||
110 | break; | ||
111 | case '.': | ||
112 | done = 1; | ||
113 | break; | ||
114 | default: | ||
115 | break; | ||
116 | } | ||
117 | GNUNET_free (s); | ||
118 | fi++; | ||
119 | } | ||
120 | return index; | ||
121 | } | ||
122 | |||
123 | static char * | ||
124 | makeHierarchy (unsigned int i, const char *tree) | ||
125 | { | ||
126 | char *fn; | ||
127 | |||
128 | fn = makeName (i); | ||
129 | makeHierarchyHelper (fn, tree, 0, 0); | ||
130 | return fn; | ||
131 | } | ||
132 | |||
133 | static int | ||
134 | checkHierarchy (unsigned int i, const char *tree) | ||
135 | { | ||
136 | char *fn; | ||
137 | int res; | ||
138 | |||
139 | fn = makeName (i); | ||
140 | if (GNUNET_disk_directory_test (NULL, fn) != GNUNET_YES) | ||
141 | { | ||
142 | GNUNET_free (fn); | ||
143 | return GNUNET_SYSERR; | ||
144 | } | ||
145 | res = | ||
146 | ((makeHierarchyHelper (fn, tree, 0, 1) == | ||
147 | -1) ? GNUNET_SYSERR : GNUNET_OK); | ||
148 | GNUNET_free (fn); | ||
149 | return res; | ||
150 | } | ||
151 | |||
152 | |||
153 | static enum GNUNET_FSUI_EventType lastEvent; | ||
154 | static enum GNUNET_FSUI_EventType waitForEvent; | ||
155 | static struct GNUNET_FSUI_Context *ctx; | ||
156 | static struct GNUNET_ECRS_URI *upURI; | ||
157 | static struct GNUNET_FSUI_DownloadList *download; | ||
158 | |||
159 | static void * | ||
160 | eventCallback (void *cls, const GNUNET_FSUI_Event * event) | ||
161 | { | ||
162 | switch (event->type) | ||
163 | { | ||
164 | case GNUNET_FSUI_download_suspended: | ||
165 | download = NULL; | ||
166 | break; | ||
167 | case GNUNET_FSUI_download_resumed: | ||
168 | download = event->data.DownloadResumed.dc.pos; | ||
169 | break; | ||
170 | break; | ||
171 | case GNUNET_FSUI_upload_progress: | ||
172 | #if DEBUG_VERBOSE > 1 | ||
173 | printf ("Upload is progressing (%llu/%llu)...\n", | ||
174 | event->data.UploadProgress.completed, | ||
175 | event->data.UploadProgress.total); | ||
176 | #endif | ||
177 | break; | ||
178 | case GNUNET_FSUI_upload_completed: | ||
179 | upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri); | ||
180 | #if DEBUG_VERBOSE | ||
181 | printf ("Upload of `%s' complete.\n", event->data.UploadCompleted.filename); | ||
182 | #endif | ||
183 | break; | ||
184 | case GNUNET_FSUI_download_completed: | ||
185 | #if DEBUG_VERBOSE | ||
186 | printf ("Download of `%s' complete.\n", | ||
187 | event->data.DownloadCompleted.filename); | ||
188 | #endif | ||
189 | if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK) | ||
190 | download_done = 1; | ||
191 | #if DEBUG_VERBOSE | ||
192 | else | ||
193 | printf ("Hierarchy check not successful yet...\n"); | ||
194 | #endif | ||
195 | break; | ||
196 | case GNUNET_FSUI_download_progress: | ||
197 | #if DEBUG_VERBOSE > 1 | ||
198 | printf ("Download is progressing (%llu/%llu)...\n", | ||
199 | event->data.DownloadProgress.completed, | ||
200 | event->data.DownloadProgress.total); | ||
201 | #endif | ||
202 | break; | ||
203 | case GNUNET_FSUI_unindex_progress: | ||
204 | #if DEBUG_VERBOSE > 1 | ||
205 | printf ("Unindex is progressing (%llu/%llu)...\n", | ||
206 | event->data.UnindexProgress.completed, | ||
207 | event->data.UnindexProgress.total); | ||
208 | #endif | ||
209 | break; | ||
210 | case GNUNET_FSUI_unindex_completed: | ||
211 | #if DEBUG_VERBOSE | ||
212 | printf ("Unindex complete.\n"); | ||
213 | #endif | ||
214 | break; | ||
215 | case GNUNET_FSUI_unindex_error: | ||
216 | FPRINTF (stderr, "Error unindexing: %s\n", | ||
217 | event->data.UnindexError.message); | ||
218 | break; | ||
219 | case GNUNET_FSUI_upload_error: | ||
220 | FPRINTF (stderr, "Error uploading: %s\n", event->data.UploadError.message); | ||
221 | break; | ||
222 | case GNUNET_FSUI_download_error: | ||
223 | FPRINTF (stderr, "Error downloading: %s\n", | ||
224 | event->data.DownloadError.message); | ||
225 | break; | ||
226 | case GNUNET_FSUI_download_aborted: | ||
227 | #if DEBUG_VERBOSE | ||
228 | printf ("Received download aborted event.\n"); | ||
229 | #endif | ||
230 | break; | ||
231 | case GNUNET_FSUI_unindex_suspended: | ||
232 | case GNUNET_FSUI_upload_suspended: | ||
233 | case GNUNET_FSUI_upload_started: | ||
234 | case GNUNET_FSUI_upload_stopped: | ||
235 | case GNUNET_FSUI_download_started: | ||
236 | case GNUNET_FSUI_download_stopped: | ||
237 | case GNUNET_FSUI_unindex_started: | ||
238 | case GNUNET_FSUI_unindex_stopped: | ||
239 | break; | ||
240 | default: | ||
241 | printf ("Unexpected event: %d\n", event->type); | ||
242 | break; | ||
243 | } | ||
244 | if (lastEvent == waitForEvent) | ||
245 | return NULL; /* ignore all other events */ | ||
246 | lastEvent = event->type; | ||
247 | return NULL; | ||
248 | } | ||
249 | |||
250 | |||
251 | #define START_DAEMON 1 | ||
252 | |||
253 | int | ||
254 | main (int argc, char *argv[]) | ||
255 | { | ||
256 | #if START_DAEMON | ||
257 | struct GNUNET_OS_Process *daemon; | ||
258 | #endif | ||
259 | int ok; | ||
260 | char *fn = NULL; | ||
261 | char *fn43 = NULL; | ||
262 | |||
263 | char *keywords[] = { | ||
264 | "down_foo", | ||
265 | "down_bar", | ||
266 | }; | ||
267 | int prog; | ||
268 | struct GNUNET_MetaData *meta = NULL; | ||
269 | struct GNUNET_ECRS_URI *kuri = NULL; | ||
270 | struct GNUNET_GC_Configuration *cfg; | ||
271 | struct GNUNET_FSUI_UploadList *upload = NULL; | ||
272 | |||
273 | ok = GNUNET_YES; | ||
274 | cfg = GNUNET_GC_create (); | ||
275 | if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) | ||
276 | { | ||
277 | GNUNET_GC_free (cfg); | ||
278 | return -1; | ||
279 | } | ||
280 | FPRINTF (stderr, "%s", "Setup...\n"); | ||
281 | #if START_DAEMON | ||
282 | GNUNET_disk_directory_remove (NULL, | ||
283 | "/tmp/gnunet-fsui-recursive_download_test/"); | ||
284 | daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); | ||
285 | GNUNET_GE_ASSERT (NULL, daemon != NULL); | ||
286 | CHECK (GNUNET_OK == | ||
287 | GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS)); | ||
288 | GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ | ||
289 | /* ACTUAL TEST CODE */ | ||
290 | #endif | ||
291 | ctx = | ||
292 | GNUNET_FSUI_start (NULL, cfg, "fsuirecursive_download_test", 32, | ||
293 | GNUNET_YES, &eventCallback, NULL); | ||
294 | CHECK (ctx != NULL); | ||
295 | fn = makeHierarchy (42, DIRECTORY_TREE_SPEC); | ||
296 | meta = GNUNET_meta_data_create (); | ||
297 | kuri = | ||
298 | GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2, | ||
299 | (const char **) keywords); | ||
300 | FPRINTF (stderr, "%s", "Uploading...\n"); | ||
301 | waitForEvent = GNUNET_FSUI_upload_completed; | ||
302 | upload = | ||
303 | GNUNET_FSUI_upload_start (ctx, fn, | ||
304 | (GNUNET_FSUI_DirectoryScanCallback) & | ||
305 | GNUNET_disk_directory_scan, NULL, 0, 0, | ||
306 | GNUNET_YES, GNUNET_NO, GNUNET_NO, | ||
307 | GNUNET_get_time () + 5 * GNUNET_CRON_HOURS, | ||
308 | meta, kuri, kuri); | ||
309 | CHECK (upload != NULL); | ||
310 | GNUNET_ECRS_uri_destroy (kuri); | ||
311 | kuri = NULL; | ||
312 | prog = 0; | ||
313 | while (lastEvent != GNUNET_FSUI_upload_completed) | ||
314 | { | ||
315 | prog++; | ||
316 | CHECK (prog < 5000); | ||
317 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | ||
318 | if (GNUNET_shutdown_test () == GNUNET_YES) | ||
319 | break; | ||
320 | } | ||
321 | GNUNET_FSUI_upload_stop (upload); | ||
322 | upload = NULL; | ||
323 | CHECK (upURI != NULL); | ||
324 | |||
325 | FPRINTF (stderr, "%s", "Downloading...\n"); | ||
326 | waitForEvent = GNUNET_FSUI_download_completed; | ||
327 | fn43 = makeName (43); | ||
328 | download = | ||
329 | GNUNET_FSUI_download_start (ctx, 0, GNUNET_YES, upURI, meta, fn43, NULL, | ||
330 | NULL); | ||
331 | CHECK (download != NULL); | ||
332 | GNUNET_free (fn43); | ||
333 | fn43 = NULL; | ||
334 | prog = 0; | ||
335 | while (!download_done) | ||
336 | { | ||
337 | prog++; | ||
338 | CHECK (prog < 5000); | ||
339 | GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); | ||
340 | if (GNUNET_shutdown_test () == GNUNET_YES) | ||
341 | break; | ||
342 | } | ||
343 | FAILURE: | ||
344 | FPRINTF (stderr, "%s", "Cleanup...\n"); | ||
345 | if (meta != NULL) | ||
346 | GNUNET_meta_data_destroy (meta); | ||
347 | if (ctx != NULL) | ||
348 | { | ||
349 | if (download != NULL) | ||
350 | GNUNET_FSUI_download_stop (download); | ||
351 | GNUNET_FSUI_stop (ctx); | ||
352 | } | ||
353 | if (fn != NULL) | ||
354 | { | ||
355 | GNUNET_disk_directory_remove (NULL, fn); | ||
356 | GNUNET_free (fn); | ||
357 | } | ||
358 | if (kuri != NULL) | ||
359 | GNUNET_ECRS_uri_destroy (kuri); | ||
360 | fn43 = makeName (43); | ||
361 | GNUNET_disk_directory_remove (NULL, fn43); | ||
362 | GNUNET_free (fn43); | ||
363 | if (upURI != NULL) | ||
364 | GNUNET_ECRS_uri_destroy (upURI); | ||
365 | |||
366 | #if START_DAEMON | ||
367 | GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); | ||
368 | GNUNET_OS_process_destroy (daemon); | ||
369 | daemon = NULL; | ||
370 | #endif | ||
371 | GNUNET_GC_free (cfg); | ||
372 | return (ok == GNUNET_YES) ? 0 : 1; | ||
373 | } | ||
374 | |||
375 | /* end of recursive_download_test.c */ | ||