aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_publish_persistence.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_persistence.c
parente825548ea9a45d1f4b25898f87b5c74f8bc4cc25 (diff)
downloadgnunet-36ca9fcc68935edd109481d30f9e6e15a825c282.tar.gz
gnunet-36ca9fcc68935edd109481d30f9e6e15a825c282.zip
-simplifying tests with new testing lib
Diffstat (limited to 'src/fs/test_fs_publish_persistence.c')
-rw-r--r--src/fs/test_fs_publish_persistence.c95
1 files changed, 7 insertions, 88 deletions
diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c
index 7d3bc32ae..cbe859531 100644
--- a/src/fs/test_fs_publish_persistence.c
+++ b/src/fs/test_fs_publish_persistence.c
@@ -17,21 +17,16 @@
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_persistence.c 21 * @file fs/test_fs_publish_persistence.c
23 * @brief simple testcase for persistence of simple publish operation 22 * @brief simple testcase for persistence of simple publish operation
24 * @author Christian Grothoff 23 * @author Christian Grothoff
25 */ 24 */
26
27#include "platform.h" 25#include "platform.h"
28#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
29#include "gnunet_arm_service.h" 27#include "gnunet_testing_lib-new.h"
30#include "gnunet_fs_service.h" 28#include "gnunet_fs_service.h"
31 29
32#define VERBOSE GNUNET_NO
33
34#define START_ARM GNUNET_YES
35 30
36/** 31/**
37 * File-size we use for testing. 32 * File-size we use for testing.
@@ -48,15 +43,6 @@
48 */ 43 */
49#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 44#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
50 45
51struct PeerContext
52{
53 struct GNUNET_CONFIGURATION_Handle *cfg;
54#if START_ARM
55 struct GNUNET_OS_Process *arm_proc;
56#endif
57};
58
59static struct PeerContext p1;
60 46
61static struct GNUNET_TIME_Absolute start; 47static struct GNUNET_TIME_Absolute start;
62 48
@@ -76,6 +62,7 @@ static int err;
76 62
77static GNUNET_SCHEDULER_TaskIdentifier rtask; 63static GNUNET_SCHEDULER_TaskIdentifier rtask;
78 64
65
79static void 66static void
80abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 67abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81{ 68{
@@ -231,44 +218,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
231 218
232 219
233static void 220static void
234setup_peer (struct PeerContext *p, const char *cfgname) 221run (void *cls,
235{
236 p->cfg = GNUNET_CONFIGURATION_create ();
237#if START_ARM
238 p->arm_proc =
239 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
240 "gnunet-service-arm",
241#if VERBOSE
242 "-L", "DEBUG",
243#endif
244 "-c", cfgname, NULL);
245#endif
246 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
247}
248
249
250static void
251stop_arm (struct PeerContext *p)
252{
253#if START_ARM
254 if (NULL != p->arm_proc)
255 {
256 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
257 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
258 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
259 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
261 GNUNET_OS_process_get_pid (p->arm_proc));
262 GNUNET_OS_process_destroy (p->arm_proc);
263 p->arm_proc = NULL;
264 }
265#endif
266 GNUNET_CONFIGURATION_destroy (p->cfg);
267}
268
269
270static void
271run (void *cls, char *const *args, const char *cfgfile,
272 const struct GNUNET_CONFIGURATION_Handle *c) 222 const struct GNUNET_CONFIGURATION_Handle *c)
273{ 223{
274 const char *keywords[] = { 224 const char *keywords[] = {
@@ -285,7 +235,6 @@ run (void *cls, char *const *args, const char *cfgfile,
285 struct GNUNET_FS_BlockOptions bo; 235 struct GNUNET_FS_BlockOptions bo;
286 236
287 cfg = c; 237 cfg = c;
288 setup_peer (&p1, "test_fs_publish_data.conf");
289 fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL, 238 fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL,
290 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 239 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
291 GNUNET_assert (NULL != fs); 240 GNUNET_assert (NULL != fs);
@@ -344,40 +293,10 @@ run (void *cls, char *const *args, const char *cfgfile,
344int 293int
345main (int argc, char *argv[]) 294main (int argc, char *argv[])
346{ 295{
347 char *const argvx[] = { 296 if (0 != GNUNET_TESTING_peer_run ("test-fs-publish-persistence",
348 "test-fs-publish-persistence", 297 "test_fs_publish_data.conf",
349 "-c", 298 &run, NULL))
350 "test_fs_publish_data.conf", 299 return 1;
351#if VERBOSE
352 "-L", "DEBUG",
353#endif
354 NULL
355 };
356 struct GNUNET_GETOPT_CommandLineOption options[] = {
357 GNUNET_GETOPT_OPTION_END
358 };
359
360 GNUNET_log_setup ("test_fs_publish_persistence",
361#if VERBOSE
362 "DEBUG",
363#else
364 "WARNING",
365#endif
366 NULL);
367 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
368 "test-fs-publish", "nohelp", options, &run, NULL);
369 stop_arm (&p1);
370 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-publish/");
371 if (fn1 != NULL)
372 {
373 GNUNET_DISK_directory_remove (fn1);
374 GNUNET_free (fn1);
375 }
376 if (fn2 != NULL)
377 {
378 GNUNET_DISK_directory_remove (fn2);
379 GNUNET_free (fn2);
380 }
381 return err; 300 return err;
382} 301}
383 302