* @brief Unit test cleanup function * * This function performs cleanup operations after running tests: * - Deletes callback synchronization event * - Restores original network configuration * - Restores original DHCP settings * - Restores original default network device * * @return rt_err_t RT_EOK on success */
| 1037 | * @return rt_err_t RT_EOK on success |
| 1038 | */ |
| 1039 | static rt_err_t utest_tc_cleanup(void) |
| 1040 | { |
| 1041 | rt_err_t res; |
| 1042 | |
| 1043 | /* Delete callback event */ |
| 1044 | if (callback_event) |
| 1045 | { |
| 1046 | rt_event_delete(callback_event); |
| 1047 | callback_event = RT_NULL; |
| 1048 | } |
| 1049 | |
| 1050 | /* Restore initial network configuration */ |
| 1051 | if (netdev_default != RT_NULL) |
| 1052 | { |
| 1053 | rt_kprintf("Restoring initial network configuration...\n"); |
| 1054 | |
| 1055 | /* First disable DHCP if it's enabled */ |
| 1056 | if (netdev_is_dhcp_enabled(netdev_default)) |
| 1057 | { |
| 1058 | res = netdev_dhcp_enabled(netdev_default, RT_FALSE); |
| 1059 | if (res != RT_EOK) |
| 1060 | { |
| 1061 | rt_kprintf("Warning: Failed to disable DHCP: %d\n", res); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | /* Restore network configuration */ |
| 1066 | res = netdev_set_ipaddr(netdev_default, &initial_ip_addr); |
| 1067 | if (res != RT_EOK) rt_kprintf("Warning: Failed to restore IP address: %d\n", res); |
| 1068 | |
| 1069 | res = netdev_set_netmask(netdev_default, &initial_netmask); |
| 1070 | if (res != RT_EOK) rt_kprintf("Warning: Failed to restore netmask: %d\n", res); |
| 1071 | |
| 1072 | res = netdev_set_gw(netdev_default, &initial_gw); |
| 1073 | if (res != RT_EOK) rt_kprintf("Warning: Failed to restore gateway: %d\n", res); |
| 1074 | |
| 1075 | res = netdev_set_dns_server(netdev_default, 0, &initial_dns0); |
| 1076 | if (res != RT_EOK) rt_kprintf("Warning: Failed to restore DNS0: %d\n", res); |
| 1077 | |
| 1078 | res = netdev_set_dns_server(netdev_default, 1, &initial_dns1); |
| 1079 | if (res != RT_EOK) rt_kprintf("Warning: Failed to restore DNS1: %d\n", res); |
| 1080 | |
| 1081 | /* Restore DHCP state */ |
| 1082 | if (initial_dhcp_enabled) |
| 1083 | { |
| 1084 | rt_kprintf("Restoring DHCP...\n"); |
| 1085 | res = netdev_dhcp_enabled(netdev_default, RT_TRUE); |
| 1086 | if (res != RT_EOK) |
| 1087 | { |
| 1088 | rt_kprintf("Warning: Failed to restore DHCP: %d\n", res); |
| 1089 | } |
| 1090 | else |
| 1091 | { |
| 1092 | rt_kprintf("DHCP restored, waiting for IP address...\n"); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | rt_kprintf("Network configuration restoration completed\n"); |
nothing calls this directly
no test coverage detected