Testing/Validation ¶
Unit Testing Frameworks ¶
Supported Testing Libraries ¶
STM32CubeIDE projects can leverage several unit testing libraries tailored for embedded systems development. Commonly used frameworks include:
-
Unity: A lightweight and easy-to-use C unit testing framework designed for embedded environments.
-
Ceedling: A build system and test runner built on top of Unity, providing automation and test management features.
-
CppUTest: A C/C++ testing framework suitable for embedded systems with support for mocks and test doubles.
-
Google Test: While more common in desktop environments, it can be adapted for embedded testing with cross-compilation.
These libraries facilitate writing and running unit tests to validate individual modules and functions in isolation.
Writing and Running Unit Tests ¶
To write effective unit tests:
-
Organize tests by module or functionality.
-
Use assertions provided by the testing framework to verify expected behavior.
-
Mock hardware dependencies to isolate logic under test.
-
Automate test execution using build scripts or test runners like Ceedling.
Running unit tests can be done:
-
Directly on the host machine using cross-compiled test binaries.
-
On the target hardware via debug probes or serial output.
-
Integrated into continuous integration pipelines for automated validation.
Integration and System Testing ¶
Automated Test Execution ¶
Automated test execution streamlines validation by running test suites without manual intervention. In VS Code, this can be configured using tasks or external scripts triggered after builds.
Key practices include:
-
Scheduling tests to run on code commits or nightly builds.
-
Collecting and reporting test results in standardized formats.
-
Integrating with continuous integration (CI) tools for end-to-end automation.
Test Coverage Analysis ¶
Test coverage tools measure the extent to which your codebase is exercised by tests, identifying untested areas.
For STM32CubeIDE projects:
-
Use GCC’s –coverage flags ( -fprofile-arcs -ftest-coverage ) to instrument code.
-
Generate coverage reports with tools like gcov and lcov .
-
Analyze reports to improve test completeness and quality.
Hardware-in-the-Loop (HIL) Testing ¶
Setting up HIL Environments ¶
Hardware-in-the-Loop testing involves running your embedded software on real hardware connected to simulated environments that mimic real-world inputs and conditions.
To set up HIL testing:
-
Connect the STM32 target to simulation hardware or software simulators.
-
Configure interfaces such as UART, CAN, or GPIO for test signal exchange.
-
Develop test scenarios that stimulate hardware inputs and verify outputs.
-
Use tools like MATLAB/Simulink or dedicated HIL platforms for simulation control.
Debugging Test Failures ¶
Debugging failures in testing requires systematic analysis:
-
Review test logs and output messages for error indications.
-
Use debug probes and breakpoints to step through failing code sections.
-
Verify hardware connections and signal integrity in HIL setups.
-
Isolate failures by running smaller test cases or unit tests.
-
Collaborate with hardware and software teams to resolve integration issues.