LLM Reasoning 相关度: 8/10

SPARC: Scenario Planning and Reasoning for Automated C Unit Test Generation

Jaid Monwar Chowdhury, Chi-An Fu, Reyhaneh Jabbarvand
arXiv: 2602.16671v1 发布: 2026-02-18 更新: 2026-02-18

AI 摘要

SPARC通过神经符号方法提升LLM在C语言单元测试生成中的性能。

主要贡献

  • 提出SPARC框架,结合CFG分析、操作映射、路径目标测试合成和自纠正验证循环。
  • SPARC在真实和算法测试用例上优于prompt生成baseline和KLEE。
  • SPARC生成的测试代码具有更高的可读性和可维护性。

方法论

SPARC利用LLM进行测试用例生成,并通过神经符号技术(CFG分析,操作映射)和迭代反馈循环来改进测试质量。

原文摘要

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.

标签

LLM Unit Test Generation C Language Neuro-Symbolic

arXiv 分类

cs.SE cs.AI