aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_start_stop.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-23 10:54:26 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-23 10:54:26 +0000
commitdf6cfdf376e83edfd04e083c6feafa8577bc237c (patch)
treeca1e65baf6ee3041c2fe59d0fe8cd55515dde1ea /src/fs/test_fs_start_stop.c
parent129376c98b928d01c998dcfcb811bcf08cfae288 (diff)
downloadgnunet-df6cfdf376e83edfd04e083c6feafa8577bc237c.tar.gz
gnunet-df6cfdf376e83edfd04e083c6feafa8577bc237c.zip
hacking on fs
Diffstat (limited to 'src/fs/test_fs_start_stop.c')
-rw-r--r--src/fs/test_fs_start_stop.c150
1 files changed, 102 insertions, 48 deletions
diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c
index 1ec1176a6..e25de8e70 100644
--- a/src/fs/test_fs_start_stop.c
+++ b/src/fs/test_fs_start_stop.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006 Christian Grothoff (and other contributing authors) 3 (C) 2004, 2005, 2006, 2009 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -19,71 +19,125 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file applications/fs/fsui/fsui_start_stop_test.c 22 * @file fs/test_fs_start_stop.c
23 * @brief testcase for fsui (start-stop only) 23 * @brief testcase for fs.c (start-stop only)
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_fsui_lib.h" 29#include "gnunet_arm_service.h"
30#include "gnunet_fs_service.h"
30 31
31#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto FAILURE; } 32#define START_ARM GNUNET_YES
32 33
34static struct GNUNET_SCHEDULER_Handle *sched;
35
36static struct PeerContext p1;
37
38struct PeerContext
39{
40 struct GNUNET_CONFIGURATION_Handle *cfg;
41 struct GNUNET_PeerIdentity id;
42#if START_ARM
43 pid_t arm_pid;
44#endif
45};
33 46
34static struct GNUNET_FSUI_Context *ctx;
35 47
36static void * 48static void *
37eventCallback (void *cls, const GNUNET_FSUI_Event * event) 49progress_cb (void *cls,
50 const struct GNUNET_FS_ProgressInfo *event)
38{ 51{
39 return NULL; 52 return NULL;
40} 53}
41 54
42#define START_DAEMON 1
43 55
44int 56static void
45main (int argc, char *argv[]) 57setup_peer (struct PeerContext *p, const char *cfgname)
46{ 58{
47#if START_DAEMON 59 p->cfg = GNUNET_CONFIGURATION_create ();
48 pid_t daemon; 60#if START_ARM
61 p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
62 "gnunet-service-arm",
63#if VERBOSE
64 "-L", "DEBUG",
49#endif 65#endif
50 int ok; 66 "-c", cfgname, NULL);
51 struct GNUNET_GC_Configuration *cfg; 67 sleep (1); /* allow ARM to start */
52
53 cfg = GNUNET_GC_create ();
54 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
55 {
56 GNUNET_GC_free (cfg);
57 return -1;
58 }
59#if START_DAEMON
60 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
61 GNUNET_GE_ASSERT (NULL, daemon > 0);
62 CHECK (GNUNET_OK ==
63 GNUNET_wait_for_daemon_running (NULL, cfg,
64 60 * GNUNET_CRON_SECONDS));
65#endif 68#endif
66 ok = GNUNET_YES; 69 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
67 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ 70 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
68 71}
69 /* ACTUAL TEST CODE */ 72
70 ctx = GNUNET_FSUI_start (NULL, cfg, "fsui_start_stop_test", 32, GNUNET_YES, /* do resume! */ 73
71 &eventCallback, NULL); 74static void
72 CHECK (ctx != NULL); 75stop_arm (struct PeerContext *p)
73 GNUNET_FSUI_stop (ctx); 76{
74 ctx = 77#if START_ARM
75 GNUNET_FSUI_start (NULL, cfg, "fsui_start_stop_test", 32, GNUNET_YES, 78 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
76 &eventCallback, NULL); 79 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
77 CHECK (ctx != NULL); 80 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
78FAILURE: 81 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
79 if (ctx != NULL) 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
80 GNUNET_FSUI_stop (ctx); 83 "ARM process %u stopped\n", p->arm_pid);
81#if START_DAEMON
82 GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
83#endif 84#endif
84 GNUNET_GC_free (cfg); 85 GNUNET_CONFIGURATION_destroy (p->cfg);
86}
87
85 88
86 return (ok == GNUNET_YES) ? 0 : 1; 89static void
90run (void *cls,
91 struct GNUNET_SCHEDULER_Handle *s,
92 char *const *args,
93 const char *cfgfile,
94 const struct GNUNET_CONFIGURATION_Handle *cfg)
95{
96 struct GNUNET_FS_Handle *fs;
97
98 sched = s;
99 setup_peer (&p1, "test_fs_data.conf");
100 fs = GNUNET_FS_start (sched,
101 cfg,
102 "test-fs-start-stop",
103 &progress_cb,
104 NULL,
105 GNUNET_FS_FLAGS_NONE,
106 GNUNET_FS_OPTIONS_END);
107 GNUNET_assert (NULL != fs);
108 GNUNET_FS_stop (fs);
109}
110
111
112int
113main (int argc, char *argv[])
114{
115 char *const argvx[] = {
116 "test-fs-start-stop",
117 "-c",
118 "test_fs_data.conf",
119#if VERBOSE
120 "-L", "DEBUG",
121#endif
122 NULL
123 };
124 struct GNUNET_GETOPT_CommandLineOption options[] = {
125 GNUNET_GETOPT_OPTION_END
126 };
127
128 GNUNET_log_setup ("test_fs_start_stop",
129#if VERBOSE
130 "DEBUG",
131#else
132 "WARNING",
133#endif
134 NULL);
135 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
136 argvx, "test-fs-start-stop",
137 "nohelp", options, &run, NULL);
138 stop_arm (&p1);
139 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs/");
140 return 0;
87} 141}
88 142
89/* end of fsui_start_stop_test.c */ 143/* end of test_fs_start_stop.c */