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 it
6 # under the terms of the GNU Affero General Public License as published
7 # by the Free Software Foundation, either version 3 of the License,
8 # or (at your 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 # Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Testcase for gnunet-peerinfo
27 gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts")
28 if gnunet_pyexpect_dir not in sys.path:
29 sys.path.append(gnunet_pyexpect_dir)
31 from gnunet_pyexpect import pexpect
33 if os.name == 'posix':
34 peerinfo = './gnunet-peerinfo'
35 gnunetarm = 'gnunet-arm'
36 gnunettesting = 'gnunet-testing'
38 peerinfo = './gnunet-peerinfo.exe'
39 gnunetarm = 'gnunet-arm.exe'
40 gnunettesting = 'gnunet-testing.exe'
46 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True)
48 shutil.rmtree("/tmp/gnunet-test-peerinfo", True)
50 # create hostkey via testing lib # FIXME: The /tmp/ location needs to be adjusted to the TMP variable!
51 hkk = subprocess.Popen([gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k', '/tmp/gnunet-test-peerinfo/.hostkey'])
54 arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf'])
58 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
59 pinfo.expect("stdout", re.compile(r'I am peer `.*\'.\r?\n'))
61 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
62 pinfo.expect("stdout", re.compile(r'....................................................\r?\n'))
64 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
65 pinfo.expect("stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n'))
67 arm = subprocess.Popen([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf'])
71 pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
72 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
73 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
74 while len(m.group(0)) > 0:
75 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
77 pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
78 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
79 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
80 while len(m.group(0)) > 0:
81 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
83 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
84 pid = pinfo.read("stdout")
88 arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf'])
91 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True)
93 shutil.rmtree("/tmp/gnunet-test-peerinfo", True)