#![allow(dead_code)] use mpstthree::binary::struct_trait::end::End; use mpstthree::binary::struct_trait::recv::Recv; use mpstthree::binary::struct_trait::send::Send; use mpstthree::role::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use mpstthree::{ checker_concat, checker_concat_impl, create_meshedchannels, create_multiple_normal_name, create_multiple_normal_role, }; use petgraph::dot::Dot; use std::fs::read_to_string; // Create new MeshedChannels create_meshedchannels!(MeshedChannels, 3); // Create new roles create_multiple_normal_role!( RoleS, RoleADual | RoleM, RoleBDual | RoleC, RoleCDual | ); // Create new names create_multiple_normal_name!(NameS, NameM, NameC); // Payload types struct Req; struct Data; struct Ko; struct Error; struct Okay; struct Log; // Types // C type Choose0fromCtoM = Send; type Choose0fromCtoS = Send; type Recurs1CfromS = Recv; enum Branches1CfromS { Okay(MeshedChannels, RoleS, NameC>), Error(MeshedChannels, RoleS, NameC>), Ko(MeshedChannels, RoleS, NameC>), } // M type Recurs0MfromC = Recv; enum Branches0MfromC { End(MeshedChannels), Looping(MeshedChannels, NameM>), } type Recurs1MfromS = Recv; enum Branches1MfromS { Okay(MeshedChannels), Error(MeshedChannels, RoleS, NameM>), Ko(MeshedChannels, NameM>), } // S type Recurs0SfromC = Recv; enum Branches0SfromC { End(MeshedChannels), Looping( MeshedChannels, Choose1fromStoM, RoleC, NameS>, ), } type Choose1fromStoC = Send; type Choose1fromStoM = Send; // Creating the MP sessions // For S type EndpointSOkay = MeshedChannels< Send>, Recv, RoleC>>, NameS, >; type EndpointSError = MeshedChannels; type EndpointSKo = MeshedChannels>, End, RoleC>>, NameS>; type EndpointSFull = MeshedChannels, NameS>; // For M type EndpointMFull = MeshedChannels, NameM>; // For C type EndpointCEnd = MeshedChannels; type EndpointCLooping = MeshedChannels>, RoleS>>, NameC>; type EndpointCFull = MeshedChannels; ///////////////////////////////////////// checker_concat_impl!( [Branches0MfromC, End, Branches0SfromC, End], [Branches0MfromC, Looping, Branches0SfromC, Looping], [Branches1CfromS, Okay, Branches1MfromS, Okay], [Branches1CfromS, Ko, Branches1MfromS, Ko], [Branches1CfromS, Error, Branches1MfromS, Error] ); pub fn main() { let (graphs, kmc) = checker_concat!( "async_paper_ext_rev_sync", EndpointCFull, EndpointSFull, EndpointMFull => [ EndpointCEnd, Branches0MfromC, End, Branches0SfromC, End ], [ EndpointCLooping, Branches0MfromC, Looping, Branches0SfromC, Looping ], [ EndpointSOkay, Branches1CfromS, Okay, Branches1MfromS, Okay ], [ EndpointSKo, Branches1CfromS, Ko, Branches1MfromS, Ko ], [ EndpointSError, Branches1CfromS, Error, Branches1MfromS, Error ] ) .unwrap(); ////////////// Test graph S let graph_s = &graphs["RoleS"]; assert_eq!( format!("{:?}", Dot::new(&graph_s)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"0.1\\\"\" ]\n \ 2 [ label = \"\\\"0.1\\\"\" ]\n \ 3 [ label = \"\\\"0.1.1\\\"\" ]\n \ 4 [ label = \"\\\"0.1.1\\\"\" ]\n \ 5 [ label = \"\\\"0.1.2\\\"\" ]\n \ 6 [ label = \"\\\"0.1.1\\\"\" ]\n \ 7 [ label = \"\\\"0.1.2\\\"\" ]\n \ 8 [ label = \"\\\"0.1.3\\\"\" ]\n \ 9 [ label = \"\\\"0.1.4\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"0\\\"\" ]\n \ 0 -> 2 [ label = \"\\\"RoleS?RoleC: Req\\\"\" ]\n \ 2 -> 3 [ label = \"\\\"0\\\"\" ]\n \ 2 -> 4 [ label = \"\\\"RoleS!RoleC: Ko\\\"\" ]\n \ 4 -> 5 [ label = \"\\\"RoleS?RoleC: Data\\\"\" ]\n \ 5 -> 0 [ label = \"\\\"µ\\\"\" ]\n \ 2 -> 6 [ label = \"\\\"RoleS!RoleC: Okay\\\"\" ]\n \ 6 -> 7 [ label = \"\\\"RoleS?RoleC: Data\\\"\" ]\n \ 7 -> 8 [ label = \"\\\"RoleS?RoleM: Log\\\"\" ]\n \ 8 -> 9 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test graph M let graph_m = &graphs["RoleM"]; assert_eq!( format!("{:?}", Dot::new(&graph_m)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"0.1\\\"\" ]\n \ 2 [ label = \"\\\"0.0.1\\\"\" ]\n \ 3 [ label = \"\\\"0.0.2\\\"\" ]\n \ 4 [ label = \"\\\"0.0.1\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"0\\\"\" ]\n \ 0 -> 2 [ label = \"\\\"RoleM!RoleS: Log\\\"\" ]\n \ 2 -> 3 [ label = \"\\\"0\\\"\" ]\n \ 0 -> 4 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test graph C let graph_c = &graphs["RoleC"]; assert_eq!( format!("{:?}", Dot::new(&graph_c)), "digraph {\n \ 0 [ label = \"\\\"0\\\"\" ]\n \ 1 [ label = \"\\\"0.1\\\"\" ]\n \ 2 [ label = \"\\\"0.1\\\"\" ]\n \ 3 [ label = \"\\\"0.2\\\"\" ]\n \ 4 [ label = \"\\\"0.2.1\\\"\" ]\n \ 5 [ label = \"\\\"0.2.2\\\"\" ]\n \ 6 [ label = \"\\\"0.2.1\\\"\" ]\n \ 7 [ label = \"\\\"0.2.1\\\"\" ]\n \ 8 [ label = \"\\\"0.2.2\\\"\" ]\n \ 0 -> 1 [ label = \"\\\"0\\\"\" ]\n \ 0 -> 2 [ label = \"\\\"RoleC!RoleS: Req\\\"\" ]\n \ 2 -> 3 [ label = \"\\\"RoleC!RoleS: Data\\\"\" ]\n \ 3 -> 4 [ label = \"\\\"RoleC?RoleS: Error\\\"\" ]\n \ 4 -> 5 [ label = \"\\\"0\\\"\" ]\n \ 3 -> 6 [ label = \"\\\"RoleC?RoleS: Ko\\\"\" ]\n \ 6 -> 0 [ label = \"\\\"µ\\\"\" ]\n \ 3 -> 7 [ label = \"\\\"RoleC?RoleS: Okay\\\"\" ]\n \ 7 -> 8 [ label = \"\\\"0\\\"\" ]\n\ }\n" ); ////////////// Test KMC output assert_eq!( "CSA: \u{1b}[92mTrue\n\ \u{1b}[0mBasic: \u{1b}[92mTrue\n\ \u{1b}[0mreduced 1-exhaustive: \u{1b}[92mTrue\n\ \u{1b}[0mreduced 1-safe: \u{1b}[92mTrue\n\ \u{1b}[0m\n", read_to_string("outputs/async_paper_ext_rev_sync_1_kmc.txt").unwrap() ); ////////////// Test KMC number assert_eq!(kmc, Some(1)); }