test_fping.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import time
  3. import infra.basetest
  4. class TestFping(infra.basetest.BRTest):
  5. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  6. """
  7. BR2_PACKAGE_FPING=y
  8. BR2_TARGET_ROOTFS_CPIO=y
  9. # BR2_TARGET_ROOTFS_TAR is not set
  10. """
  11. def test_run(self):
  12. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  13. self.emulator.boot(arch="armv5",
  14. kernel="builtin",
  15. options=["-initrd", cpio_file])
  16. self.emulator.login()
  17. # Check the program can execute.
  18. self.assertRunOk("fping --version")
  19. # Fping v5.1 need to wait few seconds after a kernel booted
  20. # before starting. This sleep time can be removed when the
  21. # issue will be closed and the package updated. See:
  22. # https://github.com/schweikert/fping/issues/288
  23. time.sleep(5 * self.timeout_multiplier)
  24. # Run 3 pings on localhost.
  25. self.assertRunOk("fping -e -c 3 localhost")
  26. # Run pings on a local subnet and print statistics.
  27. self.assertRunOk("fping -s -g 127.0.0.0/28")
  28. # Test an IPv6 ping.
  29. self.assertRunOk("fping -6 ::1")
  30. # Create a prohibited route to make fping fail.
  31. self.assertRunOk("ip route add to prohibit 192.168.12.0/24")
  32. # We expect fping to fail when pinging the prohibited network.
  33. _, ret = self.emulator.run("fping 192.168.12.34")
  34. self.assertNotEqual(ret, 0)