* @brief Test DNS server configuration and hostname resolution * * This function tests: * - Setting incorrect DNS server and verifying hostname resolution fails * - Setting correct DNS server and verifying hostname resolution succeeds * - DNS server configuration operations * * @note DNS configuration will be restored in utest_tc_cleanup */
| 177 | * @note DNS configuration will be restored in utest_tc_cleanup |
| 178 | */ |
| 179 | static void test_netdev_dns(void) |
| 180 | { |
| 181 | #define UTEST_DNS "114.114.114.114" /* Valid DNS server */ |
| 182 | #define UTEST_WRONG_DNS "13.19.123.143" /* Invalid DNS server */ |
| 183 | #define UTEST_WRONG_HOST_NAME "www.abcde.com" /* Test hostname */ |
| 184 | #define UTEST_HOST_ADDR "www.rt-thread.org" /* RT-Thread official website */ |
| 185 | |
| 186 | ip_addr_t ipaddr = {0}; |
| 187 | struct hostent *res = RT_NULL; |
| 188 | struct sal_proto_family *netdev_inet = RT_NULL; |
| 189 | |
| 190 | /* Get SAL protocol family for DNS operations */ |
| 191 | netdev_inet = netdev_default->sal_user_data; |
| 192 | if (netdev_inet == RT_NULL) |
| 193 | { |
| 194 | rt_kprintf("get sal proto family fail!"); |
| 195 | uassert_true(RT_FALSE); |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | /* Test with wrong DNS server - hostname resolution should fail */ |
| 200 | inet_aton(UTEST_WRONG_DNS, &ipaddr); |
| 201 | netdev_default->ops->set_dns_server(netdev_default, 0, &ipaddr); |
| 202 | netdev_default->ops->set_dns_server(netdev_default, 1, &ipaddr); |
| 203 | res = netdev_inet->netdb_ops->gethostbyname(UTEST_WRONG_HOST_NAME); |
| 204 | if (res == RT_NULL) |
| 205 | { |
| 206 | uassert_true(RT_TRUE); /* Expected failure */ |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | uassert_true(RT_FALSE); /* Unexpected success */ |
| 211 | } |
| 212 | |
| 213 | /* Test with correct DNS server - hostname resolution should succeed */ |
| 214 | inet_aton(UTEST_DNS, &ipaddr); |
| 215 | netdev_default->ops->set_dns_server(netdev_default, 0, &ipaddr); |
| 216 | netdev_default->ops->set_dns_server(netdev_default, 1, &ipaddr); |
| 217 | res = netdev_inet->netdb_ops->gethostbyname(UTEST_HOST_ADDR); |
| 218 | uassert_true(res != RT_NULL); |
| 219 | |
| 220 | /* DNS will be restored in utest_tc_cleanup */ |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @brief Test DHCP functionality |
nothing calls this directly
no test coverage detected