aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_search_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_search_persistence.c
parente825548ea9a45d1f4b25898f87b5c74f8bc4cc25 (diff)
downloadgnunet-36ca9fcc68935edd109481d30f9e6e15a825c282.tar.gz
gnunet-36ca9fcc68935edd109481d30f9e6e15a825c282.zip
-simplifying tests with new testing lib
Diffstat (limited to 'src/fs/test_fs_search_persistence.c')
-rw-r--r--src/fs/test_fs_search_persistence.c110
1 files changed, 16 insertions, 94 deletions
diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c
index d18b50eb5..cedf4b8a5 100644
--- a/src/fs/test_fs_search_persistence.c
+++ b/src/fs/test_fs_search_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_search_persistence.c 21 * @file fs/test_fs_search_persistence.c
23 * @brief simple testcase for persistence of search operation 22 * @brief simple testcase for persistence of search 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,16 +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 struct GNUNET_PeerIdentity id;
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
@@ -69,6 +54,7 @@ static struct GNUNET_FS_PublishContext *publish;
69 54
70static const struct GNUNET_CONFIGURATION_Handle *cfg; 55static const struct GNUNET_CONFIGURATION_Handle *cfg;
71 56
57
72static void 58static void
73abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 59abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
74{ 60{
@@ -99,8 +85,6 @@ restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99} 85}
100 86
101 87
102
103
104/** 88/**
105 * Consider scheduling the restart-task. 89 * Consider scheduling the restart-task.
106 * Only runs the restart task once per event 90 * Only runs the restart task once per event
@@ -135,14 +119,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
135 switch (event->status) 119 switch (event->status)
136 { 120 {
137 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 121 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
138#if VERBOSE 122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
139 printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", 123 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
140 (unsigned long long) event->value.publish.completed, 124 (unsigned long long) event->value.publish.completed,
141 (unsigned long long) event->value.publish.size, 125 (unsigned long long) event->value.publish.size,
142 event->value.publish.specifics.progress.depth, 126 event->value.publish.specifics.progress.depth,
143 (unsigned long long) event->value.publish.specifics. 127 (unsigned long long) event->value.publish.specifics.
144 progress.offset); 128 progress.offset);
145#endif
146 break; 129 break;
147 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 130 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
148 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); 131 kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords);
@@ -163,9 +146,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
163 case GNUNET_FS_STATUS_SEARCH_RESULT: 146 case GNUNET_FS_STATUS_SEARCH_RESULT:
164 /* FIXME: consider_restart (event->status); cannot be tested with 147 /* FIXME: consider_restart (event->status); cannot be tested with
165 * search result since we exit here after the first one... */ 148 * search result since we exit here after the first one... */
166#if VERBOSE 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167 printf ("Search complete.\n"); 150 "Search complete.\n");
168#endif
169 GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL, 151 GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL,
170 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 152 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
171 break; 153 break;
@@ -231,44 +213,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
231 213
232 214
233static void 215static void
234setup_peer (struct PeerContext *p, const char *cfgname) 216run (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) 217 const struct GNUNET_CONFIGURATION_Handle *c)
273{ 218{
274 const char *keywords[] = { 219 const char *keywords[] = {
@@ -283,7 +228,6 @@ run (void *cls, char *const *args, const char *cfgfile,
283 struct GNUNET_FS_BlockOptions bo; 228 struct GNUNET_FS_BlockOptions bo;
284 229
285 cfg = c; 230 cfg = c;
286 setup_peer (&p1, "test_fs_search_data.conf");
287 fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL, 231 fs = GNUNET_FS_start (cfg, "test-fs-search-persistence", &progress_cb, NULL,
288 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 232 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END);
289 GNUNET_assert (NULL != fs); 233 GNUNET_assert (NULL != fs);
@@ -313,32 +257,10 @@ run (void *cls, char *const *args, const char *cfgfile,
313int 257int
314main (int argc, char *argv[]) 258main (int argc, char *argv[])
315{ 259{
316 char *const argvx[] = { 260 if (0 != GNUNET_TESTING_peer_run ("test-fs-search-persistence",
317 "test-fs-search-persistence", 261 "test_fs_search_data.conf",
318 "-c", 262 &run, NULL))
319 "test_fs_search_data.conf", 263 return 1;
320#if VERBOSE
321 "-L", "DEBUG",
322#endif
323 NULL
324 };
325 struct GNUNET_GETOPT_CommandLineOption options[] = {
326 GNUNET_GETOPT_OPTION_END
327 };
328
329 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
330 GNUNET_log_setup ("test_fs_search_persistence",
331#if VERBOSE
332 "DEBUG",
333#else
334 "WARNING",
335#endif
336 NULL);
337 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
338 "test-fs-search-persistence", "nohelp", options, &run,
339 NULL);
340 stop_arm (&p1);
341 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/");
342 return 0; 264 return 0;
343} 265}
344 266