Files
STM32F4-Base/test/board/ch395f_test.h
T
wandering1 2055de0303 测试:落地测试架构改进 T-1~T-5(套件开关门禁/汇总行校验/通用 harness/公共断言宏/多套件编排)
背景:L0.5 主机侧单测落地后复审测试架构,给出 6 条改进意见(P0~P3),
登记进 docs/待处理内容.md「测试与验证基础设施」后逐条实施。

- T-1(P0) 测试套件开关门禁:新增 scripts/check_test_suite.py + pre-commit 钩子
  test-suite-switch,默认要求产品构建(全部 TEST_SUITE_* 注释),跑套件回归用
  --allow-test-build / ALLOW_TEST_BUILD=1 显式放行。顺带把 test_config.h 中长期
  开启的 TEST_SUITE_CH395F 改回注释(仓库此前躺着的是测试固件)。
- T-2(P1) verify_log.py 增加 --require-suite-summary:要求
  "=== <名称>: N/M PASSED (failed=0) ===" 且 N>0,堵住"套件没跑到汇总行/
  断言数为 0 仍判 PASS"的盲区;run_boot_test.py 同名参数透传。不传参向后兼容。
- T-3(P1) 抽取通用 harness test/host/common/unit_test_harness.py(工具链探测/
  INCLUDE-LIB 拼接/wd4819/GBK 解码/退出码契约);watchdog 运行器 170→55 行,只声明 TestBuild。
- T-4(P2) 新增 test/board/test_common.h 集中断言内核(TEST_CHECK_IMPL/TEST_REPORT_IMPL),
  4 套件各用一行宏绑定自身统计变量(保持 g_xxx_stats 独立、防跨套件串数)。
  刻意不 include dbg_log.h——否则冻结 DBG_TAG 默认值触发 #47-D 重定义警告。
- T-5(P2) 新增 test/run_all_suites.py 多套件回归编排,try/finally 无条件还原套件开关。

验证:@build 产品构建 0 错 0 警;4 套件逐一构建均 0/0;看门狗单测 39/39 PASS;
pre-commit 14 钩子全通过;编排脚本 dry-run/开关切换/异常还原均实测通过。
2026-10-01 07:28:57 +08:00

