-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[utest][netdev]add netdev api testcases. #10697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
🏷️ Tag: workflowReviewers: Rbb666 kurisaW supperthomas Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-09-14 12:37 CST)
📝 Review Instructions
|
这种测试代码适合 @coderabbitai 和 @Copilot 让它们帮忙检查,也可以让它们参考这个模板风格继续完善或者写别的测试模块 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive unit test cases for the RT-Thread netdev API framework. The tests validate network device functionality including DHCP operations, network connectivity, interface configuration, DNS resolution, and device management.
- Adds extensive netdev API test coverage across 13 different test scenarios
- Implements network connectivity tests using ping operations with 80% success rate threshold
- Includes callback mechanism testing with event synchronization for network state changes
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
components/net/utest/tc_netdev.c | New comprehensive test suite with 1144 lines covering all major netdev API functions and network operations |
components/net/utest/SConscript | Updated build configuration to include netdev tests alongside existing lwIP tests |
components/net/utest/Kconfig | Added configuration options for netdev unit tests with default network interface settings |
.github/workflows/utest_auto_run.yml | Extended CI pipeline to include netdev test execution in automation workflow |
.github/utest/netdev/netdev.cfg | New CI configuration file specifying dependencies and settings for netdev testing |
test_netdev = RT_NULL; | ||
rt_free(test_netdev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting test_netdev
to RT_NULL
before calling rt_free(test_netdev)
will result in freeing a null pointer. The order should be reversed: free first, then set to null. / 在调用 rt_free(test_netdev)
之前将 test_netdev
设置为 RT_NULL
会导致释放空指针。应该颠倒顺序:先释放,然后设置为null。
test_netdev = RT_NULL; | |
rt_free(test_netdev); | |
rt_free(test_netdev); | |
test_netdev = RT_NULL; |
Copilot uses AI. Check for mistakes.
if (result == RT_EOK) | ||
{ | ||
test_netdev = RT_NULL; | ||
rt_free(test_netdev); | ||
} | ||
else | ||
{ | ||
rt_kprintf("Failed to unregister test netdev: %d\n", result); | ||
/* Manual cleanup if unregister failed */ | ||
if (test_netdev != RT_NULL) | ||
{ | ||
rt_free(test_netdev); | ||
test_netdev = RT_NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cleanup code is unreachable because test_netdev
was already set to RT_NULL
at line 942. Either remove the premature null assignment or remove this redundant cleanup block. / 这段清理代码无法到达,因为 test_netdev
在第942行已经被设置为 RT_NULL
。要么移除过早的null赋值,要么移除这个多余的清理块。
if (result == RT_EOK) | |
{ | |
test_netdev = RT_NULL; | |
rt_free(test_netdev); | |
} | |
else | |
{ | |
rt_kprintf("Failed to unregister test netdev: %d\n", result); | |
/* Manual cleanup if unregister failed */ | |
if (test_netdev != RT_NULL) | |
{ | |
rt_free(test_netdev); | |
test_netdev = RT_NULL; | |
} | |
if (test_netdev != RT_NULL) | |
{ | |
rt_free(test_netdev); | |
test_netdev = RT_NULL; | |
} | |
if (result != RT_EOK) | |
{ | |
rt_kprintf("Failed to unregister test netdev: %d\n", result); |
Copilot uses AI. Check for mistakes.
New netdev api test cases.
DHCP测试:验证DHCP启用/禁用操作。
Ping测试:验证网络连通性,通过ping操作测试网关、外部IP、域名和无效地址,基于80%成功率阈值判断结果 (netdev_ping、multiple_ping_test)。
接口配置测试:验证网络接口配置和状态,包括接口UP状态、链路状态、IP地址、网关、子网掩码和DNS服务器配置有效性 (netdev_is_up、netdev_is_link_up、ip_addr_isany)。
网络统计测试:验证网络统计功能可用性 (netdev_ops->netstat)。
DNS测试:验证DNS服务器配置和主机名解析,包括设置正确/错误DNS服务器,验证域名到IP地址转换 (netdev_set_dns_server、gethostbyname)。
接口配置设置测试:验证手动设置网络接口配置参数,包括IP地址和网关设置,验证配置正确性和恢复 (netdev_set_ipaddr、netdev_set_gw、netdev_dhcp_enabled)。
默认网络设备测试:验证设置网络设备为系统默认网络接口的能力 (netdev_set_default、netdev_get_by_name)。
IP地址转换测试:验证IPv4地址字符串与二进制转换、地址验证和边界情况处理 (netdev_ip4addr_aton、netdev_ip4addr_ntoa、inet_pton、inet_ntop)。
设备检索测试:验证通过名称、IP地址、接口索引等查找网络设备的功能,验证成功和失败场景 (netdev_get_by_name、netdev_get_by_ipaddr、netdev_get_by_ifindex)。
状态设置测试:验证网络设备状态设置操作,包括接口UP/DOWN操作和链路状态设置 (netdev_set_up、netdev_set_down、netdev_low_level_set_link_status)。
配置设置测试:验证网络设备配置设置操作,包括子网掩码和DNS服务器设置,包含配置备份和恢复 (netdev_set_netmask、netdev_set_dns_server、netdev_set_if)。
回调机制测试:验证网络设备回调机制,包括IP地址、网关和DHCP状态变化回调,使用事件同步验证回调执行 (netdev_set_status_callback、netdev_set_addr_callback)。
多接口测试:验证多网络接口功能,包括创建注册新设备、设备查找、默认设备切换、接口索引管理和设备注销 (netdev_register、netdev_get_by_name、netdev_set_default、netdev_unregister)。
本地测试结果:
注意:ci 的这两个错误可以忽略,测试发现 github ci 无法访问外网导致报错: