test

A command for generating and running tests for embedded C code, either on a computer or on a physical development board. It creates both runnable test code and a written list of test cases.

In plain words
What is it for?
Use it to test a selected C file or function with lightweight unit tests, or to create acceptance tests for a board feature. Results show which cases passed or failed.
Why use it?
It removes much of the manual work needed to test hardware-related code and records what each test is meant to check. Simple functions can be tested on a computer, while hardware-dependent logic can be tested on the board.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/jzl-maker/ea-skill/test
Clone the repo
git clone --depth 1 https://github.com/jzl-maker/EA-SKILL
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,131 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01131
Opus 5 $0.00000 $0.00566
Sonnet 5 $0.00000 $0.00226
Haiku 4.5 $0.00000 $0.00113

Measured 2d ago against content hash c744c1dd142f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/test.md · 69 lines

How it starts

The opening of the file, as written. The whole thing — 69 lines — stays where its author put it; the contents beside it link to each section on GitHub.

命令: /ea test (测试生成与执行)

功能

测试双产出:每个测试都生成「测试用例文档 + 可运行测试代码」。

  • unit:纯函数 host 单元测试(轻量自研:桩函数 + 断言 + main,零框架依赖)
  • board:板级工装验收测试(用例文档 + 板载测试固件/驱动脚本)

触发

/ea test unit <文件>               # 对指定 .c 文件的纯函数生成单测
/ea test unit <文件> <函数名>      # 只测某个函数
/ea test board <功能描述>          # 对功能/需求生成板级工装用例

单元测试(unit)

流程

  1. 【读 context】 确认工程上下文
  2. 【扫描目标】 tools/test-runner/scripts/test_gen.py unit <文件> 提取函数签名,识别纯函数(无硬件外设调用)
  3. 【生成双产出】 写入 <STATE_DIR>/tests/unit/
    • 测试代码 <name>.c:桩函数(mock GPIO_SetBits/USART_SendData 等硬件调用)+ 断言测试体 + main runner
    • 测试用例文档 <name>.md:用例ID / 输入 / 预期输出 / 覆盖点
  4. 【host 编译运行】 --cc gcc 直接编译运行(Windows 用 mingw gcc;也可用 arm-none-eabi-gcc 纯函数编译)
  5. 【输出结果】 每个用例 PASS/FAIL;生成器产出骨架断言,AI 负责按需求核对输入/预期后再判

调用方式

python ~/.claude/skills/ea-skill/tools/test-runner/scripts/test_gen.py \
  unit <目标.c> --cc gcc
# 产物: <STATE_DIR>/tests/unit/<name>.c + <name>.md

硬件耦合处理

  • 目标函数直接调用硬件寄存器/外设库且无法桩化 → 提示「该逻辑适合板级测试」→ 走 board
  • 测试代码中桩函数与真实实现冲突时,用 #ifdef EA_TEST 包裹被测模块

板级工装测试(board)

流程

  1. 【读 context】 芯片/外设/调试接口(串口端口、GPIO、J-Link)
  2. 【生成用例】templates/board-test-templates.md 模板库(上电/LED/按键/串口/外设响应/异常复位),写入 <STATE_DIR>/tests/board/
    • 用例文档 <case>.md:前置条件 / 操作步骤 / 预期结果 / 判定方法
    • 测试代码:板载测试固件 <case>_test.c(调被测逻辑,结果按协议串口输出 [TEST] PASS/FAIL)或 host 驱动脚本 <case>_driver.py(用 serial/debug 工具自动执行 + 判定)
  3. 【执行】 AI 驱动:
    • 板载固件:编译→烧录→串口收集 [TEST] 输出
    • host 脚本:直接驱动 serial/debug 读结果/寄存器
  4. 【判定】 按用例预期逐条判定,写入用例文档「实际结果」

输出示例(用例文档)

# 板级用例: 按键 KEY0 触发功能
- 前置: 上电,串口 COM5@115200
- 步骤: 按下 KEY0 → 观察串口输出
- 预期: 串口出现 `[KEY0] pressed`,LED 翻转
- 判定: 串口断言 + 物理观察 LED

设计原则

  • ✅ 用例 + 代码双产出:文档给人看、代码给机器跑
  • ✅ 零框架依赖:单测用 assert+桩,不引入第三方测试框架
  • ✅ 板级贴近真实:工装用例用串口/调试接口做判定锚点

相关文件

  • tools/test-runner/scripts/test_gen.py — 测试生成器
  • templates/unit-test-runner.c — 单测骨架模板
  • templates/board-test-case.md — 板级用例模板
  • templates/board-test-templates.md — 验收用例模板库
  • commands/build.md / flash.md / serial.md / debug.md — 执行依赖

Read the full file on GitHub · 69 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 69 lines · 0 tokens per session scan A c744c1dd142f

Subscribe to this mod's changes

test is a command published in the GitHub repository jzl-maker/EA-SKILL (6 stars, last pushed 5d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,131 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.