aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_download.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-14 17:34:48 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-14 17:34:48 +0000
commitb1055e6385d821fa7d328f2b4d63209a41e6167d (patch)
tree694368f1ab9ff916d05356563516a544c61334ae /src/fs/test_fs_download.c
parentc44b94ee1f25110f259688c221d8ffcb42cd5aa5 (diff)
downloadgnunet-b1055e6385d821fa7d328f2b4d63209a41e6167d.tar.gz
gnunet-b1055e6385d821fa7d328f2b4d63209a41e6167d.zip
-cleaning up fs-download testcases
Diffstat (limited to 'src/fs/test_fs_download.c')
-rw-r--r--src/fs/test_fs_download.c146
1 files changed, 40 insertions, 106 deletions
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
52struct PeerContext
53{
54 struct GNUNET_CONFIGURATION_Handle *cfg;
55#if START_ARM
56 struct GNUNET_OS_Process *arm_proc;
57#endif
58};
59
60static struct PeerContext p1;
61 49
62static struct GNUNET_TIME_Absolute start; 50static struct GNUNET_TIME_Absolute start;
63 51
@@ -73,15 +61,16 @@ static char *fn;
73 61
74static int err; 62static int err;
75 63
64
76static void 65static void
77timeout_kill_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 66timeout_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
94static void 84static void
95abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 85abort_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
104static void 95static void
105stop_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 96stop_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
111static void 103static void
112abort_download_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 104abort_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
242static void 234static void
243setup_peer (struct PeerContext *p, const char *cfgname) 235run (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
259static void
260stop_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
279static void
280run (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,
323int 277int
324main (int argc, char *argv[]) 278main (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