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

Function utest_tc_init

components/net/utest/tc_netdev.c:973–1026  ·  view source on GitHub ↗

* @brief Unit test initialization function * * This function performs setup operations before running tests: * - Creates callback synchronization event * - Locates and configures the test network device * - Saves initial network configuration for restoration * - Waits for network connectivity to be established * - Sets the test network device as default * * @return rt_err_t RT_EOK on succ

Source from the content-addressed store, hash-verified

971 * @return rt_err_t RT_EOK on success, -RT_ERROR on failure
972 */
973static rt_err_t utest_tc_init(void)
974{
975 struct netdev *netdev_lwip = RT_NULL;
976
977 /* Create event for callback synchronization */
978 callback_event = rt_event_create("callback_event", RT_IPC_FLAG_FIFO);
979 if (callback_event == RT_NULL)
980 {
981 rt_kprintf("Failed to create callback event\n");
982 return -RT_ERROR;
983 }
984
985 netdev_lwip = netdev_get_by_name(RT_UTEST_DEFAULT_NETDEV_NAME);
986 if (netdev_lwip == RT_NULL)
987 {
988 rt_kprintf("Network interface device not found!\n");
989 return -RT_ERROR;
990 }
991
992 /* Save initial network configuration */
993 initial_ip_addr = netdev_lwip->ip_addr;
994 initial_netmask = netdev_lwip->netmask;
995 initial_gw = netdev_lwip->gw;
996 initial_dns0 = netdev_lwip->dns_servers[0];
997 initial_dns1 = netdev_lwip->dns_servers[1];
998 initial_dhcp_enabled = netdev_is_dhcp_enabled(netdev_lwip);
999
1000 rt_kprintf("Saved initial network config - IP: %s, DHCP: %s\n",
1001 inet_ntoa(initial_ip_addr),
1002 initial_dhcp_enabled ? "enabled" : "disabled");
1003
1004 /* Wait for network connect successful */
1005 while (1)
1006 {
1007 if (!ip_addr_isany(&netdev_lwip->ip_addr))
1008 {
1009 rt_kprintf("IP address assigned: %s\n", inet_ntoa(netdev_lwip->ip_addr));
1010 break;
1011 }
1012 rt_thread_mdelay(500);
1013 }
1014
1015 /* Save the old netdev */
1016 netdev_default_old = netdev_default;
1017 netdev_set_default(netdev_lwip);
1018
1019 if (netdev_default == RT_NULL)
1020 {
1021 rt_kprintf("No default network interface!\n");
1022 return -RT_ERROR;
1023 }
1024
1025 return RT_EOK;
1026}
1027
1028/**
1029 * @brief Unit test cleanup function

Callers

nothing calls this directly

Calls 6

rt_event_createFunction · 0.85
rt_kprintfFunction · 0.85
netdev_get_by_nameFunction · 0.85
ip_addr_isanyFunction · 0.85
rt_thread_mdelayFunction · 0.85
netdev_set_defaultFunction · 0.85

Tested by

no test coverage detected