MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / multiple_ping_test

Function multiple_ping_test

components/net/utest/tc_netdev.c:51–75  ·  view source on GitHub ↗

* @brief Execute multiple ping tests and calculate success rate * * This function performs multiple ping operations to a specified host and determines * test results based on success rate. The test passes if success rate exceeds 80%. * * @param netdev Network device pointer * @param host Target host address (IP address or domain name) * @param n Number of ping test attempts * @return rt_er

Source from the content-addressed store, hash-verified

49 * @note This function uses 32-byte data packets with a 5-second timeout
50 */
51rt_err_t multiple_ping_test(struct netdev *netdev, const char *host, rt_uint32_t n)
52{
53#define UTEST_PING_DATA_LEN 32 /* Ping data packet size */
54#define UTEST_PING_TIMEOUT (5 * RT_TICK_PER_SECOND) /* Ping timeout: 5 seconds */
55
56 rt_uint32_t success_num = 0, i;
57 rt_err_t res = RT_EOK;
58 struct netdev_ping_resp ping_resp;
59
60 /* Execute ping operations n times */
61 for (i = 0; i < n; i++)
62 {
63 res = netdev->ops->ping(netdev, host, UTEST_PING_DATA_LEN, UTEST_PING_TIMEOUT, &ping_resp, RT_FALSE);
64 if (res == RT_EOK)
65 {
66 success_num++;
67 }
68 }
69
70 /* Test passes if success rate is more than 80 percent */
71 if (success_num >= ceil(0.8 * n))
72 return RT_EOK;
73 else
74 return -RT_ERROR;
75}
76
77/**
78 * @brief Test network connectivity using ping operations

Callers 2

test_netdev_pingFunction · 0.85
test_netdev_ifconfig_setFunction · 0.85

Calls 1

ceilFunction · 0.85

Tested by 2

test_netdev_pingFunction · 0.68
test_netdev_ifconfig_setFunction · 0.68