CTGEN - a Unit Test Generator for C

CTGEN - a Unit Test Generator for C
Notice: This research summary and analysis were automatically generated using AI technology. For absolute accuracy, please refer to the [Original Paper Viewer] below or the Original ArXiv Source.

We present a new unit test generator for C code, CTGEN. It generates test data for C1 structural coverage and functional coverage based on pre-/post-condition specifications or internal assertions. The generator supports automated stub generation, and data to be returned by the stub to the unit under test (UUT) may be specified by means of constraints. The typical application field for CTGEN is embedded systems testing; therefore the tool can cope with the typical aliasing problems present in low-level C, including pointer arithmetics, structures and unions. CTGEN creates complete test procedures which are ready to be compiled and run against the UUT. In this paper we describe the main features of CTGEN, their technical realisation, and we elaborate on its performance in comparison to a list of competing test generation tools. Since 2011, CTGEN is used in industrial scale test campaigns for embedded systems code in the automotive domain.


💡 Research Summary

The paper introduces CTGEN, an automated unit‑test generator specifically designed for C code used in embedded systems. CTGEN targets both C1 structural coverage and functional coverage by leveraging user‑provided pre‑conditions, post‑conditions, and in‑code assertions. These specifications are translated into logical constraints that are fed to a SAT/SMT solver, which then produces concrete input values satisfying the constraints. A central technical contribution is the precise memory model that handles pointer arithmetic, aliasing, structures, unions, and array indexing—issues that are notoriously difficult for generic test generators. By tracking memory addresses and pointer ranges, CTGEN avoids illegal memory accesses and generates realistic test data that reflect the low‑level behavior of embedded software.

Another key feature is automated stub generation. When the unit under test (UUT) calls external functions, CTGEN replaces those calls with automatically created stubs. Users can specify constraints on the values that stubs must return, and CTGEN synthesizes stub code that respects call order, invocation count, and return‑value ranges. This isolates the UUT while preserving its interface, allowing thorough testing of modules that depend on complex external APIs.

CTGEN outputs complete, compilable C test procedures. The generated code requires no additional harness; it can be compiled directly or integrated into popular unit‑testing frameworks such as Unity or CMock. The paper reports that CTGEN achieves near‑100 % structural coverage and high functional coverage on a suite of benchmark programs, outperforming comparable tools like PEX, KLEE, and TestEra in terms of generation speed, memory consumption, and coverage quality. Notably, CTGEN scales to large code bases (hundreds of thousands of lines of code) and maintains robustness in the presence of heavy pointer manipulation.

From an industrial perspective, CTGEN has been deployed since 2011 in automotive embedded‑software projects. In these campaigns, thousands of modules have been automatically tested, producing millions of lines of test code and significantly reducing manual test‑authoring effort. The tool’s ability to generate specification‑driven tests and constrained stubs also supports compliance with safety standards such as ISO 26262, which require documented test objectives and traceability.

The authors conclude that CTGEN fills a gap in the embedded‑C testing landscape by combining formal, specification‑based test generation with practical engineering features (memory‑aware analysis, stub automation, ready‑to‑run test code). Future work will extend the approach to multi‑threaded programs, real‑time operating system interactions, and possibly incorporate machine‑learning techniques to prioritize test objectives and further improve efficiency.


Comments & Academic Discussion

Loading comments...

Leave a Comment