aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_publish.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-15 08:38:53 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-15 08:38:53 +0000
commit36ca9fcc68935edd109481d30f9e6e15a825c282 (patch)
tree5c976b741a314b5c3486124a9bff74b4ab5f5b78 /src/fs/test_fs_publish.c
parente825548ea9a45d1f4b25898f87b5c74f8bc4cc25 (diff)
downloadgnunet-36ca9fcc68935edd109481d30f9e6e15a825c282.tar.gz
gnunet-36ca9fcc68935edd109481d30f9e6e15a825c282.zip
-simplifying tests with new testing lib
Diffstat (limited to 'src/fs/test_fs_publish.c')
-rw-r--r--src/fs/test_fs_publish.c111
1 files changed, 14 insertions, 97 deletions
diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c
index 1560f4ea3..47a604c1d 100644
--- a/src/fs/test_fs_publish.c
+++ b/src/fs/test_fs_publish.c
@@ -17,23 +17,17 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20
21/** 20/**
22 * @file fs/test_fs_publish.c 21 * @file fs/test_fs_publish.c
23 * @brief simple testcase for publish operation (indexing, listing 22 * @brief simple testcase for publish operation (indexing, listing
24 * indexed, directory structure) 23 * indexed, directory structure)
25 * @author Christian Grothoff 24 * @author Christian Grothoff
26 */ 25 */
27
28#include "platform.h" 26#include "platform.h"
29#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
30#include "gnunet_arm_service.h" 28#include "gnunet_testing_lib-new.h"
31#include "gnunet_fs_service.h" 29#include "gnunet_fs_service.h"
32 30
33#define VERBOSE GNUNET_NO
34
35#define START_ARM GNUNET_YES
36
37/** 31/**
38 * File-size we use for testing. 32 * File-size we use for testing.
39 */ 33 */
@@ -49,15 +43,6 @@
49 */ 43 */
50#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 44#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51 45
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 46
62static struct GNUNET_TIME_Absolute start; 47static struct GNUNET_TIME_Absolute start;
63 48
@@ -71,6 +56,7 @@ static char *fn2;
71 56
72static int err; 57static int err;
73 58
59
74static void 60static void
75abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 61abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
76{ 62{
@@ -107,14 +93,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
107 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 93 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
108 ret = event->value.publish.cctx; 94 ret = event->value.publish.cctx;
109 GNUNET_assert (publish == event->value.publish.pc); 95 GNUNET_assert (publish == event->value.publish.pc);
110#if VERBOSE 96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 97 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
112 (unsigned long long) event->value.publish.completed, 98 (unsigned long long) event->value.publish.completed,
113 (unsigned long long) event->value.publish.size, 99 (unsigned long long) event->value.publish.size,
114 event->value.publish.specifics.progress.depth, 100 event->value.publish.specifics.progress.depth,
115 (unsigned long long) event->value.publish.specifics. 101 (unsigned long long) event->value.publish.specifics.
116 progress.offset); 102 progress.offset);
117#endif
118 break; 103 break;
119 case GNUNET_FS_STATUS_PUBLISH_ERROR: 104 case GNUNET_FS_STATUS_PUBLISH_ERROR:
120 ret = event->value.publish.cctx; 105 ret = event->value.publish.cctx;
@@ -168,44 +153,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
168 153
169 154
170static void 155static void
171setup_peer (struct PeerContext *p, const char *cfgname) 156run (void *cls,
172{
173 p->cfg = GNUNET_CONFIGURATION_create ();
174#if START_ARM
175 p->arm_proc =
176 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
177 "gnunet-service-arm",
178#if VERBOSE
179 "-L", "DEBUG",
180#endif
181 "-c", cfgname, NULL);
182#endif
183 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
184}
185
186
187static void
188stop_arm (struct PeerContext *p)
189{
190#if START_ARM
191 if (NULL != p->arm_proc)
192 {
193 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
194 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
195 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
196 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
198 GNUNET_OS_process_get_pid (p->arm_proc));
199 GNUNET_OS_process_destroy (p->arm_proc);
200 p->arm_proc = NULL;
201 }
202#endif
203 GNUNET_CONFIGURATION_destroy (p->cfg);
204}
205
206
207static void
208run (void *cls, char *const *args, const char *cfgfile,
209 const struct GNUNET_CONFIGURATION_Handle *cfg) 157 const struct GNUNET_CONFIGURATION_Handle *cfg)
210{ 158{
211 const char *keywords[] = { 159 const char *keywords[] = {
@@ -221,7 +169,6 @@ run (void *cls, char *const *args, const char *cfgfile,
221 size_t i; 169 size_t i;
222 struct GNUNET_FS_BlockOptions bo; 170 struct GNUNET_FS_BlockOptions bo;
223 171
224 setup_peer (&p1, "test_fs_publish_data.conf");
225 fs = GNUNET_FS_start (cfg, "test-fs-publish", &progress_cb, NULL, 172 fs = GNUNET_FS_start (cfg, "test-fs-publish", &progress_cb, NULL,
226 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 173 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
227 GNUNET_assert (NULL != fs); 174 GNUNET_assert (NULL != fs);
@@ -283,40 +230,10 @@ run (void *cls, char *const *args, const char *cfgfile,
283int 230int
284main (int argc, char *argv[]) 231main (int argc, char *argv[])
285{ 232{
286 char *const argvx[] = { 233 if (0 != GNUNET_TESTING_peer_run ("test-fs-publish",
287 "test-fs-publish", 234 "test_fs_publish_data.conf",
288 "-c", 235 &run, NULL))
289 "test_fs_publish_data.conf", 236 return 1;
290#if VERBOSE
291 "-L", "DEBUG",
292#endif
293 NULL
294 };
295 struct GNUNET_GETOPT_CommandLineOption options[] = {
296 GNUNET_GETOPT_OPTION_END
297 };
298
299 GNUNET_log_setup ("test_fs_publish",
300#if VERBOSE
301 "DEBUG",
302#else
303 "WARNING",
304#endif
305 NULL);
306 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
307 "test-fs-publish", "nohelp", options, &run, NULL);
308 stop_arm (&p1);
309 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
310 if (fn1 != NULL)
311 {
312 GNUNET_DISK_directory_remove (fn1);
313 GNUNET_free (fn1);
314 }
315 if (fn2 != NULL)
316 {
317 GNUNET_DISK_directory_remove (fn2);
318 GNUNET_free (fn2);
319 }
320 return err; 237 return err;
321} 238}
322 239