test_netcat.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. in_file = "input.bin"
  20. out_file = "output.bin"
  21. port = 12345
  22. cmd = f"dd if=/dev/urandom of={in_file} bs=1k count=1k"
  23. self.assertRunOk(cmd)
  24. cmd = f"nc -l -p {port} > {out_file} &"
  25. self.assertRunOk(cmd)
  26. time.sleep(1)
  27. cmd = f"cat {in_file} | nc -c 127.0.0.1 {port}"
  28. self.assertRunOk(cmd)
  29. cmd = f"cmp {in_file} {out_file}"
  30. self.assertRunOk(cmd)