test_python_magic_wormhole.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import os
  2. import time
  3. from tests.package.test_python import TestPythonPackageBase
  4. class TestPythonPy3MagicWormhole(TestPythonPackageBase):
  5. __test__ = True
  6. config = TestPythonPackageBase.config + \
  7. """
  8. BR2_PACKAGE_PYTHON3=y
  9. BR2_PACKAGE_PYTHON_MAGIC_WORMHOLE=y
  10. BR2_PACKAGE_PYTHON_MAGIC_WORMHOLE_MAILBOX_SERVER=y
  11. BR2_PACKAGE_PYTHON_MAGIC_WORMHOLE_TRANSIT_RELAY=y
  12. BR2_TARGET_ROOTFS_CPIO=y
  13. # BR2_TARGET_ROOTFS_TAR is not set
  14. """
  15. timeout = 60
  16. def twistd_cmd(self, command):
  17. s = "twistd"
  18. s += " --pidfile=/tmp/{}.pid".format(command)
  19. s += " --logfile=/tmp/{}.log".format(command)
  20. s += " {}".format(command)
  21. return s
  22. def test_run(self):
  23. code = "123-hello-buildroot"
  24. text = "Hello Buildroot!"
  25. relay_url = "ws://localhost:4000/v1"
  26. transit_helper = "tcp:localhost:4001"
  27. img = os.path.join(self.builddir, "images", "rootfs.cpio")
  28. self.emulator.boot(arch="armv5", kernel="builtin",
  29. options=["-initrd", img])
  30. self.emulator.login()
  31. cmd = self.twistd_cmd("wormhole-mailbox")
  32. self.assertRunOk(cmd, timeout=30)
  33. cmd = self.twistd_cmd("transitrelay")
  34. self.assertRunOk(cmd, timeout=30)
  35. wormhole_cmd = "wormhole --relay-url={} --transit-helper={}".format(
  36. relay_url, transit_helper)
  37. cmd = wormhole_cmd
  38. cmd += f" send --code={code} --text=\"{text}\""
  39. cmd += " &> /dev/null &"
  40. self.assertRunOk(cmd)
  41. time.sleep(30 * self.timeout_multiplier)
  42. wormhole_env = "_MAGIC_WORMHOLE_TEST_KEY_TIMER=100 "
  43. wormhole_env += "_MAGIC_WORMHOLE_TEST_VERIFY_TIMER=100 "
  44. cmd = wormhole_env + wormhole_cmd + " receive {}".format(code)
  45. output, exit_code = self.emulator.run(cmd, timeout=35)
  46. self.assertEqual(exit_code, 0)
  47. self.assertEqual(output[0], text)