diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-20 11:39:22 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-20 11:39:22 +0000 |
commit | 07b4a99662666ee11fc1a3684faa3bb55cf8b66f (patch) | |
tree | e15244990b4a35b339b5a7ef548c0b0403d613a9 /src | |
parent | ec15a41714409824c2ac2ab1ee250ad917fa0a0c (diff) | |
download | gnunet-07b4a99662666ee11fc1a3684faa3bb55cf8b66f.tar.gz gnunet-07b4a99662666ee11fc1a3684faa3bb55cf8b66f.zip |
creating a correct testcase
Diffstat (limited to 'src')
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 152 | ||||
-rw-r--r-- | src/hostlist/test_learning_adv_peer.conf | 46 | ||||
-rw-r--r-- | src/hostlist/test_learning_learn_peer.conf | 46 |
3 files changed, 154 insertions, 90 deletions
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index e903574b2..244329ebe 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c | |||
@@ -18,24 +18,26 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file hostlist/test_gnunet_daemon_hostlist_learning.c | 21 | * @file hostlist/test_gnunet_daemon_hostlist.c |
22 | * @brief test for gnunet_daemon_hostslist.c | 22 | * @brief test for gnunet_daemon_hostslist.c |
23 | * @author Christian Grothoff, Matthias Wachs | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
27 | #include "gnunet_arm_service.h" | 27 | #include "gnunet_arm_service.h" |
28 | #include "gnunet_transport_service.h" | 28 | #include "gnunet_transport_service.h" |
29 | 29 | ||
30 | #define VERBOSE GNUNET_YES | ||
30 | 31 | ||
31 | #define START_ARM GNUNET_YES | 32 | #define START_ARM GNUNET_YES |
32 | 33 | ||
34 | |||
33 | /** | 35 | /** |
34 | * How long until we give up on transmitting the message? | 36 | * How long until we give up on transmitting the message? |
35 | */ | 37 | */ |
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) | 38 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
37 | 39 | ||
38 | static int ok; | 40 | static int failure; |
39 | 41 | ||
40 | static struct GNUNET_SCHEDULER_Handle *sched; | 42 | static struct GNUNET_SCHEDULER_Handle *sched; |
41 | 43 | ||
@@ -52,23 +54,22 @@ struct PeerContext | |||
52 | #endif | 54 | #endif |
53 | }; | 55 | }; |
54 | 56 | ||
55 | static struct PeerContext p1; | 57 | static struct PeerContext adv_peer; |
56 | |||
57 | static struct PeerContext p2; | ||
58 | 58 | ||
59 | static struct PeerContext learn_peer; | ||
59 | 60 | ||
60 | static void | 61 | static void |
61 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 62 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
62 | { | 63 | { |
63 | if (p1.th != NULL) | 64 | if (adv_peer.th != NULL) |
64 | { | 65 | { |
65 | GNUNET_TRANSPORT_disconnect (p1.th); | 66 | GNUNET_TRANSPORT_disconnect (adv_peer.th); |
66 | p1.th = NULL; | 67 | adv_peer.th = NULL; |
67 | } | 68 | } |
68 | if (p2.th != NULL) | 69 | if (learn_peer.th != NULL) |
69 | { | 70 | { |
70 | GNUNET_TRANSPORT_disconnect (p2.th); | 71 | GNUNET_TRANSPORT_disconnect (learn_peer.th); |
71 | p2.th = NULL; | 72 | learn_peer.th = NULL; |
72 | } | 73 | } |
73 | GNUNET_SCHEDULER_shutdown (sched); | 74 | GNUNET_SCHEDULER_shutdown (sched); |
74 | } | 75 | } |
@@ -81,59 +82,33 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
81 | { | 82 | { |
82 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 83 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
83 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 84 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
84 | "Timeout trying to connect peers, test failed.\n"); | 85 | "Timeout while executing testcase, test failed.\n"); |
86 | failure = GNUNET_YES; | ||
85 | clean_up (NULL, tc); | 87 | clean_up (NULL, tc); |
86 | } | 88 | } |
87 | 89 | ||
88 | |||
89 | /** | ||
90 | * Function called to notify transport users that another | ||
91 | * peer connected to us. | ||
92 | * | ||
93 | * @param cls closure | ||
94 | * @param peer the peer that connected | ||
95 | * @param latency current latency of the connection | ||
96 | * @param distance in overlay hops, as given by transport plugin | ||
97 | */ | ||
98 | static void | 90 | static void |
99 | notify_connect (void *cls, | 91 | setup_learn_peer (struct PeerContext *p, const char *cfgname) |
100 | const struct GNUNET_PeerIdentity * peer, | ||
101 | struct GNUNET_TIME_Relative latency, | ||
102 | unsigned int distance) | ||
103 | { | 92 | { |
104 | if (peer == NULL) | 93 | p->cfg = GNUNET_CONFIGURATION_create (); |
105 | return; | 94 | #if START_ARM |
106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 95 | p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
107 | "Peers connected, shutting down.\n"); | 96 | "gnunet-service-arm", |
108 | /* | 97 | #if VERBOSE |
109 | ok = 0; | 98 | "-L", "DEBUG", |
110 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | 99 | #endif |
111 | { | 100 | "-c", cfgname, NULL); |
112 | GNUNET_SCHEDULER_cancel (sched, | 101 | #endif |
113 | timeout_task); | 102 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
114 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 103 | GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); |
115 | } | 104 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, |
116 | GNUNET_SCHEDULER_add_now (sched, | 105 | NULL, NULL); |
117 | &clean_up, NULL); | 106 | GNUNET_assert (p->th != NULL); |
118 | */ | ||
119 | } | ||
120 | |||
121 | |||
122 | static void | ||
123 | process_hello (void *cls, | ||
124 | const struct GNUNET_MessageHeader *message) | ||
125 | { | ||
126 | struct PeerContext *p = cls; | ||
127 | |||
128 | GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); | ||
129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
130 | "Received HELLO, starting hostlist service.\n"); | ||
131 | GNUNET_ARM_start_services (p->cfg, sched, "hostlist", NULL); | ||
132 | } | 107 | } |
133 | 108 | ||
134 | 109 | ||
135 | static void | 110 | static void |
136 | setup_peer (struct PeerContext *p, const char *cfgname) | 111 | setup_adv_peer (struct PeerContext *p, const char *cfgname) |
137 | { | 112 | { |
138 | p->cfg = GNUNET_CONFIGURATION_create (); | 113 | p->cfg = GNUNET_CONFIGURATION_create (); |
139 | #if START_ARM | 114 | #if START_ARM |
@@ -147,21 +122,21 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
147 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 122 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
148 | GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); | 123 | GNUNET_ARM_start_services (p->cfg, sched, "core", NULL); |
149 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, | 124 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, |
150 | ¬ify_connect, NULL); | 125 | NULL, NULL); |
151 | GNUNET_assert (p->th != NULL); | 126 | GNUNET_assert (p->th != NULL); |
152 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); | ||
153 | } | 127 | } |
154 | 128 | ||
155 | 129 | ||
130 | |||
156 | static void | 131 | static void |
157 | waitpid_task (void *cls, | 132 | waitpid_task (void *cls, |
158 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 133 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
159 | { | 134 | { |
160 | struct PeerContext *p = cls; | 135 | struct PeerContext *p = cls; |
161 | 136 | ||
162 | #if START_ARM | 137 | #if START_ARM |
163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
164 | "Killing ARM process.\n"); | 139 | "Killing ARM process.\n"); |
165 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) | 140 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) |
166 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 141 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
167 | if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) | 142 | if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) |
@@ -175,20 +150,20 @@ waitpid_task (void *cls, | |||
175 | 150 | ||
176 | static void | 151 | static void |
177 | stop_cb (void *cls, | 152 | stop_cb (void *cls, |
178 | int success) | 153 | int success) |
179 | { | 154 | { |
180 | struct PeerContext *p = cls; | 155 | struct PeerContext *p = cls; |
181 | 156 | ||
182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
183 | success | 158 | success |
184 | ? "ARM stopped core service\n" | 159 | ? "ARM stopped core service\n" |
185 | : "ARM failed to stop core service\n"); | 160 | : "ARM failed to stop core service\n"); |
186 | GNUNET_ARM_disconnect (p->arm); | 161 | GNUNET_ARM_disconnect (p->arm); |
187 | p->arm = NULL; | 162 | p->arm = NULL; |
188 | /* make sure this runs after all other tasks are done */ | 163 | /* make sure this runs after all other tasks are done */ |
189 | GNUNET_SCHEDULER_add_delayed (sched, | 164 | GNUNET_SCHEDULER_add_delayed (sched, |
190 | GNUNET_TIME_UNIT_SECONDS, | 165 | GNUNET_TIME_UNIT_SECONDS, |
191 | &waitpid_task, p); | 166 | &waitpid_task, p); |
192 | } | 167 | } |
193 | 168 | ||
194 | 169 | ||
@@ -196,10 +171,10 @@ static void | |||
196 | stop_arm (struct PeerContext *p) | 171 | stop_arm (struct PeerContext *p) |
197 | { | 172 | { |
198 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
199 | "Asking ARM to stop core service\n"); | 174 | "Asking ARM to stop core service\n"); |
200 | p->arm = GNUNET_ARM_connect (p->cfg, sched, NULL); | 175 | p->arm = GNUNET_ARM_connect (p->cfg, sched, NULL); |
201 | GNUNET_ARM_stop_service (p->arm, "core", GNUNET_TIME_UNIT_SECONDS, | 176 | GNUNET_ARM_stop_service (p->arm, "core", GNUNET_TIME_UNIT_SECONDS, |
202 | &stop_cb, p); | 177 | &stop_cb, p); |
203 | } | 178 | } |
204 | 179 | ||
205 | 180 | ||
@@ -209,8 +184,8 @@ stop_arm (struct PeerContext *p) | |||
209 | static void | 184 | static void |
210 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 185 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
211 | { | 186 | { |
212 | stop_arm (&p1); | 187 | stop_arm (&adv_peer); |
213 | stop_arm (&p2); | 188 | stop_arm (&learn_peer); |
214 | } | 189 | } |
215 | 190 | ||
216 | 191 | ||
@@ -221,27 +196,25 @@ run (void *cls, | |||
221 | const char *cfgfile, | 196 | const char *cfgfile, |
222 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 197 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
223 | { | 198 | { |
224 | GNUNET_assert (ok == 1); | 199 | failure = GNUNET_NO; |
225 | ok++; | ||
226 | sched = s; | 200 | sched = s; |
227 | |||
228 | timeout_task = GNUNET_SCHEDULER_add_delayed (sched, | 201 | timeout_task = GNUNET_SCHEDULER_add_delayed (sched, |
229 | TIMEOUT, | 202 | TIMEOUT, |
230 | &timeout_error, | 203 | &timeout_error, |
231 | NULL); | 204 | NULL); |
232 | GNUNET_SCHEDULER_add_delayed (sched, | 205 | GNUNET_SCHEDULER_add_delayed (sched, |
233 | GNUNET_TIME_UNIT_FOREVER_REL, | 206 | GNUNET_TIME_UNIT_FOREVER_REL, |
234 | &shutdown_task, | 207 | &shutdown_task, |
235 | NULL); | 208 | NULL); |
236 | setup_peer (&p1, "learning_peer1.conf"); | 209 | setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf"); |
237 | setup_peer (&p2, "learning_peer2.conf"); | 210 | setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); |
238 | } | 211 | } |
239 | 212 | ||
240 | 213 | ||
241 | static int | 214 | static int |
242 | check () | 215 | check () |
243 | { | 216 | { |
244 | char *const argv[] = { "test_gnunet_daemon_hostlist_learning", | 217 | char *const argv[] = { "test-gnunet-daemon-hostlist", |
245 | "-c", "learning_data.conf", | 218 | "-c", "learning_data.conf", |
246 | #if VERBOSE | 219 | #if VERBOSE |
247 | "-L", "DEBUG", | 220 | "-L", "DEBUG", |
@@ -251,23 +224,22 @@ check () | |||
251 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 224 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
252 | GNUNET_GETOPT_OPTION_END | 225 | GNUNET_GETOPT_OPTION_END |
253 | }; | 226 | }; |
254 | ok = 1; | 227 | failure = GNUNET_NO; |
255 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 228 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
256 | argv, "test_gnunet_daemon_hostlist_learning", | 229 | argv, "test-gnunet-daemon-hostlist", |
257 | "nohelp", options, &run, &ok); | 230 | "nohelp", options, &run, NULL); |
258 | 231 | return failure; | |
259 | return ok; | ||
260 | } | 232 | } |
261 | 233 | ||
262 | |||
263 | int | 234 | int |
264 | main (int argc, char *argv[]) | 235 | main (int argc, char *argv[]) |
265 | { | 236 | { |
266 | 237 | ||
267 | int ret; | 238 | int ret; |
239 | |||
268 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-hostlist-peer-1"); | 240 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-hostlist-peer-1"); |
269 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-hostlist-peer-2"); | 241 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-hostlist-peer-2"); |
270 | GNUNET_log_setup ("test-gnunet-daemon-hostlist_learning", | 242 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", |
271 | #if VERBOSE | 243 | #if VERBOSE |
272 | "DEBUG", | 244 | "DEBUG", |
273 | #else | 245 | #else |
diff --git a/src/hostlist/test_learning_adv_peer.conf b/src/hostlist/test_learning_adv_peer.conf new file mode 100644 index 000000000..d77c43ced --- /dev/null +++ b/src/hostlist/test_learning_adv_peer.conf | |||
@@ -0,0 +1,46 @@ | |||
1 | [PATHS] | ||
2 | SERVICEHOME = /tmp/test-gnunetd-hostlist-peer-2/ | ||
3 | DEFAULTCONFIG = test_learning_adv_peer.conf | ||
4 | |||
5 | [resolver] | ||
6 | PORT = 22964 | ||
7 | |||
8 | [transport] | ||
9 | PORT = 22965 | ||
10 | PLUGINS = tcp | ||
11 | #DEBUG = YES | ||
12 | |||
13 | [arm] | ||
14 | PORT = 22966 | ||
15 | DEFAULTSERVICES = resolver transport core statistics topology hostlist | ||
16 | #GLOBAL_PREFIX = xterm -e gdb -x cmd --args | ||
17 | #DEBUG=NO | ||
18 | |||
19 | [statistics] | ||
20 | PORT = 22967 | ||
21 | |||
22 | [transport-tcp] | ||
23 | PORT = 22968 | ||
24 | |||
25 | [peerinfo] | ||
26 | PORT = 22969 | ||
27 | |||
28 | [core] | ||
29 | PORT = 22970 | ||
30 | #DEBUG = YES | ||
31 | #PREFIX = valgrind --tool=memcheck | ||
32 | |||
33 | [testing] | ||
34 | WEAKRANDOM = YES | ||
35 | |||
36 | [hostlist] | ||
37 | HTTPPORT = 12981s | ||
38 | SERVERS = http://localhost:12980/ | ||
39 | OPTIONS = -b -p -a | ||
40 | DEBUG = YES | ||
41 | HOSTLISTFILE = hostlists_adv_peer.file | ||
42 | #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist | ||
43 | |||
44 | [topology] | ||
45 | #DEBUG = YES | ||
46 | #PREFIX = valgrind --tool=memcheck | ||
diff --git a/src/hostlist/test_learning_learn_peer.conf b/src/hostlist/test_learning_learn_peer.conf new file mode 100644 index 000000000..09fbc37a4 --- /dev/null +++ b/src/hostlist/test_learning_learn_peer.conf | |||
@@ -0,0 +1,46 @@ | |||
1 | [PATHS] | ||
2 | SERVICEHOME = /tmp/test-gnunetd-hostlist-peer-1/ | ||
3 | DEFAULTCONFIG = test_learning_learn_peer.conf | ||
4 | [resolver] | ||
5 | PORT = 12964 | ||
6 | |||
7 | [transport] | ||
8 | PORT = 12965 | ||
9 | PLUGINS = tcp | ||
10 | #DEBUG = YES | ||
11 | |||
12 | [arm] | ||
13 | PORT = 12966 | ||
14 | DEFAULTSERVICES = resolver transport core statistics topology hostlist | ||
15 | #GLOBAL_PREFIX = xterm -e gdb -x cmd --args | ||
16 | #DEBUG=NO | ||
17 | |||
18 | [statistics] | ||
19 | PORT = 12967 | ||
20 | |||
21 | [transport-tcp] | ||
22 | PORT = 12968 | ||
23 | |||
24 | [peerinfo] | ||
25 | PORT = 12969 | ||
26 | |||
27 | [core] | ||
28 | PORT = 12970 | ||
29 | #DEBUG = YES | ||
30 | #PREFIX = valgrind --tool=memcheck | ||
31 | |||
32 | [testing] | ||
33 | WEAKRANDOM = YES | ||
34 | |||
35 | [hostlist] | ||
36 | HTTPPORT = 12980 | ||
37 | SERVERS = http://localhost:12981/ | ||
38 | OPTIONS = -b -p -e | ||
39 | DEBUG = YES | ||
40 | HOSTLISTFILE = hostlists_learn_peer.file | ||
41 | #BINARY = /home/grothoff/bin/gnunet-daemon-hostlist | ||
42 | |||
43 | |||
44 | [topology] | ||
45 | #DEBUG = YES | ||
46 | #PREFIX = valgrind --tool=memcheck | ||