aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo-tool/test_gnunet_peerinfo.py.in
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-28 16:41:51 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-28 16:41:51 +0000
commit5b67d6c02e73b430db312cbcffa5f6bc51f3eedd (patch)
treef1cc70b0cfae2ced97ec337036103b4871830676 /src/peerinfo-tool/test_gnunet_peerinfo.py.in
parent95bb20a634949a52cbd097ac929a390f150af413 (diff)
downloadgnunet-5b67d6c02e73b430db312cbcffa5f6bc51f3eedd.tar.gz
gnunet-5b67d6c02e73b430db312cbcffa5f6bc51f3eedd.zip
mantis 1739
Diffstat (limited to 'src/peerinfo-tool/test_gnunet_peerinfo.py.in')
-rwxr-xr-xsrc/peerinfo-tool/test_gnunet_peerinfo.py.in145
1 files changed, 113 insertions, 32 deletions
diff --git a/src/peerinfo-tool/test_gnunet_peerinfo.py.in b/src/peerinfo-tool/test_gnunet_peerinfo.py.in
index 86ce87eda..7751d533c 100755
--- a/src/peerinfo-tool/test_gnunet_peerinfo.py.in
+++ b/src/peerinfo-tool/test_gnunet_peerinfo.py.in
@@ -18,47 +18,128 @@
18# Boston, MA 02111-1307, USA. 18# Boston, MA 02111-1307, USA.
19# 19#
20# Testcase for gnunet-peerinfo 20# Testcase for gnunet-peerinfo
21import pexpect 21#import pexpect
22from __future__ import print_function
22import os 23import os
23import signal 24#import signal
24import re 25import re
26import subprocess
27import sys
28import shutil
29import time
25 30
26pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf') 31class pexpect (object):
27pinfo.expect ('Error in communication with PEERINFO service\r') 32 def __init__ (self):
28pinfo.expect (pexpect.EOF); 33 super (pexpect, self).__init__ ()
29os.system ('rm -rf /tmp/gnunet-test-peerinfo/') 34
30os.system ('gnunet-arm -sq -c test_gnunet_peerinfo_data.conf') 35 def spawn (self, stdin, arglist, *pargs, **kwargs):
36 self.proc = subprocess.Popen (arglist, *pargs, **kwargs)
37 if self.proc is None:
38 print ("Failed to spawn a process {0}".format (arglist))
39 sys.exit (1)
40 if stdin is not None:
41 self.stdo, self.stde = self.proc.communicate (stdin)
42 else:
43 self.stdo, self.stde = self.proc.communicate ()
44 return self.proc
45
46 def expect (self, s, r, flags=0):
47 stream = self.stdo if s == 'stdout' else self.stde
48 if isinstance (r, str):
49 if r == "EOF":
50 if len (stream) == 0:
51 return True
52 else:
53 print ("Failed to match {0} with `{1}'. {0} is `{2}'".format (s, r, stream))
54 sys.exit (2)
55 raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r))
56 m = r.match (stream, flags)
57 if not m:
58 print ("Failed to match {0} with `{1}'. {0} is `{2}'".format (s, r.pattern, stream))
59 sys.exit (2)
60 stream = stream[m.end ():]
61 if s == 'stdout':
62 self.stdo = stream
63 else:
64 self.stde = stream
65 return m
66
67 def read (self, s, size=-1):
68 stream = self.stdo if s == 'stdout' else self.stde
69 result = ""
70 if size < 0:
71 result = stream
72 new_stream = ""
73 else:
74 result = stream[0:size]
75 new_stream = stream[size:]
76 if s == 'stdout':
77 self.stdo = new_stream
78 else:
79 self.stde = new_stream
80 return result
81
82if os.name == 'posix':
83 peerinfo = 'gnunet-peerinfo'
84 gnunetarm = 'gnunet-arm'
85elif os.name == 'nt':
86 peerinfo = 'gnunet-peerinfo.exe'
87 gnunetarm = 'gnunet-arm.exe'
31 88
32try:
33 pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -s')
34 pinfo.expect (re.compile ("I am peer `.*\'.\r"));
35 pinfo.expect (pexpect.EOF);
36 89
37 pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -qs')
38 pinfo.expect (re.compile (".......................................................................................................\r"));
39 pinfo.expect (pexpect.EOF);
40 90
41 pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf invalid') 91pinfo = pexpect ()
42 pinfo.expect (re.compile ("Invalid command line argument `invalid\'\r")); 92pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-L', 'ERROR'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
43 pinfo.expect (pexpect.EOF); 93pinfo.expect ("stdout", re.compile (r'Error in communication with PEERINFO service\r?\n'))
94pinfo.expect ("stdout", "EOF")
44 95
96if os.name == "nt":
97 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "tmp", "gnunet-test-peerinfo"), True)
98else:
99 shutil.rmtree ("/tmp/gnunet-test-peerinfo", True)
100arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf'])
101arm.communicate ()
45 102
46 os.system ('gnunet-arm -q -i transport -c test_gnunet_peerinfo_data.conf') 103try:
47 os.system ('sleep 1') 104 pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
48 pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf') 105 pinfo.expect ("stdout", re.compile (r'I am peer `.*\'.\r?\n'))
49 pinfo.expect (re.compile ("Peer `.*\'\r")); 106 pinfo.expect ("stdout", "EOF")
50 pinfo.expect (re.compile (" *:24357\r")); 107
51 pinfo.expect (pexpect.EOF); 108 pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
109 pinfo.expect ("stdout", re.compile (r'.......................................................................................................\r?\n'))
110 pinfo.expect ("stdout", "EOF")
111
112 pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
113 pinfo.expect ("stdout", re.compile (r'Invalid command line argument `invalid\'\r?\n'))
114 pinfo.expect ("stdout", "EOF")
52 115
53 pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -n') 116 arm = subprocess.Popen ([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf'])
54 pinfo.expect (re.compile ("Peer `.*\'\r")); 117 arm.communicate ()
55 pinfo.expect (re.compile (" *:24357\r")); 118 time.sleep (1)
56 pinfo.expect (pexpect.EOF);
57 119
58 pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -qs') 120 pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
59 pid = pinfo.read (-1) 121 pinfo.expect ("stdout", re.compile ("Peer `.*'\r?\n"))
60 pid = pid.strip () 122 m = pinfo.expect ("stdout", re.compile ("\s.*:24357\r?\n"))
123 while len (m.group (0)) > 0:
124 m = pinfo.expect ("stdout", re.compile ("(\s.*:24357\r?\n|\r?\n|)"))
125 pinfo.expect ("stdout", "EOF")
61 126
127 pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
128 pinfo.expect ("stdout", re.compile ("Peer `.*'\r?\n"))
129 m = pinfo.expect ("stdout", re.compile ("\s.*:24357\r?\n"))
130 while len (m.group (0)) > 0:
131 m = pinfo.expect ("stdout", re.compile ("(\s.*:24357\r?\n|\r?\n|)"))
132 pinfo.expect ("stdout", "EOF")
133
134 pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
135 pid = pinfo.read ("stdout")
136 pid.strip ()
137
62finally: 138finally:
63 os.system ('gnunet-arm -c test_gnunet_peerinfo_data.conf -eq') 139 arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf'])
64 os.system ('rm -rf /tmp/gnunet-test-peerinfo/') 140 arm.communicate ()
141 if os.name == "nt":
142 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "tmp", "gnunet-test-peerinfo"), True)
143 else:
144 shutil.rmtree ("/tmp/gnunet-test-peerinfo", True)
145