arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2602.16671cs.SEcs.AI
收藏

SPARC:面向自动化C单元测试生成的场景规划与推理

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

Bangladesh University of Engineering and Technology(孟加拉工程科技大学);National Taiwan University(台湾国立大学);University of Illinois at Urbana-Champaign(伊利诺伊大学厄巴纳-香槟分校)

Jaid Monwar Chowdhury, Chi-An Fu, Reyhaneh Jabbarvand

AI总结:

SPARC通过神经符号方法和场景规划,提升C语言单元测试生成的覆盖率和代码质量,显著优于传统方法。

摘要:

由于高级程序意图与指针算术和手动内存管理的严格语法约束之间存在语义鸿沟,自动化生成C语言单元测试仍然是一个重大挑战。尽管大语言模型(LLMs)展现出强大的生成能力,但直接从意图生成代码时常常会遇到‘跳码失败’模式,即模型在未基于程序结构、约束和语义的情况下提前生成代码,导致无法编译的测试用例、虚构的函数签名、低分支覆盖率以及无法正确捕捉bug的语义无关断言。我们引入了SPARC,一种神经符号、基于场景的框架,通过四个阶段弥合这一鸿沟:(1)控制流图(CFG)分析,(2)一个将LLM推理与已验证的实用程序助手相结合的操作图,(3)针对路径的测试合成,以及(4)使用编译器和运行时反馈的迭代自我纠正验证循环。我们在59个真实世界和算法主题上评估了SPARC,其在行覆盖率上比 vanilla 提示生成基线高出31.36%,在分支覆盖率上高出26.01%,在突变分数上高出20.78%,在复杂主题上与符号执行工具KLEE持平或超过。SPARC通过迭代修复保留了94.3%的测试用例,并生成具有显著更高开发者评分的可读性和可维护性代码。通过将LLM推理与程序结构对齐,SPARC为遗留C代码库的工业级测试提供了可扩展的路径。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