test_tcpdump.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os
  2. import time
  3. import infra.basetest
  4. class TestTcpdump(infra.basetest.BRTest):
  5. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  6. """
  7. BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
  8. BR2_PACKAGE_TCPDUMP=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. capture_file = "capture.pcap"
  19. decode_log = "decode.log"
  20. # Check the program can execute.
  21. self.assertRunOk("tcpdump --version")
  22. # Run ping in background.
  23. cmd = "ping localhost >/dev/null &"
  24. self.assertRunOk(cmd)
  25. time.sleep(1)
  26. # Capture 3 packets with the message.
  27. cmd = f"tcpdump -c 3 -w {capture_file} icmp"
  28. self.assertRunOk(cmd)
  29. # Decode the capture file.
  30. cmd = f"tcpdump -r {capture_file} > {decode_log}"
  31. self.assertRunOk(cmd)
  32. # Check we have ICMP echo requests/replies in the
  33. # decoded capture.
  34. cmd = f"grep -E 'ICMP echo (request|reply)' {decode_log}"
  35. self.assertRunOk(cmd)