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

Function test_netdev_ping

components/net/utest/tc_netdev.c:90–123  ·  view source on GitHub ↗

* @brief Test network connectivity using ping operations * * This function tests network connectivity by pinging various targets: * - Gateway address (should succeed) * - Invalid internal IP address (should fail) * - External IP address (should succeed) * - Invalid external IP address (should fail) * - External URL (should succeed) * - Invalid external URL (should fail) * * @note This te

Source from the content-addressed store, hash-verified

88 * @note This test verifies both successful and failed ping scenarios
89 */
90static void test_netdev_ping(void)
91{
92#define UTEST_INTRANET_WRONG_IP_ADDR "192.256.0.321" /* Invalid IP format */
93#define UTEST_EXTERNAL_IP_ADDR "8.8.8.8" /* Valid external IP */
94#define UTEST_EXTERNAL_WRONG_IP_ADDR "123.456.789.012" /* Invalid IP format */
95#define UTEST_EXTERNAL_URL "www.baidu.com" /* Valid external URL */
96#define UTEST_EXTERNAL_WRONG_URL "www.abcsdd.com" /* Non-existent URL */
97
98 rt_err_t res = RT_EOK;
99
100 /* Test ping to gateway address - should succeed */
101 res = multiple_ping_test(netdev_default, inet_ntoa(netdev_default->gw), 10);
102 uassert_true(res == RT_EOK);
103
104 /* Test ping to invalid internal IP - should fail */
105 res = multiple_ping_test(netdev_default, UTEST_INTRANET_WRONG_IP_ADDR, 1);
106 uassert_false(res == RT_EOK);
107
108 /* Test ping to external IP address - should succeed */
109 res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_IP_ADDR, 10);
110 uassert_true(res == RT_EOK);
111
112 /* Test ping to invalid external IP - should fail */
113 res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_WRONG_IP_ADDR, 1);
114 uassert_false(res == RT_EOK);
115
116 /* Test ping to external URL - should succeed */
117 res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_URL, 10);
118 uassert_true(res == RT_EOK);
119
120 /* Test ping to invalid external URL - should fail */
121 res = multiple_ping_test(netdev_default, UTEST_EXTERNAL_WRONG_URL, 1);
122 uassert_false(res == RT_EOK);
123}
124
125/**
126 * @brief Test network interface configuration and status

Callers

nothing calls this directly

Calls 1

multiple_ping_testFunction · 0.85

Tested by

no test coverage detected