104 lines
5.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 模块名称:CH395F Driver Test Suite
* 模块功能:CH395F 驱动各功能模块的测试入口,分阶段组织测试用例,
* 覆盖 SPI 命令路径、协议栈配置、Socket 状态机、大文件传输、
* 边界条件、KeepAlive、PHY 链路恢复等,基于单连接 socket 模式
* 适用平台:STM32F4 系列(CH395F 以太网芯片)
* 作者:王建锋
* 创建日期:2026-07-19
* 修改记录:
* 2026-07-22 全面重构为单连接模式,增加大文件传输、边界条件等测试
*
* === 测试阶段一览(硬件层 1~5/12 → NET 层 6~11/13/14,严格顺序执行) ===
* Phase | 层 | 描述
* ---------|----------|-----------------------------------------------
* Phase 1 | 硬件层 | 独立运行:寄存器读写 + SPI 命令路径验证
* Phase 2 | 硬件层 | PC 配合:TCP Client 收发 + 关闭重连
* Phase 3 | 硬件层 | PC 配合:UDP Server Echo(60 轮动态源地址回显,HELLO 探针不计数)
* Phase 4 | 硬件层 | PC 配合:DHCP 自动获取 IP
* Phase 5 | 硬件层 | PC 配合:大文件分块回传(裸命令,tcp_server 配合)
* Phase 6 | NET 层 | testTask:TCP Echo(单连接模式,基础收发验证)
* Phase 7 | NET 层 | testTask:TCP Client 主动连接(回显收发 + 关闭重连 + 连接超时)
* Phase 8 | NET 层 | testTask:大文件传输(20KB+ 分块收发)
* Phase 9 | NET 层 | testTask:Select/Poll I/O 多路复用
* Phase 10 | NET 层 | testTask:边界条件测试(零长度、DMA 边界、缓冲溢出)
* Phase 11 | NET 层 | testTask:KeepAlive 超时断开测试
* Phase 12 | 硬件层 | 独立运行:SPI 字节命令 / DMA 时延基线(L1/L2,无需 PC)
* Phase 13 | NET 层 | testTask:芯片 + 队列时延(L3~L7/L10,需 PC peer,独立运行)
* Phase 14 | NET 层 | testTask:生产路径时延(L8~L11 + 模拟器 A/B,需 PC peer)〔M3 规划〕
* 时延分段定义/判定基线/执行流程:docs/测试说明/链路延迟测试说明.md
*/
#ifndef CH395F_TEST_H
#define CH395F_TEST_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "test_common.h"
/*
* 阶段使能开关(取消注释即启用对应阶段)
*
* 构建模式互斥(详见 docs/测试说明/CH395F_Test_Guide.md「构建模式与执行顺序」):
* 硬件层模式(阶段 1~5):netTask 入口自挂起(创建但不运行),testTask 独占 CH395F
* NET 层模式 (阶段 6~11):完整网络栈,netTask 轮询 + testTask 监听循环
*
* 注意:同层内可多选(Phase 6~10 共享 testTask 循环);
* Phase 4 (DHCP) 会改变 IP,必须独立运行;
* 两层同时启用会在下方触发 #error。
*/
/* ---- 硬件层(阶段 1~5/12)---- */
//#define ENABLE_PHASE1_TESTS /* [硬] 寄存器读写 + SPI 命令路径 */
//#define ENABLE_PHASE2_TESTS /* [硬] TCP Client 收发 + 关闭重连 */
//#define ENABLE_PHASE3_TESTS /* [硬] UDP Server Echo */
//#define ENABLE_PHASE4_TESTS /* [硬] DHCP 自动获取 IP(会改 IP!独立运行) */
//#define ENABLE_PHASE5_TESTS /* [硬] 大文件传输(硬件层,PC 配合) */
/* ---- NET 层(阶段 6~11)---- */
//#define ENABLE_PHASE6_TESTS /* [网] TCP Echo(单连接基础收发) */
//#define ENABLE_PHASE7_TESTS /* [网] TCP Client 主动连接(回显收发 + 关闭重连 + 连接超时) */
//#define ENABLE_PHASE8_TESTS /* [网] 大文件传输(100KB 文件收发) */
//#define ENABLE_PHASE9_TESTS /* [网] Select/Poll I/O 多路复用 */
//#define ENABLE_PHASE10_TESTS /* [网] 边界条件测试 */
//#define ENABLE_PHASE11_TESTS /* [网] KeepAlive 超时断开测试 */
/* ---- 链路时延基线(M1;分段/阈值见 docs/测试说明/链路延迟测试说明.md)---- */
//#define ENABLE_PHASE12_TESTS /* [硬] SPI 字节命令 / DMA 时延基线(L1/L2,无需 PC)—— M1 已完成,基线见说明文档 §6.1 */
/* ---- 链路时延(M2/M3;分段/阈值见 docs/测试说明/链路延迟测试说明.md)---- */
//#define ENABLE_PHASE13_TESTS /* [网] 芯片 + 队列时延(L3~L7/L10,需 PC peer)—— M2 已完成,基线见说明文档 §6.2 */
#define ENABLE_PHASE14_TESTS /* [网] 生产路径时延(L8~L11 + 模拟器 Δ)—— M3,需 peer --mode remo(:7003) */
#if defined(ENABLE_PHASE1_TESTS) || defined(ENABLE_PHASE2_TESTS) || \
defined(ENABLE_PHASE3_TESTS) || defined(ENABLE_PHASE4_TESTS) || \
defined(ENABLE_PHASE5_TESTS) || defined(ENABLE_PHASE12_TESTS)
#define ENABLE_HW_LAYER_TESTS 1
#endif
#if defined(ENABLE_PHASE6_TESTS) || defined(ENABLE_PHASE7_TESTS) || \
defined(ENABLE_PHASE8_TESTS) || defined(ENABLE_PHASE9_TESTS) || \
defined(ENABLE_PHASE10_TESTS) || defined(ENABLE_PHASE11_TESTS) || \
defined(ENABLE_PHASE13_TESTS) || defined(ENABLE_PHASE14_TESTS)
#define ENABLE_NET_LAYER_TESTS 1
#endif
#if defined(ENABLE_HW_LAYER_TESTS) && defined(ENABLE_NET_LAYER_TESTS)
#error "硬件层(1~5)与NET层(6~11)测试互斥:请分两次构建,见 CH395F_Test_Guide 构建模式与执行顺序"
#endif
/* 测试统计(本套件独立,防跨套件串数;内核见 test_common.h) */
typedef test_stats_t ch395f_stats_t;
extern ch395f_stats_t g_test_stats;
#define TEST_CHECK(cond, fmt, ...) \
TEST_CHECK_IMPL(g_test_stats, cond, fmt, ##__VA_ARGS__)
#define TEST_REPORT(name) TEST_REPORT_IMPL(g_test_stats, name)
#ifdef __cplusplus
}
#endif
#endif /* CH395F_TEST_H */