From Resource Flow to Executable Tests: Petri-Net-Guided LLM Test Generation for Concurrent Stateful Rust APIs

· Source: cs.SE updates on arXiv.org · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Expert, extended

Summary

SyncPetri introduces a novel methodology for generating executable tests for concurrent stateful Rust APIs by combining Petri nets and large language models (LLMs). This approach addresses the challenge of testing APIs with evolving resource ownership and complex interleavings, where LLMs alone often produce invalid or shallow tests. The method represents API resources and dependencies as colored Petri nets to derive legal deep-state, near-legal, and partial-order concurrent scenarios. These scenarios serve as a constrained intermediate representation for LLM-based code synthesis. A local-faithfulness contract and structural repair loop ensure modeled intent is preserved, while a multi-layer semantic oracle distinguishes synthesis failures from actual API bugs. A prototype for Rust concurrency libraries was evaluated, successfully generating 45 lines of code for a 7-event MPSC channel scenario with 2 legal linearizations, demonstrating executability and structural fidelity.

Key takeaway

For AI Engineers developing or testing concurrent Rust APIs, SyncPetri offers a structured approach to overcome the limitations of purely LLM-driven test generation. You should consider adopting this Petri-net-guided methodology to ensure your tests accurately reflect complex resource protocols and expose subtle race conditions. This method helps you generate semantically meaningful, executable tests that maintain fidelity to the intended API behavior, reducing false positives from concretization errors.

Key insights

Petri nets specify semantic intent and resource flow, while LLMs realize library-specific syntax and assertions for concurrency testing.

Principles

Method

SyncPetri synthesizes deep-state, near-legal, and partial-order scenarios from a colored Petri net, concretizes them via a constrained LLM prompt and repair loop, then judges execution with a multi-layer semantic oracle.

In practice

Topics

Best for: Research Scientist, AI Scientist, Software Engineer, AI Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by cs.SE updates on arXiv.org.