From d5c0b4fdc19bbe98ccd48b6c8ab51552849da8ad 2020-09-29 17:14:41 From: Christopher Esterhuyse Date: 2020-09-29 17:14:41 Subject: [PATCH] more robust test dir creation --- diff --git a/examples/bench_4/main.c b/examples/bench_4/main.c index 398b5ee5a162f71c07607442caeb6a034b217ee2..f898b13596e4483661f33688b6f0a93e76946f65 100644 --- a/examples/bench_4/main.c +++ b/examples/bench_4/main.c @@ -15,7 +15,8 @@ int main(int argc, char** argv) { char logpath[] = "./bench_4.txt"; Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1); for (i=0; i +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, port_pairs, proto_components; + port_pairs = atoi(argv[1]); + proto_components = atoi(argv[2]); + printf("port_pairs %d, proto_components: %d\n", port_pairs, proto_components); + + const unsigned char pdl[] = + "primitive trivial_loop() { " + " while(true) synchronous{}" + "} " + ; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + char logpath[] = "./bench_5.txt"; + Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1); + for (i=0; i +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, self_syncs; + self_syncs = atoi(argv[1]); + printf("self_syncs %d\n", self_syncs); + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + char logpath[] = "./bench_6.txt"; + Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1); + for (i=0; i +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, forwards; + forwards = atoi(argv[1]); + printf("forwards %d\n", forwards); + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + char logpath[] = "./bench_7.txt"; + Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1); + + PortId native_putter, native_getter; + connector_add_port_pair(c, &native_putter, &native_getter); + for (i=0; i +#include "../../reowolf.h" +#include "../utility.c" +int main(int argc, char** argv) { + int i, forwards; + forwards = atoi(argv[1]); + printf("forwards %d\n", forwards); + unsigned char pdl[] = ""; + Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1); + printf("Error str `%s`\n", reowolf_error_peek(NULL)); + char logpath[] = "./bench_8.txt"; + Connector * c = connector_new_logging(pd, logpath, sizeof(logpath)-1); + + PortId native_putter, native_getter; + connector_add_port_pair(c, &native_putter, &native_getter); + for (i=0; i { for port in moved_ports.iter() { self.ips.port_info.map.get_mut(port).unwrap().owner = new_cid; } + if let Some(set) = self.ips.port_info.owned.get_mut(&self.proto_component_id) { + set.retain(|x| !moved_ports.contains(x)); + } + self.ips.port_info.owned.insert(new_cid, moved_ports.clone()); } // Facilitates callback from the component to the connector runtime, @@ -1406,6 +1410,12 @@ impl NonsyncProtoContext<'_> { owner: self.proto_component_id, }, ); + self.ips + .port_info + .owned + .entry(self.proto_component_id) + .or_default() + .extend([o, i].iter().copied()); log!( self.logger, "Component {:?} port pair (out->in) {:?} -> {:?}", diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 249d24aa72edaf9e017050f6eb6d2b7211d2c28d..ba664998818ec5995e083ac074dc2eab9a78310b 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -317,7 +317,11 @@ struct MyPortInfo { // useful methods #[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)] struct PortInfoMap { + // invariant: self.invariant_preserved() + // `owned` is redundant information, allowing for fast lookup + // of a component's owned ports (which occurs during the sync round a lot) map: HashMap, + owned: HashMap>, } // A convenient substructure for containing port info and the ID manager. @@ -483,7 +487,7 @@ impl VecSet { } impl PortInfoMap { fn ports_owned_by(&self, owner: ComponentId) -> impl Iterator { - self.map.iter().filter(move |(_, port_info)| port_info.owner == owner).map(|(port, _)| port) + self.owned.get(&owner).into_iter().flat_map(HashSet::iter) } fn spec_var_for(&self, port: PortId) -> SpecVar { // Every port maps to a speculative variable @@ -495,6 +499,33 @@ impl PortInfoMap { Putter => info.peer.unwrap(), }) } + fn invariant_preserved(&self) -> bool { + // for every port P with some owner O, + // P is in O's owned set + for (port, info) in self.map.iter() { + match self.owned.get(&info.owner) { + Some(set) if set.contains(port) => {} + _ => { + println!("{:#?}\n WITH port {:?}", self, port); + return false; + } + } + } + // for every port P owned by every owner O, + // P's owner is O + for (&owner, set) in self.owned.iter() { + for port in set { + match self.map.get(port) { + Some(info) if info.owner == owner => {} + _ => { + println!("{:#?}\n WITH owner {:?} port {:?}", self, owner, port); + return false; + } + } + } + } + true + } } impl SpecVarStream { fn next(&mut self) -> SpecVar { @@ -615,6 +646,13 @@ impl Connector { polarity: Getter, }, ); + cu.ips + .port_info + .owned + .entry(cu.native_component_id) + .or_default() + .extend([o, i].iter().copied()); + log!(cu.logger, "Added port pair (out->in) {:?} -> {:?}", o, i); [o, i] } @@ -665,6 +703,10 @@ impl Connector { None => unreachable!(), } } + if let Some(set) = cu.ips.port_info.owned.get_mut(&cu.native_component_id) { + set.retain(|x| !ports.contains(x)); + } + cu.ips.port_info.owned.insert(new_cid, ports.iter().copied().collect()); Ok(()) } } diff --git a/src/runtime/setup.rs b/src/runtime/setup.rs index 37dd16c8f019f4eb609b0ed1b92e6800a5bb12ef..3e35d1aead0774491e75544ac3440cef14ff8271 100644 --- a/src/runtime/setup.rs +++ b/src/runtime/setup.rs @@ -131,6 +131,15 @@ impl Connector { peer_addr, getter_for_incoming: nin, }); + + // update owned sets + cu.ips + .port_info + .owned + .entry(cu.native_component_id) + .or_default() + .extend([nin, nout].iter().copied()); + cu.ips.port_info.owned.insert(udp_cid, maplit::hashset! {uin, uout}); // Return the native's output, input port pair Ok([nout, nin]) } @@ -175,6 +184,8 @@ impl Connector { endpoint_polarity, getter_for_incoming: new_pid, }); + // update owned set + cu.ips.port_info.owned.entry(cu.native_component_id).or_default().insert(new_pid); Ok(new_pid) } } @@ -240,6 +251,7 @@ impl Connector { // Connect procedure successful! Commit changes by... // ... commiting new port info for ConnectorUnphased for (port, info) in extra_port_info.info.drain() { + cu.ips.port_info.owned.entry(info.owner).or_default().insert(port); cu.ips.port_info.map.insert(port, info); } for (port, peer) in extra_port_info.peers.drain() { @@ -1002,6 +1014,7 @@ fn apply_my_optimizations( } = session_info; // simply overwrite the contents cu.ips.port_info = port_info; + assert!(cu.ips.port_info.invariant_preserved()); cu.proto_components = proto_components; cu.proto_description = serde_proto_description.0; for (ee, getter) in comm diff --git a/src/runtime/tests.rs b/src/runtime/tests.rs index 913f12767c698475a148dc96f2629bdb0df361ea..9e558be20b3d78599677f97bc3cd877c37dd1fa1 100644 --- a/src/runtime/tests.rs +++ b/src/runtime/tests.rs @@ -30,9 +30,9 @@ fn file_logged_configured_connector( dir_path: &Path, pd: Arc, ) -> Connector { - let _ = std::fs::create_dir(dir_path); // we will check failure soon + let _ = std::fs::create_dir_all(dir_path).expect("Failed to create log output dir"); let path = dir_path.join(format!("cid_{:?}.txt", connector_id)); - let file = File::create(path).unwrap(); + let file = File::create(path).expect("Failed to create log output file!"); let file_logger = Box::new(FileLogger::new(connector_id, file)); Connector::new(file_logger, pd, connector_id) }