About this project
AutoFFF is a Python-based utility designed to automatically generate FFF (Fake Functions Framework) fake function definitions for C API header files, addressing a common pain point in embedded C unit testing.
The core problem it solves is that testing embedded C code on a host machine is often infeasible, as the host architecture differs from the target platform, and embedded environments typically lack support for dynamic linking while C has no built-in runtime reflection capabilities to manipulate code under test at runtime. Faking target platform APIs by linking code under test against fake implementations solves this, but manually writing fake definitions for API functions is tedious, labor-intensive, and error-prone, with manually maintained test headers prone to "code rot" as original APIs evolve.
AutoFFF automates this process by parsing C API header files and generating ready-to-use test headers with FFF-compatible fake definitions. It follows the "wrapping" faking philosophy: generated test headers include the original API header to inherit all its type, variable, and function declarations, only adding the necessary fake definitions. This approach is far more maintainable than the alternative "banning" strategy, which requires manually re-declaring all API elements and is more prone to falling out of sync with original headers.
The tool includes a built-in workaround for functions defined directly inside header files, which would normally cause redefinition errors when faked. This workaround uses macro re-routing to redirect calls to the original in-header function to the generated fake, as long as the test header is included before the code under test in test files.
AutoFFF supports working with libraries that have strict include policies (such as FreeRTOS or CMSIS) via command-line options to inject required headers or define preprocessor macros during parsing. It offers multiple integration options: it can be run as a standalone command-line module, used as a Python package in custom scripts, or integrated into build systems like Make via provided example Makefiles.
It provides two generator modes: the BareFakeGenerator outputs only raw FFF macro definitions without header boilerplate for users who want to add custom processing, while the SimpleFakeGenerator produces minimum viable, compilable test headers with include guards and required includes out of the box.
AutoFFF is distributed under the MIT license, available via PyPI, and requires the pycparser project's fake_libc_include header collection for C parsing, which is not bundled with the pip release and must be obtained separately from the pycparser repository.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.