Skip to main content

clm_rust_core/layer1/
runtime_dispatch.rs

1//! Stage 1.4 native runtime dispatch.
2//!
3//! Provides a single `petri_run_net` entry point dispatching directly to the
4//! native CPN-VM executor (`cpn::vm`).
5
6/// Run a Petri net topology, dispatching to the native CPN-VM executor.
7pub fn petri_run_net(topo_file: &str, clm_root: &str) -> Result<String, String> {
8    crate::cpn::vm::petri_run_net(topo_file, clm_root)
9}
10
11#[cfg(test)]
12mod tests {
13    use super::*;
14    use std::io::Write;
15
16    #[test]
17    fn test_dispatch_native_backend() {
18        // Verify the dispatcher delegates to the native backend. The native
19        // backend will fail to parse an intentionally invalid YAML, which is
20        // expected and proves the native code path is reached.
21        let dir = std::env::temp_dir().join("clm_runtime_dispatch_native_test");
22        std::fs::create_dir_all(&dir).unwrap();
23        let path = dir.join("net.yaml");
24        {
25            let mut f = std::fs::File::create(&path).unwrap();
26            f.write_all(b"not a valid topology\n").unwrap();
27        }
28        let result = petri_run_net(path.to_str().unwrap(), "/tmp/clm_root");
29        assert!(result.is_err());
30    }
31}