diff --git a/src/test/connector.rs b/src/test/connector.rs index 423fec99ceb0ff16bc1eac0f95c60f3fe821b71c..dd2a974d7d461b9da08714d7b38bd060559cdee7 100644 --- a/src/test/connector.rs +++ b/src/test/connector.rs @@ -10,84 +10,96 @@ use test_generator::test_resources; use crate::common::*; use crate::runtime::*; -#[test_resources("testdata/connector/duo/*.apdl")] -fn batch1(resource: &str) { - let a = Path::new(resource); - let b = a.with_extension("bpdl"); - let a = fs::read_to_string(a).unwrap(); - let b = fs::read_to_string(b).unwrap(); - duo(a, b); -} - -fn duo(one: String, two: String) { +#[test] +fn incremental() { + let timeout = Duration::from_millis(1_500); + let addrs = ["127.0.0.1:7010".parse().unwrap(), "127.0.0.1:7011".parse().unwrap()]; let a = thread::spawn(move || { - let timeout = Duration::from_millis(1_500); - let addrs = ["127.0.0.1:7010".parse().unwrap(), "127.0.0.1:7011".parse().unwrap()]; let mut x = Connector::Unconfigured(Unconfigured { controller_id: 0 }); - x.configure(one.as_bytes()).unwrap(); + x.configure( + b"primitive main(out a, out b) { + synchronous { + msg m = create(0); + put(a, m); + } + }", + ) + .unwrap(); x.bind_port(0, PortBinding::Passive(addrs[0])).unwrap(); - x.bind_port(1, PortBinding::Active(addrs[1])).unwrap(); + x.bind_port(1, PortBinding::Passive(addrs[1])).unwrap(); x.connect(timeout).unwrap(); assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); }); let b = thread::spawn(move || { - let timeout = Duration::from_millis(1_500); - let addrs = ["127.0.0.1:7010".parse().unwrap(), "127.0.0.1:7011".parse().unwrap()]; let mut x = Connector::Unconfigured(Unconfigured { controller_id: 1 }); - x.configure(two.as_bytes()).unwrap(); - x.bind_port(0, PortBinding::Passive(addrs[1])).unwrap(); - x.bind_port(1, PortBinding::Active(addrs[0])).unwrap(); + x.configure( + b"primitive main(in a, in b) { + synchronous { + get(a); + } + }", + ) + .unwrap(); + x.bind_port(0, PortBinding::Active(addrs[0])).unwrap(); + x.bind_port(1, PortBinding::Active(addrs[1])).unwrap(); x.connect(timeout).unwrap(); assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); - assert_eq!(0, x.sync(timeout).unwrap()); }); handle(a.join()); handle(b.join()); } #[test] -fn incremental() { +fn duo() { let timeout = Duration::from_millis(1_500); - let addrs = ["127.0.0.1:7010".parse().unwrap(), "127.0.0.1:7011".parse().unwrap()]; + let addrs = ["127.0.0.1:7012".parse().unwrap(), "127.0.0.1:7013".parse().unwrap()]; let a = thread::spawn(move || { let mut x = Connector::Unconfigured(Unconfigured { controller_id: 0 }); - x.configure( - b"primitive main(out a, out b) { + x.configure(b" + primitive main(out a, out b) { + synchronous {} + synchronous {} synchronous { msg m = create(0); put(a, m); } - }", - ) - .unwrap(); + synchronous { + msg m = create(0); + put(b, m); + } + }").unwrap(); x.bind_port(0, PortBinding::Passive(addrs[0])).unwrap(); x.bind_port(1, PortBinding::Passive(addrs[1])).unwrap(); x.connect(timeout).unwrap(); assert_eq!(0, x.sync(timeout).unwrap()); + assert_eq!(0, x.sync(timeout).unwrap()); + assert_eq!(0, x.sync(timeout).unwrap()); + assert_eq!(0, x.sync(timeout).unwrap()); }); let b = thread::spawn(move || { let mut x = Connector::Unconfigured(Unconfigured { controller_id: 1 }); - x.configure( - b"primitive main(in a, in b) { - synchronous { - get(a); + x.configure(b" + primitive main(in a, in b) { + while (true) { + synchronous { + if (fires(a)) { + get(a); + } + } + synchronous { + if (fires(b)) { + get(b); + } + } } - }", - ) - .unwrap(); + }").unwrap(); x.bind_port(0, PortBinding::Active(addrs[0])).unwrap(); x.bind_port(1, PortBinding::Active(addrs[1])).unwrap(); x.connect(timeout).unwrap(); assert_eq!(0, x.sync(timeout).unwrap()); + assert_eq!(0, x.sync(timeout).unwrap()); + assert_eq!(0, x.sync(timeout).unwrap()); + assert_eq!(0, x.sync(timeout).unwrap()); }); handle(a.join()); handle(b.join()); diff --git a/testdata/connector/duo/1.apdl b/testdata/connector/duo/1.apdl deleted file mode 100644 index 8eab469cf3ef8f6833122305f02e61df3d1c733c..0000000000000000000000000000000000000000 --- a/testdata/connector/duo/1.apdl +++ /dev/null @@ -1,23 +0,0 @@ -// Network Topology: -// two nodes, a and b, and two channels -// Node a: -// Two ports, a0 and a1, where a0 is passive and a1 is active -// Node b: -// Two ports, b0 and b1, where b0 is active and b1 is passive -// Channel a0--b0, where b0 initiates -// Channel a1--b1, where a1 initiates - -primitive main(in a0, in a1) { - while (true) { - synchronous { - if (fires(a0)) { - msg x = get(a0); - } - } - synchronous { - if (fires(a1)) { - msg y = get(a1); - } - } - } -} \ No newline at end of file diff --git a/testdata/connector/duo/1.bpdl b/testdata/connector/duo/1.bpdl deleted file mode 100644 index 6a77860c3aa8030a626cf8cca60790d185e411f1..0000000000000000000000000000000000000000 --- a/testdata/connector/duo/1.bpdl +++ /dev/null @@ -1,25 +0,0 @@ -// Network Topology: -// two nodes, a and b, and two channels -// Node a: -// Two ports, a0 and a1, where a0 is passive and a1 is active -// Node b: -// Two ports, b0 and b1, where b0 is active and b1 is passive -// Channel a0--b0, where b0 initiates -// Channel a1--b1, where a1 initiates - -primitive main(out b0, out b1) { - synchronous {} - synchronous {} - synchronous { - msg x = create(0); - put(b0, x); - } - synchronous {} - synchronous { - msg y = create(0); - put(b1, y); - } - while (true) { - synchronous {} - } -} \ No newline at end of file