diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-15 08:38:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-15 08:38:53 +0000 |
commit | 36ca9fcc68935edd109481d30f9e6e15a825c282 (patch) | |
tree | 5c976b741a314b5c3486124a9bff74b4ab5f5b78 /src/fs/test_fs_search.c | |
parent | e825548ea9a45d1f4b25898f87b5c74f8bc4cc25 (diff) | |
download | gnunet-36ca9fcc68935edd109481d30f9e6e15a825c282.tar.gz gnunet-36ca9fcc68935edd109481d30f9e6e15a825c282.zip |
-simplifying tests with new testing lib
Diffstat (limited to 'src/fs/test_fs_search.c')
-rw-r--r-- | src/fs/test_fs_search.c | 95 |
1 files changed, 15 insertions, 80 deletions
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index 04c5897ac..1ae84a8d0 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.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.c | 21 | * @file fs/test_fs_search.c |
23 | * @brief simple testcase for simple publish + search operation | 22 | * @brief simple testcase for simple publish + 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 | ||
51 | struct 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 | |||
60 | static struct PeerContext p1; | ||
61 | 46 | ||
62 | static struct GNUNET_TIME_Absolute start; | 47 | static struct GNUNET_TIME_Absolute start; |
63 | 48 | ||
@@ -96,14 +81,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
96 | switch (event->status) | 81 | switch (event->status) |
97 | { | 82 | { |
98 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 83 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
99 | #if VERBOSE | 84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
100 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 85 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
101 | (unsigned long long) event->value.publish.completed, | 86 | (unsigned long long) event->value.publish.completed, |
102 | (unsigned long long) event->value.publish.size, | 87 | (unsigned long long) event->value.publish.size, |
103 | event->value.publish.specifics.progress.depth, | 88 | event->value.publish.specifics.progress.depth, |
104 | (unsigned long long) event->value.publish.specifics. | 89 | (unsigned long long) event->value.publish.specifics. |
105 | progress.offset); | 90 | progress.offset); |
106 | #endif | ||
107 | break; | 91 | break; |
108 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 92 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
109 | kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); | 93 | kuri = GNUNET_FS_uri_ksk_create_from_args (1, keywords); |
@@ -115,9 +99,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
115 | GNUNET_assert (search != NULL); | 99 | GNUNET_assert (search != NULL); |
116 | break; | 100 | break; |
117 | case GNUNET_FS_STATUS_SEARCH_RESULT: | 101 | case GNUNET_FS_STATUS_SEARCH_RESULT: |
118 | #if VERBOSE | 102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
119 | printf ("Search complete.\n"); | 103 | "Search complete.\n"); |
120 | #endif | ||
121 | GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL, | 104 | GNUNET_SCHEDULER_add_continuation (&abort_search_task, NULL, |
122 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 105 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
123 | break; | 106 | break; |
@@ -169,41 +152,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
169 | 152 | ||
170 | 153 | ||
171 | static void | 154 | static void |
172 | setup_peer (struct PeerContext *p, const char *cfgname) | 155 | run (void *cls, |
173 | { | ||
174 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
175 | #if START_ARM | ||
176 | p->arm_proc = | ||
177 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
178 | "gnunet-service-arm", | ||
179 | "-c", cfgname, NULL); | ||
180 | #endif | ||
181 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
182 | } | ||
183 | |||
184 | |||
185 | static void | ||
186 | stop_arm (struct PeerContext *p) | ||
187 | { | ||
188 | #if START_ARM | ||
189 | if (NULL != p->arm_proc) | ||
190 | { | ||
191 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
192 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
193 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | ||
194 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | ||
196 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
197 | GNUNET_OS_process_destroy (p->arm_proc); | ||
198 | p->arm_proc = NULL; | ||
199 | } | ||
200 | #endif | ||
201 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
202 | } | ||
203 | |||
204 | |||
205 | static void | ||
206 | run (void *cls, char *const *args, const char *cfgfile, | ||
207 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 156 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
208 | { | 157 | { |
209 | const char *keywords[] = { | 158 | const char *keywords[] = { |
@@ -217,7 +166,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
217 | struct GNUNET_FS_FileInformation *fi; | 166 | struct GNUNET_FS_FileInformation *fi; |
218 | size_t i; | 167 | size_t i; |
219 | 168 | ||
220 | setup_peer (&p1, "test_fs_search_data.conf"); | ||
221 | fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, | 169 | fs = GNUNET_FS_start (cfg, "test-fs-search", &progress_cb, NULL, |
222 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 170 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
223 | GNUNET_assert (NULL != fs); | 171 | GNUNET_assert (NULL != fs); |
@@ -247,23 +195,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
247 | int | 195 | int |
248 | main (int argc, char *argv[]) | 196 | main (int argc, char *argv[]) |
249 | { | 197 | { |
250 | char *const argvx[] = { | 198 | if (0 != GNUNET_TESTING_peer_run ("test-fs-search", |
251 | "test-fs-search", | 199 | "test_fs_search_data.conf", |
252 | "-c", | 200 | &run, NULL)) |
253 | "test_fs_search_data.conf", | 201 | return 1; |
254 | NULL | ||
255 | }; | ||
256 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
257 | GNUNET_GETOPT_OPTION_END | ||
258 | }; | ||
259 | |||
260 | GNUNET_log_setup ("test_fs_search", | ||
261 | "WARNING", | ||
262 | NULL); | ||
263 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | ||
264 | "test-fs-search", "nohelp", options, &run, NULL); | ||
265 | stop_arm (&p1); | ||
266 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-search/"); | ||
267 | return 0; | 202 | return 0; |
268 | } | 203 | } |
269 | 204 | ||