diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-05-26 20:01:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-05-26 20:01:48 +0000 |
commit | 43677cdd03d9a1219b9a1211f27c04f69732dfbc (patch) | |
tree | 65bef0307a192d6bc3815d80d1cdf1071389ee2c | |
parent | d0e25cca5eb56a18bd4feddcb4235aff09131a80 (diff) | |
download | gnunet-43677cdd03d9a1219b9a1211f27c04f69732dfbc.tar.gz gnunet-43677cdd03d9a1219b9a1211f27c04f69732dfbc.zip |
harness
-rw-r--r-- | src/fs/Makefile.am | 10 | ||||
-rw-r--r-- | src/fs/test_gnunet_service_fs_migration.c | 209 |
2 files changed, 219 insertions, 0 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 9ba7f1062..463ba2875 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -133,6 +133,7 @@ check_PROGRAMS = \ | |||
133 | test_fs_unindex \ | 133 | test_fs_unindex \ |
134 | test_fs_unindex_persistence \ | 134 | test_fs_unindex_persistence \ |
135 | test_fs_uri \ | 135 | test_fs_uri \ |
136 | test_gnunet_service_fs_migration \ | ||
136 | test_gnunet_service_fs_p2p | 137 | test_gnunet_service_fs_p2p |
137 | 138 | ||
138 | 139 | ||
@@ -161,6 +162,7 @@ TESTS = \ | |||
161 | test_fs_unindex_persistence \ | 162 | test_fs_unindex_persistence \ |
162 | test_fs_uri \ | 163 | test_fs_uri \ |
163 | test_fs_test_lib \ | 164 | test_fs_test_lib \ |
165 | test_gnunet_service_fs_migration \ | ||
164 | test_gnunet_service_fs_p2p \ | 166 | test_gnunet_service_fs_p2p \ |
165 | $(check_SCRIPTS) | 167 | $(check_SCRIPTS) |
166 | # $(check_PROGRAMS) | 168 | # $(check_PROGRAMS) |
@@ -282,6 +284,14 @@ test_gnunet_service_fs_p2p_LDADD = \ | |||
282 | $(top_builddir)/src/fs/libgnunetfs.la \ | 284 | $(top_builddir)/src/fs/libgnunetfs.la \ |
283 | $(top_builddir)/src/util/libgnunetutil.la | 285 | $(top_builddir)/src/util/libgnunetutil.la |
284 | 286 | ||
287 | test_gnunet_service_fs_migration_SOURCES = \ | ||
288 | test_gnunet_service_fs_migration.c | ||
289 | test_gnunet_service_fs_migration_LDADD = \ | ||
290 | $(top_builddir)/src/fs/libgnunetfstest.a \ | ||
291 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
292 | $(top_builddir)/src/fs/libgnunetfs.la \ | ||
293 | $(top_builddir)/src/util/libgnunetutil.la | ||
294 | |||
285 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' | 295 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' |
286 | 296 | ||
287 | test_gnunet_fs_psd.py: test_gnunet_fs_psd.py.in Makefile | 297 | test_gnunet_fs_psd.py: test_gnunet_fs_psd.py.in Makefile |
diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c new file mode 100644 index 000000000..8227895ba --- /dev/null +++ b/src/fs/test_gnunet_service_fs_migration.c | |||
@@ -0,0 +1,209 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010 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 fs/test_gnunet_service_fs_migration.c | ||
23 | * @brief test content migration between two peers | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | * TODO: | ||
27 | * - change configuration to enable migration | ||
28 | * - shutdown source peer during download | ||
29 | * - wait long enough to allow for migration between | ||
30 | * publish and download | ||
31 | */ | ||
32 | #include "platform.h" | ||
33 | #include "fs_test_lib.h" | ||
34 | |||
35 | #define VERBOSE GNUNET_NO | ||
36 | |||
37 | /** | ||
38 | * File-size we use for testing. | ||
39 | */ | ||
40 | #define FILESIZE (1024 * 1024 * 2) | ||
41 | |||
42 | /** | ||
43 | * How long until we give up on transmitting the message? | ||
44 | */ | ||
45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600) | ||
46 | |||
47 | #define NUM_DAEMONS 2 | ||
48 | |||
49 | #define SEED 42 | ||
50 | |||
51 | static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS]; | ||
52 | |||
53 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
54 | |||
55 | static int ok; | ||
56 | |||
57 | static struct GNUNET_TIME_Absolute start_time; | ||
58 | |||
59 | static void | ||
60 | do_stop (void *cls, | ||
61 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
62 | { | ||
63 | struct GNUNET_TIME_Relative del; | ||
64 | char *fancy; | ||
65 | |||
66 | GNUNET_FS_TEST_daemons_stop (sched, | ||
67 | NUM_DAEMONS, | ||
68 | daemons); | ||
69 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | ||
70 | { | ||
71 | del = GNUNET_TIME_absolute_get_duration (start_time); | ||
72 | if (del.value == 0) | ||
73 | del.value = 1; | ||
74 | fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.value); | ||
75 | fprintf (stdout, | ||
76 | "Download speed was %s/s\n", | ||
77 | fancy); | ||
78 | GNUNET_free (fancy); | ||
79 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
80 | "Finished download, shutting down\n", | ||
81 | (unsigned long long) FILESIZE); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
86 | "Timeout during download, shutting down with error\n"); | ||
87 | ok = 1; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | |||
92 | static void | ||
93 | do_download (void *cls, | ||
94 | const struct GNUNET_FS_Uri *uri) | ||
95 | { | ||
96 | if (NULL == uri) | ||
97 | { | ||
98 | GNUNET_FS_TEST_daemons_stop (sched, | ||
99 | NUM_DAEMONS, | ||
100 | daemons); | ||
101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
102 | "Timeout during upload attempt, shutting down with error\n"); | ||
103 | ok = 1; | ||
104 | return; | ||
105 | } | ||
106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
107 | "Downloading %llu bytes\n", | ||
108 | (unsigned long long) FILESIZE); | ||
109 | start_time = GNUNET_TIME_absolute_get (); | ||
110 | GNUNET_FS_TEST_download (sched, | ||
111 | daemons[0], | ||
112 | TIMEOUT, | ||
113 | 1, SEED, uri, | ||
114 | VERBOSE, | ||
115 | &do_stop, NULL); | ||
116 | } | ||
117 | |||
118 | |||
119 | static void | ||
120 | do_publish (void *cls, | ||
121 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
122 | { | ||
123 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | ||
124 | { | ||
125 | GNUNET_FS_TEST_daemons_stop (sched, | ||
126 | NUM_DAEMONS, | ||
127 | daemons); | ||
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
129 | "Timeout during connect attempt, shutting down with error\n"); | ||
130 | ok = 1; | ||
131 | return; | ||
132 | } | ||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
134 | "Publishing %llu bytes\n", | ||
135 | (unsigned long long) FILESIZE); | ||
136 | GNUNET_FS_TEST_publish (sched, | ||
137 | daemons[1], | ||
138 | TIMEOUT, | ||
139 | 1, GNUNET_NO, FILESIZE, SEED, | ||
140 | VERBOSE, | ||
141 | &do_download, NULL); | ||
142 | } | ||
143 | |||
144 | |||
145 | static void | ||
146 | do_connect (void *cls, | ||
147 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
148 | { | ||
149 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); | ||
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
151 | "Daemons started, will now try to connect them\n"); | ||
152 | GNUNET_FS_TEST_daemons_connect (sched, | ||
153 | daemons[0], | ||
154 | daemons[1], | ||
155 | TIMEOUT, | ||
156 | &do_publish, | ||
157 | NULL); | ||
158 | } | ||
159 | |||
160 | |||
161 | static void | ||
162 | run (void *cls, | ||
163 | struct GNUNET_SCHEDULER_Handle *s, | ||
164 | char *const *args, | ||
165 | const char *cfgfile, | ||
166 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
167 | { | ||
168 | sched = s; | ||
169 | GNUNET_FS_TEST_daemons_start (sched, | ||
170 | TIMEOUT, | ||
171 | NUM_DAEMONS, | ||
172 | daemons, | ||
173 | &do_connect, | ||
174 | NULL); | ||
175 | } | ||
176 | |||
177 | |||
178 | int | ||
179 | main (int argc, char *argv[]) | ||
180 | { | ||
181 | char *const argvx[] = { | ||
182 | "test-gnunet-service-fs-migration", | ||
183 | "-c", | ||
184 | "fs_test_lib_data.conf", | ||
185 | #if VERBOSE | ||
186 | "-L", "DEBUG", | ||
187 | #endif | ||
188 | NULL | ||
189 | }; | ||
190 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
191 | GNUNET_GETOPT_OPTION_END | ||
192 | }; | ||
193 | |||
194 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | ||
195 | GNUNET_log_setup ("test_gnunet_service_fs_migration", | ||
196 | #if VERBOSE | ||
197 | "DEBUG", | ||
198 | #else | ||
199 | "WARNING", | ||
200 | #endif | ||
201 | NULL); | ||
202 | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, | ||
203 | argvx, "test-gnunet-service-fs-migration", | ||
204 | "nohelp", options, &run, NULL); | ||
205 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); | ||
206 | return ok; | ||
207 | } | ||
208 | |||
209 | /* end of test_gnunet_service_fs_migration.c */ | ||