aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/integration-tests/gnunet_testing.py.in47
-rwxr-xr-xsrc/integration-tests/test_integration_bootstrap_and_connect.py.in15
-rwxr-xr-xsrc/integration-tests/test_integration_clique.py.in475
-rwxr-xr-xsrc/integration-tests/test_integration_disconnect.py.in295
4 files changed, 222 insertions, 610 deletions
diff --git a/src/integration-tests/gnunet_testing.py.in b/src/integration-tests/gnunet_testing.py.in
index be288ff44..3fb6221fd 100644
--- a/src/integration-tests/gnunet_testing.py.in
+++ b/src/integration-tests/gnunet_testing.py.in
@@ -27,9 +27,10 @@ import time
27 27
28 28
29class Check: 29class Check:
30 def __init__(self): 30 def __init__(self, test):
31 self.fulfilled = False 31 self.fulfilled = False
32 self.conditions = list() 32 self.conditions = list()
33 self.test = test
33 def add (self, condition): 34 def add (self, condition):
34 self.conditions.append(condition) 35 self.conditions.append(condition)
35 def run (self): 36 def run (self):
@@ -42,7 +43,7 @@ class Check:
42 neg += 1 43 neg += 1
43 else: 44 else:
44 pos += 1 45 pos += 1
45 print (str(pos) +' out of '+ str (pos+neg) + ' conditions fulfilled') 46 self.test.p (str(pos) +' out of '+ str (pos+neg) + ' conditions fulfilled')
46 return fulfilled 47 return fulfilled
47 def run_blocking (self, timeout, pos_cont, neg_cont): 48 def run_blocking (self, timeout, pos_cont, neg_cont):
48 execs = 0; 49 execs = 0;
@@ -52,17 +53,37 @@ class Check:
52 time.sleep(1) 53 time.sleep(1)
53 execs += 1 54 execs += 1
54 if (res == False): 55 if (res == False):
55 neg_cont () 56 neg_cont (self)
56 else: 57 else:
57 pos_cont () 58 pos_cont (self)
59 def eval(self, failed_only):
60 pos = 0
61 neg = 0
62 for c in self.conditions:
63 if (False == c.eval (failed_only)):
64 neg += 1
65 else:
66 pos += 1
67 print (str(pos) +' out of '+ str (pos+neg) + ' conditions fulfilled')
68 return self.fulfilled
69
58 70
59 71
60class Condition: 72class Condition:
73 def __init__(self):
74 self.fulfilled = False
75 self.type = 'generic'
61 def __init__(self, type): 76 def __init__(self, type):
62 self.fulfilled = False 77 self.fulfilled = False
63 self.type = type 78 self.type = type
64 def check(self): 79 def check(self):
65 return False; 80 return False;
81 def eval(self, failed_only):
82 if ((self.fulfilled == False) and (failed_only == True)):
83 print str(self.type) + 'condition for was ' + str(self.fulfilled)
84 elif (failed_only == False):
85 print str(self.type) + 'condition for was ' + str(self.fulfilled)
86 return self.fulfilled
66 87
67class FileExistCondition (Condition): 88class FileExistCondition (Condition):
68 def __init__(self, file): 89 def __init__(self, file):
@@ -79,6 +100,12 @@ class FileExistCondition (Condition):
79 return False 100 return False
80 else: 101 else:
81 return True 102 return True
103 def eval(self, failed_only):
104 if ((self.fulfilled == False) and (failed_only == True)):
105 print str(self.type) + 'condition for file '+self.file+' was ' + str(self.fulfilled)
106 elif (failed_only == False):
107 print str(self.type) + 'condition for file '+self.file+' was ' + str(self.fulfilled)
108 return self.fulfilled
82 109
83class StatisticsCondition (Condition): 110class StatisticsCondition (Condition):
84 def __init__(self, peer, subsystem, name, value): 111 def __init__(self, peer, subsystem, name, value):
@@ -98,6 +125,13 @@ class StatisticsCondition (Condition):
98 return False 125 return False
99 else: 126 else:
100 return True 127 return True
128 def eval(self, failed_only):
129 if ((self.fulfilled == False) and (failed_only == True)):
130 print str(self.type) + ' condition for value "'+str(self.value)+'" in subsystem "' + self.subsystem +'" : "' + self.name +'" was ' + str(self.fulfilled)
131 elif (failed_only == False):
132 print str(self.type) + ' condition for value "'+str(self.value)+'" in subsystem "' + self.subsystem +'" : "' + self.name +'" was ' + str(self.fulfilled)
133 return self.fulfilled
134
101class Test: 135class Test:
102 def __init__(self, testname, verbose): 136 def __init__(self, testname, verbose):
103 self.verbose = verbose; 137 self.verbose = verbose;
@@ -120,7 +154,8 @@ class Test:
120 else: 154 else:
121 shutil.rmtree ("/tmp/" + testname, True) 155 shutil.rmtree ("/tmp/" + testname, True)
122 def p (self, msg): 156 def p (self, msg):
123 print msg 157 if (self.verbose == True):
158 print msg
124 159
125class Peer: 160class Peer:
126 def __init__(self, test, cfg_file): 161 def __init__(self, test, cfg_file):
@@ -147,6 +182,8 @@ class Peer:
147 self.started = True 182 self.started = True
148 return True 183 return True
149 def stop (self): 184 def stop (self):
185 if (self.started == False):
186 return False
150 self.test.p ("Stopping peer using cfg " + self.cfg) 187 self.test.p ("Stopping peer using cfg " + self.cfg)
151 try: 188 try:
152 server = subprocess.Popen ([self.test.gnunetarm, '-eq', '-c', self.cfg]) 189 server = subprocess.Popen ([self.test.gnunetarm, '-eq', '-c', self.cfg])
diff --git a/src/integration-tests/test_integration_bootstrap_and_connect.py.in b/src/integration-tests/test_integration_bootstrap_and_connect.py.in
index 38746544c..581179f99 100755
--- a/src/integration-tests/test_integration_bootstrap_and_connect.py.in
+++ b/src/integration-tests/test_integration_bootstrap_and_connect.py.in
@@ -42,8 +42,7 @@ from gnunet_testing import *
42#definitions 42#definitions
43 43
44testname = "test_integration_bootstrap_and_connect" 44testname = "test_integration_bootstrap_and_connect"
45verbose = True 45verbose = False
46success = False
47timeout = 100 46timeout = 100
48 47
49 48
@@ -55,16 +54,18 @@ def cleanup ():
55 shutil.rmtree ("/tmp/c_bootstrap_server/", True) 54 shutil.rmtree ("/tmp/c_bootstrap_server/", True)
56 shutil.rmtree ("/tmp/c_no_nat_client/", True) 55 shutil.rmtree ("/tmp/c_no_nat_client/", True)
57 56
58def success (): 57def success_cont (check):
59 global success 58 global success
60 success = True; 59 success = True;
61def fail (): 60
61def fail_cont (check):
62 global success 62 global success
63 success= False; 63 success= False;
64 check.eval(True)
64 65
65def check (): 66def check ():
66 67
67 check = Check () 68 check = Check (test)
68 check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) 69 check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
69 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1)) 70 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1))
70 check.add (StatisticsCondition (client, 'core', '# entries in session map',1)) 71 check.add (StatisticsCondition (client, 'core', '# entries in session map',1))
@@ -78,11 +79,12 @@ def check ():
78 check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) 79 check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
79 check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) 80 check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
80 81
81 check.run_blocking (10, success, fail) 82 check.run_blocking (10, success_cont, fail_cont)
82 83
83# 84#
84# Test execution 85# Test execution
85# 86#
87success = False
86 88
87test = Test ('test_integration_bootstrap_and_connect.py', verbose) 89test = Test ('test_integration_bootstrap_and_connect.py', verbose)
88 90
@@ -93,6 +95,7 @@ client = Peer(test, './confs/c_no_nat_client.conf');
93client.start(); 95client.start();
94 96
95if ((client.started == True) and (server.started == True)): 97if ((client.started == True) and (server.started == True)):
98 test.p ('Peers started, running check')
96 check () 99 check ()
97 100
98server.stop () 101server.stop ()
diff --git a/src/integration-tests/test_integration_clique.py.in b/src/integration-tests/test_integration_clique.py.in
index fbdadae12..ce254ca7b 100755
--- a/src/integration-tests/test_integration_clique.py.in
+++ b/src/integration-tests/test_integration_clique.py.in
@@ -31,76 +31,18 @@ import re
31import shutil 31import shutil
32import time 32import time
33import pexpect 33import pexpect
34from gnunet_testing import Peer
35from gnunet_testing import Test
36from gnunet_testing import Check
37from gnunet_testing import Condition
38from gnunet_testing import *
39
34 40
35#definitions 41#definitions
36 42
37testname = "test_integration_clique" 43testname = "test_integration_clique"
38verbose = False 44verbose = True
39gnunetarm = "" 45check_timeout = 120
40gnunetstatistics = ""
41success = False
42timeout = 10
43
44s_server = False;
45s_c1 = False;
46s_c2 = False;
47
48#test conditions
49
50
51def vprintf (msg):
52 if verbose == True:
53 print msg
54
55def setup ():
56 srcdir = "../.."
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
61 global gnunetarm
62 global gnunetstatistics
63 if os.name == 'posix':
64 gnunetarm = 'gnunet-arm'
65 gnunetstatistics = 'gnunet-statistics'
66 elif os.name == 'nt':
67 gnunetarm = 'gnunet-arm.exe'
68 gnunetstatistics = 'gnunet-statistics.exe'
69 if os.name == "nt":
70 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
71 else:
72 shutil.rmtree ("/tmp/" + testname, True)
73
74def start ():
75 vprintf ("Starting bootstrap server & client")
76 try:
77 server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf'])
78 server.communicate ()
79 except OSError:
80 print "Can not start bootstrap server, exiting..."
81 exit (1)
82 try:
83 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf'])
84 client.communicate ()
85 except OSError:
86 print "Can not start bootstrap client, exiting..."
87 exit (1)
88 try:
89 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client_2.conf'])
90 client.communicate ()
91 except OSError:
92 print "Can not start bootstrap client 2, exiting..."
93 exit (1)
94 vprintf ("Bootstrap server & client started")
95
96def stop ():
97 try:
98 client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf'])
99 client.communicate ()
100 except OSError:
101 print "Can not stop bootstrap client 1, exiting..."
102 exit (1)
103 vprintf ("Bootstrap client stopped")
104 46
105 47
106def cleanup (): 48def cleanup ():
@@ -113,335 +55,122 @@ def cleanup ():
113 shutil.rmtree ("/tmp/c_no_nat_client/", True) 55 shutil.rmtree ("/tmp/c_no_nat_client/", True)
114 shutil.rmtree ("/tmp/c_no_nat_client_2/", True) 56 shutil.rmtree ("/tmp/c_no_nat_client_2/", True)
115 57
116def check_statistics (conf, subsystem, name, value):
117 from gnunet_pyexpect import pexpect
118 server = 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):
123 return False
124 else:
125 return True
126
127
128 58
129def check_connect (): 59def success_cont (check):
130 server_transport_connected = False 60 global success
131 server_topology_connected = False 61 success = True;
132 server_core_connected = False 62
133 server_core_session_map = False 63def fail_cont (check):
134 server_fs_connected = False 64 global success
135 client_transport_connected = False 65 success= False;
136 client_topology_connected = False 66 check.eval(True)
137 client_core_connected = False 67
138 client_core_session_map = False 68
139 client_fs_connected = False 69def check_disconnect_client ():
70 test.p ('Shutting down bootstrap client')
71 client.stop ()
72 check = Check (test)
140 73
141 client2_transport_connected = False 74 check.add (StatisticsCondition (client2, 'transport', '# peers connected',0))
142 client2_topology_connected = False 75 check.add (StatisticsCondition (client2, 'core', '# neighbour entries allocated',0))
143 client2_core_connected = False 76 check.add (StatisticsCondition (client2, 'core', '# entries in session map',0))
144 client2_core_session_map = False 77 check.add (StatisticsCondition (client2, 'topology', '# peers connected',0))
145 client2_fs_connected = False 78 check.add (StatisticsCondition (client2, 'fs', '# peers connected',0))
146 79
147 connected = False 80 check.run_blocking (check_timeout, success_cont, fail_cont)
148 count = 1
149 while ((connected == False) and (count <= timeout)):
150 # Perform TRANSPORT
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')
154
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')
158
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')
162 81
163 # Perform TRANSPORT 82
164 if ((False == server_core_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# neighbour entries allocated',2))): 83def success_disconnect_server_cont (check):
165 server_core_connected = True 84 check_disconnect_client ()
166 vprintf ('Server core services is connected')
167
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')
171 85
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')
175
176 # Perform TRANSPORT
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')
180
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')
184 86
185 if ((False == client2_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'core', '# entries in session map',2))): 87def fail_disconnect_server_cont (check):
186 client2_core_session_map = True 88 global success
187 vprintf ('Client2 core notifies about connected') 89 success= False;
90 check.eval(True)
188 91
189 # Perform TRANSPORT 92
190 if ((False == server_topology_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'topology', '# peers connected',2))): 93def check_disconnect_server ():
191 server_topology_connected = True 94 test.p ('Shutting down bootstrap server')
192 vprintf ('Server topology services is connected') 95 server.stop ()
193 96 check = Check (test)
194 if ((False == client_topology_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',2))): 97 check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
195 client_topology_connected = True 98 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1))
196 vprintf ('Client topology services is connected') 99 check.add (StatisticsCondition (client, 'core', '# entries in session map',1))
100 check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
101 check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
102
103 check.add (StatisticsCondition (client2, 'transport', '# peers connected',1))
104 check.add (StatisticsCondition (client2, 'core', '# neighbour entries allocated',1))
105 check.add (StatisticsCondition (client2, 'core', '# entries in session map',1))
106 check.add (StatisticsCondition (client2, 'topology', '# peers connected',1))
107 check.add (StatisticsCondition (client2, 'fs', '# peers connected',1))
108
109 check.run_blocking (check_timeout, success_disconnect_server_cont, fail_disconnect_server_cont)
197 110
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')
201
202 # Perform TRANSPORT
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')
206 111
207 if ((False == client_fs_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',2))): 112def success_connect_cont (check):
208 client_fs_connected = True 113 check_disconnect_server ()
209 vprintf ('Client fs services is connected')
210 114
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')
214
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)):
221 connected = True
222 break
223 print '.',
224 time.sleep(1)
225 count += 1
226 if (connected == False):
227 print ''
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')
236
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')
245
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')
254 return False
255 else:
256 return True
257 115
258def check_disconnect_client (): 116def fail_connect_cont (check):
259 vprintf ("Shutting down client 2") 117 global success
260 try: 118 success= False;
261 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_no_nat_client_2.conf']) 119 check.eval(True)
262 server.communicate ()
263 except OSError:
264 print "Can not stop client 2, exiting..."
265 exit (1)
266
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
272
273 disconnected = False
274 count = 1
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')
279
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')
283
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')
287
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')
291
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')
295
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)):
302 disconnected = True
303 break
304 print '.',
305 time.sleep(1)
306 count += 1
307 if (disconnected == False):
308 print ''
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')
317 return False
318 else:
319 return True
320
321def check_disconnect_server ():
322 vprintf ("Shutting down bootstrap server")
323 try:
324 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf'])
325 server.communicate ()
326 except OSError:
327 print "Can not stop bootstrap server, exiting..."
328 exit (1)
329
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
335 120
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
341
342 disconnected = False
343 count = 1
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')
348
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')
352
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')
356
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')
360
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')
364 121
365 if ((False == client2_transport_disconnected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'transport', '# peers connected',1))): 122def check_connect ():
366 client2_transport_disconnected = True 123 check = Check (test)
367 vprintf ('Client2 transport services is disconnected') 124 check.add (StatisticsCondition (client, 'transport', '# peers connected',2))
368 125 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',2))
369 if ((False == client2_core_disconnected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'core', '# neighbour entries allocated',1))): 126 check.add (StatisticsCondition (client, 'core', '# entries in session map',2))
370 client2_core_disconnected = True 127 check.add (StatisticsCondition (client, 'topology', '# peers connected',2))
371 vprintf ('Client2 core services is disconnected') 128 check.add (StatisticsCondition (client, 'fs', '# peers connected',2))
372 129
373 if ((False == client2_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'core', '# entries in session map',1))): 130 check.add (StatisticsCondition (client2, 'transport', '# peers connected',2))
374 client2_core_session_map = True 131 check.add (StatisticsCondition (client2, 'core', '# neighbour entries allocated',2))
375 vprintf ('Client2 core notifies about disconnected') 132 check.add (StatisticsCondition (client2, 'core', '# entries in session map',2))
376 133 check.add (StatisticsCondition (client2, 'topology', '# peers connected',2))
377 if ((False == client2_topology_disconnected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'topology', '# peers connected',1))): 134 check.add (StatisticsCondition (client2, 'fs', '# peers connected',2))
378 client2_topology_disconnected = True 135
379 vprintf ('Client2 topology services is disconnected') 136 check.add (StatisticsCondition (server, 'transport', '# peers connected',2))
380 137 check.add (StatisticsCondition (server, 'core', '# neighbour entries allocated',2))
381 if ((False == client2_fs_disconnected) and (True == check_statistics ('./confs/c_no_nat_client_2.conf', 'fs', '# peers connected',1))): 138 check.add (StatisticsCondition (server, 'core', '# entries in session map',2))
382 client2_fs_disconnected = True 139 check.add (StatisticsCondition (server, 'topology', '# peers connected',2))
383 vprintf ('Client2 fs services is disconnected') 140 check.add (StatisticsCondition (server, 'fs', '# peers connected',2))
384 141
385 142 check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont)
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)):
397 disconnected = True
398 #break
399 print '.'
400 time.sleep(1)
401 count += 1
402 if (disconnected == False):
403 print ''
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')
420 return False
421 else:
422 return True
423 143
424# 144#
425# Test execution 145# Test execution
426# 146#
427 147
428vprintf ("Running " + testname) 148success = False
429setup () 149
430start () 150test = Test ('test_integration_disconnect', verbose)
431 151
432ret = check_connect () 152server = Peer(test, './confs/c_bootstrap_server.conf');
433if (ret == True): 153server.start();
434 vprintf ('Peers connected') 154
435 if (True == check_disconnect_server ()): 155client = Peer(test, './confs/c_no_nat_client.conf');
436 if (True == check_disconnect_client ()): 156client.start();
437 success = True 157
158client2 = Peer(test, './confs/c_no_nat_client_2.conf');
159client2.start();
160
161if ((client.started == True) and (client2.started == True) and (server.started == True)):
162 test.p ('Peers started, running check')
163 check_connect ()
164
165server.stop ()
166client.stop ()
167client2.stop ()
438 168
439stop ()
440cleanup () 169cleanup ()
441 170
442if (success == False): 171if (success == False):
443 print ('Test failed') 172 print ('Test failed')
444 exit (1) 173 exit (1)
445else: 174else:
446 exit (0) 175 exit (0)
447 176
diff --git a/src/integration-tests/test_integration_disconnect.py.in b/src/integration-tests/test_integration_disconnect.py.in
index 3ded5dd7a..0397fafd2 100755
--- a/src/integration-tests/test_integration_disconnect.py.in
+++ b/src/integration-tests/test_integration_disconnect.py.in
@@ -25,6 +25,12 @@ import re
25import shutil 25import shutil
26import time 26import time
27import pexpect 27import pexpect
28from gnunet_testing import Peer
29from gnunet_testing import Test
30from gnunet_testing import Check
31from gnunet_testing import Condition
32from gnunet_testing import *
33
28 34
29# 35#
30# This test tests if a fresh peer bootstraps from a hostlist server and then 36# This test tests if a fresh peer bootstraps from a hostlist server and then
@@ -38,61 +44,7 @@ import pexpect
38 44
39testname = "test_integration_disconnect" 45testname = "test_integration_disconnect"
40verbose = False 46verbose = False
41gnunetarm = "" 47check_timeout = 30
42gnunetstatistics = ""
43success = False
44timeout = 100
45
46#test conditions
47
48
49def vprintf (msg):
50 if verbose == True:
51 print msg
52
53def setup ():
54 srcdir = "../.."
55 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
56 if gnunet_pyexpect_dir not in sys.path:
57 sys.path.append (gnunet_pyexpect_dir)
58 from gnunet_pyexpect import pexpect
59 global gnunetarm
60 global gnunetstatistics
61 if os.name == 'posix':
62 gnunetarm = 'gnunet-arm'
63 gnunetstatistics = 'gnunet-statistics'
64 elif os.name == 'nt':
65 gnunetarm = 'gnunet-arm.exe'
66 gnunetstatistics = 'gnunet-statistics.exe'
67 if os.name == "nt":
68 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
69 else:
70 shutil.rmtree ("/tmp/" + testname, True)
71
72def start ():
73 vprintf ("Starting bootstrap server & client")
74 try:
75 server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf'])
76 server.communicate ()
77 except OSError:
78 print "Can not start bootstrap server, exiting..."
79 exit (1)
80 try:
81 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf'])
82 client.communicate ()
83 except OSError:
84 print "Can not start bootstrap client, exiting..."
85 exit (1)
86 vprintf ("Bootstrap server & client started")
87
88def stop ():
89 try:
90 client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf'])
91 client.communicate ()
92 except OSError:
93 print "Can not stop bootstrap client, exiting..."
94 exit (1)
95 vprintf ("Bootstrap client stopped")
96 48
97 49
98def cleanup (): 50def cleanup ():
@@ -101,188 +53,82 @@ def cleanup ():
101 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True) 53 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True)
102 else: 54 else:
103 shutil.rmtree ("/tmp/c_bootstrap_server/", True) 55 shutil.rmtree ("/tmp/c_bootstrap_server/", True)
104 shutil.rmtree ("/tmp/c_no_nat_client/", True) 56 shutil.rmtree ("/tmp/c_no_nat_client/", True)
105 57
106def check_statistics (conf, subsystem, name, value):
107 from gnunet_pyexpect import pexpect
108 server = pexpect ()
109 server.spawn (None, [gnunetstatistics, '-c', conf ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
110 #server.expect ("stdout", re.compile (r""))
111 test = server.read("stdout", 10240)
112 if (test.find(str(value)) == -1):
113 return False
114 else:
115 return True
116
117
118 58
119def check_connect (): 59def success_disconnect_cont (check):
120 server_transport_connected = False 60 global success
121 server_topology_connected = False 61 success = True;
122 server_core_connected = False
123 server_core_session_map = False
124 server_fs_connected = False
125 client_transport_connected = False
126 client_topology_connected = False
127 client_core_connected = False
128 client_core_session_map = False
129 client_fs_connected = False
130
131 connected = False
132 count = 1
133 while ((connected == False) and (count <= timeout)):
134 # Perform checks
135 if ((False == server_transport_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'transport', '# peers connected',1))):
136 server_transport_connected = True
137 vprintf ('Server transport services is connected')
138
139 if ((False == client_transport_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',1))):
140 client_transport_connected = True
141 vprintf ('Client transport services is connected')
142 62
143 if ((False == server_core_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# neighbour entries allocated',1))):
144 server_core_connected = True
145 vprintf ('Server core services is connected')
146
147 if ((False == client_core_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',1))):
148 client_core_connected = True
149 vprintf ('Client core services is connected')
150
151 if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# entries in session map',1))):
152 client_core_session_map = True
153 vprintf ('Server core services is connected')
154
155 if ((False == server_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',1))):
156 server_core_session_map = True
157 vprintf ('Client core notifies about connected')
158 63
159 if ((False == server_topology_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'topology', '# peers connected',1))): 64def fail_disconnect_cont (check):
160 server_topology_connected = True 65 global success
161 vprintf ('Server topology services is connected') 66 success = False;
162 67 check.eval(True)
163 if ((False == client_topology_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',1))): 68
164 client_topology_connected = True
165 vprintf ('Client topology services is connected')
166
167 if ((False == client_fs_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',1))):
168 client_fs_connected = True
169 vprintf ('Client fs services is connected')
170 if ((False == server_fs_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'fs', '# peers connected',1))):
171 server_fs_connected = True
172 vprintf ('Server fs services is connected')
173
174 # Check if conditions fulfilled
175 if ((True == client_transport_connected) and (True == server_transport_connected) and
176 (True == client_topology_connected) and (True == server_topology_connected) and
177 (True == client_core_connected) and (True == server_core_connected) and
178 (True == client_core_session_map) and (True == server_core_session_map) and
179 (True == client_fs_connected) and (True == server_fs_connected)):
180 connected = True
181 break
182 print '.',
183 time.sleep(1)
184 count += 1
185 if (connected == False):
186 print ''
187 if (client_transport_connected == False):
188 print ('Client transport was NOT connected')
189 if (server_transport_connected == False):
190 print ('Server transport was NOT connected')
191 if (client_topology_connected == False):
192 print ('Client topology was NOT connected')
193 if (server_topology_connected == False):
194 print ('Server topology was NOT connected')
195 if (client_core_connected == False):
196 print ('Client core was NOT connected')
197 if (server_core_connected == False):
198 print ('Server core was NOT connected')
199 if (client_core_session_map == False):
200 print ('Client core sessions did NOT increase')
201 if (server_core_session_map == False):
202 print ('Server core sessions did NOT increase')
203 return False
204 else:
205 return True
206 69
207def check_disconnect (): 70def check_disconnect ():
208 vprintf ("Shutting down bootstrap server") 71 test.p ('Shutting down bootstrap server')
209 try: 72 server.stop ()
210 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf']) 73 check = Check (test)
211 server.communicate () 74 check.add (StatisticsCondition (client, 'transport', '# peers connected',0))
212 except OSError: 75 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',0))
213 print "Can not stop bootstrap server, exiting..." 76 check.add (StatisticsCondition (client, 'core', '# entries in session map',0))
214 exit (1) 77 check.add (StatisticsCondition (client, 'topology', '# peers connected',0))
215 78 check.add (StatisticsCondition (client, 'fs', '# peers connected',0))
216 client_transport_disconnected = False 79 check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont)
217 client_topology_disconnected = False 80
218 client_core_disconnected = False 81
219 client_core_session_map = False 82def success_connect_cont (check):
220 client_fs_disconnected = False 83 check_disconnect ()
221 84
222 disconnected = False 85
223 count = 1 86def fail_connect_cont (check):
224 while ((disconnected == False) and (count <= timeout)): 87 global success
225 if ((False == client_transport_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',0))): 88 success= False;
226 client_transport_disconnected = True 89 check.eval(True)
227 vprintf ('Client transport services is disconnected') 90
228 91
229 if ((False == client_core_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',0))): 92def check_connect ():
230 client_core_disconnected = True 93 check = Check (test)
231 vprintf ('Client core services is disconnected') 94 check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
232 95 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1))
233 if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',0))): 96 check.add (StatisticsCondition (client, 'core', '# entries in session map',1))
234 client_core_session_map = True 97 check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
235 vprintf ('Client core notifies about disconnected') 98 check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
236 99
237 if ((False == client_topology_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',0))): 100 check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
238 client_topology_disconnected = True 101 check.add (StatisticsCondition (server, 'core', '# neighbour entries allocated',1))
239 vprintf ('Client topology services is disconnected') 102 check.add (StatisticsCondition (server, 'core', '# entries in session map',1))
240 103 check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
241 if ((False == client_fs_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',0))): 104 check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
242 client_fs_disconnected = True 105
243 vprintf ('Client fs services is disconnected') 106 check.run_blocking (10, success_connect_cont, fail_connect_cont)
244 107
245 # Check if conditions fulfilled 108#
246 if ((True == client_transport_disconnected) and 109# Test execution
247 (True == client_topology_disconnected) and 110#
248 (True == client_core_disconnected) and
249 (True == client_core_session_map) and
250 (True == client_fs_disconnected)):
251 disconnected = True
252 break
253 print '.'
254 time.sleep(1)
255 count += 1
256 if (disconnected == False):
257 print ''
258 if (client_transport_disconnected == False):
259 print ('Client transport was NOT disconnected')
260 if (client_topology_disconnected == False):
261 print ('Client topology was NOT disconnected')
262 if (client_core_disconnected == False):
263 print ('Client core was NOT disconnected')
264 if (client_core_session_map == False):
265 print ('Server core sessions did NOT decrease')
266 return False
267 else:
268 return True
269 111
270# 112#
271# Test execution 113# Test execution
272# 114#
115success = False
116
117test = Test ('test_integration_disconnect', verbose)
273 118
274vprintf ("Running " + testname) 119server = Peer(test, './confs/c_bootstrap_server.conf');
275setup () 120server.start();
276start ()
277 121
278ret = check_connect () 122client = Peer(test, './confs/c_no_nat_client.conf');
279if (ret == True): 123client.start();
280 vprintf ('Peers connected')
281 if (True == check_disconnect ()):
282 success = True
283 124
284stop ()
285 125
126if ((client.started == True) and (server.started == True)):
127 test.p ('Peers started, running check')
128 check_connect ()
129
130server.stop ()
131client.stop ()
286 132
287cleanup () 133cleanup ()
288 134
@@ -291,6 +137,3 @@ if (success == False):
291 exit (1) 137 exit (1)
292else: 138else:
293 exit (0) 139 exit (0)
294
295
296