Organizations: Bangladesh University of Engineering and Technology, Dhaka, Bangladesh · National Taiwan University, Taipei, Taiwan · University of Illinois at Urbana-Champaign, Champaign, IL, USA
Automated unit test generation for C remains a formidable challenge due to the semantic gap between high-level program intent and the rigid syntactic constraints of pointer arithmetic and manual memory management. While Large Language Models (LLMs) exhibit strong generative capabilities, direct intent-to-code synthesis frequently suffers from the leap-to-code failure mode, where models prematurely emit code without grounding in program structure, constraints, and semantics. This will result in non-compilable tests, hallucinated function signatures, low branch coverage, and semantically irrelevant assertions that cannot properly capture bugs. We introduce SPARC, a neuro-symbolic, scenario-based framework that bridges this gap through four stages: (1) Control Flow Graph (CFG) analysis, (2) an Operation Map that grounds LLM reasoning in validated utility helpers, (3) Path-targeted test synthesis, and (4) an iterative, self-correction validation loop using compiler and runtime feedback. We evaluate SPARC on 59 real-world and algorithmic subjects, where it outperforms the vanilla prompt generation baseline by 31.36% in line coverage, 26.01% in branch coverage, and 20.78% in mutation score, matching or exceeding the symbolic execution tool KLEE on complex subjects. SPARC retains 94.3% of tests through iterative repair and produces code with significantly higher developer-rated readability and maintainability. By aligning LLM reasoning with program structure, SPARC provides a scalable path for industrial-grade testing of legacy C codebases.
Figures & tables
Figure 1. An extracted execution path and its corresponding generated unit test for a BST insert function.
Figure 2. Three failure modes of vanilla prompt generation compared with SPARC on kohonen_som_trace.c .
Figure 3. The four-stage SPARC pipeline. (1) Pre-processing extracts functions, their dependencies, and control-flow paths. (2) RAG-augmented operation map construction retrieves and assigns helper functions per path. (3) Path-targeted synthesis generates a test case for each scenario. (4) Iterative validation compiles, executes, and repairs failing tests.
Dataset
Subjects
#Control-flow Paths
#Function
#Line
#Branch
Function Cov. (%)
Line Cov. (%)
Branch Cov. (%)
Mutation Score (%)
SPARC
DS
KLEE
SPARC
DS
KLEE
SPARC
DS
KLEE
SPARC
DS
Rustine
heman
493
298
8,385
1,581
65.10
53.02
61.41
47.27
15.69
33.77
20.18
10.62
18.22
39
9
lodepng
2,420
225
6,328
2,853
65.33
40.00
64.89
42.00
17.04
37.60
20.01
5.68
16.86
28
15
tulipindicators
517
269
4,706
2,446
83.64
53.16
63.36
59.57
21.31
45.23
25.27
5.52
18.40
13
3
genann
26
15
176
110
100.00
100.00
100.00
92.60
80.10
94.20
80.90
65.50
68.80
64
42
rgba
45
13
95
126
100.00
92.30
100.00
96.80
81.10
93.00
75.40
63.50
68.10
83
30
Table 1. Comparing SPARC with DeepSeek V3.2 (DS), and KLEE (subjects arranged in descending order of LOC; only the top 15 bigger subjects are shown independently and the combined results of all subjects are in the last row).
Large Language Models (LLMs) are increasingly used for automated unit test generation. However, it remains unclear whether these tests reflect genuine reasoning about program behavior or simply reproduce superficial patterns learned during training. If the latter dominates, LLM-generated tests may exhibit weaknesses such as reduced coverage, missed regressions, and undetected faults. Understanding how LLMs generate tests and how those tests respond to code evolution is therefore essential. We present a large-scale empirical study of LLM-based test generation under program changes. Using an automated mutation-driven framework, we analyze how generated tests react to semantic-altering changes (SAC) and semantic-preserving changes (SPC) across eight LLMs and 22,374 program variants. LLMs achieve strong baseline results, reaching 79% line coverage and 76% branch coverage with fully passing test suites on the original programs. However, performance degrades as programs evolve. Under SACs, the pass rate of newly generated tests drops to 66%, and branch coverage declines to 60%. More than 99% of failing SAC tests pass on the original program while executing the modified region, indicating residual alignment with the original behavior rather than adaptation to updated semantics. Performance also declines under SPCs despite unchanged functionality: pass rates fall to 79% and branch coverage to 69%. Although SPC edits preserve semantics, they often introduce larger syntactic changes, leading to instability in generated test suites. Models generate more new tests while discarding many baseline tests, suggesting sensitivity to lexical changes rather than true semantic impact. Overall, our results indicate that current LLM-based test generation relies heavily on surface-level cues and struggles to maintain regression awareness as programs evolve.
Sabaat Haroon, Mohammad Taha Khan, Muhammad Ali Gulzar
Virginia Tech, USA · Carnegie Mellon University, USA
Traditional approaches to test case generation often involve manual effort and incur significant computational overhead. Additionally, these approaches are not scalable, and hence, unsuitable for complex software systems. Recently, Large Language Models (LLMs) have been applied to software testing. However, single-shot prompt engineering-based approaches tend to hallucinate and generate redundant test cases, resulting in fewer branches. To handle the above-mentioned limitations, in this paper, we propose FeedbackLLM, a novel automated language-agnostic test case generation framework based on tightly coupled two-stage approach. In the first stage, FeedbackLLM extracts the input constraints by parsing source code and generates the possible test cases. The quality of the test cases is evaluated in the second stage by the following two specialized LLM feedback agents: (i) Line Feedback Agent: extracts the metadata related to missed line executions and (ii) Branch Feedback Agent: extracts the metadata of the unexecuted branch conditions. The above agents operate in a two-stage process, communicating in tandem, and this procedure is repeated for k-steps. Further, we also introduced a redundancy prevention cache to avoid duplicate API requests and avoid unnecessary execution cycles. The performance of the proposed architecture is evaluated on the standard benchmark programs related to C and Python programs. FeedbackLLM demonstrated more line and branch coverage than baseline tools while scaling linearly in execution time.
Validating changes in low-level C firmware is expensive because unit tests (UTs) are fragile under strict build constraints, where missing headers, unresolved symbols, and dependency mismatches frequently prevent compilation and linking. This study introduces an automated UT authoring workflow for the Open-Source Silicon Initialization Library (openSIL) firmware codebase maintained by Advanced Micro Devices (AMD) that reduces manual effort through a large language model (LLM) guided multi-agent pipeline. The workflow combines automated generation of test scaffolds, library-aware creation or reuse of stubs, mocks, and fakes, and an iterative compile-dispatch repair loop driven by build logs and line-coverage feedback. We evaluate the approach using compilation success, repair iterations, dispatch success, and line coverage, with time, cost, and token usage as secondary measures. Across 76 functions under test, the workflow generated compilable UTs for 73 functions. In a configuration without line coverage guidance or retrieval augmentation, mean line coverage reached 73.9%. On a 48-function subset evaluated under both configurations, mean line coverage reached 98.8% with line-coverage guidance alone and reached 94.7% when combined with vector-database retrieval. Results show that automated generation-and-repair pipelines can substantially improve UT creation efficiency and coverage for constrained firmware environments while reducing manual debugging effort.
Ma Toan Bach, Yuchi Zheng, Haingo Razafindranto +4
School of Software Design and Data Science Seneca Polytechnic Canada · Advanced Micro Devices Canada