3.1.29. waf_tools.mock
CMock and Unity test runner integration for the Waf build system.
This tool automates the generation of mock source files (via CMock)
and test-runner source files (via Unity’s generate_test_runner.rb)
for C unit tests. It is designed to work together with the preprocess
and gcov tools in this toolchain.
3.1.29.1. Usage
Load the tool during
configuredef configure(ctx): ctx.find_program("ruby", var="RUBY") ctx.load("mock", tooldir=TOOLDIR)
Declare test targets in a
test.jsonfile (one per test directory)[ { "source": [ "src/app/abc/abc.c" ], "test": "test_abc.c", "includes": [ "src/app/abc", "src/app/def" ], "mocks": [ "src/app/def/def.h" ], "defines": [ "EXAMPLE_DEFINE=1u" ], "use": [ "M" ] } ]
In the variant’s build script (
tests/unit/wscript), load and instantiate the test configurationsdef build(bld): bld.load_test_configs() for i, cfg in enumerate(bld.test_configs): bld( features=cfg["features"], target=cfg["target"], source=cfg["source"], includes=cfg["includes"], mocks=cfg["mocks"] + ["test-framework", f"{var}-c-test-constants"], cmock_config=cfg["cmock_config"], uselib=cfg["COVERAGE"], defines=cfg["defines"], cflags=cfg["cflags"], path=cfg["path"], idx=i, )
3.1.29.2. Dependencies
Ruby interpreter (stored in
env.RUBY)CMock (bundled under
tools/cmock/)Unity (bundled as CMock vendor dependency)
preprocesswaf tool (this toolchain)
Functions
|
Append mock-specific warning-suppression flags to mock compilation tasks. |
|
Configure paths to CMock and the Unity test runner generator. |
|
Declare mock output nodes for each header to be mocked. |
|
Create aggregated unit-test result files per target from the stored test results. |
|
Declare the runner output node under |
|
Group unit-test results by target name. |
|
Find the test source file associated with the current target. |
|
Load test configurations from JSON files. |
|
Resolve a path string to a waf Node. |
|
Set up mock generation and test runner creation for a test target. |
Classes
|
Task that generates CMock mock source files from header files. |
|
Task that generates Unity test runner source files. |