aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-03-28 14:10:02 +0000
committerChristian Grothoff <christian@grothoff.org>2013-03-28 14:10:02 +0000
commit677157767fc70a2176ecffadf60dc0fdf4eda5f8 (patch)
treedc35e3bdffd4b78a98876084599058ec48dfcc15 /src/fs
parent87d828d4d8615c4958684f225c3917ff7516519b (diff)
downloadgnunet-677157767fc70a2176ecffadf60dc0fdf4eda5f8.tar.gz
gnunet-677157767fc70a2176ecffadf60dc0fdf4eda5f8.zip
-timeout
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/test_fs_search_persistence.c26
-rw-r--r--src/fs/test_fs_search_probes.c27
-rw-r--r--src/fs/test_fs_search_ranking.c246
3 files changed, 51 insertions, 248 deletions
diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c
index d66c5ec8e..4b60192e8 100644
--- a/src/fs/test_fs_search_persistence.c
+++ b/src/fs/test_fs_search_persistence.c
@@ -54,6 +54,28 @@ static struct GNUNET_FS_PublishContext *publish;
54 54
55static const struct GNUNET_CONFIGURATION_Handle *cfg; 55static const struct GNUNET_CONFIGURATION_Handle *cfg;
56 56
57static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
58
59static int err;
60
61
62static void
63abort_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
64{
65 fprintf (stderr,
66 "Timeout\n");
67 if (NULL != publish)
68 {
69 GNUNET_FS_publish_stop (publish);
70 publish = NULL;
71 }
72 if (NULL != search)
73 {
74 GNUNET_FS_search_stop (search);
75 search = NULL;
76 }
77 err = 1;
78}
57 79
58static void 80static void
59abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 81abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -252,6 +274,8 @@ run (void *cls,
252 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, 274 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
253 GNUNET_FS_PUBLISH_OPTION_NONE); 275 GNUNET_FS_PUBLISH_OPTION_NONE);
254 GNUNET_assert (publish != NULL); 276 GNUNET_assert (publish != NULL);
277 timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME,
278 &abort_error, NULL);
255} 279}
256 280
257 281
@@ -262,7 +286,7 @@ main (int argc, char *argv[])
262 "test_fs_search_data.conf", 286 "test_fs_search_data.conf",
263 &run, NULL)) 287 &run, NULL))
264 return 1; 288 return 1;
265 return 0; 289 return err;
266} 290}
267 291
268/* end of test_fs_search_persistence.c */ 292/* end of test_fs_search_persistence.c */
diff --git a/src/fs/test_fs_search_probes.c b/src/fs/test_fs_search_probes.c
index 0b02532e8..b2f1e0bf1 100644
--- a/src/fs/test_fs_search_probes.c
+++ b/src/fs/test_fs_search_probes.c
@@ -53,6 +53,29 @@ static struct GNUNET_FS_SearchContext *search;
53 53
54static struct GNUNET_FS_PublishContext *publish; 54static struct GNUNET_FS_PublishContext *publish;
55 55
56static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
57
58static int err;
59
60
61static void
62abort_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
63{
64 fprintf (stderr,
65 "Timeout\n");
66 if (NULL != publish)
67 {
68 GNUNET_FS_publish_stop (publish);
69 publish = NULL;
70 }
71 if (NULL != search)
72 {
73 GNUNET_FS_search_stop (search);
74 search = NULL;
75 }
76 err = 1;
77}
78
56 79
57static void 80static void
58abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 81abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -194,6 +217,8 @@ run (void *cls,
194 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL, 217 GNUNET_FS_publish_start (fs, fi, NULL, NULL, NULL,
195 GNUNET_FS_PUBLISH_OPTION_NONE); 218 GNUNET_FS_PUBLISH_OPTION_NONE);
196 GNUNET_assert (publish != NULL); 219 GNUNET_assert (publish != NULL);
220 timeout_task = GNUNET_SCHEDULER_add_delayed (LIFETIME,
221 &abort_error, NULL);
197} 222}
198 223
199 224
@@ -204,7 +229,7 @@ main (int argc, char *argv[])
204 "test_fs_search_data.conf", 229 "test_fs_search_data.conf",
205 &run, NULL)) 230 &run, NULL))
206 return 1; 231 return 1;
207 return 0; 232 return err;
208} 233}
209 234
210/* end of test_fs_search_probes.c */ 235/* end of test_fs_search_probes.c */
diff --git a/src/fs/test_fs_search_ranking.c b/src/fs/test_fs_search_ranking.c
deleted file mode 100644
index 5ad7da224..000000000
--- a/src/fs/test_fs_search_ranking.c
+++ /dev/null
@@ -1,246 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2004, 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 3, 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/fsui/search_ranking_test.c
23 * @brief testcase for search ranking (availability, etc)
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunet_util.h"
29#include "gnunet_fsui_lib.h"
30
31#define CHECK_VERBOSE GNUNET_NO
32
33#define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(NULL, 0); goto FAILURE; }
34
35static char *
36makeName (unsigned int i)
37{
38 char *fn;
39
40 fn = GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14);
41 GNUNET_snprintf (fn, strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14,
42 "/tmp/gnunet-fsui-searchranktest/FSUITEST%u", i);
43 GNUNET_disk_directory_create_for_file (NULL, fn);
44 return fn;
45}
46
47static struct GNUNET_FSUI_SearchList *search;
48
49static enum GNUNET_FSUI_EventType lastEvent;
50
51static struct GNUNET_ECRS_URI *uri;
52
53static int availability;
54
55static unsigned int rank;
56
57static enum GNUNET_FSUI_EventType waitForEvent;
58
59static void *
60eventCallback (void *cls, const GNUNET_FSUI_Event * event)
61{
62 static char unused;
63
64 switch (event->type)
65 {
66 case GNUNET_FSUI_search_resumed:
67 search = event->data.SearchResumed.sc.pos;
68 break;
69 case GNUNET_FSUI_search_suspended:
70 search = NULL;
71 break;
72 case GNUNET_FSUI_search_update:
73 availability = event->data.SearchUpdate.availability_rank;
74 rank = event->data.SearchUpdate.applicability_rank;
75 break;
76 case GNUNET_FSUI_search_paused:
77 case GNUNET_FSUI_search_restarted:
78 break;
79 case GNUNET_FSUI_download_resumed:
80 case GNUNET_FSUI_upload_resumed:
81 case GNUNET_FSUI_unindex_resumed:
82 return &unused;
83 case GNUNET_FSUI_search_result:
84#if CHECK_VERBOSE
85 printf ("Received search result\n");
86#endif
87 uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
88 break;
89 case GNUNET_FSUI_upload_completed:
90#if CHECK_VERBOSE
91 printf ("Upload complete.\n");
92#endif
93 break;
94 case GNUNET_FSUI_download_completed:
95#if CHECK_VERBOSE
96 printf ("Download complete.\n");
97#endif
98 break;
99 case GNUNET_FSUI_unindex_completed:
100#if CHECK_VERBOSE
101 printf ("Unindex complete.\n");
102#endif
103 break;
104 case GNUNET_FSUI_upload_error:
105 printf ("Upload error.\n");
106 break;
107 case GNUNET_FSUI_download_error:
108 printf ("Download error.\n");
109 break;
110 case GNUNET_FSUI_unindex_error:
111 printf ("Unindex error.\n");
112 break;
113 default:
114 break;
115 }
116 if (lastEvent != waitForEvent)
117 lastEvent = event->type;
118 return NULL;
119}
120
121#define START_DAEMON 1
122
123int
124main (int argc, char *argv[])
125{
126#if START_DAEMON
127 struct GNUNET_OS_Process *daemon;
128#endif
129 int ok;
130 char *fn = NULL;
131
132 char *keywords[] = {
133 "search_foo",
134 "search_bar",
135 };
136 char keyword[40];
137 int prog;
138 struct GNUNET_MetaData *meta;
139 struct GNUNET_ECRS_URI *kuri;
140 struct GNUNET_GC_Configuration *cfg;
141 struct GNUNET_FSUI_UploadList *upload;
142 struct GNUNET_ECRS_URI *luri;
143 struct GNUNET_FSUI_Context *ctx = NULL;
144
145 ok = GNUNET_YES;
146 cfg = GNUNET_GC_create ();
147 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
148 {
149 GNUNET_GC_free (cfg);
150 return -1;
151 }
152#if START_DAEMON
153 GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-searchranktest/");
154 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
155 GNUNET_GE_ASSERT (NULL, daemon != NULL);
156 CHECK (GNUNET_OK ==
157 GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS));
158 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
159 /* ACTUAL TEST CODE */
160#endif
161 ctx =
162 GNUNET_FSUI_start (NULL, cfg, "fsuisearchranktest", 32, GNUNET_YES,
163 &eventCallback, NULL);
164 CHECK (ctx != NULL);
165 /* upload */
166 fn = makeName (42);
167 GNUNET_disk_file_write (NULL, fn, "foo bar test!", strlen ("foo bar test!"),
168 "600");
169 meta = GNUNET_meta_data_create ();
170 kuri =
171 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
172 (const char **) keywords);
173 waitForEvent = GNUNET_FSUI_upload_completed;
174 upload =
175 GNUNET_FSUI_upload_start (ctx, fn,
176 (GNUNET_FSUI_DirectoryScanCallback) &
177 GNUNET_disk_directory_scan, NULL, 0, 0,
178 GNUNET_YES, GNUNET_NO, GNUNET_NO,
179 GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
180 meta, kuri, kuri);
181 CHECK (NULL != upload);
182 GNUNET_free (fn);
183 fn = NULL;
184 GNUNET_ECRS_uri_destroy (kuri);
185 GNUNET_meta_data_destroy (meta);
186 prog = 0;
187 while (lastEvent != GNUNET_FSUI_upload_completed)
188 {
189 prog++;
190 if (prog == 10000)
191 {
192 FPRINTF (stderr, "Upload failed to complete -- last event: %u\n",
193 lastEvent);
194 }
195 CHECK (prog < 10000);
196 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
197 if (GNUNET_shutdown_test () == GNUNET_YES)
198 break;
199 }
200 GNUNET_FSUI_upload_stop (upload);
201
202 /* search */
203 GNUNET_snprintf (keyword, 40, "%s %s", keywords[0], keywords[1]);
204 luri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
205 uri = NULL;
206 search = GNUNET_FSUI_search_start (ctx, 0, luri);
207 GNUNET_ECRS_uri_destroy (luri);
208 luri = NULL;
209 CHECK (NULL != search);
210 GNUNET_FSUI_search_pause (search);
211 GNUNET_FSUI_search_restart (search);
212 while ((uri == NULL) && (availability < 3) && (rank != 2) &&
213 (GNUNET_shutdown_test () != GNUNET_YES))
214 {
215 prog++;
216 CHECK (prog < 10000);
217 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
218 }
219 GNUNET_FSUI_search_abort (search);
220 GNUNET_FSUI_search_stop (search);
221 CHECK (uri != NULL);
222
223
224 /* END OF TEST CODE */
225FAILURE:
226 if (ctx != NULL)
227 GNUNET_FSUI_stop (ctx);
228 GNUNET_free_non_null (fn);
229 /* TODO: verify file 'fn(42)' == file 'fn(43)' */
230 fn = makeName (42);
231 UNLINK (fn);
232 GNUNET_free (fn);
233 fn = makeName (43);
234 UNLINK (fn);
235 GNUNET_free (fn);
236
237#if START_DAEMON
238 GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
239 GNUNET_OS_process_destroy (daemon);
240 daemon = NULL;
241#endif
242 GNUNET_GC_free (cfg);
243 return (ok == GNUNET_YES) ? 0 : 1;
244}
245
246/* end of searchtest.c */