构建测试

This commit is contained in:
2026-08-22 19:53:24 +08:00
parent a7f367f6a3
commit fc88bc8752
15 changed files with 2050 additions and 1578 deletions

81
test/ch395f_test.h Normal file
View File

@@ -0,0 +1,81 @@
/*
* 模块名称CH395F Driver Test Suite
* 模块功能CH395F 驱动各功能模块的测试入口,分阶段组织测试用例,
* 覆盖 SPI 命令路径、协议栈配置、Socket 状态机、大文件传输、
* 边界条件、KeepAlive、PHY 链路恢复等,基于单连接 socket 模式
* 适用平台STM32F4 系列CH395F 以太网芯片)
* 作者:王建锋
* 创建日期2026-07-19
* 修改记录:
* 2026-07-22 全面重构为单连接模式,增加大文件传输、边界条件等测试
*
* === 测试阶段一览 ===
* Phase | 类型 | 描述
* ---------|--------------|-----------------------------------------------
* Phase 1 | 独立运行 | 寄存器读写 + SPI 命令路径验证
* Phase 2 | PC 配合 | TCP Client 收发 + 关闭重连
* Phase 3 | PC 配合 | UDP Server EchoHELLO + PING + 大包)
* Phase 4 | testTask | NET 层 TCP Echo单连接模式基础收发验证
* Phase 5 | testTask | NET 层大文件传输20KB+ 分块收发)
* Phase 6 | PC 配合 | DHCP 自动获取 IP
* Phase 7 | testTask | Select/Poll I/O 多路复用
* Phase 8 | testTask | 边界条件测试零长度、DMA 边界、缓冲溢出)
* Phase 9 | 需拔插网线 | PHY 链路恢复
* Phase 10 | testTask | KeepAlive 超时断开测试
*/
#ifndef __CH395F_TEST_H
#define __CH395F_TEST_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/*
* 阶段使能开关(取消注释即启用对应阶段)
* 注意一次仅启用一个阶段Phase 4/5/7/8 共享 testTask 循环,可同时启用)
* Phase 6 (DHCP) 会改变 IP必须独立运行
*/
#define ENABLE_PHASE1_TESTS /* 寄存器读写 + SPI 命令路径 */
//#define ENABLE_PHASE2_TESTS /* TCP Client 收发 + 关闭重连 */
//#define ENABLE_PHASE3_TESTS /* UDP Server Echo */
//#define ENABLE_PHASE4_TESTS /* NET 层 TCP Echo单连接基础收发 */
//#define ENABLE_PHASE5_TESTS /* NET 层大文件传输20KB+ 分块) */
//#define ENABLE_PHASE6_TESTS /* DHCP 自动获取 IP会改 IP独立运行 */
//#define ENABLE_PHASE7_TESTS /* Select/Poll I/O 多路复用 */
//#define ENABLE_PHASE8_TESTS /* 边界条件测试 */
//#define ENABLE_PHASE9_TESTS /* PHY 链路恢复测试 */
//#define ENABLE_PHASE10_TESTS /* KeepAlive 超时断开测试 */
/* 测试统计 */
typedef struct {
uint16_t total;
uint16_t passed;
uint16_t failed;
} test_stats_t;
extern test_stats_t g_test_stats;
#define TEST_CHECK(cond, fmt, ...) do { \
g_test_stats.total++; \
if (cond) { \
g_test_stats.passed++; \
DBG_INFO("[PASS] " fmt, ##__VA_ARGS__); \
} else { \
g_test_stats.failed++; \
DBG_ERROR("[FAIL] " fmt, ##__VA_ARGS__); \
} \
} while (0)
#define TEST_REPORT(name) do { \
DBG_INFO("=== %s: %d/%d PASSED (failed=%d) ===", \
name, g_test_stats.passed, g_test_stats.total, g_test_stats.failed); \
} while (0)
#ifdef __cplusplus
}
#endif
#endif /* __CH395F_TEST_H */