Generate mock SDK layers for embedded unit testing — describe your external SDK headers in a YAML template, and mockware produces compilable stubs with overridable function pointers for C and virtual methods for C++.
# Create a YAML template describing your SDK dependencies
$ cat > template.yml << 'EOF'
headers:
"esp_err.h":
macros:
ESP_OK: "0"
types:
esp_err_t: int
"driver/gpio.h":
includes: ["esp_err.h"]
functions:
gpio_set_level:
return: esp_err_t
params: ["int pin", "int level"]
EOF
# Generate the mock SDK
$ mockware generate template.yml -o mock-sdk
Each function generates a _mock pointer and a
_default implementation. Replace at test time by
assigning to func_mock.
Classes generate virtual methods with default implementations. Override in test subclasses โ idiomatic C++ mocking.
Full C++ namespace support with nested classes, enums, typedefs, and free functions inside namespaces.
driver/gpio.h in YAML produces
include/driver/gpio.h and
source/driver/gpio.c.
Function-like macros (e.g. ESP_LOGI(...)) become
no-ops in test builds to suppress logging output.
Each header entry has a language field (c
or cpp). Generate both C and C++ mocks in one pass.
# Option A: Download a pre-built binary from GitHub Releases
# https://github.com/Ronika-Co/Mockware/releases
# Option B: Run directly from source (no install needed)
git clone https://github.com/Ronika-Co/Mockware.git
cd Mockware
uv run mockware --help
Describe the external SDK headers your project depends on. You can
organize them in separate files by domain (e.g. esp.yml,
freertos.yml) or keep everything in one file.
# esp.yml
headers:
"esp_err.h":
macros:
ESP_OK: "0"
types:
esp_err_t: int
"driver/gpio.h":
includes: ["esp_err.h"]
functions:
gpio_set_level:
return: esp_err_t
params: ["int pin", "int level"]
body: "return ESP_OK;"
# From a directory of templates
mockware generate templates/ -o mock-sdk
# From individual files
mockware generate esp.yml freertos.yml -o mock-sdk
# From a single template file
mockware generate template.yml -o mock-sdk
mock-sdk/
โโโ include/
โ โโโ esp_err.h
โ โโโ driver/gpio.h # stub headers
โ โโโ mockware/
โ โโโ fakes.h # extern function pointer decls
โโโ source/
โโโ driver/gpio.c # mock implementations
โโโ ...
// test_gpio.cpp
#include <cassert>
#include "driver/gpio.h"
#include "mockware/fakes.h"
void test_gpio_set_level_success() {
// Replace the mock to return success
gpio_set_level_mock = [](int pin, int level) -> esp_err_t {
return ESP_OK;
};
esp_err_t result = gpio_set_level(1, 1);
assert(result == ESP_OK);
}