aboutsummaryrefslogtreecommitdiff
path: root/src/integration-tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/integration-tests')
-rw-r--r--src/integration-tests/gnunet_pyexpect.py.in83
-rw-r--r--src/integration-tests/gnunet_testing.py.in82
-rwxr-xr-xsrc/integration-tests/test_integration_bootstrap_and_connect.py.in24
-rwxr-xr-xsrc/integration-tests/test_integration_clique.py.in6
-rwxr-xr-xsrc/integration-tests/test_integration_clique_nat.py.in6
-rwxr-xr-xsrc/integration-tests/test_integration_disconnect.py.in4
-rwxr-xr-xsrc/integration-tests/test_integration_restart.py.in4
7 files changed, 151 insertions, 58 deletions
diff --git a/src/integration-tests/gnunet_pyexpect.py.in b/src/integration-tests/gnunet_pyexpect.py.in
new file mode 100644
index 000000000..9e5c83fa3
--- /dev/null
+++ b/src/integration-tests/gnunet_pyexpect.py.in
@@ -0,0 +1,83 @@
1#!@PYTHON@
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# Testcase for gnunet-peerinfo
21from __future__ import print_function
22import os
23import re
24import subprocess
25import sys
26import shutil
27import time
28
29class pexpect (object):
30 def __init__ (self):
31 super (pexpect, self).__init__ ()
32
33 def spawn (self, stdin, arglist, *pargs, **kwargs):
34 env = kwargs.pop ('env', None)
35 if env is None:
36 env = os.environ.copy ()
37 # This messes up some testcases, disable log redirection
38 env.pop ('GNUNET_FORCE_LOGFILE', None)
39 self.proc = subprocess.Popen (arglist, *pargs, env=env, **kwargs)
40 if self.proc is None:
41 print ("Failed to spawn a process {0}".format (arglist))
42 sys.exit (1)
43 if stdin is not None:
44 self.stdo, self.stde = self.proc.communicate (stdin)
45 else:
46 self.stdo, self.stde = self.proc.communicate ()
47 return self.proc
48
49 def expect (self, s, r, flags=0):
50 stream = self.stdo if s == 'stdout' else self.stde
51 if isinstance (r, str):
52 if r == "EOF":
53 if len (stream) == 0:
54 return True
55 else:
56 print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream)))
57 sys.exit (2)
58 raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r))
59 m = r.search (stream, flags)
60 if not m:
61 print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream))
62 sys.exit (2)
63 stream = stream[m.end ():]
64 if s == 'stdout':
65 self.stdo = stream
66 else:
67 self.stde = stream
68 return m
69
70 def read (self, s, size=-1):
71 stream = self.stdo if s == 'stdout' else self.stde
72 result = ""
73 if size < 0:
74 result = stream
75 new_stream = ""
76 else:
77 result = stream[0:size]
78 new_stream = stream[size:]
79 if s == 'stdout':
80 self.stdo = new_stream
81 else:
82 self.stde = new_stream
83 return result
diff --git a/src/integration-tests/gnunet_testing.py.in b/src/integration-tests/gnunet_testing.py.in
index 9d4a32877..cbafb0e31 100644
--- a/src/integration-tests/gnunet_testing.py.in
+++ b/src/integration-tests/gnunet_testing.py.in
@@ -1,4 +1,4 @@
1#!@PYTHON@ 1#!/usr/bin/python
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 Christian Grothoff (and other contributing authors)
4# 4#
@@ -19,12 +19,11 @@
19# 19#
20# Functions for integration testing 20# Functions for integration testing
21import os 21import os
22import re
23import subprocess 22import subprocess
24import sys 23import sys
25import shutil 24import shutil
26import time 25import time
27 26from gnunet_pyexpect import pexpect
28 27
29class Check: 28class Check:
30 def __init__(self, test): 29 def __init__(self, test):
@@ -56,11 +55,11 @@ class Check:
56 neg_cont (self) 55 neg_cont (self)
57 else: 56 else:
58 pos_cont (self) 57 pos_cont (self)
59 def eval(self, failed_only): 58 def evaluate (self, failed_only):
60 pos = 0 59 pos = 0
61 neg = 0 60 neg = 0
62 for c in self.conditions: 61 for c in self.conditions:
63 if (False == c.eval (failed_only)): 62 if (False == c.evaluate (failed_only)):
64 neg += 1 63 neg += 1
65 else: 64 else:
66 pos += 1 65 pos += 1
@@ -76,7 +75,7 @@ class Condition:
76 self.type = type 75 self.type = type
77 def check(self): 76 def check(self):
78 return False; 77 return False;
79 def eval(self, failed_only): 78 def evaluate (self, failed_only):
80 if ((self.fulfilled == False) and (failed_only == True)): 79 if ((self.fulfilled == False) and (failed_only == True)):
81 print str(self.type) + 'condition for was ' + str(self.fulfilled) 80 print str(self.type) + 'condition for was ' + str(self.fulfilled)
82 elif (failed_only == False): 81 elif (failed_only == False):
@@ -98,7 +97,7 @@ class FileExistCondition (Condition):
98 return False 97 return False
99 else: 98 else:
100 return True 99 return True
101 def eval(self, failed_only): 100 def evaluate (self, failed_only):
102 if ((self.fulfilled == False) and (failed_only == True)): 101 if ((self.fulfilled == False) and (failed_only == True)):
103 print str(self.type) + 'condition for file '+self.file+' was ' + str(self.fulfilled) 102 print str(self.type) + 'condition for file '+self.file+' was ' + str(self.fulfilled)
104 elif (failed_only == False): 103 elif (failed_only == False):
@@ -124,11 +123,11 @@ class StatisticsCondition (Condition):
124 return False 123 return False
125 else: 124 else:
126 return True 125 return True
127 def eval(self, failed_only): 126 def evaluate (self, failed_only):
128 if (self.result == -1): 127 if (self.result == -1):
129 res = 'NaN' 128 res = 'NaN'
130 else: 129 else:
131 res = str(self.result) 130 res = str(self.result)
132 if (self.fulfilled == False): 131 if (self.fulfilled == False):
133 fail = " FAIL!" 132 fail = " FAIL!"
134 op = " != " 133 op = " != "
@@ -144,47 +143,50 @@ class StatisticsCondition (Condition):
144class Test: 143class Test:
145 def __init__(self, testname, verbose): 144 def __init__(self, testname, verbose):
146 self.peers = list() 145 self.peers = list()
147 self.verbose = verbose; 146 self.verbose = verbose;
148 self.name = testname; 147 self.name = testname;
149 srcdir = "../.." 148 srcdir = "../.."
150 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") 149 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
151 if gnunet_pyexpect_dir not in sys.path: 150 if gnunet_pyexpect_dir not in sys.path:
152 sys.path.append (gnunet_pyexpect_dir) 151 sys.path.append (gnunet_pyexpect_dir)
153 from gnunet_pyexpect import pexpect
154 self.gnunetarm = '' 152 self.gnunetarm = ''
155 self.gnunetstatistics = '' 153 self.gnunetstatistics = ''
156 if os.name == 'posix': 154 if os.name == 'posix':
157 self.gnunetarm = 'gnunet-arm' 155 self.gnunetarm = 'gnunet-arm'
158 self.gnunetstatistics = 'gnunet-statistics' 156 self.gnunetstatistics = 'gnunet-statistics'
157 self.gnunetpeerinfo = 'gnunet-peerinfo'
159 elif os.name == 'nt': 158 elif os.name == 'nt':
160 self.gnunetarm = 'gnunet-arm.exe' 159 self.gnunetarm = 'gnunet-arm.exe'
161 self.gnunetstatistics = 'gnunet-statistics.exe' 160 self.gnunetstatistics = 'gnunet-statistics.exe'
161 self.gnunetpeerinfo = 'gnunet-peerinfo.exe'
162 if os.name == "nt": 162 if os.name == "nt":
163 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True) 163 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
164 else: 164 else:
165 shutil.rmtree ("/tmp/" + testname, True) 165 shutil.rmtree ("/tmp/" + testname, True)
166 def add_peer (peer): 166 def add_peer (self, peer):
167 self.conditions.append(condition) 167 self.peers.append(peer)
168 def p (self, msg): 168 def p (self, msg):
169 if (self.verbose == True): 169 if (self.verbose == True):
170 print msg 170 print msg
171 171
172class Peer: 172class Peer:
173 def __init__(self, test, cfg_file): 173 def __init__(self, test, cfg_file):
174 if (False == os.path.isfile(cfg_file)): 174 if (False == os.path.isfile(cfg_file)):
175 print ("Peer cfg " + cfg_file + ": FILE NOT FOUND") 175 print ("Peer cfg " + cfg_file + ": FILE NOT FOUND")
176 self.id = ""
176 self.test = test 177 self.test = test
177 self.started = False 178 self.started = False
178 self.cfg = cfg_file 179 self.cfg = cfg_file
179 def __del__(self): 180 def __del__(self):
180 if (self.started == True): 181 if (self.started == True):
181 print 'ERROR! Peer using cfg ' + self.cfg + ' was not stopped' 182 print 'ERROR! Peer using cfg ' + self.cfg + ' was not stopped'
182 if (ret == self.stop ()): 183 ret = self.stop ()
183 print 'ERROR! Peer using cfg ' + self.cfg + ' could not be stopped' 184 if (False == ret):
184 self.started == False 185 print 'ERROR! Peer using cfg ' + self.cfg + ' could not be stopped'
185 return ret 186 self.started = False
186 else: 187 return ret
187 return False 188 else:
189 return False
188 def start (self): 190 def start (self):
189 self.test.p ("Starting peer using cfg " + self.cfg) 191 self.test.p ("Starting peer using cfg " + self.cfg)
190 try: 192 try:
@@ -194,11 +196,20 @@ class Peer:
194 print "Can not start peer" 196 print "Can not start peer"
195 self.started = False 197 self.started = False
196 return False 198 return False
197 self.started = True 199 self.started = True;
200 test = ''
201 try:
202 server = pexpect ()
203 server.spawn (None, [self.test.gnunetpeerinfo, '-c', self.cfg ,'-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
204 test = server.read("stdout", 1024)
205 except OSError:
206 print "Can not get peer identity"
207 test = (test.split('`')[1])
208 self.id = test.split('\'')[0]
198 return True 209 return True
199 def stop (self): 210 def stop (self):
200 if (self.started == False): 211 if (self.started == False):
201 return False 212 return False
202 self.test.p ("Stopping peer using cfg " + self.cfg) 213 self.test.p ("Stopping peer using cfg " + self.cfg)
203 try: 214 try:
204 server = subprocess.Popen ([self.test.gnunetarm, '-eq', '-c', self.cfg]) 215 server = subprocess.Popen ([self.test.gnunetarm, '-eq', '-c', self.cfg])
@@ -209,7 +220,6 @@ class Peer:
209 self.started = False 220 self.started = False
210 return True; 221 return True;
211 def get_statistics_value (self, subsystem, name): 222 def get_statistics_value (self, subsystem, name):
212 from gnunet_pyexpect import pexpect
213 server = pexpect () 223 server = pexpect ()
214 server.spawn (None, [self.test.gnunetstatistics, '-c', self.cfg ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 224 server.spawn (None, [self.test.gnunetstatistics, '-c', self.cfg ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
215 #server.expect ("stdout", re.compile (r"")) 225 #server.expect ("stdout", re.compile (r""))
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 7738c72d8..1492d479d 100755
--- a/src/integration-tests/test_integration_bootstrap_and_connect.py.in
+++ b/src/integration-tests/test_integration_bootstrap_and_connect.py.in
@@ -1,4 +1,4 @@
1#!@PYTHON@ 1#!/usr/bin/python
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 Christian Grothoff (and other contributing authors)
4# 4#
@@ -68,7 +68,7 @@ def success_cont (check):
68def fail_cont (check): 68def fail_cont (check):
69 global success 69 global success
70 success = False; 70 success = False;
71 check.eval(True) 71 check.evaluate(True)
72 72
73def check (): 73def check ():
74 check = Check (test) 74 check = Check (test)
@@ -103,13 +103,13 @@ def run ():
103 server = Peer(test, './confs/c_bootstrap_server.conf'); 103 server = Peer(test, './confs/c_bootstrap_server.conf');
104 client = Peer(test, './confs/c_no_nat_client.conf'); 104 client = Peer(test, './confs/c_no_nat_client.conf');
105 105
106 server.start(); 106 assert (True == server.start());
107 client.start(); 107 assert (True == client.start());
108 108
109 if ((client.started == True) and (server.started == True)): 109 if ((client.started == True) and (server.started == True)):
110 test.p ('Peers started, running check') 110 test.p ('Peers started, running check')
111 time.sleep(5) 111 time.sleep(5)
112 check () 112 check ()
113 server.stop () 113 server.stop ()
114 client.stop () 114 client.stop ()
115 115
@@ -122,12 +122,12 @@ def run ():
122 return True 122 return True
123 123
124try: 124try:
125 run () 125 run ()
126except (KeyboardInterrupt, SystemExit): 126except (KeyboardInterrupt, SystemExit):
127 print 'Test interrupted' 127 print 'Test interrupted'
128 server.stop () 128 server.stop ()
129 client.stop () 129 client.stop ()
130 cleanup () 130 cleanup ()
131if (success == False): 131if (success == False):
132 sys.exit(1) 132 sys.exit(1)
133else: 133else:
diff --git a/src/integration-tests/test_integration_clique.py.in b/src/integration-tests/test_integration_clique.py.in
index 5cd8d9bb5..49a2c592c 100755
--- a/src/integration-tests/test_integration_clique.py.in
+++ b/src/integration-tests/test_integration_clique.py.in
@@ -63,7 +63,7 @@ def success_cont (check):
63def fail_cont (check): 63def fail_cont (check):
64 global success 64 global success
65 success= False; 65 success= False;
66 check.eval(True) 66 check.evaluate(True)
67 67
68 68
69def check_disconnect_client (): 69def check_disconnect_client ():
@@ -87,7 +87,7 @@ def success_disconnect_server_cont (check):
87def fail_disconnect_server_cont (check): 87def fail_disconnect_server_cont (check):
88 global success 88 global success
89 success= False; 89 success= False;
90 check.eval(True) 90 check.evaluate(True)
91 91
92 92
93def check_disconnect_server (): 93def check_disconnect_server ():
@@ -116,7 +116,7 @@ def success_connect_cont (check):
116def fail_connect_cont (check): 116def fail_connect_cont (check):
117 global success 117 global success
118 success= False; 118 success= False;
119 check.eval(True) 119 check.evaluate(True)
120 120
121 121
122def check_connect (): 122def check_connect ():
diff --git a/src/integration-tests/test_integration_clique_nat.py.in b/src/integration-tests/test_integration_clique_nat.py.in
index 0ea0a78cf..e8f771950 100755
--- a/src/integration-tests/test_integration_clique_nat.py.in
+++ b/src/integration-tests/test_integration_clique_nat.py.in
@@ -63,7 +63,7 @@ def success_cont (check):
63def fail_cont (check): 63def fail_cont (check):
64 global success 64 global success
65 success= False; 65 success= False;
66 check.eval(True) 66 check.evaluate(True)
67 67
68 68
69def check_disconnect_client (): 69def check_disconnect_client ():
@@ -87,7 +87,7 @@ def success_disconnect_server_cont (check):
87def fail_disconnect_server_cont (check): 87def fail_disconnect_server_cont (check):
88 global success 88 global success
89 success= False; 89 success= False;
90 check.eval(True) 90 check.evaluate(False)
91 91
92 92
93def check_disconnect_server (): 93def check_disconnect_server ():
@@ -116,7 +116,7 @@ def success_connect_cont (check):
116def fail_connect_cont (check): 116def fail_connect_cont (check):
117 global success 117 global success
118 success= False; 118 success= False;
119 check.eval(True) 119 check.evaluate(False)
120 120
121 121
122def check_connect (): 122def check_connect ():
diff --git a/src/integration-tests/test_integration_disconnect.py.in b/src/integration-tests/test_integration_disconnect.py.in
index 4c08289f5..5e137cfff 100755
--- a/src/integration-tests/test_integration_disconnect.py.in
+++ b/src/integration-tests/test_integration_disconnect.py.in
@@ -64,7 +64,7 @@ def success_disconnect_cont (check):
64def fail_disconnect_cont (check): 64def fail_disconnect_cont (check):
65 global success 65 global success
66 success = False; 66 success = False;
67 check.eval(True) 67 check.evaluate(True)
68 68
69 69
70def check_disconnect (): 70def check_disconnect ():
@@ -86,7 +86,7 @@ def success_connect_cont (check):
86def fail_connect_cont (check): 86def fail_connect_cont (check):
87 global success 87 global success
88 success= False; 88 success= False;
89 check.eval(True) 89 check.evaluate(True)
90 90
91 91
92def check_connect (): 92def check_connect ():
diff --git a/src/integration-tests/test_integration_restart.py.in b/src/integration-tests/test_integration_restart.py.in
index 6a5c2ba4f..e2a72e729 100755
--- a/src/integration-tests/test_integration_restart.py.in
+++ b/src/integration-tests/test_integration_restart.py.in
@@ -68,7 +68,7 @@ def success_restart_cont (check):
68def fail_restart_cont (check): 68def fail_restart_cont (check):
69 global success 69 global success
70 success = False; 70 success = False;
71 check.eval(True) 71 check.evaluate(True)
72 72
73 73
74def success_connect_cont (check): 74def success_connect_cont (check):
@@ -101,7 +101,7 @@ def success_connect_cont (check):
101def fail_connect_cont (check): 101def fail_connect_cont (check):
102 global success 102 global success
103 success= False; 103 success= False;
104 check.eval(True) 104 check.evaluate(True)
105 105
106 106
107def check_connect (): 107def check_connect ():