Files
STM32F4-Base/test/board/ioboard_test.h
T
wandering1 10323c4c22 feat(ioboard): board test suite for DI/DO, fix default_task conditional compile
Bench verification of the IO board needs an observation window: production
build has no consumer of ioboard_di_snap_read(), so the DI values were
invisible. Add TEST_SUITE_IOBOARD as a semi-automatic bench sequence and fix
two real bugs found while wiring it in.

New files:
- test/board/ioboard_test.h, test/board/ioboard_test_task.c

Test suite:
- Owns its own thread (iobTest, 4096 words) instead of running in testTask:
  testTask is osPriorityBelowNormal, below defaultTask whose 1ms console
  drain loop can starve a blocking wait in a lower priority context.
- Phases: bit-order self-check, DI eight-point bijection, DO point-by-point
  toggle with operator confirmation, release-all on every exit path.
- Only exit is ioboard_release_all(); it is called from the entry guard,
  every phase failure, the write-failure branch and the thread tail.
- Sample window is 20 reads x 2ms = 40ms and does overlap the 50ms
  production poll. That is stated as harmless in the header: the driver
  wraps the whole read in taskENTER_CRITICAL (26us, not the whole 40ms),
  both sides only read, and a torn cross-reader sample is caught by the
  debounce layer rather than acted upon.

default_task.c fix:
- DEFAULT_TASK_DI_PUBLISH_EN was defined twice: once at file scope and once
  inside default_task_func(). #define has no scope, so the second was a
  redefinition of the first. Collapsed to a single authoritative site.
- Add TEST_SUITE_STORAGE to the disable list: the STORAGE suite owns the
  file system via testTask, and default_task_di_poll() referenced four
  statics that live inside an !TEST_SUITE_STORAGE block, which broke the
  STORAGE build with 11 errors.
- Shrink the !TEST_SUITE_STORAGE block to cover only
  default_task_net_cfg_save_notify() and move the three declarations out;
  move edges/fails into the #else branch so the empty branch references
  none of the four statics.

Registration and gates:
- MDK-ARM/STM32F407-Demo.uvprojx and simulator/CMakeLists.txt entries.
- scripts/check_test_suite.py: whitelist TEST_SUITE_IOBOARD.
- scripts/stack_report.py: let a self-started thread that is not declared in
  Src/freertos.c osThreadAttr_t still be budget checked.
- test/run_all_suites.py: bring the suite into the orchestrator view.

Verified: six-build matrix all 0 errors 0 warnings. CH395F/STORAGE/GD5F/RTC
and the product build are bit-identical at Code=257936; the IOBOARD build is
Code=264640 (+6704), which is the evidence that the suite really enters the
image. Host unit tests 100/100, stack report 1760/4096 words (57%).
2026-11-16 19:35:15 +08:00

