diff --git a/src/runtime/communication.rs b/src/runtime/communication.rs index 4ef22a5789e6fe957ccfff8cfc4c5722ac34f07d..30f7f4b74ab9feca14968d12ab5749e9583859b1 100644 --- a/src/runtime/communication.rs +++ b/src/runtime/communication.rs @@ -48,6 +48,9 @@ impl ReplaceBoolTrue for bool { // CuUndecided provides a mostly immutable view into the ConnectorUnphased structure, // making it harder to accidentally mutate its contents in a way that cannot be rolled back. impl CuUndecided for ConnectorUnphased { + fn logger_and_protocol_description(&mut self) -> (&mut dyn Logger, &ProtocolDescription) { + (&mut *self.inner.logger, &self.proto_description) + } fn logger(&mut self) -> &mut dyn Logger { &mut *self.inner.logger } @@ -217,13 +220,14 @@ impl Connector { proto_component_id, unrun_components.len() ); + let (logger, proto_description) = cu.logger_and_protocol_description(); let mut ctx = NonsyncProtoContext { current_state: &mut current_state, - logger: &mut *cu.inner.logger, + logger, proto_component_id, unrun_components: &mut unrun_components, }; - let blocker = component.nonsync_run(&mut ctx, &cu.proto_description); + let blocker = component.nonsync_run(&mut ctx, proto_description); log!( cu.logger(), "proto component {:?} ran to nonsync blocker {:?}", @@ -252,7 +256,8 @@ impl Connector { current_state, solution_storage: { let n = std::iter::once(SubtreeId::LocalComponent(cu.inner.native_component_id)); - let c = cu.proto_components.keys().map(|&cid| SubtreeId::LocalComponent(cid)); + let c = + branching_proto_components.keys().map(|&cid| SubtreeId::LocalComponent(cid)); let e = comm .neighborhood .children @@ -1170,7 +1175,6 @@ impl NonsyncProtoContext<'_> { &state, &moved_ports ); - println!("MOVED PORTS {:#?}", &moved_ports); // sanity check for port in moved_ports.iter() { assert_eq!( @@ -1248,46 +1252,3 @@ impl<'a, K: Eq + Hash + 'static, V: 'static> CyclicDrainer<'a, K, V> { Ok(()) } } - -// struct ConnectorComm { -// logger: Box, -// pd: Arc, -// current_state: CurrentState, -// components: HashMap, -// ports: HashMap, -// endpoint_manager: EndpointManager, -// neighborhood: Neighborhood, -// native_batches: Vec, -// round_result: Result, SyncError>, -// } - -// struct RoundTemp<'a> { -// deadline: Option, -// msg_buf: Vec<(PortId, SendPayloadMsg)>, -// solution_storage: SolutionStorage, -// override_ports: HashMap, -// spec_var_stream: SpecVarStream, -// branching_proto: HashMap, -// branching_native: BranchingNative, -// comm: &'a mut ConnectorComm, -// } -// impl ConnectorComm { -// fn sync(&mut self, deadline: Option) -> Result { -// RoundTemp { -// msg_buf: Default::default(), -// deadline: todo!(), -// solution_storage: todo!(), -// override_ports: Default::default(), -// spec_var_stream: todo!(), -// branching_proto: Default::default(), -// branching_native: todo!(), -// comm: self, -// } -// .sync() -// } -// } -// impl RoundTemp<'_> { -// fn sync(&mut self) -> Result { -// todo!() -// } -// } diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 3bb91116e2fe5e89700c3fcd581541514f7869b5..d641d186c085938d0413976b1afe4bd1114ee7c7 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -270,6 +270,7 @@ trait CuUndecided { fn logger(&mut self) -> &mut dyn Logger; fn proto_description(&self) -> &ProtocolDescription; fn native_component_id(&self) -> ComponentId; + fn logger_and_protocol_description(&mut self) -> (&mut dyn Logger, &ProtocolDescription); } #[derive(Debug, Default)] struct NativeBatch { diff --git a/src/runtime/tests.rs b/src/runtime/tests.rs index 660e6da4fef7a9dd59b1ff8b040ff9bd66e741d9..e758c82a34f270a78d78d1574f131a6c9a574246 100644 --- a/src/runtime/tests.rs +++ b/src/runtime/tests.rs @@ -1059,65 +1059,65 @@ fn sequencer3_prim() { } } -// #[test] -// fn sequencer3_comp() { -// let test_log_path = Path::new("./logs/sequencer3_comp"); -// let pdl = b" -// primitive fifo1_init(msg m, in a, out b) { -// while(true) synchronous { -// if(m != null && fires(b)) { -// put(b, m); -// m = null; -// } else if (m == null && fires(a)) { -// m = get(a); -// } -// } -// } -// composite fifo1_full(in a, out b) { -// new fifo1_init(create(0), a, b); -// } -// composite fifo1(in a, out b) { -// new fifo1_init(null, a, b); -// } -// composite seq3composite(out a, out b, out c) { -// channel d -> e; -// channel f -> g; -// channel h -> i; -// channel j -> k; -// channel l -> m; -// channel n -> o; +#[test] +fn sequencer3_comp() { + let test_log_path = Path::new("./logs/sequencer3_comp"); + let pdl = b" + primitive fifo1_init(msg m, in a, out b) { + while(true) synchronous { + if(m != null && fires(b)) { + put(b, m); + m = null; + } else if (m == null && fires(a)) { + m = get(a); + } + } + } + composite fifo1_full(in a, out b) { + new fifo1_init(create(0), a, b); + } + composite fifo1(in a, out b) { + new fifo1_init(null, a, b); + } + composite seq3composite(out a, out b, out c) { + channel d -> e; + channel f -> g; + channel h -> i; + channel j -> k; + channel l -> m; + channel n -> o; -// new fifo1_full(o, d); -// new replicator2(e, f, a); -// new fifo1(g, h); -// new replicator2(i, j, b); -// new fifo1(k, l); -// new replicator2(m, n, c); -// } -// "; -// let pd = reowolf::ProtocolDescription::parse(pdl).unwrap(); -// let mut c = file_logged_configured_connector(0, test_log_path, Arc::new(pd)); + new fifo1_full(o, d); + new replicator2(e, f, a); + new fifo1(g, h); + new replicator2(i, j, b); + new fifo1(k, l); + new replicator2(m, n, c); + } + "; + let pd = reowolf::ProtocolDescription::parse(pdl).unwrap(); + let mut c = file_logged_configured_connector(0, test_log_path, Arc::new(pd)); -// // setup a session between (a) native, and (b) composite sequencer3, connected by 3 ports. -// let [p0, g0] = c.new_port_pair(); -// let [p1, g1] = c.new_port_pair(); -// let [p2, g2] = c.new_port_pair(); -// c.add_component(b"seq3composite", &[p0, p1, p2]).unwrap(); -// c.connect(None).unwrap(); + // setup a session between (a) native, and (b) composite sequencer3, connected by 3 ports. + let [p0, g0] = c.new_port_pair(); + let [p1, g1] = c.new_port_pair(); + let [p2, g2] = c.new_port_pair(); + c.add_component(b"seq3composite", &[p0, p1, p2]).unwrap(); + c.connect(None).unwrap(); -// let mut which_of_three = move || { -// // setup three sync batches. sync. return which succeeded -// c.get(g0).unwrap(); -// c.next_batch().unwrap(); -// c.get(g1).unwrap(); -// c.next_batch().unwrap(); -// c.get(g2).unwrap(); -// c.sync(None).unwrap() -// }; + let mut which_of_three = move || { + // setup three sync batches. sync. return which succeeded + c.get(g0).unwrap(); + c.next_batch().unwrap(); + c.get(g1).unwrap(); + c.next_batch().unwrap(); + c.get(g2).unwrap(); + c.sync(None).unwrap() + }; -// const TEST_ROUNDS: usize = 50; -// // check that the batch index for rounds 0..TEST_ROUNDS are [0, 1, 2, 0, 1, 2, ...] -// for expected_batch_idx in (0..=2).cycle().take(TEST_ROUNDS) { -// assert_eq!(expected_batch_idx, which_of_three()); -// } -// } + const TEST_ROUNDS: usize = 50; + // check that the batch index for rounds 0..TEST_ROUNDS are [0, 1, 2, 0, 1, 2, ...] + for expected_batch_idx in (0..=2).cycle().take(TEST_ROUNDS) { + assert_eq!(expected_batch_idx, which_of_three()); + } +}