test_gnunet_peerinfo.py.in 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!@PYTHON@
  2. # This file is part of GNUnet.
  3. # (C) 2010, 2018 Christian Grothoff (and other contributing authors)
  4. #
  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.
  9. #
  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.
  14. #
  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/>.
  17. #
  18. # SPDX-License-Identifier: AGPL3.0-or-later
  19. #
  20. # Testcase for gnunet-peerinfo
  21. import sys
  22. import os
  23. import subprocess
  24. import re
  25. import shutil
  26. import time
  27. srcdir = "../.."
  28. gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts")
  29. if gnunet_pyexpect_dir not in sys.path:
  30. sys.path.append(gnunet_pyexpect_dir)
  31. from gnunet_pyexpect import pexpect
  32. if os.name == 'posix':
  33. peerinfo = './gnunet-peerinfo'
  34. gnunetarm = 'gnunet-arm'
  35. gnunettesting = 'gnunet-testing'
  36. elif os.name == 'nt':
  37. peerinfo = './gnunet-peerinfo.exe'
  38. gnunetarm = 'gnunet-arm.exe'
  39. gnunettesting = 'gnunet-testing.exe'
  40. pinfo = pexpect()
  41. if os.name == "nt":
  42. shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True)
  43. else:
  44. shutil.rmtree("/tmp/gnunet-test-peerinfo", True)
  45. # create hostkey via testing lib # FIXME: The /tmp/ location needs to be adjusted to the TMP variable!
  46. hkk = subprocess.Popen([gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k', '/tmp/gnunet-test-peerinfo/.hostkey'])
  47. hkk.communicate()
  48. arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf'])
  49. arm.communicate()
  50. try:
  51. pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  52. pinfo.expect("stdout", re.compile(r'I am peer `.*\'.\r?\n'))
  53. pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  54. pinfo.expect("stdout", re.compile(r'....................................................\r?\n'))
  55. pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  56. pinfo.expect("stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n'))
  57. arm = subprocess.Popen([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf'])
  58. arm.communicate()
  59. time.sleep(1)
  60. pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  61. pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
  62. m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
  63. while len(m.group(0)) > 0:
  64. m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
  65. pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  66. pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
  67. m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
  68. while len(m.group(0)) > 0:
  69. m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
  70. pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  71. pid = pinfo.read("stdout")
  72. pid.strip()
  73. finally:
  74. arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf'])
  75. arm.communicate()
  76. if os.name == "nt":
  77. shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True)
  78. else:
  79. shutil.rmtree("/tmp/gnunet-test-peerinfo", True)