主机单测:新增 ADC 输入层(L1)用例 70 项并登记 L1/L2 单测钩子

新增 App/algo/adc_input.c 的主机侧单测(L1),补齐 L1/L2 算法层
"每个函数都可离线验证"的最后一处空白。

- test/host/adc_input/{adc_input_test.c,run_unit_test.py,stub/}:
  70 个用例,覆盖 6 个公开函数 + map_check + stm32_scan。
  关键判据 = "通道号 <-> Rank 顺序 <-> 语义"三者映射:给每个 Rank
  注入互不相同的码值,逐通道钉死映射(板端无信号源,无法验此项)。
  另钉死 HAL 启动失败 / 轮询超时 / 参数错 / 无有效数据等分支。
- .pre-commit-config.yaml:登记 phasor-unit-test(7d)与
  adc-input-unit-test(7e)两个主机侧单测钩子。

主机侧全套:adc_input 70/70、phasor 52/52,均 0 失败、无 /W4 告警。
This commit is contained in:
2026-10-10 17:46:45 +08:00
parent 3762c03bb4
commit 696a1a49a9
5 changed files with 631 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
/*
* 主机侧单测桩:adc.h
* 模块功能:为 App/algo/adc_input.c 提供主机可编译的 STM32 ADC1 句柄与 HAL 接口
* 声明(真实 Inc/adc.h 会经 main.h 拖入整套 HAL,主机侧无法编译)。
*
* ⚠ 仅供 test/host/adc_input/ 使用,不参与 MCU 构建。
*
* 保真点:F4 HAL 的 ADC_CHANNEL_x 宏值**即通道号 x**(0..15),本桩按此定义,
* 故被测代码里 `(uint8_t)ADC_CHANNEL_14` 得到 14 —— 与真机一致。
* 另声明 4 个 HAL_ADC_* 接口,由测试单元给强符号桩(可注入失败/超时/返回值)。
*
* 创建日期:2026-10-10
*/
#ifndef ADC_H
#define ADC_H
#include <stdint.h>
/* HAL 状态码(与 stm32f4xx_hal_def.h 同值,仅取被测代码用到的子集) */
typedef enum {
HAL_OK = 0x00,
HAL_ERROR = 0x01,
HAL_BUSY = 0x02,
HAL_TIMEOUT = 0x03
} HAL_StatusTypeDef;
/* ADC 句柄:被测代码只把 &hadc1 透传给 HAL 接口,从不读其字段,故为不透明占位 */
typedef struct {
uint32_t reserved;
} ADC_HandleTypeDef;
extern ADC_HandleTypeDef hadc1;
/* ADC 通道宏(F4:宏值 = 通道号) */
#define ADC_CHANNEL_0 (0x00000000U)
#define ADC_CHANNEL_1 (0x00000001U)
#define ADC_CHANNEL_2 (0x00000002U)
#define ADC_CHANNEL_3 (0x00000003U)
#define ADC_CHANNEL_4 (0x00000004U)
#define ADC_CHANNEL_5 (0x00000005U)
#define ADC_CHANNEL_6 (0x00000006U)
#define ADC_CHANNEL_7 (0x00000007U)
#define ADC_CHANNEL_8 (0x00000008U)
#define ADC_CHANNEL_9 (0x00000009U)
#define ADC_CHANNEL_10 (0x0000000AU)
#define ADC_CHANNEL_11 (0x0000000BU)
#define ADC_CHANNEL_12 (0x0000000CU)
#define ADC_CHANNEL_13 (0x0000000DU)
#define ADC_CHANNEL_14 (0x0000000EU)
#define ADC_CHANNEL_15 (0x0000000FU)
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc);
HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout);
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef *hadc);
HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef *hadc);
#endif /* ADC_H */
+28
View File
@@ -0,0 +1,28 @@
/*
* 主机侧单测桩:tpafe5160.h
* 模块功能:为 App/algo/adc_input.c 提供主机可编译的 TPAFE5160 快照接口声明
* (真实头会经 main.h 拖入 HAL 与 GPIO 宏,主机侧无法编译)。
*
* ⚠ 仅供 test/host/adc_input/ 使用,不参与 MCU 构建。
*
* 被测代码只消费 tpafe5160_snapshot()(E-58 原子快照),故桩只保留该声明;
* 其返回值语义(1=新帧 / 0=无新帧 / -1=参数错)与真实驱动一致,由测试单元
* 给强符号桩并按用例注入。
*
* 创建日期:2026-10-10
*/
#ifndef TPAFE5160_H
#define TPAFE5160_H
#include <stdint.h>
/*
* 函数功能:原子快照最新一帧(消费者取数的唯一正确姿势)
* 入口参数:dst - 输出缓冲区 int16_t* 不为 NULL
* count - 拷贝通道数 uint8_t 1 - 8
* 返 回 值:1 - 取到新帧,0 - 无新帧,-1 - 参数无效
*/
int tpafe5160_snapshot(int16_t *dst, uint8_t count);
#endif /* TPAFE5160_H */