diff options
Diffstat (limited to 'src/integration-tests')
-rw-r--r-- | src/integration-tests/gnunet_testing.py.in | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/integration-tests/gnunet_testing.py.in b/src/integration-tests/gnunet_testing.py.in new file mode 100644 index 000000000..18fc7a249 --- /dev/null +++ b/src/integration-tests/gnunet_testing.py.in | |||
@@ -0,0 +1,90 @@ | |||
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 | # Functions for integration testing | ||
21 | import os | ||
22 | import re | ||
23 | import subprocess | ||
24 | import sys | ||
25 | import shutil | ||
26 | import time | ||
27 | |||
28 | class Test: | ||
29 | def __init__(self, testname, verbose): | ||
30 | self.verbose = verbose; | ||
31 | self.name = testname; | ||
32 | srcdir = "../.." | ||
33 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | ||
34 | if gnunet_pyexpect_dir not in sys.path: | ||
35 | sys.path.append (gnunet_pyexpect_dir) | ||
36 | from gnunet_pyexpect import pexpect | ||
37 | self.gnunetarm = '' | ||
38 | self.gnunetstatistics = '' | ||
39 | if os.name == 'posix': | ||
40 | self.gnunetarm = 'gnunet-arm' | ||
41 | self.gnunetstatistics = 'gnunet-statistics' | ||
42 | elif os.name == 'nt': | ||
43 | self.gnunetarm = 'gnunet-arm.exe' | ||
44 | self.gnunetstatistics = 'gnunet-statistics.exe' | ||
45 | if os.name == "nt": | ||
46 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True) | ||
47 | else: | ||
48 | shutil.rmtree ("/tmp/" + testname, True) | ||
49 | def p (self, msg): | ||
50 | print msg | ||
51 | |||
52 | class Peer: | ||
53 | def __init__(self, test, cfg_file): | ||
54 | if (False == os.path.isfile(cfg_file)): | ||
55 | print ("Peer cfg " + cfg_file + ": FILE NOT FOUND") | ||
56 | self.test = test | ||
57 | self.started = False | ||
58 | self.cfg = cfg_file | ||
59 | def start (self): | ||
60 | self.test.p ("Starting peer using cfg " + self.cfg) | ||
61 | try: | ||
62 | server = subprocess.Popen ([self.test.gnunetarm, '-sq', '-c', self.cfg]) | ||
63 | server.communicate () | ||
64 | except OSError: | ||
65 | print "Can not start peer" | ||
66 | self.started = False | ||
67 | return False | ||
68 | self.started = True | ||
69 | return True | ||
70 | def stop (self): | ||
71 | self.test.p ("Stopping peer using cfg " + self.cfg) | ||
72 | try: | ||
73 | server = subprocess.Popen ([self.test.gnunetarm, '-eq', '-c', self.cfg]) | ||
74 | server.communicate () | ||
75 | except OSError: | ||
76 | print "Can not stop peer" | ||
77 | return False | ||
78 | self.started = False | ||
79 | return True; | ||
80 | def check (self, subsystem, name, value): | ||
81 | from gnunet_pyexpect import pexpect | ||
82 | server = pexpect () | ||
83 | server.spawn (None, [self.test.gnunetstatistics, '-c', self.cfg ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
84 | #server.expect ("stdout", re.compile (r"")) | ||
85 | test = server.read("stdout", 10240) | ||
86 | if (test.find(str(value)) == -1): | ||
87 | return False | ||
88 | else: | ||
89 | return True | ||
90 | \ No newline at end of file | ||