mockware

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++.

bash
# 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

Features

C function-pointer mocking

Each function generates a _mock pointer and a _default implementation. Replace at test time by assigning to func_mock.

C++ virtual method mocking

Classes generate virtual methods with default implementations. Override in test subclasses โ€” idiomatic C++ mocking.

Namespaces & enums

Full C++ namespace support with nested classes, enums, typedefs, and free functions inside namespaces.

Nested directory output

driver/gpio.h in YAML produces include/driver/gpio.h and source/driver/gpio.c.

Variadic macros

Function-like macros (e.g. ESP_LOGI(...)) become no-ops in test builds to suppress logging output.

Mixed C/C++ projects

Each header entry has a language field (c or cpp). Generate both C and C++ mocks in one pass.

Quick start

1. Download or run from source

# 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

2. Create YAML templates

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;"

3. Generate mocks

# 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

4. Output structure

mock-sdk/
โ”œโ”€โ”€ include/
โ”‚   โ”œโ”€โ”€ esp_err.h
โ”‚   โ”œโ”€โ”€ driver/gpio.h          # stub headers
โ”‚   โ””โ”€โ”€ mockware/
โ”‚       โ””โ”€โ”€ fakes.h            # extern function pointer decls
โ””โ”€โ”€ source/
    โ”œโ”€โ”€ driver/gpio.c          # mock implementations
    โ””โ”€โ”€ ...

5. Write tests

// 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);
}