aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_search_ranking.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-08-22 17:57:31 +0000
committerChristian Grothoff <christian@grothoff.org>2009-08-22 17:57:31 +0000
commit2ae973618f3b51fa9bbf5532eaa1352cafc24ecc (patch)
treeea8bb13a4c7d390f88318b61bc6caf50ea6cf400 /src/fs/test_fs_search_ranking.c
parent9a10e9c06a3b08c8ab73edb7d2093a6d452ecc05 (diff)
downloadgnunet-2ae973618f3b51fa9bbf5532eaa1352cafc24ecc.tar.gz
gnunet-2ae973618f3b51fa9bbf5532eaa1352cafc24ecc.zip
stuff
Diffstat (limited to 'src/fs/test_fs_search_ranking.c')
-rw-r--r--src/fs/test_fs_search_ranking.c250
1 files changed, 250 insertions, 0 deletions
diff --git a/src/fs/test_fs_search_ranking.c b/src/fs/test_fs_search_ranking.c
new file mode 100644
index 000000000..caaa0f9f1
--- /dev/null
+++ b/src/fs/test_fs_search_ranking.c
@@ -0,0 +1,250 @@
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 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/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 =
41 GNUNET_malloc (strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14);
42 GNUNET_snprintf (fn,
43 strlen ("/tmp/gnunet-fsui-searchranktest/FSUITEST") + 14,
44 "/tmp/gnunet-fsui-searchranktest/FSUITEST%u", i);
45 GNUNET_disk_directory_create_for_file (NULL, fn);
46 return fn;
47}
48
49static struct GNUNET_FSUI_SearchList *search;
50
51static volatile enum GNUNET_FSUI_EventType lastEvent;
52
53static volatile struct GNUNET_ECRS_URI *uri;
54
55static volatile int availability;
56
57static volatile unsigned int rank;
58
59static volatile enum GNUNET_FSUI_EventType waitForEvent;
60
61static void *
62eventCallback (void *cls, const GNUNET_FSUI_Event * event)
63{
64 static char unused;
65
66 switch (event->type)
67 {
68 case GNUNET_FSUI_search_resumed:
69 search = event->data.SearchResumed.sc.pos;
70 break;
71 case GNUNET_FSUI_search_suspended:
72 search = NULL;
73 break;
74 case GNUNET_FSUI_search_update:
75 availability = event->data.SearchUpdate.availability_rank;
76 rank = event->data.SearchUpdate.applicability_rank;
77 break;
78 case GNUNET_FSUI_search_paused:
79 case GNUNET_FSUI_search_restarted:
80 break;
81 case GNUNET_FSUI_download_resumed:
82 case GNUNET_FSUI_upload_resumed:
83 case GNUNET_FSUI_unindex_resumed:
84 return &unused;
85 case GNUNET_FSUI_search_result:
86#if CHECK_VERBOSE
87 printf ("Received search result\n");
88#endif
89 uri = GNUNET_ECRS_uri_duplicate (event->data.SearchResult.fi.uri);
90 break;
91 case GNUNET_FSUI_upload_completed:
92#if CHECK_VERBOSE
93 printf ("Upload complete.\n");
94#endif
95 break;
96 case GNUNET_FSUI_download_completed:
97#if CHECK_VERBOSE
98 printf ("Download complete.\n");
99#endif
100 break;
101 case GNUNET_FSUI_unindex_completed:
102#if CHECK_VERBOSE
103 printf ("Unindex complete.\n");
104#endif
105 break;
106 case GNUNET_FSUI_upload_error:
107 printf ("Upload error.\n");
108 break;
109 case GNUNET_FSUI_download_error:
110 printf ("Download error.\n");
111 break;
112 case GNUNET_FSUI_unindex_error:
113 printf ("Unindex error.\n");
114 break;
115 default:
116 break;
117 }
118 if (lastEvent != waitForEvent)
119 lastEvent = event->type;
120 return NULL;
121}
122
123#define START_DAEMON 1
124
125int
126main (int argc, char *argv[])
127{
128#if START_DAEMON
129 pid_t daemon;
130#endif
131 int ok;
132 char *fn = NULL;
133 char *keywords[] = {
134 "search_foo",
135 "search_bar",
136 };
137 char keyword[40];
138 int prog;
139 struct GNUNET_MetaData *meta;
140 struct GNUNET_ECRS_URI *kuri;
141 struct GNUNET_GC_Configuration *cfg;
142 struct GNUNET_FSUI_UploadList *upload;
143 struct GNUNET_ECRS_URI *luri;
144 struct GNUNET_FSUI_Context *ctx = NULL;
145
146 ok = GNUNET_YES;
147 cfg = GNUNET_GC_create ();
148 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
149 {
150 GNUNET_GC_free (cfg);
151 return -1;
152 }
153#if START_DAEMON
154 GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-searchranktest/");
155 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
156 GNUNET_GE_ASSERT (NULL, daemon > 0);
157 CHECK (GNUNET_OK ==
158 GNUNET_wait_for_daemon_running (NULL, cfg,
159 30 * GNUNET_CRON_SECONDS));
160 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
161 /* ACTUAL TEST CODE */
162#endif
163 ctx = GNUNET_FSUI_start (NULL,
164 cfg, "fsuisearchranktest", 32, GNUNET_YES,
165 &eventCallback, NULL);
166 CHECK (ctx != NULL);
167 /* upload */
168 fn = makeName (42);
169 GNUNET_disk_file_write (NULL,
170 fn, "foo bar test!", strlen ("foo bar test!"),
171 "600");
172 meta = GNUNET_meta_data_create ();
173 kuri =
174 GNUNET_ECRS_keyword_command_line_to_uri (NULL, 2,
175 (const char **) keywords);
176 waitForEvent = GNUNET_FSUI_upload_completed;
177 upload =
178 GNUNET_FSUI_upload_start (ctx,
179 fn,
180 (GNUNET_FSUI_DirectoryScanCallback) &
181 GNUNET_disk_directory_scan, NULL, 0, 0,
182 GNUNET_YES, GNUNET_NO, GNUNET_NO,
183 GNUNET_get_time () + 5 * GNUNET_CRON_HOURS,
184 meta, kuri, kuri);
185 CHECK (NULL != upload);
186 GNUNET_free (fn);
187 fn = NULL;
188 GNUNET_ECRS_uri_destroy (kuri);
189 GNUNET_meta_data_destroy (meta);
190 prog = 0;
191 while (lastEvent != GNUNET_FSUI_upload_completed)
192 {
193 prog++;
194 if (prog == 10000)
195 {
196 fprintf (stderr,
197 "Upload failed to complete -- last event: %u\n",
198 lastEvent);
199 }
200 CHECK (prog < 10000);
201 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
202 if (GNUNET_shutdown_test () == GNUNET_YES)
203 break;
204 }
205 GNUNET_FSUI_upload_stop (upload);
206
207 /* search */
208 GNUNET_snprintf (keyword, 40, "%s %s", keywords[0], keywords[1]);
209 luri = GNUNET_ECRS_keyword_string_to_uri (NULL, keyword);
210 uri = NULL;
211 search = GNUNET_FSUI_search_start (ctx, 0, luri);
212 GNUNET_ECRS_uri_destroy (luri);
213 luri = NULL;
214 CHECK (NULL != search);
215 GNUNET_FSUI_search_pause (search);
216 GNUNET_FSUI_search_restart (search);
217 while ((uri == NULL) &&
218 (availability < 3) &&
219 (rank != 2) && (GNUNET_shutdown_test () != GNUNET_YES))
220 {
221 prog++;
222 CHECK (prog < 10000);
223 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
224 }
225 GNUNET_FSUI_search_abort (search);
226 GNUNET_FSUI_search_stop (search);
227 CHECK (uri != NULL);
228
229
230 /* END OF TEST CODE */
231FAILURE:
232 if (ctx != NULL)
233 GNUNET_FSUI_stop (ctx);
234 GNUNET_free_non_null (fn);
235 /* TODO: verify file 'fn(42)' == file 'fn(43)' */
236 fn = makeName (42);
237 UNLINK (fn);
238 GNUNET_free (fn);
239 fn = makeName (43);
240 UNLINK (fn);
241 GNUNET_free (fn);
242
243#if START_DAEMON
244 GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
245#endif
246 GNUNET_GC_free (cfg);
247 return (ok == GNUNET_YES) ? 0 : 1;
248}
249
250/* end of searchtest.c */