aboutsummaryrefslogtreecommitdiff
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
parent129376c98b928d01c998dcfcb811bcf08cfae288 (diff)
downloadgnunet-df6cfdf376e83edfd04e083c6feafa8577bc237c.tar.gz
gnunet-df6cfdf376e83edfd04e083c6feafa8577bc237c.zip
hacking on fs
-rw-r--r--src/fs/Makefile.am29
-rw-r--r--src/fs/fs_download.c2
-rw-r--r--src/fs/fs_search.c4
-rw-r--r--src/fs/gnunet-service-fs.c2
-rw-r--r--src/fs/test_fs_data.conf42
-rw-r--r--src/fs/test_fs_download.c3
-rw-r--r--src/fs/test_fs_download_data.conf4
-rw-r--r--src/fs/test_fs_namespace.c214
-rw-r--r--src/fs/test_fs_search.c15
-rw-r--r--src/fs/test_fs_search_data.conf2
-rw-r--r--src/fs/test_fs_start_stop.c150
-rw-r--r--src/fs/test_namespace.c136
12 files changed, 404 insertions, 199 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index fc98509a0..82467c14c 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -1,3 +1,4 @@
1
1INCLUDES = -I$(top_srcdir)/src/include 2INCLUDES = -I$(top_srcdir)/src/include
2 3
3if MINGW 4if MINGW
@@ -106,11 +107,17 @@ check_PROGRAMS = \
106 test_fs_directory \ 107 test_fs_directory \
107 test_fs_download \ 108 test_fs_download \
108 test_fs_getopt \ 109 test_fs_getopt \
110 test_fs_namespace \
109 test_fs_search \ 111 test_fs_search \
112 test_fs_start_stop \
110 test_fs_uri 113 test_fs_uri
111 114
112TESTS = test_fs_directory test_fs_download test_fs_uri 115TESTS = \
113 116 test_fs_directory \
117 test_fs_download \
118 test_fs_search \
119 test_fs_start_stop \
120 test_fs_uri
114# $(check_PROGRAMS) 121# $(check_PROGRAMS)
115 122
116test_fs_collection_SOURCES = \ 123test_fs_collection_SOURCES = \
@@ -132,9 +139,22 @@ test_fs_download_LDADD = \
132 $(top_builddir)/src/arm/libgnunetarm.la \ 139 $(top_builddir)/src/arm/libgnunetarm.la \
133 $(top_builddir)/src/util/libgnunetutil.la 140 $(top_builddir)/src/util/libgnunetutil.la
134 141
142test_fs_namespace_SOURCES = \
143 test_fs_namespace.c
144test_fs_namespace_LDADD = \
145 $(top_builddir)/src/fs/libgnunetfs.la \
146 $(top_builddir)/src/arm/libgnunetarm.la \
147 $(top_builddir)/src/util/libgnunetutil.la
148
135test_fs_search_SOURCES = \ 149test_fs_search_SOURCES = \
136 test_fs_search.c 150 test_fs_search.c
137test_fs_search_LDADD = \ 151test_fs_search_LDADD = $(top_builddir)/src/fs/libgnunetfs.la \
152 $(top_builddir)/src/arm/libgnunetarm.la \
153 $(top_builddir)/src/util/libgnunetutil.la
154
155test_fs_start_stop_SOURCES = \
156 test_fs_start_stop.c
157test_fs_start_stop_LDADD = \
138 $(top_builddir)/src/fs/libgnunetfs.la \ 158 $(top_builddir)/src/fs/libgnunetfs.la \
139 $(top_builddir)/src/arm/libgnunetarm.la \ 159 $(top_builddir)/src/arm/libgnunetarm.la \
140 $(top_builddir)/src/util/libgnunetutil.la 160 $(top_builddir)/src/util/libgnunetutil.la
@@ -152,6 +172,9 @@ test_fs_uri_LDADD = \
152 $(top_builddir)/src/util/libgnunetutil.la 172 $(top_builddir)/src/util/libgnunetutil.la
153 173
154EXTRA_DIST = \ 174EXTRA_DIST = \
175 test_fs_data.conf \
155 test_fs_collection_data.conf \ 176 test_fs_collection_data.conf \
156 test_fs_download_data.conf \ 177 test_fs_download_data.conf \
178 test_fs_namespace_data.conf \
179 test_fs_search_data.conf \
157 test_fs_uri_data.conf 180 test_fs_uri_data.conf
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index ca1a8325a..22b92aa09 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -36,7 +36,7 @@
36#include "fs.h" 36#include "fs.h"
37#include "fs_tree.h" 37#include "fs_tree.h"
38 38
39#define DEBUG_DOWNLOAD GNUNET_YES 39#define DEBUG_DOWNLOAD GNUNET_NO
40 40
41/** 41/**
42 * We're storing the IBLOCKS after the 42 * We're storing the IBLOCKS after the
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 52153dcb0..ae681577f 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -208,7 +208,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
208 int is_new; 208 int is_new;
209 209
210 /* check if new */ 210 /* check if new */
211 if (! GNUNET_FS_uri_test_ksk (uri)) 211 if (! GNUNET_FS_uri_test_chk (uri))
212 { 212 {
213 GNUNET_break_op (0); 213 GNUNET_break_op (0);
214 return; 214 return;
@@ -380,7 +380,7 @@ process_kblock (struct GNUNET_FS_SearchContext *sc,
380 } 380 }
381 /* decrypt */ 381 /* decrypt */
382 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv); 382 GNUNET_CRYPTO_hash_to_aes_key (&sc->requests[i].key, &skey, &iv);
383 GNUNET_CRYPTO_aes_encrypt (&kb[1], 383 GNUNET_CRYPTO_aes_decrypt (&kb[1],
384 size - sizeof (struct KBlock), 384 size - sizeof (struct KBlock),
385 &skey, 385 &skey,
386 &iv, 386 &iv,
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 0eede0c99..dc97b2cb8 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -47,7 +47,7 @@
47#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
48#include "fs.h" 48#include "fs.h"
49 49
50#define DEBUG_FS GNUNET_YES 50#define DEBUG_FS GNUNET_NO
51 51
52 52
53/** 53/**
diff --git a/src/fs/test_fs_data.conf b/src/fs/test_fs_data.conf
new file mode 100644
index 000000000..632c23ea7
--- /dev/null
+++ b/src/fs/test_fs_data.conf
@@ -0,0 +1,42 @@
1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-fs/
3DEFAULTCONFIG = test_fs_data.conf
4
5[gnunetd]
6HOSTKEY = $SERVICEHOME/.hostkey
7
8[resolver]
9PORT = 42464
10HOSTNAME = localhost
11
12[transport]
13PORT = 42465
14PLUGINS =
15
16[arm]
17PORT = 42466
18HOSTNAME = localhost
19DEFAULTSERVICES = resolver datastore transport core fs
20
21[datastore]
22#DEBUG = YES
23
24[statistics]
25PORT = 42467
26HOSTNAME = localhost
27
28[peerinfo]
29PORT = 42469
30HOSTNAME = localhost
31
32[core]
33PORT = 42470
34HOSTNAME = localhost
35
36[fs]
37PORT = 42471
38HOSTNAME = localhost
39#DEBUG = YES
40
41[testing]
42WEAKRANDOM = YES
diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c
index 003840fa7..1d1813c56 100644
--- a/src/fs/test_fs_download.c
+++ b/src/fs/test_fs_download.c
@@ -29,7 +29,7 @@
29#include "gnunet_arm_service.h" 29#include "gnunet_arm_service.h"
30#include "gnunet_fs_service.h" 30#include "gnunet_fs_service.h"
31 31
32#define VERBOSE GNUNET_YES 32#define VERBOSE GNUNET_NO
33 33
34#define START_ARM GNUNET_YES 34#define START_ARM GNUNET_YES
35 35
@@ -324,6 +324,7 @@ main (int argc, char *argv[])
324 argvx, "test-fs-download", 324 argvx, "test-fs-download",
325 "nohelp", options, &run, NULL); 325 "nohelp", options, &run, NULL);
326 stop_arm (&p1); 326 stop_arm (&p1);
327 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
327 return 0; 328 return 0;
328} 329}
329 330
diff --git a/src/fs/test_fs_download_data.conf b/src/fs/test_fs_download_data.conf
index 41678142c..d55191a32 100644
--- a/src/fs/test_fs_download_data.conf
+++ b/src/fs/test_fs_download_data.conf
@@ -19,7 +19,7 @@ HOSTNAME = localhost
19DEFAULTSERVICES = resolver datastore transport core fs 19DEFAULTSERVICES = resolver datastore transport core fs
20 20
21[datastore] 21[datastore]
22DEBUG = YES 22#DEBUG = YES
23 23
24[statistics] 24[statistics]
25PORT = 42467 25PORT = 42467
@@ -36,7 +36,7 @@ HOSTNAME = localhost
36[fs] 36[fs]
37PORT = 42471 37PORT = 42471
38HOSTNAME = localhost 38HOSTNAME = localhost
39DEBUG = YES 39#DEBUG = YES
40 40
41[testing] 41[testing]
42WEAKRANDOM = YES 42WEAKRANDOM = YES
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c
new file mode 100644
index 000000000..8ee9ab37a
--- /dev/null
+++ b/src/fs/test_fs_namespace.c
@@ -0,0 +1,214 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file fs/test_fs_namespace.c
23 * @brief Test for fs_namespace.c
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_arm_service.h"
30#include "gnunet_fs_service.h"
31
32#define START_ARM GNUNET_YES
33
34static struct GNUNET_SCHEDULER_Handle *sched;
35
36static struct PeerContext p1;
37
38static struct GNUNET_FS_Handle *fs;
39
40
41struct PeerContext
42{
43 struct GNUNET_CONFIGURATION_Handle *cfg;
44 struct GNUNET_PeerIdentity id;
45#if START_ARM
46 pid_t arm_pid;
47#endif
48};
49
50
51static void *
52progress_cb (void *cls,
53 const struct GNUNET_FS_ProgressInfo *event)
54{
55 return NULL;
56}
57
58
59static void
60setup_peer (struct PeerContext *p, const char *cfgname)
61{
62 p->cfg = GNUNET_CONFIGURATION_create ();
63#if START_ARM
64 p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm",
65 "gnunet-service-arm",
66#if VERBOSE
67 "-L", "DEBUG",
68#endif
69 "-c", cfgname, NULL);
70 sleep (1); /* allow ARM to start */
71#endif
72 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
73 GNUNET_ARM_start_services (p->cfg, sched, "core", NULL);
74}
75
76
77static void
78stop_arm (struct PeerContext *p)
79{
80#if START_ARM
81 if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
82 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
83 if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
84 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "ARM process %u stopped\n", p->arm_pid);
87#endif
88 GNUNET_CONFIGURATION_destroy (p->cfg);
89}
90
91
92static void
93spcb (void *cls,
94 const char *name,
95 const GNUNET_HashCode * key)
96{
97}
98
99
100static void
101publish_cont (void *cls,
102 const struct GNUNET_FS_Uri *uri,
103 const char *emsg)
104{
105 struct GNUNET_FS_SearchContext *search;
106
107 GNUNET_assert (NULL == emsg);
108 fprintf (stderr, "Starting namespace search...\n");
109 search = GNUNET_FS_search_start (fs, uri, 1);
110}
111
112
113static void
114testNamespace ()
115{
116 struct GNUNET_FS_Namespace *ns;
117 struct GNUNET_FS_Uri *adv;
118 struct GNUNET_FS_Uri *rootUri;
119 struct GNUNET_CONTAINER_MetaData *meta;
120 struct GNUNET_TIME_Absolute expiration;
121
122 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
123 meta = GNUNET_CONTAINER_meta_data_create ();
124 adv = GNUNET_FS_uri_ksk_create ("testNamespace", NULL);
125 ns = GNUNET_FS_namespace_create (fs,
126 "testNamespace");
127 rootUri = GNUNET_FS_namespace_advertise (fs,
128 ns,
129 meta,
130 1, 1,
131 expiration,
132 adv,
133 "root");
134 GNUNET_assert (NULL != rootUri);
135 GNUNET_FS_publish_sks (fs,
136 ns,
137 "this",
138 "next",
139 meta,
140 rootUri,
141 expiration,
142 1, 1,
143 GNUNET_FS_PUBLISH_OPTION_NONE,
144 &publish_cont,
145 NULL);
146 GNUNET_CONTAINER_meta_data_destroy (meta);
147}
148
149#if 0
150 fprintf (stderr, "Completed namespace search...\n");
151 GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (NULL, cfg, &pid));
152 GNUNET_assert (GNUNET_SYSERR == GNUNET_FS_namespace_delete (NULL, cfg, &pid));
153 GNUNET_FS_uri_destroy (rootURI);
154 GNUNET_FS_uri_destroy (advURI);
155 GNUNET_assert (match == 1);
156 return 0;
157}
158#endif
159
160
161static void
162run (void *cls,
163 struct GNUNET_SCHEDULER_Handle *s,
164 char *const *args,
165 const char *cfgfile,
166 const struct GNUNET_CONFIGURATION_Handle *cfg)
167{
168 sched = s;
169 setup_peer (&p1, "test_fs_download_data.conf");
170 fs = GNUNET_FS_start (sched,
171 cfg,
172 "test-fs-namespace",
173 &progress_cb,
174 NULL,
175 GNUNET_FS_FLAGS_NONE,
176 GNUNET_FS_OPTIONS_END);
177 testNamespace ();
178}
179
180
181int
182main (int argc, char *argv[])
183{
184 char *const argvx[] = {
185 "test-fs-namespace",
186 "-c",
187 "test_fs_namespace_data.conf",
188#if VERBOSE
189 "-L", "DEBUG",
190#endif
191 NULL
192 };
193 struct GNUNET_GETOPT_CommandLineOption options[] = {
194 GNUNET_GETOPT_OPTION_END
195 };
196
197 GNUNET_log_setup ("test_fs_namespace",
198#if VERBOSE
199 "DEBUG",
200#else
201 "WARNING",
202#endif
203 NULL);
204 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
205 argvx, "test-fs-namespace",
206 "nohelp", options, &run, NULL);
207 stop_arm (&p1);
208 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
209 return 0;
210}
211
212
213
214/* end of test_fs_namespace.c */
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c
index b600bc3ed..01bb3c1f7 100644
--- a/src/fs/test_fs_search.c
+++ b/src/fs/test_fs_search.c
@@ -29,7 +29,7 @@
29#include "gnunet_arm_service.h" 29#include "gnunet_arm_service.h"
30#include "gnunet_fs_service.h" 30#include "gnunet_fs_service.h"
31 31
32#define VERBOSE GNUNET_YES 32#define VERBOSE GNUNET_NO
33 33
34#define START_ARM GNUNET_YES 34#define START_ARM GNUNET_YES
35 35
@@ -83,7 +83,8 @@ static void
83abort_search_task (void *cls, 83abort_search_task (void *cls,
84 const struct GNUNET_SCHEDULER_TaskContext *tc) 84 const struct GNUNET_SCHEDULER_TaskContext *tc)
85{ 85{
86 GNUNET_FS_search_stop (search); 86 if (search != NULL)
87 GNUNET_FS_search_stop (search);
87 search = NULL; 88 search = NULL;
88} 89}
89 90
@@ -118,7 +119,9 @@ progress_cb (void *cls,
118 GNUNET_assert (search != NULL); 119 GNUNET_assert (search != NULL);
119 break; 120 break;
120 case GNUNET_FS_STATUS_SEARCH_RESULT: 121 case GNUNET_FS_STATUS_SEARCH_RESULT:
122#if VERBOSE
121 printf ("Search complete.\n"); 123 printf ("Search complete.\n");
124#endif
122 GNUNET_SCHEDULER_add_continuation (sched, 125 GNUNET_SCHEDULER_add_continuation (sched,
123 GNUNET_NO, 126 GNUNET_NO,
124 &abort_search_task, 127 &abort_search_task,
@@ -165,6 +168,8 @@ progress_cb (void *cls,
165 // GNUNET_assert (0 == strcmp ("search", event->value.search.cctx)); 168 // GNUNET_assert (0 == strcmp ("search", event->value.search.cctx));
166 GNUNET_assert (1 == event->value.search.anonymity); 169 GNUNET_assert (1 == event->value.search.anonymity);
167 break; 170 break;
171 case GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED:
172 break;
168 case GNUNET_FS_STATUS_SEARCH_STOPPED: 173 case GNUNET_FS_STATUS_SEARCH_STOPPED:
169 GNUNET_assert (search == event->value.search.sc); 174 GNUNET_assert (search == event->value.search.sc);
170 GNUNET_SCHEDULER_add_continuation (sched, 175 GNUNET_SCHEDULER_add_continuation (sched,
@@ -174,8 +179,9 @@ progress_cb (void *cls,
174 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 179 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
175 break; 180 break;
176 default: 181 default:
177 printf ("Unexpected event: %d\n", 182 fprintf (stderr,
178 event->status); 183 "Unexpected event: %d\n",
184 event->status);
179 break; 185 break;
180 } 186 }
181 return NULL; 187 return NULL;
@@ -295,6 +301,7 @@ main (int argc, char *argv[])
295 argvx, "test-fs-search", 301 argvx, "test-fs-search",
296 "nohelp", options, &run, NULL); 302 "nohelp", options, &run, NULL);
297 stop_arm (&p1); 303 stop_arm (&p1);
304 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
298 return 0; 305 return 0;
299} 306}
300 307
diff --git a/src/fs/test_fs_search_data.conf b/src/fs/test_fs_search_data.conf
index d55191a32..fd82a15fc 100644
--- a/src/fs/test_fs_search_data.conf
+++ b/src/fs/test_fs_search_data.conf
@@ -1,5 +1,5 @@
1[PATHS] 1[PATHS]
2SERVICEHOME = /tmp/gnunet-test-fs-download/ 2SERVICEHOME = /tmp/gnunet-test-fs-search/
3DEFAULTCONFIG = test_fs_download_data.conf 3DEFAULTCONFIG = test_fs_download_data.conf
4 4
5[gnunetd] 5[gnunetd]
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 */
diff --git a/src/fs/test_namespace.c b/src/fs/test_namespace.c
deleted file mode 100644
index 81c0e1559..000000000
--- a/src/fs/test_namespace.c
+++ /dev/null
@@ -1,136 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005, 2006, 2008 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file applications/fs/ecrs/namespacetest.c
23 * @brief Test for namespace.c
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunet_util.h"
29#include "gnunet_ecrs_lib.h"
30#include "ecrs.h"
31
32#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; }
33#define CHECK(c) { do { if (!(c)) ABORT(); } while(0); }
34
35#define CHECKNAME "gnunet-namespace-test"
36
37static struct GNUNET_GC_Configuration *cfg;
38
39static int match;
40
41static int
42spcb (const GNUNET_ECRS_FileInfo * fi,
43 const GNUNET_HashCode * key, int isRoot, void *closure)
44{
45 struct GNUNET_ECRS_URI *want = closure;
46
47 if (GNUNET_ECRS_uri_test_equal (want, fi->uri))
48 match = 1;
49 else
50 fprintf (stderr,
51 "Namespace search returned unexpected result: \nHAVE: %s\nWANT: %s...\n",
52 GNUNET_ECRS_uri_to_string (fi->uri),
53 GNUNET_ECRS_uri_to_string (want));
54 return GNUNET_OK;
55}
56
57static int
58tt (void *unused)
59{
60 if (match == 1)
61 return GNUNET_SYSERR;
62 return GNUNET_OK;
63}
64
65static int
66testNamespace ()
67{
68 GNUNET_HashCode pid;
69 struct GNUNET_ECRS_URI *adv;
70 struct GNUNET_ECRS_URI *advURI;
71 struct GNUNET_ECRS_URI *rootURI;
72 struct GNUNET_MetaData *meta;
73
74 meta = GNUNET_meta_data_create ();
75 adv = GNUNET_ECRS_keyword_string_to_uri (NULL, "testNamespace");
76 rootURI =
77 GNUNET_ECRS_namespace_create (NULL,
78 cfg,
79 meta,
80 0, 0,
81 GNUNET_get_time () +
82 15 * GNUNET_CRON_MINUTES, adv, "root");
83 CHECK (NULL != rootURI);
84 GNUNET_ECRS_uri_get_namespace_from_sks (rootURI, &pid);
85 advURI = GNUNET_ECRS_namespace_add_content (NULL, cfg, &pid, 1, /* anonymity */
86 1000, /* priority */
87 5 * GNUNET_CRON_MINUTES +
88 GNUNET_get_time (),
89 "this", "next", rootURI, meta);
90 CHECK (NULL != advURI);
91 fprintf (stderr, "Starting namespace search...\n");
92 CHECK (GNUNET_OK == GNUNET_ECRS_search (NULL,
93 cfg,
94 advURI, 1, &spcb, rootURI, &tt,
95 NULL));
96 fprintf (stderr, "Completed namespace search...\n");
97 CHECK (GNUNET_OK == GNUNET_ECRS_namespace_delete (NULL, cfg, &pid));
98 CHECK (GNUNET_SYSERR == GNUNET_ECRS_namespace_delete (NULL, cfg, &pid));
99 GNUNET_meta_data_destroy (meta);
100 GNUNET_ECRS_uri_destroy (rootURI);
101 GNUNET_ECRS_uri_destroy (advURI);
102 CHECK (match == 1);
103 return 0;
104}
105
106int
107main (int argc, char *argv[])
108{
109 pid_t daemon;
110 int failureCount = 0;
111
112 GNUNET_disable_entropy_gathering ();
113 cfg = GNUNET_GC_create ();
114 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
115 {
116 GNUNET_GC_free (cfg);
117 return -1;
118 }
119 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
120 GNUNET_GE_ASSERT (NULL, daemon > 0);
121 if (GNUNET_OK !=
122 GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS))
123 {
124 failureCount++;
125 }
126 else
127 {
128 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
129 failureCount += testNamespace ();
130 }
131 GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
132
133 return (failureCount == 0) ? 0 : 1;
134}
135
136/* end of namespacetest.c */