aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_list_indexed.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_list_indexed.c
parent9f4e1f6e097b3c97abe0971b68b2ab686a61f036 (diff)
downloadgnunet-e825548ea9a45d1f4b25898f87b5c74f8bc4cc25.tar.gz
gnunet-e825548ea9a45d1f4b25898f87b5c74f8bc4cc25.zip
-simplifying tests with new testing lib
Diffstat (limited to 'src/fs/test_fs_list_indexed.c')
-rw-r--r--src/fs/test_fs_list_indexed.c112
1 files changed, 15 insertions, 97 deletions
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
index d046a20c6..2b53bc5a4 100644
--- a/src/fs/test_fs_list_indexed.c
+++ b/src/fs/test_fs_list_indexed.c
@@ -27,16 +27,11 @@
27 * TODO: 27 * TODO:
28 * - actually call list_indexed API! 28 * - actually call list_indexed API!
29 */ 29 */
30
31#include "platform.h" 30#include "platform.h"
32#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
33#include "gnunet_arm_service.h" 32#include "gnunet_testing_lib-new.h"
34#include "gnunet_fs_service.h" 33#include "gnunet_fs_service.h"
35 34
36#define VERBOSE GNUNET_NO
37
38#define START_ARM GNUNET_YES
39
40/** 35/**
41 * File-size we use for testing. 36 * File-size we use for testing.
42 */ 37 */
@@ -52,15 +47,6 @@
52 */ 47 */
53#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 48#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
54 49
55struct PeerContext
56{
57 struct GNUNET_CONFIGURATION_Handle *cfg;
58#if START_ARM
59 struct GNUNET_OS_Process *arm_proc;
60#endif
61};
62
63static struct PeerContext p1;
64 50
65static struct GNUNET_TIME_Absolute start; 51static struct GNUNET_TIME_Absolute start;
66 52
@@ -74,6 +60,7 @@ static char *fn2;
74 60
75static int err; 61static int err;
76 62
63
77static void 64static void
78abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 65abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
79{ 66{
@@ -120,14 +107,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
120 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 107 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
121 ret = event->value.publish.cctx; 108 ret = event->value.publish.cctx;
122 GNUNET_assert (publish == event->value.publish.pc); 109 GNUNET_assert (publish == event->value.publish.pc);
123#if VERBOSE 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
124 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 111 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
125 (unsigned long long) event->value.publish.completed, 112 (unsigned long long) event->value.publish.completed,
126 (unsigned long long) event->value.publish.size, 113 (unsigned long long) event->value.publish.size,
127 event->value.publish.specifics.progress.depth, 114 event->value.publish.specifics.progress.depth,
128 (unsigned long long) event->value.publish.specifics. 115 (unsigned long long) event->value.publish.specifics.
129 progress.offset); 116 progress.offset);
130#endif
131 break; 117 break;
132 case GNUNET_FS_STATUS_PUBLISH_ERROR: 118 case GNUNET_FS_STATUS_PUBLISH_ERROR:
133 ret = event->value.publish.cctx; 119 ret = event->value.publish.cctx;
@@ -183,44 +169,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
183 169
184 170
185static void 171static void
186setup_peer (struct PeerContext *p, const char *cfgname) 172run (void *cls,
187{
188 p->cfg = GNUNET_CONFIGURATION_create ();
189#if START_ARM
190 p->arm_proc =
191 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
192 "gnunet-service-arm",
193#if VERBOSE
194 "-L", "DEBUG",
195#endif
196 "-c", cfgname, NULL);
197#endif
198 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
199}
200
201
202static void
203stop_arm (struct PeerContext *p)
204{
205#if START_ARM
206 if (NULL != p->arm_proc)
207 {
208 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
209 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
210 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
211 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
213 GNUNET_OS_process_get_pid (p->arm_proc));
214 GNUNET_OS_process_destroy (p->arm_proc);
215 p->arm_proc = NULL;
216 }
217#endif
218 GNUNET_CONFIGURATION_destroy (p->cfg);
219}
220
221
222static void
223run (void *cls, char *const *args, const char *cfgfile,
224 const struct GNUNET_CONFIGURATION_Handle *cfg) 173 const struct GNUNET_CONFIGURATION_Handle *cfg)
225{ 174{
226 const char *keywords[] = { 175 const char *keywords[] = {
@@ -236,7 +185,6 @@ run (void *cls, char *const *args, const char *cfgfile,
236 size_t i; 185 size_t i;
237 struct GNUNET_FS_BlockOptions bo; 186 struct GNUNET_FS_BlockOptions bo;
238 187
239 setup_peer (&p1, "test_fs_list_indexed_data.conf");
240 fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL, 188 fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL,
241 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 189 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
242 GNUNET_assert (NULL != fs); 190 GNUNET_assert (NULL != fs);
@@ -298,41 +246,11 @@ run (void *cls, char *const *args, const char *cfgfile,
298int 246int
299main (int argc, char *argv[]) 247main (int argc, char *argv[])
300{ 248{
301 char *const argvx[] = { 249 if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed",
302 "test-fs-list_indexed", 250 "test_fs_list_indexed_data.conf",
303 "-c", 251 &run, NULL))
304 "test_fs_list_indexed_data.conf", 252 return 1;
305#if VERBOSE 253 return 0;
306 "-L", "DEBUG",
307#endif
308 NULL
309 };
310 struct GNUNET_GETOPT_CommandLineOption options[] = {
311 GNUNET_GETOPT_OPTION_END
312 };
313
314 GNUNET_log_setup ("test_fs_list_indexed",
315#if VERBOSE
316 "DEBUG",
317#else
318 "WARNING",
319#endif
320 NULL);
321 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
322 "test-fs-list_indexed", "nohelp", options, &run, NULL);
323 stop_arm (&p1);
324 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-list-indexed/");
325 if (fn1 != NULL)
326 {
327 GNUNET_DISK_directory_remove (fn1);
328 GNUNET_free (fn1);
329 }
330 if (fn2 != NULL)
331 {
332 GNUNET_DISK_directory_remove (fn2);
333 GNUNET_free (fn2);
334 }
335 return err;
336} 254}
337 255
338/* end of test_fs_list_indexed.c */ 256/* end of test_fs_list_indexed.c */