100 lines
5.1 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.
/******************************************************************************
* 模块名称:开入开出板测试套件(TEST_SUITE_IOBOARD)
* 模块功能:8 路开入位序双射判据 + 4 路开出逐个点动的台架观察窗口。
* 半自动:时间轴自动推进,人工按日志提示短接 DI / 听继电器动作。
* 适用平台:STM32F407 + 开入开出板(Drivers/BSP/IOBOARD)
* 作者:王建锋
* 创建日期:2026-11-16
* 修改记录:
* 2026-11-16 王建锋 创建。开入开出驱动早已上线,但 8 路开入的实际位序与
* 4 路开出的动作在台架上没有任何观察窗口
* (ioboard_di_snap_read() 至今无消费者),本套件即那扇窗口。
******************************************************************************/
#ifndef IOBOARD_TEST_H
#define IOBOARD_TEST_H
#include <stdint.h>
#include "test_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* 开入开出板测试套件(TEST_SUITE_IOBOARD)
*
* 为什么存在:开入开出驱动早已在板上跑起来(Src/main.c 的 ioboard_init()、
* defaultTask 每 50 ms 喂一拍去抖),但 8 路开入的**实际位序**与 4 路开出的
* **动作**在台架上没有任何观察窗口——去抖快照 ioboard_di_snap_read() 至今
* 没有消费者。本套件就是那扇窗口:一次跑完,日志里逐路可见。
*
* ⚠ 本套件**半自动**:本平台没有串口输入通道(serial_tool.py 只有采集与发送,
* 且 defaultTask 是唯一串口写者),无法「等操作员敲命令」。所以序列是**时间轴
* 自动推进 + 打印提示让人配合**:提示出现后操作员按提示短接/断开端子、
* 听继电器动作,套件按固定节拍采信。
*
* ⚠ 本头文件**不 include dbg_log.h**:理由见 test_common.h 文件头(DBG_TAG 冻结)。
*/
/* ============ Phase 使能开关(取消注释即启用,默认全开) ============ */
#define ENABLE_IOBOARD_SELFTEST_TESTS /* Phase 0: ioboard_init 确认 + 开出现状 */
#define ENABLE_IOBOARD_DI_ORDER_TESTS /* Phase 1: 开入位序(单比特两端 + 双射,位序主判据) */
#define ENABLE_IOBOARD_DI_STABLE_TESTS /* Phase 2: 全断开稳定性(20 次一致,证去抖生效) */
#define ENABLE_IOBOARD_DO_TESTS /* Phase 3: 开出逐个点动(空载,人工听动作声) */
/*
* 开入位序的采样口径(Phase 1 / Phase 2 共用)。
* 每「采样一轮」= 在一次 ioDelay(IOBOARD_TEST_DI_SAMPLE_GAP_MS) 间隔内连读
* IOBOARD_TEST_DI_SAMPLES 次,并计其按位与(all)与按位或(any):
* all == any → 这一轮没有抖动;否则这一轮内部就在抖。
* 选择「采样而不是单读」的理由:去抖在软件层(ioboard_di.c),ioboard_di_read()
* 读到的是引脚原始态,单读一次会被触点抖动骗到。
*/
#define IOBOARD_TEST_DI_SAMPLES 20U
#define IOBOARD_TEST_DI_SAMPLE_GAP_MS 2U
/* 人工配合窗口:提示出现后等这么久再采信(给操作员留出动手时间) */
#define IOBOARD_TEST_DI_ARM_MS 3000U
/* Phase 2 的采样轮数(每轮 20 次×2 ms ≈ 40 ms) */
#define IOBOARD_TEST_DI_STABLE_ROUNDS 20U
/* 开出点动保持时长:1 s(空载继电器,动作声足以辨认) */
#define IOBOARD_TEST_DO_ARM_MS 1000U
/* 开出释放后的稳定时长 */
#define IOBOARD_TEST_DO_RELEASE_MS 300U
/* 单个采样隔拍上限(防误配出荒谬值) */
#define IOBOARD_TEST_DI_SAMPLE_GAP_MAX_MS 100U
/* ============ 测试统计(本套件独立,防跨套件串数;内核见 test_common.h) ============ */
typedef test_stats_t ioboard_test_stats_t;
extern ioboard_test_stats_t g_ioboard_test_stats;
#define IOBOARD_TEST_CHECK(cond, fmt, ...) \
TEST_CHECK_IMPL(g_ioboard_test_stats, cond, fmt, ##__VA_ARGS__)
#define IOBOARD_TEST_REPORT(name) TEST_REPORT_IMPL(g_ioboard_test_stats, name)
/*
* 函数功能:套件入口(由 start_test_task 经 TEST_SUITE_IOBOARD 调度)
* 入口参数:无
* 返回值:无
* 限定条件:在 testTask 上下文被调用;内部**自起一个 Normal 优先级线程**跑序列,
* 本函数立即返回(理由见 ioboard_test_task.c 的启动段注释)。
* 函数说明:**本套件不干预 defaultTask 的开入轮询**——驱动已用
* taskENTER_CRITICAL() 把单次读整段护住,两处只读不写同一组引脚,
* 因此不存在数据损坏。注意时序上两处**必然交叠**(套件采样窗约 40 ms,
* defaultTask 每 50 ms 读一次),但交叠只影响跨读者一致性、不影响单次读
* 完整性,本套件判据的成立也不依赖 defaultTask 是否同时读。
* 完整论证见 ioboard_test_task.c 文件头。
* 若台架实跑出现两份不一致的开入视图,最小规避手段是让 defaultTask 的
* poll 在套件期间跳过,但那需要改 App/task/default_task.c,届时先报 Lead。
*/
void ioboard_test_run(void);
#ifdef __cplusplus
}
#endif
#endif /* IOBOARD_TEST_H */