diff options
Diffstat (limited to 'src/integration-tests/gnunet_testing.py.in')
-rw-r--r-- | src/integration-tests/gnunet_testing.py.in | 82 |
1 files changed, 46 insertions, 36 deletions
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 |
21 | import os | 21 | import os |
22 | import re | ||
23 | import subprocess | 22 | import subprocess |
24 | import sys | 23 | import sys |
25 | import shutil | 24 | import shutil |
26 | import time | 25 | import time |
27 | 26 | from gnunet_pyexpect import pexpect | |
28 | 27 | ||
29 | class Check: | 28 | class 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): | |||
144 | class Test: | 143 | class 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 | ||
172 | class Peer: | 172 | class 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"")) |