aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_unindex_persistence.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-15 08:10:52 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-15 08:10:52 +0000
commite825548ea9a45d1f4b25898f87b5c74f8bc4cc25 (patch)
tree0a0236af09b77d8e32693c1e9fb7db4affd9ce8a /src/fs/test_fs_unindex_persistence.c
parent9f4e1f6e097b3c97abe0971b68b2ab686a61f036 (diff)
downloadgnunet-e825548ea9a45d1f4b25898f87b5c74f8bc4cc25.tar.gz
gnunet-e825548ea9a45d1f4b25898f87b5c74f8bc4cc25.zip
-simplifying tests with new testing lib
Diffstat (limited to 'src/fs/test_fs_unindex_persistence.c')
-rw-r--r--src/fs/test_fs_unindex_persistence.c119
1 files changed, 21 insertions, 98 deletions
diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c
index c6b1062e1..8f4364c28 100644
--- a/src/fs/test_fs_unindex_persistence.c
+++ b/src/fs/test_fs_unindex_persistence.c
@@ -25,13 +25,9 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_arm_service.h" 28#include "gnunet_testing_lib-new.h"
29#include "gnunet_fs_service.h" 29#include "gnunet_fs_service.h"
30 30
31#define VERBOSE GNUNET_NO
32
33#define START_ARM GNUNET_YES
34
35/** 31/**
36 * File-size we use for testing. 32 * File-size we use for testing.
37 */ 33 */
@@ -47,15 +43,6 @@
47 */ 43 */
48#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 44#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
49 45
50struct PeerContext
51{
52 struct GNUNET_CONFIGURATION_Handle *cfg;
53#if START_ARM
54 struct GNUNET_OS_Process *arm_proc;
55#endif
56};
57
58static struct PeerContext p1;
59 46
60static struct GNUNET_TIME_Absolute start; 47static struct GNUNET_TIME_Absolute start;
61 48
@@ -69,6 +56,7 @@ static char *fn;
69 56
70static const struct GNUNET_CONFIGURATION_Handle *cfg; 57static const struct GNUNET_CONFIGURATION_Handle *cfg;
71 58
59
72static void 60static void
73abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 61abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
74{ 62{
@@ -136,14 +124,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
136 switch (event->status) 124 switch (event->status)
137 { 125 {
138 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 126 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
139#if VERBOSE 127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 128 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
141 (unsigned long long) event->value.publish.completed, 129 (unsigned long long) event->value.publish.completed,
142 (unsigned long long) event->value.publish.size, 130 (unsigned long long) event->value.publish.size,
143 event->value.publish.specifics.progress.depth, 131 event->value.publish.specifics.progress.depth,
144 (unsigned long long) event->value.publish.specifics. 132 (unsigned long long) event->value.publish.specifics.
145 progress.offset); 133 progress.offset);
146#endif
147 break; 134 break;
148 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 135 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
149 printf ("Publishing complete, %llu kbps.\n", 136 printf ("Publishing complete, %llu kbps.\n",
@@ -167,14 +154,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
167 case GNUNET_FS_STATUS_UNINDEX_PROGRESS: 154 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
168 consider_restart (event->status); 155 consider_restart (event->status);
169 GNUNET_assert (unindex == event->value.unindex.uc); 156 GNUNET_assert (unindex == event->value.unindex.uc);
170#if VERBOSE 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n", 158 "Unindex is progressing (%llu/%llu at level %u off %llu)...\n",
172 (unsigned long long) event->value.unindex.completed, 159 (unsigned long long) event->value.unindex.completed,
173 (unsigned long long) event->value.unindex.size, 160 (unsigned long long) event->value.unindex.size,
174 event->value.unindex.specifics.progress.depth, 161 event->value.unindex.specifics.progress.depth,
175 (unsigned long long) event->value.unindex.specifics. 162 (unsigned long long) event->value.unindex.specifics.
176 progress.offset); 163 progress.offset);
177#endif
178 break; 164 break;
179 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 165 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
180 if (event->value.publish.pc == publish) 166 if (event->value.publish.pc == publish)
@@ -244,44 +230,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
244 230
245 231
246static void 232static void
247setup_peer (struct PeerContext *p, const char *cfgname) 233run (void *cls,
248{
249 p->cfg = GNUNET_CONFIGURATION_create ();
250#if START_ARM
251 p->arm_proc =
252 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
253 "gnunet-service-arm",
254#if VERBOSE
255 "-L", "DEBUG",
256#endif
257 "-c", cfgname, NULL);
258#endif
259 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
260}
261
262
263static void
264stop_arm (struct PeerContext *p)
265{
266#if START_ARM
267 if (NULL != p->arm_proc)
268 {
269 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
270 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
271 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
272 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
274 GNUNET_OS_process_get_pid (p->arm_proc));
275 GNUNET_OS_process_destroy (p->arm_proc);
276 p->arm_proc = NULL;
277 }
278#endif
279 GNUNET_CONFIGURATION_destroy (p->cfg);
280}
281
282
283static void
284run (void *cls, char *const *args, const char *cfgfile,
285 const struct GNUNET_CONFIGURATION_Handle *c) 234 const struct GNUNET_CONFIGURATION_Handle *c)
286{ 235{
287 const char *keywords[] = { 236 const char *keywords[] = {
@@ -296,7 +245,6 @@ run (void *cls, char *const *args, const char *cfgfile,
296 struct GNUNET_FS_BlockOptions bo; 245 struct GNUNET_FS_BlockOptions bo;
297 246
298 cfg = c; 247 cfg = c;
299 setup_peer (&p1, "test_fs_unindex_data.conf");
300 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); 248 fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst");
301 fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL, 249 fs = GNUNET_FS_start (cfg, "test-fs-unindex-persistence", &progress_cb, NULL,
302 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 250 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
@@ -332,35 +280,10 @@ run (void *cls, char *const *args, const char *cfgfile,
332int 280int
333main (int argc, char *argv[]) 281main (int argc, char *argv[])
334{ 282{
335 char *const argvx[] = { 283 if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex-persistence",
336 "test-fs-unindex", 284 "test_fs_unindex_data.conf",
337 "-c", 285 &run, NULL))
338 "test_fs_unindex_data.conf", 286 return 1;
339#if VERBOSE
340 "-L", "DEBUG",
341#endif
342 NULL
343 };
344 struct GNUNET_GETOPT_CommandLineOption options[] = {
345 GNUNET_GETOPT_OPTION_END
346 };
347
348 GNUNET_log_setup ("test_fs_unindex_persistence",
349#if VERBOSE
350 "DEBUG",
351#else
352 "WARNING",
353#endif
354 NULL);
355 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
356 "test-fs-unindex", "nohelp", options, &run, NULL);
357 stop_arm (&p1);
358 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/");
359 if (NULL != fn)
360 {
361 GNUNET_DISK_directory_remove (fn);
362 GNUNET_free (fn);
363 }
364 return 0; 287 return 0;
365} 288}
366 289