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 # SPDX-License-Identifier: AGPL3.0-or-later
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 #save LANG and set it to C
36 mylang = os.environ['LANG']
37 os.environ['LANG'] = 'C'
39 if os.name == 'posix':
40 peerinfo = './gnunet-peerinfo'
41 gnunetarm = 'gnunet-arm'
42 gnunettesting = 'gnunet-testing'
44 peerinfo = './gnunet-peerinfo.exe'
45 gnunetarm = 'gnunet-arm.exe'
46 gnunettesting = 'gnunet-testing.exe'
51 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True)
53 shutil.rmtree("/tmp/gnunet-test-peerinfo", True)
55 # create hostkey via testing lib # FIXME: The /tmp/ location needs to be adjusted to the TMP variable!
56 hkk = subprocess.Popen([
57 gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k',
58 '/tmp/gnunet-test-peerinfo/.hostkey'
62 arm = subprocess.Popen([
63 gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf'
69 None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'],
70 stdout=subprocess.PIPE,
71 stderr=subprocess.STDOUT
73 pinfo.expect("stdout", re.compile(r'I am peer `.*\'.\r?\n'))
76 None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'],
77 stdout=subprocess.PIPE,
78 stderr=subprocess.STDOUT
83 compile(r'....................................................\r?\n')
87 None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'],
88 stdout=subprocess.PIPE,
89 stderr=subprocess.STDOUT
92 "stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n')
95 arm = subprocess.Popen([
96 gnunetarm, '-q', '-i', 'transport', '-c',
97 'test_gnunet_peerinfo_data.conf'
103 None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'],
104 stdout=subprocess.PIPE,
105 stderr=subprocess.STDOUT
107 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
108 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
109 while len(m.group(0)) > 0:
110 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
113 None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'],
114 stdout=subprocess.PIPE,
115 stderr=subprocess.STDOUT
117 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
118 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
119 while len(m.group(0)) > 0:
120 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
123 None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'],
124 stdout=subprocess.PIPE,
125 stderr=subprocess.STDOUT
127 pid = pinfo.read("stdout")
131 arm = subprocess.Popen([
132 gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf'
137 os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True
140 shutil.rmtree("/tmp/gnunet-test-peerinfo", True)
142 os.environ['LANG'] = mylang