AgentSkillsCN

testing-debugging

Zephyr RTOS 的测试与调试。涵盖用于单元测试与集成测试的 Ztest 框架、用于自动化 HIL/SIM 验证的 Twister 测试运行器,以及先进的跟踪与调试技术(SystemView、Thread Analyzer、堆栈分析)。在编写单元测试、搭建 CI/CD 流水线,或分析系统性能与延迟时,可触发此流程。

SKILL.md
--- frontmatter
name: testing-debugging
description: Testing and debugging for Zephyr RTOS. Covers the Ztest framework for unit and integration tests, the Twister test runner for automated HIL/SIM validation, and advanced tracing/debugging techniques (SystemView, Thread Analyzer, Stack analysis). Trigger when writing unit tests, setting up CI/CD pipelines, or analyzing system performance and latency.

Zephyr Testing & Debugging

Ensure code quality and system reliability using Zephyr's comprehensive testing framework and observability tools.

Core Workflows

1. Ztest Framework

Write robust unit and integration tests for native simulation and real hardware.

2. Twister Test Runner

Automate test execution across multiple platforms and generate professional reports.

  • Reference: twister_testing.md
  • Key Tools: twister script, testcase.yaml, hardware mapping.

3. Tracing & Debugging

Analyze system behavior, timing, and memory usage with advanced tracing tools.

  • Reference: tracing_debugging.md
  • Key Tools: CONFIG_TRACING, Segger SystemView, Thread Analyzer.

Quick Start (Ztest)

c
#include <zephyr/ztest.h>

ZTEST_SUITE(basic_test, NULL, NULL, NULL, NULL, NULL);

ZTEST(basic_test, test_pass) {
    zassert_true(true, "Boolean evaluation failed");
}

Professional Patterns (Reliability)

  • Continuous Integration: Integrate Twister reports (twister.json) into CI/CD pipelines for automated regression testing.
  • HIL Validation: Use hardware maps to consistently run critical hardware tests on real devices during every release cycle.
  • Stack Safety: Always enable CONFIG_STACK_SENTINEL and the Thread Analyzer during development to catch memory issues early.

Resources

  • References:
    • ztest_framework.md: Writing tests with expectations and suites.
    • twister_testing.md: Using the test runner and metadata.
    • tracing_debugging.md: Tracing, stack analysis, and debugging backends.