testing-debugging
npx machina-cli add skill beriberikix/zephyr-agent-skills/testing-debugging --openclawZephyr 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.
- Reference: ztest_framework.md
- Key Tools:
ZTEST_SUITE,ZTEST,zassert_equal.
2. Twister Test Runner
Automate test execution across multiple platforms and generate professional reports.
- Reference: twister_testing.md
- Key Tools:
twisterscript,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)
#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_SENTINELand 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.
Source
git clone https://github.com/beriberikix/zephyr-agent-skills/blob/main/skills/testing-debugging/SKILL.mdView on GitHub Overview
This skill covers Zephyr's Ztest framework for unit and integration tests, the Twister test runner for automated HIL/SIM validation, and advanced tracing/debugging tools like SystemView, Thread Analyzer, and Stack analysis. Together, these tools help ensure code quality, reliability, and performance across devices and configurations.
How This Skill Works
Develop tests with ZTEST_SUITE and ZTEST and assert macros such as zassert_equal; Twister automates test execution across platforms and produces comprehensive reports (twister.json) and metadata; Tracing tools (CONFIG_TRACING, SystemView, Thread Analyzer) collect timing and memory data for analysis.
When to Use It
- Writing unit and integration tests for Zephyr components using the Ztest framework (ZTEST_SUITE, ZTEST, zassert_*)
- Automating cross-board test execution and reporting with Twister in CI/CD
- Performing hardware-in-the-loop (HIL) validation on real devices during releases
- Diagnosing timing, memory usage, and latency issues with SystemView, Thread Analyzer, and stack analysis
- Setting up CI/CD pipelines to gather test results (twister.json) and track regressions
Quick Start
- Step 1: Create a Ztest suite using ZTEST_SUITE and add test cases with ZTEST
- Step 2: Use zassert_* macros (e.g., zassert_equal) to validate behavior
- Step 3: Run tests with Twister across platforms and enable tracing (CONFIG_TRACING) for observability
Best Practices
- Regularly enable CONFIG_STACK_SENTINEL and use Thread Analyzer during development to catch memory and stack issues early
- Write deterministic Ztest suites with clear setup/teardown hooks and meaningful zassert_* checks
- Integrate Twister reports (twister.json) into CI/CD to surface regressions automatically
- Use hardware maps and consistent per-board configurations for reliable HIL tests
- Enable SystemView tracing to correlate events with timing and performance
Example Use Cases
- A driver team validates a new sensor driver with Ztest unit tests and CI-run reports
- A project switches to Twister to execute tests across Linux native sim plus multiple boards and collects twister.json
- Tracing reveals a memory leak under load; SystemView traces identify hotspot functions
- Thread Analyzer flags a deep stack usage in a newly added task and helps optimize stack size
- Latency analysis shows end-to-end delay increase after a feature change, guiding optimization