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