arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2506.09002cs.SE
收藏

PALM:协同程序分析与LLM以提升Rust单元测试覆盖率

PALM: Synergizing Program Analysis and LLMs to Enhance Rust Unit Test Coverage

State Key Laboratory for Novel Software Technology, Nanjing University(南京大学软件新技术国家重点实验室);Software Engineering Application Technology Lab, Huawei(华为软件工程应用技术研发实验室)

Bei Chu, Yang Feng, Kui Liu, Hange Shi, Zifan Nan, Zhaoqiang Guo, Baowen Xu

AI总结:

本文提出PALM框架,通过程序分析提取分支条件与路径约束并构造LLM提示,自动生成Rust高覆盖率单元测试,在15个开源crates上达到接近人工的覆盖率且多数提交被接受。

摘要:

单元测试对于确保软件的可靠性和正确性至关重要。用于生成单元测试的经典基于搜索的软件测试(SBST)方法以及基于混合执行的方法,往往因难以处理复杂程序单元(如分支条件和外部依赖)而无法实现高覆盖率。近期工作越来越多地利用大型语言模型(LLM)生成测试用例,通过提供更好的上下文并纠正模型输出中的错误来提升测试生成质量。然而,这些方法依赖固定提示词,导致编译成功率和覆盖率相对较低。本文提出PALM,一种利用大型语言模型(LLM)增强高覆盖率单元测试生成的方法。PALM执行程序分析以识别函数内的分支条件,随后将其组合成路径约束。这些约束及相关上下文信息用于构建提示词,引导LLM生成单元测试。我们实现了该方法,并在15个开源Rust crates上对其进行评估。实验结果表明,仅需两三个小时,PALM相比经典方法即可显著提升测试覆盖率,在某些情况下整体项目覆盖率增幅超过50%,其生成的测试平均覆盖率达到72.30%,与人工工作(70.94%)相当,凸显了LLM在自动化测试生成中的潜力。我们提交了91个针对新代码的PALM生成单元测试。在这些提交中,80个被接受,5个被拒绝,6个仍在等待评审。结果证明了将程序分析与AI相结合的有效性,并为未来自动化软件测试研究开辟了新途径。

英文摘要:

Unit testing is essential for ensuring software reliability and correctness. Classic Search-Based Software Testing (SBST) methods and concolic execution-based approaches for generating unit tests often fail to achieve high coverage due to difficulties in handling complex program units, such as branching conditions and external dependencies. Recent work has increasingly utilized large language models (LLMs) to generate test cases, improving the quality of test generation by providing better context and correcting errors in the model's output. However, these methods rely on fixed prompts, resulting in relatively low compilation success rates and coverage. This paper presents PALM, an approach that leverages large language models (LLMs) to enhance the generation of high-coverage unit tests. PALM performs program analysis to identify branching conditions within functions, which are then combined into path constraints. These constraints and relevant contextual information are used to construct prompts that guide the LLMs in generating unit tests. We implement the approach and evaluate it in 15 open-source Rust crates. Experimental results show that within just two or three hours, PALM can significantly improve test coverage compared to classic methods, with increases in overall project coverage exceeding 50% in some instances and its generated tests achieving an average coverage of 72.30%, comparable to human effort (70.94%), highlighting the potential of LLMs in automated test generation. We submitted 91 PALM-generated unit tests targeting new code. Of these submissions, 80 were accepted, 5 were rejected, and 6 remain pending review. The results demonstrate the effectiveness of integrating program analysis with AI and open new avenues for future research in automated software testing.

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

↑