aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo-tool/test_gnunet_peerinfo.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo-tool/test_gnunet_peerinfo.py.in')
-rwxr-xr-xsrc/peerinfo-tool/test_gnunet_peerinfo.py.in93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/peerinfo-tool/test_gnunet_peerinfo.py.in b/src/peerinfo-tool/test_gnunet_peerinfo.py.in
new file mode 100755
index 0000000..ee8bc4a
--- /dev/null
+++ b/src/peerinfo-tool/test_gnunet_peerinfo.py.in
@@ -0,0 +1,93 @@
+#!@PYTHON@
+# This file is part of GNUnet.
+# (C) 2010 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING. If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# Testcase for gnunet-peerinfo
+import sys
+import os
+import subprocess
+import re
+import shutil
+import time
+
+srcdir = "../.."
+gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
+if gnunet_pyexpect_dir not in sys.path:
+ sys.path.append (gnunet_pyexpect_dir)
+
+from gnunet_pyexpect import pexpect
+
+if os.name == 'posix':
+ peerinfo = 'gnunet-peerinfo'
+ gnunetarm = 'gnunet-arm'
+elif os.name == 'nt':
+ peerinfo = 'gnunet-peerinfo.exe'
+ gnunetarm = 'gnunet-arm.exe'
+
+
+
+pinfo = pexpect ()
+pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-L', 'ERROR'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+pinfo.expect ("stdout", re.compile (r'Error in communication with PEERINFO service\r?\n'))
+pinfo.expect ("stdout", "EOF")
+
+if os.name == "nt":
+ shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-peerinfo"), True)
+else:
+ shutil.rmtree ("/tmp/gnunet-test-peerinfo", True)
+arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf'])
+arm.communicate ()
+
+try:
+ pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ pinfo.expect ("stdout", re.compile (r'I am peer `.*\'.\r?\n'))
+
+ pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ pinfo.expect ("stdout", re.compile (r'.......................................................................................................\r?\n'))
+
+ pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ pinfo.expect ("stdout", re.compile (r'Invalid command line argument `invalid\'\r?\n'))
+
+ arm = subprocess.Popen ([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf'])
+ arm.communicate ()
+ time.sleep (1)
+
+ pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ pinfo.expect ("stdout", re.compile ("Peer `.*'\r?\n"))
+ m = pinfo.expect ("stdout", re.compile ("\s.*:24357\r?\n"))
+ while len (m.group (0)) > 0:
+ m = pinfo.expect ("stdout", re.compile ("(\s.*:24357\r?\n|\r?\n|)"))
+
+ pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ pinfo.expect ("stdout", re.compile ("Peer `.*'\r?\n"))
+ m = pinfo.expect ("stdout", re.compile ("\s.*:24357\r?\n"))
+ while len (m.group (0)) > 0:
+ m = pinfo.expect ("stdout", re.compile ("(\s.*:24357\r?\n|\r?\n|)"))
+
+ pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ pid = pinfo.read ("stdout")
+ pid.strip ()
+
+finally:
+ arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf'])
+ arm.communicate ()
+ if os.name == "nt":
+ shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-peerinfo"), True)
+ else:
+ shutil.rmtree ("/tmp/gnunet-test-peerinfo", True)
+