diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-15 08:10:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-15 08:10:52 +0000 |
commit | e825548ea9a45d1f4b25898f87b5c74f8bc4cc25 (patch) | |
tree | 0a0236af09b77d8e32693c1e9fb7db4affd9ce8a /src/fs/test_fs_unindex.c | |
parent | 9f4e1f6e097b3c97abe0971b68b2ab686a61f036 (diff) | |
download | gnunet-e825548ea9a45d1f4b25898f87b5c74f8bc4cc25.tar.gz gnunet-e825548ea9a45d1f4b25898f87b5c74f8bc4cc25.zip |
-simplifying tests with new testing lib
Diffstat (limited to 'src/fs/test_fs_unindex.c')
-rw-r--r-- | src/fs/test_fs_unindex.c | 118 |
1 files changed, 20 insertions, 98 deletions
diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index ee76bf9f3..52e1845a7 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c | |||
@@ -23,15 +23,11 @@ | |||
23 | * @brief simple testcase for simple publish + unindex operation | 23 | * @brief simple testcase for simple publish + unindex operation |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_arm_service.h" | ||
30 | #include "gnunet_fs_service.h" | 28 | #include "gnunet_fs_service.h" |
29 | #include "gnunet_testing_lib-new.h" | ||
31 | 30 | ||
32 | #define VERBOSE GNUNET_NO | ||
33 | |||
34 | #define START_ARM GNUNET_YES | ||
35 | 31 | ||
36 | /** | 32 | /** |
37 | * File-size we use for testing. | 33 | * File-size we use for testing. |
@@ -48,15 +44,6 @@ | |||
48 | */ | 44 | */ |
49 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 45 | #define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
50 | 46 | ||
51 | struct PeerContext | ||
52 | { | ||
53 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
54 | #if START_ARM | ||
55 | struct GNUNET_OS_Process *arm_proc; | ||
56 | #endif | ||
57 | }; | ||
58 | |||
59 | static struct PeerContext p1; | ||
60 | 47 | ||
61 | static struct GNUNET_TIME_Absolute start; | 48 | static struct GNUNET_TIME_Absolute start; |
62 | 49 | ||
@@ -95,14 +82,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
95 | switch (event->status) | 82 | switch (event->status) |
96 | { | 83 | { |
97 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 84 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
98 | #if VERBOSE | 85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
99 | printf ("Publish is progressing (%llu/%llu at level %u off %llu)...\n", | 86 | "Publish is progressing (%llu/%llu at level %u off %llu)...\n", |
100 | (unsigned long long) event->value.publish.completed, | 87 | (unsigned long long) event->value.publish.completed, |
101 | (unsigned long long) event->value.publish.size, | 88 | (unsigned long long) event->value.publish.size, |
102 | event->value.publish.specifics.progress.depth, | 89 | event->value.publish.specifics.progress.depth, |
103 | (unsigned long long) event->value.publish.specifics. | 90 | (unsigned long long) event->value.publish.specifics. |
104 | progress.offset); | 91 | progress.offset); |
105 | #endif | ||
106 | break; | 92 | break; |
107 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 93 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
108 | printf ("Publishing complete, %llu kbps.\n", | 94 | printf ("Publishing complete, %llu kbps.\n", |
@@ -125,14 +111,13 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
125 | break; | 111 | break; |
126 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 112 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
127 | GNUNET_assert (unindex == event->value.unindex.uc); | 113 | GNUNET_assert (unindex == event->value.unindex.uc); |
128 | #if VERBOSE | 114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
129 | printf ("Unindex is progressing (%llu/%llu at level %u off %llu)...\n", | 115 | "Unindex is progressing (%llu/%llu at level %u off %llu)...\n", |
130 | (unsigned long long) event->value.unindex.completed, | 116 | (unsigned long long) event->value.unindex.completed, |
131 | (unsigned long long) event->value.unindex.size, | 117 | (unsigned long long) event->value.unindex.size, |
132 | event->value.unindex.specifics.progress.depth, | 118 | event->value.unindex.specifics.progress.depth, |
133 | (unsigned long long) event->value.unindex.specifics. | 119 | (unsigned long long) event->value.unindex.specifics. |
134 | progress.offset); | 120 | progress.offset); |
135 | #endif | ||
136 | break; | 121 | break; |
137 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 122 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
138 | FPRINTF (stderr, "Error publishing file: %s\n", | 123 | FPRINTF (stderr, "Error publishing file: %s\n", |
@@ -182,44 +167,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) | |||
182 | 167 | ||
183 | 168 | ||
184 | static void | 169 | static void |
185 | setup_peer (struct PeerContext *p, const char *cfgname) | 170 | run (void *cls, |
186 | { | ||
187 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
188 | #if START_ARM | ||
189 | p->arm_proc = | ||
190 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
191 | "gnunet-service-arm", | ||
192 | #if VERBOSE | ||
193 | "-L", "DEBUG", | ||
194 | #endif | ||
195 | "-c", cfgname, NULL); | ||
196 | #endif | ||
197 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
198 | } | ||
199 | |||
200 | |||
201 | static void | ||
202 | stop_arm (struct PeerContext *p) | ||
203 | { | ||
204 | #if START_ARM | ||
205 | if (NULL != p->arm_proc) | ||
206 | { | ||
207 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
208 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
209 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | ||
210 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | ||
212 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
213 | GNUNET_OS_process_destroy (p->arm_proc); | ||
214 | p->arm_proc = NULL; | ||
215 | } | ||
216 | #endif | ||
217 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
218 | } | ||
219 | |||
220 | |||
221 | static void | ||
222 | run (void *cls, char *const *args, const char *cfgfile, | ||
223 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 171 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
224 | { | 172 | { |
225 | const char *keywords[] = { | 173 | const char *keywords[] = { |
@@ -233,7 +181,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
233 | size_t i; | 181 | size_t i; |
234 | struct GNUNET_FS_BlockOptions bo; | 182 | struct GNUNET_FS_BlockOptions bo; |
235 | 183 | ||
236 | setup_peer (&p1, "test_fs_unindex_data.conf"); | ||
237 | fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); | 184 | fn = GNUNET_DISK_mktemp ("gnunet-unindex-test-dst"); |
238 | fs = GNUNET_FS_start (cfg, "test-fs-unindex", &progress_cb, NULL, | 185 | fs = GNUNET_FS_start (cfg, "test-fs-unindex", &progress_cb, NULL, |
239 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 186 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
@@ -269,35 +216,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
269 | int | 216 | int |
270 | main (int argc, char *argv[]) | 217 | main (int argc, char *argv[]) |
271 | { | 218 | { |
272 | char *const argvx[] = { | 219 | if (0 != GNUNET_TESTING_peer_run ("test-fs-unindex", |
273 | "test-fs-unindex", | 220 | "test_fs_unindex_data.conf", |
274 | "-c", | 221 | &run, NULL)) |
275 | "test_fs_unindex_data.conf", | 222 | return 1; |
276 | #if VERBOSE | ||
277 | "-L", "DEBUG", | ||
278 | #endif | ||
279 | NULL | ||
280 | }; | ||
281 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
282 | GNUNET_GETOPT_OPTION_END | ||
283 | }; | ||
284 | |||
285 | GNUNET_log_setup ("test_fs_unindex", | ||
286 | #if VERBOSE | ||
287 | "DEBUG", | ||
288 | #else | ||
289 | "WARNING", | ||
290 | #endif | ||
291 | NULL); | ||
292 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | ||
293 | "test-fs-unindex", "nohelp", options, &run, NULL); | ||
294 | stop_arm (&p1); | ||
295 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-unindex/"); | ||
296 | if (NULL != fn) | ||
297 | { | ||
298 | GNUNET_DISK_directory_remove (fn); | ||
299 | GNUNET_free (fn); | ||
300 | } | ||
301 | return 0; | 223 | return 0; |
302 | } | 224 | } |
303 | 225 | ||