aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_namespace_list_updateable.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_namespace_list_updateable.c
parent9f4e1f6e097b3c97abe0971b68b2ab686a61f036 (diff)
downloadgnunet-e825548ea9a45d1f4b25898f87b5c74f8bc4cc25.tar.gz
gnunet-e825548ea9a45d1f4b25898f87b5c74f8bc4cc25.zip
-simplifying tests with new testing lib
Diffstat (limited to 'src/fs/test_fs_namespace_list_updateable.c')
-rw-r--r--src/fs/test_fs_namespace_list_updateable.c86
1 files changed, 8 insertions, 78 deletions
diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c
index 2cec67ddc..50668cac3 100644
--- a/src/fs/test_fs_namespace_list_updateable.c
+++ b/src/fs/test_fs_namespace_list_updateable.c
@@ -25,14 +25,9 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_arm_service.h" 28#include "gnunet_testing_lib-new.h"
29#include "gnunet_fs_service.h" 29#include "gnunet_fs_service.h"
30 30
31#define VERBOSE GNUNET_NO
32
33#define START_ARM GNUNET_YES
34
35static struct PeerContext p1;
36 31
37static struct GNUNET_FS_Handle *fs; 32static struct GNUNET_FS_Handle *fs;
38 33
@@ -49,15 +44,6 @@ static struct GNUNET_FS_Uri *uri_next;
49static struct GNUNET_FS_BlockOptions bo; 44static struct GNUNET_FS_BlockOptions bo;
50 45
51 46
52struct PeerContext
53{
54 struct GNUNET_CONFIGURATION_Handle *cfg;
55#if START_ARM
56 struct GNUNET_OS_Process *arm_proc;
57#endif
58};
59
60
61static void * 47static void *
62progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 48progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
63{ 49{
@@ -66,38 +52,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
66 52
67 53
68static void 54static void
69setup_peer (struct PeerContext *p, const char *cfgname) 55do_shutdown ()
70{ 56{
71 p->cfg = GNUNET_CONFIGURATION_create ();
72#if START_ARM
73 p->arm_proc =
74 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
75 "gnunet-service-arm",
76#if VERBOSE
77 "-L", "DEBUG",
78#endif
79 "-c", cfgname, NULL);
80#endif
81 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
82}
83
84
85static void
86stop_arm (struct PeerContext *p)
87{
88#if START_ARM
89 if (NULL != p->arm_proc)
90 {
91 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
92 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
93 if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
94 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
96 GNUNET_OS_process_get_pid (p->arm_proc));
97 GNUNET_OS_process_destroy (p->arm_proc);
98 p->arm_proc = NULL;
99 }
100#endif
101 if (uri_this != NULL) 57 if (uri_this != NULL)
102 GNUNET_FS_uri_destroy (uri_this); 58 GNUNET_FS_uri_destroy (uri_this);
103 if (uri_next != NULL) 59 if (uri_next != NULL)
@@ -106,11 +62,9 @@ stop_arm (struct PeerContext *p)
106 GNUNET_FS_namespace_delete (ns, GNUNET_NO); 62 GNUNET_FS_namespace_delete (ns, GNUNET_NO);
107 if (meta != NULL) 63 if (meta != NULL)
108 GNUNET_CONTAINER_meta_data_destroy (meta); 64 GNUNET_CONTAINER_meta_data_destroy (meta);
109 GNUNET_CONFIGURATION_destroy (p->cfg);
110} 65}
111 66
112 67
113
114static void 68static void
115check_next (void *cls, const char *last_id, 69check_next (void *cls, const char *last_id,
116 const struct GNUNET_FS_Uri *last_uri, 70 const struct GNUNET_FS_Uri *last_uri,
@@ -143,7 +97,6 @@ sks_cont_next (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
143 GNUNET_assert (NULL == emsg); 97 GNUNET_assert (NULL == emsg);
144 err += 2; 98 err += 2;
145 GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this_next, NULL); 99 GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this_next, NULL);
146
147} 100}
148 101
149 102
@@ -162,7 +115,6 @@ check_this (void *cls, const char *last_id,
162static void 115static void
163sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) 116sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
164{ 117{
165
166 GNUNET_assert (NULL == emsg); 118 GNUNET_assert (NULL == emsg);
167 err = 1; 119 err = 1;
168 GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this, NULL); 120 GNUNET_FS_namespace_list_updateable (ns, NULL, &check_this, NULL);
@@ -172,11 +124,9 @@ sks_cont_this (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
172} 124}
173 125
174 126
175
176static void 127static void
177testNamespace () 128testNamespace ()
178{ 129{
179
180 ns = GNUNET_FS_namespace_create (fs, "testNamespace"); 130 ns = GNUNET_FS_namespace_create (fs, "testNamespace");
181 GNUNET_assert (NULL != ns); 131 GNUNET_assert (NULL != ns);
182 bo.content_priority = 1; 132 bo.content_priority = 1;
@@ -200,10 +150,9 @@ testNamespace ()
200 150
201 151
202static void 152static void
203run (void *cls, char *const *args, const char *cfgfile, 153run (void *cls,
204 const struct GNUNET_CONFIGURATION_Handle *cfg) 154 const struct GNUNET_CONFIGURATION_Handle *cfg)
205{ 155{
206 setup_peer (&p1, "test_fs_namespace_data.conf");
207 fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL, 156 fs = GNUNET_FS_start (cfg, "test-fs-namespace", &progress_cb, NULL,
208 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 157 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
209 testNamespace (); 158 testNamespace ();
@@ -213,30 +162,11 @@ run (void *cls, char *const *args, const char *cfgfile,
213int 162int
214main (int argc, char *argv[]) 163main (int argc, char *argv[])
215{ 164{
216 char *const argvx[] = { 165 if (0 != GNUNET_TESTING_peer_run ("test-fs-namespace-list-updateable",
217 "test-fs-namespace", 166 "test_fs_namespace_data.conf",
218 "-c", 167 &run, NULL))
219 "test_fs_namespace_data.conf", 168 return 1;
220#if VERBOSE 169 do_shutdown ();
221 "-L", "DEBUG",
222#endif
223 NULL
224 };
225 struct GNUNET_GETOPT_CommandLineOption options[] = {
226 GNUNET_GETOPT_OPTION_END
227 };
228
229 GNUNET_log_setup ("test_fs_namespace_list_updateable",
230#if VERBOSE
231 "DEBUG",
232#else
233 "WARNING",
234#endif
235 NULL);
236 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
237 "test-fs-namespace", "nohelp", options, &run, NULL);
238 stop_arm (&p1);
239 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-namespace/");
240 return err; 170 return err;
241} 171}
242 172