这篇论文用Petri网编排LLM,自动生成并发Rust API的测试用例,比纯LLM生成的更可靠,能挖到深层并发bug。
该论文提出一种Petri-net引导的LLM测试生成方法,用于并发有状态Rust API。方法将API资源、生命周期依赖建模为有色Petri网,推导合法深状态、近合法及偏序并发场景,作为LLM代码合成的约束中间表示。通过局部保真契约和结构修复循环确保模型意图在具体化过程中保留,Petri引导的调度塑造优先探索高冲突并发骨架。分层语义预言机区分合成失败与API预期行为违反,实验结果表明该方法在生成可执行测试和覆盖并发缺陷方面优于基线。
From Resource Flow to Executable Tests: Petri-Net-Guided LLM Test Generation for Concurrent Stateful Rust APIs
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.