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.
20 # Functions for integration testing
30 def __init__(self, test):
31 self.fulfilled = False
32 self.conditions = list()
34 def add (self, condition):
35 self.conditions.append(condition)
40 for c in self.conditions:
41 if (False == c.check ()):
46 self.test.p (str(pos) +' out of '+ str (pos+neg) + ' conditions fulfilled')
48 def run_blocking (self, timeout, pos_cont, neg_cont):
51 while ((False == res) and (execs < timeout)):
59 def eval(self, failed_only):
62 for c in self.conditions:
63 if (False == c.eval (failed_only)):
67 print (str(pos) +' out of '+ str (pos+neg) + ' conditions fulfilled')
74 self.fulfilled = False
76 def __init__(self, type):
77 self.fulfilled = 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)
88 class FileExistCondition (Condition):
89 def __init__(self, file):
90 self.fulfilled = False
94 if (self.fulfilled == False):
95 res = os.path.isfile(self.file)
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
110 class StatisticsCondition (Condition):
111 def __init__(self, peer, subsystem, name, value):
112 self.fulfilled = False
113 self.type = 'statistics'
115 self.subsystem = subsystem;
119 if (self.fulfilled == False):
120 res = self.peer.check (self.subsystem, self.name, self.value);
122 self.fulfilled = 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
136 def __init__(self, testname, verbose):
138 self.verbose = verbose;
139 self.name = testname;
141 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
142 if gnunet_pyexpect_dir not in sys.path:
143 sys.path.append (gnunet_pyexpect_dir)
144 from gnunet_pyexpect import pexpect
146 self.gnunetstatistics = ''
147 if os.name == 'posix':
148 self.gnunetarm = 'gnunet-arm'
149 self.gnunetstatistics = 'gnunet-statistics'
150 elif os.name == 'nt':
151 self.gnunetarm = 'gnunet-arm.exe'
152 self.gnunetstatistics = 'gnunet-statistics.exe'
154 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
156 shutil.rmtree ("/tmp/" + testname, True)
158 self.conditions.append(condition)
160 if (self.verbose == True):
164 def __init__(self, test, cfg_file):
165 if (False == os.path.isfile(cfg_file)):
166 print ("Peer cfg " + cfg_file + ": FILE NOT FOUND")
171 if (self.started == True):
172 print 'ERROR! Peer using cfg ' + self.cfg + ' was not stopped'
173 if (ret == self.stop ()):
174 print 'ERROR! Peer using cfg ' + self.cfg + ' could not be stopped'
175 self.started == False
180 self.test.p ("Starting peer using cfg " + self.cfg)
182 server = subprocess.Popen ([self.test.gnunetarm, '-sq', '-c', self.cfg])
183 server.communicate ()
185 print "Can not start peer"
191 if (self.started == False):
193 self.test.p ("Stopping peer using cfg " + self.cfg)
195 server = subprocess.Popen ([self.test.gnunetarm, '-eq', '-c', self.cfg])
196 server.communicate ()
198 print "Can not stop peer"
202 def check (self, subsystem, name, value):
203 from gnunet_pyexpect import pexpect
205 server.spawn (None, [self.test.gnunetstatistics, '-c', self.cfg ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
206 #server.expect ("stdout", re.compile (r""))
207 test = server.read("stdout", 10240)
208 if (test.find(str(value)) == -1):