What Is a Partial?
Slicing and dicing your C code
Ceedling reads your real source and header files, extracts their C contents, and generates new C files that comprise a Partial.
Ceedling can create two kinds of Partials:
- A Test Partial for exposing otherwise inaccessible functions and variables to your test case assertions.
- A Mock Partial for mocking otherwise inaccessible functions in your source code.
When a test file references a Partial, Ceedling excludes the original source file from that test executable's build. The generated Partial source is compiled and linked in place of the original source C.
Purpose-specific C language handling
Ceedling includes its own custom, purpose-specific lexing for recognizing
C language elements. This was the best way to handle all cases across
platforms. This custom lexer even handles many compiler extensions
(e.g. Microsoft's __declspec and GCC's __attribute__()).
On the upside, this approach provides everything Partials need. On the downside, until exercised by a great deal of real world code, this custom C handling will likely have failings and gaps.
Partials creation step-by-step
When creating a Partial, Ceedling:
- Runs your source code under test through the preprocessor to:
- Handle
#ifdefblocks and strip comments. - Collect the
#includedirectives. - Expand decorator macros (e.g.
STATICINLINE) in function signatures.
- Handle
- Lexes the code under test to collect its individual C language elements
(e.g.
typedefs, macros, functions, variables, etc.). - Generates a new set of C files in a partials/ build directory. The
contents of these new files are:
- Reconstructed with the
#includedirectives from (1) and elements from (2). - Reorganized and slightly altered so the C elements can be accessed by
assertions and mocks in your test cases. Functions are stripped of
staticandinline. Variables are stripped ofstaticandexterned.
- Reconstructed with the
- Structures the test build to omit the original source file from the resulting test executable. Generated Partials are self-sufficient stand-ins for the original C code from which the Partials are derived.
- Maps the reorganized functions in generated Partials back to the
original source module's filepath and line numbers (using GCC's
#linedirective) for correct test coverage reporting.
Walk-through example
See Partials Walk-Through Example for a complete end-to-end demonstration of Test Partials and Mock Partials.
Generated files
| Partial | Purpose | Generated filename pattern |
|---|---|---|
| Testable header |
|
ceedling_partial_<module>_impl.h |
| Testable source |
|
ceedling_partial_<module>_impl.c |
| Mockable header |
|
ceedling_partial_<module>_interface.h |
Ceedling uses CMock to generate mocks from Partials interface header files just as it does for any other mockable header files.
Do not directly access generated Partials files
You as the test author will never directly interact with generated Partials C files. Do not modify these generated files or incorporate them into your tests except with the accompanying macros.