用强化学习动态选提示词,让大模型更高效生成测试用例。
PPO guided Agentic Pipeline for Adaptive Prompt Selection and Test Case Generation

- 用PPO算法智能选择不同提示策略,动态优化测试生成。
- 在20个基准程序上,分支覆盖率最高达100%,优于现有方法。
- 适合需要高覆盖测试的大型复杂系统开发与验证场景。
针对大规模软件系统测试用例生成困难的问题,本文提出一种基于强化学习的智能测试生成框架(PPO-LLM)。该框架分为两阶段:第一阶段通过思维链引导的优化代理,在不改变功能的前提下对源码进行冗余消除;第二阶段训练一个基于PPO的策略网络,根据11维的代码复杂度与实时覆盖度状态向量,从八种提示技术(如边界值分析、随机模糊测试等)中自适应选择最优提示,驱动大模型探索未覆盖路径。PPO代理依据行覆盖、分支覆盖提升程度、未探索分支惩罚及代码长度缩减情况获得奖励。在20个基准程序上的实验表明,该方法在几乎所有情况下均优于CBMC、kS-LLM和kS-LLM++。例如在PALS套件中,当循环边界为BOUND~1时,分支覆盖率可达100%,而kS-LLM++仅为约86.8%。结果表明,由PPO驱动的自适应提示选择显著优于静态提示策略。
原文摘要 · Abstract (English)
Developing effective test cases capable of thoroughly exercising large-scale software systems is inherently difficult, especially if such systems have voluminous, complex, and deeply nested source codes. In this work, we present a novel approach for generating test cases using a reinforcement learning-driven agentic framework where Proximal Policy Optimization (PPO) is coupled with an LLM engine to guide prompt selection during test generation. Our approach consists of two phases. In Phase I, the ToT-guided optimization agent partitions and minimizes the source code by removing redundancies without changing the functional behavior of the source code. In Phase II, a PPO-based policy network is trained to solve the problem of selecting prompts among eight different prompting techniques, such as Boundary Value Analysis, Random Fuzzing, etc., based on the inputted 11-dimensional state vector representing the source code complexity metrics and live coverage metrics to direct the LLM engine towards exploring unvisited paths in the program. The PPO agent receives rewards based on a combination of increases in line and branch coverages, penalties for unexplored branches, and rewards for reducing source code length. From experiments conducted on twenty benchmark programs, it is evident that the proposed approach, PPO-LLM, outperforms CBMC, kS-LLM, and kS-LLM++ in terms of branch and line coverage in almost all cases, for various loop bound values ranging from BOUND~1 to BOUND~2000. While at BOUND~1, the coverage of branches is 100\% using PPO-LLM on the PALS suite, in comparison, it is around 86.8\% using kS-LLM++. This confirms that adaptive prompt selection driven by PPO substantially outperforms static prompting strategies on PALS type programs.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。