#!/usr/bin/env python3 # -*- coding: utf-8 -*- """通道标定层(L1.5,adc_cal)主机侧单元测试运行器(L0.5,纯标准库)。 做什么: 用本机 MSVC 编译 test/host/adc_cal/adc_cal_test.c(它以 #include 纳入 **生产源文件** App/algo/adc_cal.c 与 App/cfg/cfg_file.c),在 PC 上离线跑 Q16 系数折算 / 三态 flags / 合法带哨兵回退 / 两点标定公式 / 两段 cfg 落盘契约(含段损坏回退),失败即非 0 退出。零硬件、零烧录、毫秒级。 工具链探测 / 编译运行全部委托 test/host/common/unit_test_harness.py。 为什么要主机侧单测(而不是只用板端套件): 标定折算的判据是"读数 = 系数 × 码值"——板端**无标准源**(数据可信 §2.6), 系数错、Q16 舍入错、哨兵漏放、负零点落盘错,在台架上全都看不出来; 主机侧用独立推导的期望值 + 坏文件注入把它们一次性钉死。 用法(仓库根目录): python test/host/adc_cal/run_unit_test.py 退出码:0=PASS / 1=测试失败 / 2=环境错误。 设计依据:docs/任务规划/数据可信.md 卡 2 / 卡 4(道A); 创建日期:2026-10-25 """ import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(os.path.dirname(os.path.dirname(HERE))) sys.path.insert(0, os.path.join(ROOT, "test", "host", "common")) from unit_test_harness import TestBuild, run_host_unit_test # noqa: E402 # 顺序敏感:stub 先于生产目录(覆盖 dbg_log.h)。cfg_file.h / cfg_file_store.h / # adc_input.h / sys_log.h 用真实头;adc_input_desc 与 syslog_post 由测试单元给 # 强符号桩(后者供 cfg_file.c 的错误留痕路径)。 BUILD = TestBuild( name="ADC Cal Layer Tests", src=os.path.join(HERE, "adc_cal_test.c"), include_dirs=[ os.path.join(HERE, "stub"), os.path.join(ROOT, "App", "algo"), os.path.join(ROOT, "App", "cfg"), os.path.join(ROOT, "App", "log"), HERE, ], summary_marker="=== ADC Cal Layer Tests:", ) if __name__ == "__main__": sys.exit(run_host_unit_test(BUILD))