cmocka

cmocka is ...

an elegant unit testing framework for C with support for mock objects. It only requires the standard C library, works on a range of computing platforms (including embedded) and with different compilers.


Download here   Learn more   API

Mission Statement

The goal of this project is to provide a powerful testing framework for C, on different platforms and operating systems, which only requires the standard C library.

Support for Mock Objects
Mock objects are simulation objects that mimic the real implementation of an actual object. They are useful for simulating dependencies of an interface to help test the interface in isolation. cmocka also provides type-safe mocking macros. Some projects use the mock functionality to simulate components communicating over a network.

Only requires a C library
This allows cmocka to work on many embedded platforms. Starting with version 2.0.0, cmocka requires C99 standard and supports modern build systems including CMake and Meson.

Several supported output formats
cmocka supports several different message output formats such as Test Anything Protocol (TAP 14 with YAML diagnostics), Subunit, xUnit XML, and the original cmockery output format.

Fully documented API
The API is very well documented and cmocka provides several examples for the different features it provides.

Test Fixtures
Test fixtures are setup and teardown functions that can be shared across multiple test cases to provide common functions that prepare the test environment and destroy it afterwards.

Exception handling for signals (SIGSEGV, SIGILL, ...)
cmocka is able to recover the test state and continue running when exceptions occur, such as segmentation faults (SIGSEGV) and other signals. This allows the test suite to continue without stopping.

No fork()
cmocka doesn't use fork() for exception handling in test cases. This makes it portable to platforms that don't support fork() and enables better integration with debuggers and profiling tools.

Very well tested
cmocka has nightly builds to test on several platforms and with different compilers to ensure it works correctly. If you want to get it working on your platform you can add a nightly build and we will make sure not to break your platform or compiler.

Type-Safe Assertions
cmocka provides type-safe assertion macros for integers, floats, doubles, and pointers. These macros catch type mismatches at compile time and provide better error messages, making your tests more robust and easier to debug.

Enhanced Test Control
cmocka provides advanced test control features including the ability to skip tests dynamically, stop test execution early, and check if mocks are available. These features give you fine-grained control over test execution flow.

Platforms and compilers
cmocka works well on Linux, BSD, Solaris, Windows and embedded platforms. It is known to be working with GCC, Clang, MSVC, MinGW and many more.
License: Apache License 2.0

Development


git clone https://git.cryptomilk.org/projects/cmocka.git



GitLab   Browse GIT   Report Bugs

cmocka is an open source project. Feel free to use it and share it. If you want to collaborate, please contact us.

News


cmocka 2.0.0
2025-12-04
Version 2.0.0 has been released with major improvements including TAP 14 support with YAML diagnostics, type-safe assertion and mocking macros, new pointer assertions, and enhanced testing features. This version requires C99 and includes Meson build system support. See full changelog.


cmocka 1.1.6
2023-02-17
Version 1.1.6 has been released to fix several issues and add a few small new features.


cmocka 1.1.5
2019-03-28
Version 1.1.5 has been released with a set of new assert functions and a function to skip tests.

Projects using cmocka


cwrap - Full server/client testing made easy

Samba - Samba is the standard Windows interoperability suite of programs for Linux and Unix.

libssh - The SSH library

coreboot - Fast, secure and flexible open source firmware

BIND DNS - Versatile, Classic, Complete Name Server Software

OpenVPN - software for private tunnels (VPN)

Knot DNS - High-performance DNS server

SSSD - Security System Service Daemon

Elasto Cloud - a cloud storage client

Profanity - a console based XMPP chat client

libomemo - a C library implementing OMEMO

Netdata - realtime monitoring for servers

Automerge - a library for building collaborative applications

Discussion