test_netcat.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os
  2. import time
  3. import infra.basetest
  4. class TestNetCat(infra.basetest.BRTest):
  5. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  6. """
  7. BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
  8. BR2_PACKAGE_NETCAT=y
  9. BR2_TARGET_ROOTFS_CPIO=y
  10. # BR2_TARGET_ROOTFS_TAR is not set
  11. """
  12. def test_run(self):
  13. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  14. self.emulator.boot(arch="armv5",
  15. kernel="builtin",
  16. options=["-initrd", cpio_file])
  17. self.emulator.login()
  18. self.assertRunOk("nc --version")
  19. msg = "Hello Buildroot!"
  20. out_file = "output.txt"
  21. port = 12345
  22. cmd = f"nc -n -l -p {port} > {out_file} 2> /dev/null &"
  23. self.assertRunOk(cmd)
  24. time.sleep(5)
  25. cmd = f"echo '{msg}' | nc -n -c 127.0.0.1 {port}"
  26. self.assertRunOk(cmd)
  27. cmd = f"cat {out_file}"
  28. out, ret = self.emulator.run(cmd)
  29. self.assertEqual(ret, 0)
  30. self.assertEqual(out[0], msg)