* @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
| 49 | * @note This function uses 32-byte data packets with a 5-second timeout |
| 50 | */ |
| 51 | rt_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 |