用佩特里网引导大模型生成并发状态的Rust API测试
From Resource Flow to Executable Tests: Petri-Net-Guided LLM Test Generation for Concurrent Stateful Rust APIs
- 用有色令牌建模资源与状态,生成合法并发场景
- 生成测试覆盖高冲突并发路径,减少无效序列
- 适合需要深度并发测试的系统级Rust开发
并发状态库API的行为通过动态资源所有权、生命周期状态和竞争执行顺序展现。大语言模型可生成可执行的Rust测试,但常违反前置条件、测试深度不足,或把并发退化为偶然的串行轨迹。而基于模型和系统化的测试方法虽具语义控制力,却通常需大量手写代码将抽象场景转化为可执行测试。本文填补形式化场景设计与低成本测试实现之间的鸿沟,提出一种基于佩特里网的并发状态式Rust API测试生成方法。该方法将资源、生命周期条件与因果依赖表示为彩色令牌与变迁;推导出合法的深层状态、近合法及部分有序的并发场景;并以这些场景作为约束性中间表示,指导大模型进行代码合成。通过局部忠实性契约与结构修复循环,在具体化过程中保持原始意图;同时利用佩特里引导的调度塑形,优先探索高冲突并发骨架以实现系统性探索。分层语义验证器则区分合成失败与目标API实际行为违规。
原文摘要 · Abstract (English)
Concurrent stateful library APIs expose behavior through evolving resource ownership, lifecycle states, and competing interleavings. Large language models can synthesize executable Rust tests, but their outputs often violate API preconditions, remain shallow, or reduce concurrency to accidental sequential traces. Conversely, model-based and systematic testing techniques provide semantic control but commonly require substantial handwritten code to turn abstract scenarios into executable tests. This paper addresses the gap between formal scenario design and low-cost test concretization. We present a Petri-net-guided methodology for test generation over concurrent stateful Rust APIs. The method represents API resources, lifecycle conditions, and causal dependencies as colored tokens and transitions; derives legal deep-state, near-legal, and partial-order concurrent scenarios; and uses these scenarios as a constrained intermediate representation for LLM-based code synthesis. A local-faithfulness contract and structural repair loop preserve the modeled intent during concretization, while Petri-guided schedule shaping prioritizes high-conflict concurrency skeletons for systematic exploration. A layered semantic oracle then distinguishes synthesis failures from violations of the target API's expected behavior.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。