从资源流到可执行测试:用于并发有状态 Rust API 的 Petri 网引导的大语言模型测试生成
From Resource Flow to Executable Tests: Petri-Net-Guided LLM Test Generation for Concurrent Stateful Rust APIs
- Tongji University(同济大学)
机构由 AI 辅助整理,请以论文原文为准。
AI总结:
针对并发有状态 Rust API 测试生成问题,提出 Petri 网引导方法,将 API 相关要素表示为有色令牌和转换来导出场景,用作基于大语言模型代码合成的中间表示,经一系列机制确保测试生成的有效性和准确性。
AI中文摘要:
并发有状态库 API 通过不断演变的资源所有权、生命周期状态和竞争交织来展现行为。大语言模型能合成可执行的 Rust 测试,但输出常违反 API 前置条件、不够深入或使并发简化为偶然的顺序跟踪。基于模型和系统的测试技术虽提供语义控制,但通常需大量手写代码将抽象场景转化为可执行测试。本文解决形式化场景设计与低成本测试具体化之间的差距。我们提出一种用于并发有状态 Rust API 测试生成的 Petri 网引导方法。该方法将 API 资源、生命周期条件和因果依赖表示为有色令牌和转换;导出合法的深层状态、近合法和偏序并发场景;并将这些场景用作基于大语言模型的代码合成的约束中间表示。局部忠实契约和结构修复循环在具体化过程中保留建模意图,而 Petri 引导的调度塑造优先考虑高冲突并发骨架以进行系统探索。分层语义预言机随后区分合成失败与对目标 API 预期行为的违反。
英文摘要:
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.