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

Function test_netdev_config_set

components/net/utest/tc_netdev.c:582–648  ·  view source on GitHub ↗

* @brief Test network device configuration setting operations * * This function tests: * - Subnet mask setting and verification * - DNS server setting and verification * - Network interface parameter setting (set_if) * - Configuration restoration * - DHCP interaction with manual configuration * * @note Includes proper configuration backup and restoration */

Source from the content-addressed store, hash-verified

580 * @note Includes proper configuration backup and restoration
581 */
582static void test_netdev_config_set(void)
583{
584 ip_addr_t original_netmask = netdev_default->netmask;
585 ip_addr_t original_dns0 = netdev_default->dns_servers[0];
586 ip_addr_t original_dns1 = netdev_default->dns_servers[1];
587 ip_addr_t test_netmask = {0}, test_dns = {0};
588 rt_err_t res;
589
590 /* Test set_netmask */
591 if (netdev_is_dhcp_enabled(netdev_default))
592 {
593 res = netdev_dhcp_enabled(netdev_default, RT_FALSE);
594 if (res != RT_EOK)
595 {
596 goto skip_netmask_test;
597 }
598 }
599
600 inet_aton("255.255.255.0", &test_netmask);
601 res = netdev_set_netmask(netdev_default, &test_netmask);
602 if (res == RT_EOK)
603 {
604 uassert_true(ip_addr_cmp(&netdev_default->netmask, &test_netmask));
605 }
606
607 /* Restore netmask */
608 res = netdev_set_netmask(netdev_default, &original_netmask);
609 uassert_true(res == RT_EOK);
610
611skip_netmask_test:
612 /* Test set_dns_server */
613 inet_aton("8.8.8.8", &test_dns);
614 res = netdev_set_dns_server(netdev_default, 0, &test_dns);
615 uassert_true(res == RT_EOK);
616 uassert_true(ip_addr_cmp(&netdev_default->dns_servers[0], &test_dns));
617
618 inet_aton("8.8.4.4", &test_dns);
619 res = netdev_set_dns_server(netdev_default, 1, &test_dns);
620 uassert_true(res == RT_EOK);
621 uassert_true(ip_addr_cmp(&netdev_default->dns_servers[1], &test_dns));
622
623 /* Restore DNS servers */
624 res = netdev_set_dns_server(netdev_default, 0, &original_dns0);
625 uassert_true(res == RT_EOK);
626 res = netdev_set_dns_server(netdev_default, 1, &original_dns1);
627 uassert_true(res == RT_EOK);
628
629 /* Test set_if */
630 ip_addr_t test_ip, test_gw, test_nm;
631 ip_addr_t original_ip, original_gw, original_nm;
632
633 original_ip = netdev_default->ip_addr;
634 original_gw = netdev_default->gw;
635 original_nm = netdev_default->netmask;
636
637 inet_aton("192.168.2.100", &test_ip);
638 inet_aton("192.168.2.1", &test_gw);
639 inet_aton("255.255.255.0", &test_nm);

Callers

nothing calls this directly

Calls 7

netdev_dhcp_enabledFunction · 0.85
netdev_set_netmaskFunction · 0.85
ip_addr_cmpFunction · 0.85
netdev_set_dns_serverFunction · 0.85
netdev_set_ifFunction · 0.85
netdev_set_ipaddrFunction · 0.85
netdev_set_gwFunction · 0.85

Tested by

no test coverage detected