#
# 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
+# by the Free Software Foundation; either version 3, or (at your
# option) any later version.
#
# GNUnet is distributed in the hope that it will be useful, but
# Boston, MA 02111-1307, USA.
#
# Testcase for gnunet-peerinfo
-import pexpect
+import sys
import os
-import signal
+import subprocess
import re
+import shutil
+import time
-pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf')
-pinfo.expect ('Timeout trying to interact with PEERINFO service\r')
-pinfo.expect (pexpect.EOF);
-os.system ('rm -rf /tmp/gnunet-test-peerinfo/')
-os.system ('gnunet-arm -sq -c test_gnunet_peerinfo_data.conf')
+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'
+ gnunettesting = 'gnunet-testing'
+elif os.name == 'nt':
+ peerinfo = './gnunet-peerinfo.exe'
+ gnunetarm = 'gnunet-arm.exe'
+ gnunettesting = 'gnunet-testing.exe'
+
+pinfo = pexpect ()
+pinfo.spawn (None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-L', 'ERROR'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+pinfo.expect ("stdout", re.compile (r'Service `peerinfo\' is not running, please start GNUnet\r?\n'))
+pinfo.expect ("stdout", "EOF")
-try:
- pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -s')
- pinfo.expect (re.compile ("I am peer `.*\'.\r"));
- pinfo.expect (pexpect.EOF);
- pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -qs')
- pinfo.expect (re.compile (".......................................................................................................\r"));
- pinfo.expect (pexpect.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)
- pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf invalid')
- pinfo.expect (re.compile ("Invalid command line argument `invalid\'\r"));
- pinfo.expect (pexpect.EOF);
+# create hostkey via testing lib
+hkk = subprocess.Popen ([gnunettesting, '-n 1', '-k', '/tmp/gnunet-test-peerinfo/.hostkey'])
+hkk.communicate ()
+arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf'])
+arm.communicate ()
- os.system ('gnunet-arm -q -i transport -c test_gnunet_peerinfo_data.conf')
- os.system ('sleep 1')
- pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf')
- pinfo.expect (re.compile ("Peer `.*\' with trust *0\r"));
- pinfo.expect (re.compile (" *localhost:24357\r"));
- pinfo.expect (pexpect.EOF);
+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 = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -n')
- pinfo.expect (re.compile ("Peer `.*\' with trust *0\r"));
- pinfo.expect (re.compile (" *127..*:24357\r"));
- pinfo.expect (pexpect.EOF);
+ 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'))
- pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -qs')
- pid = pinfo.read (-1)
- pid = pid.strip ()
+ arm = subprocess.Popen ([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf'])
+ arm.communicate ()
+ time.sleep (1)
- pinfo = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf 4 ' + pid)
- pinfo.expect (re.compile ("Peer `" + pid + "\' with trust *4\r"));
- pinfo.expect (pexpect.EOF);
+ pinfo.spawn (None, [peerinfo, '-i', '-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 = pexpect.spawn ('gnunet-peerinfo -c test_gnunet_peerinfo_data.conf -- -4 ' + pid)
- pinfo.expect (re.compile ("Peer `" + pid + "\' with trust *0\r"));
- pinfo.expect (pexpect.EOF);
+ pinfo.spawn (None, [peerinfo, '-i', '-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:
- os.system ('gnunet-arm -c test_gnunet_peerinfo_data.conf -eq')
- os.system ('rm -rf /tmp/gnunet-test-peerinfo/')
+ 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)
+