2 # This file is part of GNUnet.
3 # (C) 2010 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 # This test starts 3 peers and expects bootstrap and a connected clique
24 # Conditions for successful exit:
25 # Both peers have 1 connected peer in transport, core, topology, fs
37 testname = "test_integration_clique"
57 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
58 if gnunet_pyexpect_dir not in sys.path:
59 sys.path.append (gnunet_pyexpect_dir)
60 from gnunet_pyexpect import pexpect
62 global gnunetstatistics
63 if os.name == 'posix':
64 gnunetarm = 'gnunet-arm'
65 gnunetstatistics = 'gnunet-statistics'
67 gnunetarm = 'gnunet-arm.exe'
68 gnunetstatistics = 'gnunet-statistics.exe'
70 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
72 shutil.rmtree ("/tmp/" + testname, True)
75 vprintf ("Starting bootstrap server & client")
77 server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf'])
80 print "Can not start bootstrap server, exiting..."
83 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf'])
86 print "Can not start bootstrap client, exiting..."
89 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client_2.conf'])
92 print "Can not start bootstrap client 2, exiting..."
94 vprintf ("Bootstrap server & client started")
98 client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf'])
101 print "Can not stop bootstrap client 1, exiting..."
103 vprintf ("Bootstrap client stopped")
108 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-ns"), True)
109 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True)
110 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client_2"), True)
112 shutil.rmtree ("/tmp/c_bootstrap_server/", True)
113 shutil.rmtree ("/tmp/c_no_nat_client/", True)
114 shutil.rmtree ("/tmp/c_no_nat_client_2/", True)
116 def check_statistics (conf, subsystem, name, value):
117 from gnunet_pyexpect import pexpect
119 server.spawn (None, [gnunetstatistics, '-c', conf ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
120 #server.expect ("stdout", re.compile (r""))
121 test = server.read("stdout", 10240)
122 if (test.find(str(value)) == -1):
129 def check_connect ():
130 server_transport_connected = False
131 server_topology_connected = False
132 server_core_connected = False
133 server_core_session_map = False
134 server_fs_connected = False
135 client_transport_connected = False
136 client_topology_connected = False
137 client_core_connected = False
138 client_core_session_map = False
139 client_fs_connected = False
141 client2_transport_connected = False
142 client2_topology_connected = False
143 client2_core_connected = False
144 client2_core_session_map = False
145 client2_fs_connected = False
149 while ((connected == False) and (count <= timeout)):
151 if ((False == server_transport_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'transport', '# peers connected',2))):
152 server_transport_connected = True
153 vprintf ('Server transport services is connected')
155 if ((False == client_transport_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',2))):
156 client_transport_connected = True
157 vprintf ('Client transport services is connected')
159 if ((False == client2_transport_connected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'transport', '# peers connected',2))):
160 client2_transport_connected = True
161 vprintf ('Client 2 transport services is connected')
164 if ((False == server_core_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# neighbour entries allocated',2))):
165 server_core_connected = True
166 vprintf ('Server core services is connected')
168 if ((False == client_core_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',2))):
169 client_core_connected = True
170 vprintf ('Client core services is connected')
172 if ((False == client2_core_connected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'core', '# neighbour entries allocated',2))):
173 client2_core_connected = True
174 vprintf ('Client2 core services is connected')
177 if ((False == server_core_session_map) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# entries in session map',2))):
178 server_core_session_map = True
179 vprintf ('Server core services is connected')
181 if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',2))):
182 client_core_session_map = True
183 vprintf ('Client core notifies about connected')
185 if ((False == client2_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'core', '# entries in session map',2))):
186 client2_core_session_map = True
187 vprintf ('Client2 core notifies about connected')
190 if ((False == server_topology_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'topology', '# peers connected',2))):
191 server_topology_connected = True
192 vprintf ('Server topology services is connected')
194 if ((False == client_topology_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',2))):
195 client_topology_connected = True
196 vprintf ('Client topology services is connected')
198 if ((False == client2_topology_connected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'topology', '# peers connected',2))):
199 client2_topology_connected = True
200 vprintf ('Client2 topology services is connected')
203 if ((False == server_fs_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'fs', '# peers connected',2))):
204 server_fs_connected = True
205 vprintf ('Server fs services is connected')
207 if ((False == client_fs_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',2))):
208 client_fs_connected = True
209 vprintf ('Client fs services is connected')
211 if ((False == client2_fs_connected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'fs', '# peers connected',2))):
212 client2_fs_connected = True
213 vprintf ('Client2 fs services is connected')
215 # Check if conditions fulfilled
216 if ((True == client_transport_connected) and (True == client2_transport_connected) and (True == server_transport_connected) and
217 (True == client_topology_connected) and (True == client2_topology_connected) and (True == server_topology_connected) and
218 (True == client_core_connected) and (True == client2_core_connected) and (True == server_core_connected) and
219 (True == client_core_session_map) and (True == client2_core_session_map) and (True == server_core_session_map) and
220 (True == client_fs_connected) and (True == client2_fs_connected) and (True == server_fs_connected)):
226 if (connected == False):
228 if (server_transport_connected == False):
229 print ('Server transport was NOT connected')
230 if (server_topology_connected == False):
231 print ('Server topology was NOT connected')
232 if (server_core_connected == False):
233 print ('Server core was NOT connected')
234 if (server_core_session_map == False):
235 print ('Server core sessions did NOT increase')
237 if (client_transport_connected == False):
238 print ('Client transport was NOT connected')
239 if (client_topology_connected == False):
240 print ('Client topology was NOT connected')
241 if (client_core_connected == False):
242 print ('Client core was NOT connected')
243 if (client_core_session_map == False):
244 print ('Client core sessions did NOT increase')
246 if (client2_transport_connected == False):
247 print ('Client2 transport was NOT connected')
248 if (client2_topology_connected == False):
249 print ('Client2 topology was NOT connected')
250 if (client2_core_connected == False):
251 print ('Client2 core was NOT connected')
252 if (client2_core_session_map == False):
253 print ('Client2 core sessions did NOT increase')
258 def check_disconnect_client ():
259 vprintf ("Shutting down client 2")
261 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_no_nat_client_2.conf'])
262 server.communicate ()
264 print "Can not stop client 2, exiting..."
267 client_transport_disconnected = False
268 client_topology_disconnected = False
269 client_core_disconnected = False
270 client_core_session_map = False
271 client_fs_disconnected = False
275 while ((disconnected == False) and (count <= timeout)):
276 if ((False == client_transport_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',0))):
277 client_transport_disconnected = True
278 vprintf ('Client transport services is disconnected')
280 if ((False == client_core_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',0))):
281 client_core_disconnected = True
282 vprintf ('Client core services is disconnected')
284 if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',0))):
285 client_core_session_map = True
286 vprintf ('Client core notifies about disconnected')
288 if ((False == client_topology_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',0))):
289 client_topology_disconnected = True
290 vprintf ('Client topology services is disconnected')
292 if ((False == client_fs_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',0))):
293 client_fs_disconnected = True
294 vprintf ('Client fs services is disconnected')
296 # Check if conditions fulfilled
297 if ((True == client_transport_disconnected) and
298 (True == client_topology_disconnected) and
299 (True == client_core_disconnected) and
300 (True == client_core_session_map) and
301 (True == client_fs_disconnected)):
307 if (disconnected == False):
309 if (client_transport_disconnected == False):
310 print ('Client transport was NOT disconnected')
311 if (client_topology_disconnected == False):
312 print ('Client topology was NOT disconnected')
313 if (client_core_disconnected == False):
314 print ('Client core was NOT disconnected')
315 if (client_core_session_map == False):
316 print ('Server core sessions did NOT increase')
321 def check_disconnect_server ():
322 vprintf ("Shutting down bootstrap server")
324 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf'])
325 server.communicate ()
327 print "Can not stop bootstrap server, exiting..."
330 client_transport_disconnected = False
331 client_topology_disconnected = False
332 client_core_disconnected = False
333 client_core_session_map = False
334 client_fs_disconnected = False
336 client2_transport_disconnected = False
337 client2_topology_disconnected = False
338 client2_core_disconnected = False
339 client2_core_session_map = False
340 client2_fs_disconnected = False
344 while ((disconnected == False) and (count <= timeout)):
345 if ((False == client_transport_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',1))):
346 client_transport_disconnected = True
347 vprintf ('Client transport services is disconnected')
349 if ((False == client_core_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',1))):
350 client_core_disconnected = True
351 vprintf ('Client core services is disconnected')
353 if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',1))):
354 client_core_session_map = True
355 vprintf ('Client core notifies about disconnected')
357 if ((False == client_topology_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',1))):
358 client_topology_disconnected = True
359 vprintf ('Client topology services is disconnected')
361 if ((False == client_fs_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',1))):
362 client_fs_disconnected = True
363 vprintf ('Client fs services is disconnected')
365 if ((False == client2_transport_disconnected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'transport', '# peers connected',1))):
366 client2_transport_disconnected = True
367 vprintf ('Client2 transport services is disconnected')
369 if ((False == client2_core_disconnected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'core', '# neighbour entries allocated',1))):
370 client2_core_disconnected = True
371 vprintf ('Client2 core services is disconnected')
373 if ((False == client2_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'core', '# entries in session map',1))):
374 client2_core_session_map = True
375 vprintf ('Client2 core notifies about disconnected')
377 if ((False == client2_topology_disconnected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'topology', '# peers connected',1))):
378 client2_topology_disconnected = True
379 vprintf ('Client2 topology services is disconnected')
381 if ((False == client2_fs_disconnected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'fs', '# peers connected',1))):
382 client2_fs_disconnected = True
383 vprintf ('Client2 fs services is disconnected')
386 # Check if conditions fulfilled
387 if ((True == client_transport_disconnected) and
388 (True == client_topology_disconnected) and
389 (True == client_core_disconnected) and
390 (True == client_core_session_map) and
391 (True == client_fs_disconnected) and
392 (True == client2_transport_disconnected) and
393 (True == client2_topology_disconnected) and
394 (True == client2_core_disconnected) and
395 (True == client2_core_session_map) and
396 (True == client2_fs_disconnected)):
402 if (disconnected == False):
404 if (client_transport_disconnected == False):
405 print ('Client transport was NOT disconnected')
406 if (client_topology_disconnected == False):
407 print ('Client topology was NOT disconnected')
408 if (client_core_disconnected == False):
409 print ('Client core was NOT disconnected')
410 if (client_core_session_map == False):
411 print ('Client core sessions did NOT decrease')
412 if (client2_transport_disconnected == False):
413 print ('Client2 transport was NOT disconnected')
414 if (client2_topology_disconnected == False):
415 print ('Client2 topology was NOT disconnected')
416 if (client2_core_disconnected == False):
417 print ('Client2 core was NOT disconnected')
418 if (client2_core_session_map == False):
419 print ('Client2 core sessions did NOT decrease')
428 vprintf ("Running " + testname)
432 ret = check_connect ()
434 vprintf ('Peers connected')
435 if (True == check_disconnect_server ()):
436 if (True == check_disconnect_client ()):
442 if (success == False):
443 print ('Test failed')