diff options
Diffstat (limited to 'src/fs/test_gnunet_service_fs_migration.c')
-rw-r--r-- | src/fs/test_gnunet_service_fs_migration.c | 101 |
1 files changed, 35 insertions, 66 deletions
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c index 00aab4f42..f1f2084f9 100644 --- a/src/fs/test_gnunet_service_fs_migration.c +++ b/src/fs/test_gnunet_service_fs_migration.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -25,7 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "fs_test_lib.h" | 27 | #include "fs_test_lib.h" |
28 | #include "gnunet_testing_lib.h" | 28 | #include "gnunet_testbed_service.h" |
29 | 29 | ||
30 | #define VERBOSE GNUNET_NO | 30 | #define VERBOSE GNUNET_NO |
31 | 31 | ||
@@ -46,13 +46,12 @@ | |||
46 | 46 | ||
47 | #define SEED 42 | 47 | #define SEED 42 |
48 | 48 | ||
49 | static struct GNUNET_FS_TestDaemon *daemons[2]; | 49 | static struct GNUNET_TESTBED_Peer *daemons[2]; |
50 | 50 | ||
51 | static int ok; | 51 | static int ok; |
52 | 52 | ||
53 | static struct GNUNET_TIME_Absolute start_time; | 53 | static struct GNUNET_TIME_Absolute start_time; |
54 | 54 | ||
55 | static struct GNUNET_FS_TEST_ConnectContext *cc; | ||
56 | 55 | ||
57 | static void | 56 | static void |
58 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 57 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -60,12 +59,7 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
60 | struct GNUNET_TIME_Relative del; | 59 | struct GNUNET_TIME_Relative del; |
61 | char *fancy; | 60 | char *fancy; |
62 | 61 | ||
63 | if (NULL != cc) | 62 | GNUNET_SCHEDULER_shutdown (); |
64 | { | ||
65 | GNUNET_FS_TEST_daemons_connect_cancel (cc); | ||
66 | cc = NULL; | ||
67 | } | ||
68 | GNUNET_FS_TEST_daemons_stop (2, daemons); | ||
69 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 63 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
70 | { | 64 | { |
71 | del = GNUNET_TIME_absolute_get_duration (start_time); | 65 | del = GNUNET_TIME_absolute_get_duration (start_time); |
@@ -89,13 +83,14 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
89 | 83 | ||
90 | 84 | ||
91 | static void | 85 | static void |
92 | do_download (void *cls, const char *emsg) | 86 | do_download (void *cls, |
87 | const char *emsg) | ||
93 | { | 88 | { |
94 | struct GNUNET_FS_Uri *uri = cls; | 89 | struct GNUNET_FS_Uri *uri = cls; |
95 | 90 | ||
96 | if (emsg != NULL) | 91 | if (NULL != emsg) |
97 | { | 92 | { |
98 | GNUNET_FS_TEST_daemons_stop (2, daemons); | 93 | GNUNET_SCHEDULER_shutdown (); |
99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n", | 94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to stop source daemon: %s\n", |
100 | emsg); | 95 | emsg); |
101 | GNUNET_FS_uri_destroy (uri); | 96 | GNUNET_FS_uri_destroy (uri); |
@@ -115,11 +110,9 @@ static void | |||
115 | stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 110 | stop_source_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
116 | { | 111 | { |
117 | struct GNUNET_FS_Uri *uri = cls; | 112 | struct GNUNET_FS_Uri *uri = cls; |
118 | struct GNUNET_TESTING_PeerGroup *pg; | ||
119 | 113 | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n"); | 114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping source peer\n"); |
121 | pg = GNUNET_FS_TEST_get_group (daemons); | 115 | GNUNET_TESTBED_peer_stop (daemons[1], &do_download, uri); |
122 | GNUNET_TESTING_daemons_vary (pg, 1, GNUNET_NO, TIMEOUT, &do_download, uri); | ||
123 | } | 116 | } |
124 | 117 | ||
125 | 118 | ||
@@ -130,7 +123,7 @@ do_wait (void *cls, const struct GNUNET_FS_Uri *uri) | |||
130 | 123 | ||
131 | if (NULL == uri) | 124 | if (NULL == uri) |
132 | { | 125 | { |
133 | GNUNET_FS_TEST_daemons_stop (2, daemons); | 126 | GNUNET_SCHEDULER_shutdown (); |
134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
135 | "Timeout during upload attempt, shutting down with error\n"); | 128 | "Timeout during upload attempt, shutting down with error\n"); |
136 | ok = 1; | 129 | ok = 1; |
@@ -143,14 +136,16 @@ do_wait (void *cls, const struct GNUNET_FS_Uri *uri) | |||
143 | 136 | ||
144 | 137 | ||
145 | static void | 138 | static void |
146 | do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 139 | do_publish (void *cls, |
140 | struct GNUNET_TESTBED_Operation *op, | ||
141 | const char *emsg) | ||
147 | { | 142 | { |
148 | cc = NULL; | 143 | if (NULL != emsg) |
149 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | ||
150 | { | 144 | { |
151 | GNUNET_FS_TEST_daemons_stop (2, daemons); | 145 | GNUNET_SCHEDULER_shutdown (); |
152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
153 | "Timeout during connect attempt, shutting down with error\n"); | 147 | "Error connecting peers: %s\n", |
148 | emsg); | ||
154 | ok = 1; | 149 | ok = 1; |
155 | return; | 150 | return; |
156 | } | 151 | } |
@@ -162,58 +157,32 @@ do_publish (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
162 | 157 | ||
163 | 158 | ||
164 | static void | 159 | static void |
165 | do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 160 | do_connect (void *cls, |
161 | unsigned int num_peers, | ||
162 | struct GNUNET_TESTBED_Peer **peers) | ||
166 | { | 163 | { |
167 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 164 | unsigned int i; |
168 | { | 165 | |
169 | FPRINTF (stderr, "%s", "Daemons failed to start!\n"); | 166 | GNUNET_assert (2 == num_peers); |
170 | GNUNET_break (0); | 167 | for (i=0;i<num_peers;i++) |
171 | ok = 1; | 168 | daemons[i] = peers[i]; |
172 | return; | ||
173 | } | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Daemons started, will now try to connect them\n"); | 170 | "Daemons started, will now try to connect them\n"); |
176 | cc = GNUNET_FS_TEST_daemons_connect (daemons[0], daemons[1], TIMEOUT, | 171 | GNUNET_TESTBED_overlay_connect (NULL, |
177 | &do_publish, NULL); | 172 | &do_publish, NULL, |
178 | } | 173 | daemons[0], daemons[1]); |
179 | |||
180 | |||
181 | static void | ||
182 | run (void *cls, char *const *args, const char *cfgfile, | ||
183 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
184 | { | ||
185 | GNUNET_FS_TEST_daemons_start ("test_gnunet_service_fs_migration_data.conf", | ||
186 | TIMEOUT, 2, daemons, &do_connect, NULL); | ||
187 | } | 174 | } |
188 | 175 | ||
189 | 176 | ||
190 | int | 177 | int |
191 | main (int argc, char *argv[]) | 178 | main (int argc, char *argv[]) |
192 | { | 179 | { |
193 | char *const argvx[] = { | 180 | GNUNET_TESTBED_test_run ("test-gnunet-service-fs-migration", |
194 | "test-gnunet-service-fs-migration", | 181 | "fs_test_lib_data.conf", |
195 | "-c", | 182 | 2, |
196 | "fs_test_lib_data.conf", | 183 | 0, NULL, NULL, |
197 | #if VERBOSE | 184 | &do_connect, |
198 | "-L", "DEBUG", | 185 | NULL); |
199 | #endif | ||
200 | NULL | ||
201 | }; | ||
202 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
203 | GNUNET_GETOPT_OPTION_END | ||
204 | }; | ||
205 | |||
206 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); | ||
207 | GNUNET_log_setup ("test_gnunet_service_fs_migration", | ||
208 | #if VERBOSE | ||
209 | "DEBUG", | ||
210 | #else | ||
211 | "WARNING", | ||
212 | #endif | ||
213 | NULL); | ||
214 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | ||
215 | "test-gnunet-service-fs-migration", "nohelp", options, | ||
216 | &run, NULL); | ||
217 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); | 186 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-service-fs-migration/"); |
218 | return ok; | 187 | return ok; |
219 | } | 188 | } |