Skip to content

Conversation

Rbb666
Copy link
Member

@Rbb666 Rbb666 commented Sep 14, 2025

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)。

本地测试结果:

image

注意:ci 的这两个错误可以忽略,测试发现 github ci 无法访问外网导致报错:

image

@github-actions github-actions bot added action github action yml imporve component: net Component labels Sep 14, 2025
Copy link

github-actions bot commented Sep 14, 2025

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: Maihuanyi

Changed Files (Click to expand)
  • components/net/utest/Kconfig
  • components/net/utest/SConscript
  • components/net/utest/tc_netdev.c

🏷️ Tag: workflow

Reviewers: Rbb666 kurisaW supperthomas

Changed Files (Click to expand)
  • .github/utest/netdev/netdev.cfg
  • .github/workflows/utest_auto_run.yml

📊 Current Review Status (Last Updated: 2025-09-14 12:37 CST)

  • Maihuanyi Pending Review
  • Rbb666 Pending Review
  • kurisaW Pending Review
  • supperthomas Pending Review

📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@Ryan-CW-Code
Copy link
Contributor

这种测试代码适合 @coderabbitai 和 @Copilot 让它们帮忙检查,也可以让它们参考这个模板风格继续完善或者写别的测试模块

@Rbb666 Rbb666 requested a review from Copilot September 14, 2025 19:16
Copy link
Contributor

@Copilot Copilot AI left a 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

Comment on lines +942 to +943
test_netdev = RT_NULL;
rt_free(test_netdev);
Copy link
Preview

Copilot AI Sep 14, 2025

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。

Suggested change
test_netdev = RT_NULL;
rt_free(test_netdev);
rt_free(test_netdev);
test_netdev = RT_NULL;

Copilot uses AI. Check for mistakes.

Comment on lines +940 to +953
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;
}
Copy link
Preview

Copilot AI Sep 14, 2025

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赋值,要么移除这个多余的清理块。

Suggested change
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.

@Rbb666 Rbb666 merged commit d7dded1 into RT-Thread:master Sep 18, 2025
67 checks passed
@Rbb666 Rbb666 added this to the v5.2.2 milestone Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action github action yml imporve component: net Component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants