2 # This file is part of GNUnet.
3 # (C) 2010, 2018 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 3, 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., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301, USA.
20 # Testcase for gnunet-peerinfo
29 gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts")
30 if gnunet_pyexpect_dir not in sys.path:
31 sys.path.append(gnunet_pyexpect_dir)
33 from gnunet_pyexpect import pexpect
35 if os.name == 'posix':
36 peerinfo = './gnunet-peerinfo'
37 gnunetarm = 'gnunet-arm'
38 gnunettesting = 'gnunet-testing'
40 peerinfo = './gnunet-peerinfo.exe'
41 gnunetarm = 'gnunet-arm.exe'
42 gnunettesting = 'gnunet-testing.exe'
48 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True)
50 shutil.rmtree("/tmp/gnunet-test-peerinfo", True)
52 # create hostkey via testing lib # FIXME: The /tmp/ location needs to be adjusted to the TMP variable!
53 hkk = subprocess.Popen([gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k', '/tmp/gnunet-test-peerinfo/.hostkey'])
56 arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf'])
60 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
61 pinfo.expect("stdout", re.compile(r'I am peer `.*\'.\r?\n'))
63 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
64 pinfo.expect("stdout", re.compile(r'....................................................\r?\n'))
66 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
67 pinfo.expect("stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n'))
69 arm = subprocess.Popen([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf'])
73 pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
74 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
75 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
76 while len(m.group(0)) > 0:
77 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
79 pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
80 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
81 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
82 while len(m.group(0)) > 0:
83 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
85 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
86 pid = pinfo.read("stdout")
90 arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf'])
93 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True)
95 shutil.rmtree("/tmp/gnunet-test-peerinfo", True)