测试:新增 sys_clock 主机侧单测并修复 Zeller 星期缺陷

This commit is contained in:
2026-10-02 11:40:35 +08:00
parent 9f52731ed8
commit fac9d1c409
24 changed files with 5584 additions and 3792 deletions
+32
View File
@@ -0,0 +1,32 @@
/*
* 主机侧单测桩:FreeRTOS.h
* 模块功能:为 sys_clock.c 提供主机可编译的最小替代(临界区宏)。
*
* ⚠ 仅供 test/host/sys_clock/ 使用,不参与 MCU 构建。
*
* 说明:真实 FreeRTOS 的 taskENTER_CRITICAL/taskEXIT_CRITICAL 会关中断并操作
* uxCriticalNesting。主机侧单线程、无并发,故映射为空操作——被测的
* "惰性再基准化"临界区语义(区内复核 diff)仍被完整执行,
* 单测断言的是复核后的最终状态,与关中断细节无关。
*
* 创建日期:2026-10-02
*/
#ifndef FREERTOS_H
#define FREERTOS_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* 主机侧无并发:临界区退化为空操作(单线程执行,复核逻辑照常跑) */
#define taskENTER_CRITICAL() do { } while (0)
#define taskEXIT_CRITICAL() do { } while (0)
#ifdef __cplusplus
}
#endif
#endif /* FREERTOS_H */
+33
View File
@@ -0,0 +1,33 @@
/*
* 主机侧单测桩:dbg_log.h
* 模块功能:为 sys_clock.c 提供主机可编译的日志宏(打印 + 计数)。
*
* ⚠ 仅供 test/host/sys_clock/ 使用,不参与 MCU 构建。
*
* 与 simulator/dbg_log.h 同思路:MCU 版依赖 sys_clock(RTC 时间戳)与 USART,
* 主机侧替换为 printf(可按需开启),并把 DBG_ERROR 计入计数器供单测断言
* ("RTC 异常时是否打了降级/故障日志"是可观测行为的一部分)。
*
* 创建日期:2026-10-02
*/
#ifndef DBG_LOG_H
#define DBG_LOG_H
#include <stdio.h>
/* 测试期望的错误日志计数(在 sys_clock_test.c 实现,单测断言其增量) */
extern int g_sclk_err_count;
/* DBG_ERROR 仅在需要定位问题时打开 VERBOSE;默认静默并计数 */
#ifdef SYS_CLOCK_TEST_VERBOSE
#define DBG_INFO(fmt, ...) do { printf("[CLK] " fmt "\n", ##__VA_ARGS__); } while (0)
#define DBG_DEBUG(fmt, ...) do { } while (0)
#define DBG_ERROR(fmt, ...) do { g_sclk_err_count++; printf("[CLK][ERR] " fmt "\n", ##__VA_ARGS__); } while (0)
#else
#define DBG_INFO(fmt, ...) do { } while (0)
#define DBG_DEBUG(fmt, ...) do { } while (0)
#define DBG_ERROR(fmt, ...) do { g_sclk_err_count++; } while (0)
#endif
#endif /* DBG_LOG_H */
+28
View File
@@ -0,0 +1,28 @@
/*
* 主机侧单测桩:main.h
* 模块功能:为 sys_clock.c 提供主机可编译的最小替代,仅需 HAL_GetTick() 声明。
*
* ⚠ 仅供 test/host/sys_clock/ 使用,不参与 MCU 构建。
* MCU 构建走真实 Inc/main.h(含 stm32f4xx_hal.h);本文件因 include 路径
* 优先级被优先命中(见 run 脚本 -I 顺序)。
*
* 创建日期:2026-10-02
*/
#ifndef __MAIN_H
#define __MAIN_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* HAL 毫秒时基(MCU 端 = TIM7 中断累加;主机侧由测试单元提供可控时钟) */
uint32_t HAL_GetTick(void);
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
+18
View File
@@ -0,0 +1,18 @@
/*
* 主机侧单测桩:task.h
* 模块功能:为 sys_clock.c 提供主机可编译的最小占位头(真实头仅被 include)。
*
* ⚠ 仅供 test/host/sys_clock/ 使用,不参与 MCU 构建。
*
* 说明:sys_clock.c 仅为 taskENTER_CRITICAL/taskEXIT_CRITICAL 而 include
* "FreeRTOS.h" + "task.h";两个宏都在 stub/FreeRTOS.h 中定义,本文件保持最小。
*
* 创建日期:2026-10-02
*/
#ifndef INC_TASK_H
#define INC_TASK_H
#include "FreeRTOS.h"
#endif /* INC_TASK_H */