Abstract
Automated unit testing for programs that manipulate complex heap structures, such as balanced trees or doubly-linked lists, faces a significant hurdle: generating structurally valid inputs. Traditional concolic testing often produces invalid memory configurations, leading to wasted execution paths. This paper introduces Concolic StarFinder (CSF), the first concolic testing engine to utilize Separation Logic (SL) for heap-manipulating programs. CSF combines specification-based input generation with concolic execution to ensure 100% input validity while achieving near-total branch coverage across complex data structure benchmarks.
Introduction
Automated unit testing relies on exploring as many execution paths as possible. While concolic testing—a hybrid of concrete and symbolic execution—is highly effective for numerical programs, it struggles with the heap. Programs using complex data structures require inputs that satisfy specific structural invariants.
Traditional "lazy initialization" techniques often fail here, generating invalid inputs (e.g., a cyclic graph where a tree is expected). These invalid inputs explore "impossible" code paths, providing no meaningful test coverage. Describing these structural requirements in a way that solvers can handle is a major mathematical challenge.
The CSF Approach
The authors propose CSF, a two-stage testing framework designed to handle the complexities of heap memory:
- Specification-based Testing (Black-box): CSF uses Separation Logic (SL) to define valid input shapes (e.g., a valid Binary Search Tree). A specialized solver, S2SAT_SL, generates an initial set of valid, fully-initialized heap objects based on these specifications.
- Concolic Execution (White-box): CSF executes the program with these valid inputs. If branches remain unvisited, it analyzes the path conditions and uses the SL solver to generate new valid inputs that satisfy both structural requirements and branch logic.
The use of Separation Logic allows CSF to precisely model disjoint memory regions, making it more expressive and efficient at handling unbounded data structures than previous logics like HEX.
Experimental Evaluation
CSF was evaluated against two state-of-the-art tools, JBSE and BBE, using a benchmark of 74 methods across structures like Singly and Doubly Linked Lists, Binary Search Trees, Red-Black Trees, and real-world projects like TSAFE and GanttProject.
Key Results
- 100% Validity: Every test input generated by CSF was structurally valid according to
repOKchecks. In contrast, JBSE and BBE achieved validity rates of only 4.65% and 7.83%, respectively. - High Coverage: CSF achieved 100% branch coverage for 70 out of 74 tested methods.
- Bug Discovery: When paired with Facebook Infer to automatically infer preconditions, CSF generated 292 test inputs, 89% of which triggered
RuntimeExceptions, identifying potential bugs or weak preconditions.
Discussion and Insights
A key insight from this work is that in heap-manipulating programs, validity is the primary bottleneck. CSF's success proves that formal logic like Separation Logic is a practical necessity for effective testing. Furthermore, CSF's ability to use concrete values allows it to bypass limitations of symbolic solvers, such as complex mathematical functions (e.g., Math.cos()), which pure symbolic engines cannot handle.
Limitations and Future Work
Despite its success, CSF faces challenges with native code and complex string manipulations, as seen in the TSAFE project where coverage reached only ~60%. Additionally, extremely complex structures like Red-Black Trees can cause solver timeouts. Future work aims to integrate CSF with "bi-abduction" techniques to automatically generate error specifications, enabling the tool to hunt for crashes and memory leaks without user-provided inputs.
Summary updated