Files @ 9e51e6ec5cf6
Branch filter:

Location: CSY/reowolf/src/test/connector.rs - annotation

9e51e6ec5cf6 5.9 KiB application/rls-services+xml Show Source Show as Raw Download as Raw
Hans-Dieter Hiep
Bump version
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
58e19b42641f
06f259bf8031
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
06f259bf8031
91c57e99c66e
91c57e99c66e
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
06f259bf8031
63a9f085c357
06f259bf8031
06f259bf8031
91c57e99c66e
06f259bf8031
06f259bf8031
91c57e99c66e
91c57e99c66e
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
06f259bf8031
06f259bf8031
91c57e99c66e
06f259bf8031
06f259bf8031
06f259bf8031
06f259bf8031
b788ae5c2251
b788ae5c2251
58e19b42641f
b788ae5c2251
63a9f085c357
b788ae5c2251
e71e02fb13d4
e71e02fb13d4
91c57e99c66e
91c57e99c66e
63a9f085c357
63a9f085c357
63a9f085c357
b788ae5c2251
b788ae5c2251
b788ae5c2251
b788ae5c2251
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
91c57e99c66e
91c57e99c66e
91c57e99c66e
b788ae5c2251
b788ae5c2251
b788ae5c2251
b788ae5c2251
63a9f085c357
63a9f085c357
63a9f085c357
e71e02fb13d4
b788ae5c2251
b788ae5c2251
e71e02fb13d4
e71e02fb13d4
91c57e99c66e
91c57e99c66e
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
63a9f085c357
b788ae5c2251
91c57e99c66e
91c57e99c66e
91c57e99c66e
b788ae5c2251
b788ae5c2251
b788ae5c2251
b788ae5c2251
63a9f085c357
63a9f085c357
63a9f085c357
e71e02fb13d4
b788ae5c2251
b788ae5c2251
b788ae5c2251
b788ae5c2251
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
e71e02fb13d4
58e19b42641f
e71e02fb13d4
e71e02fb13d4
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
e71e02fb13d4
e71e02fb13d4
e71e02fb13d4
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
e71e02fb13d4
e71e02fb13d4
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
e71e02fb13d4
e71e02fb13d4
e71e02fb13d4
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
58e19b42641f
extern crate test_generator;

use super::*;

use std::fs;
use std::path::Path;
use std::thread;
use test_generator::test_resources;

use crate::common::*;
use crate::runtime::*;
use crate::runtime::errors::*;

#[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 controller_id = 0;
        let mut x = Connector::Unconfigured(Unconfigured { controller_id });
        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::Passive(addrs[1])).unwrap();
        x.connect(timeout).unwrap();
        assert_eq!(0, x.sync(timeout).unwrap());
        println!("\n---------\nLOG CID={}\n{}", controller_id, x.get_mut_logger().unwrap());
    });
    let b = thread::spawn(move || {
        let controller_id = 1;
        let mut x = Connector::Unconfigured(Unconfigured { controller_id });
        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());
        println!("\n---------\nLOG CID={}\n{}", controller_id, x.get_mut_logger().unwrap());
    });
    handle(a.join());
    handle(b.join());
}

#[test]
fn duo_positive() {
    let timeout = Duration::from_millis(1_500);
    let addrs = ["127.0.0.1:7012".parse().unwrap(), "127.0.0.1:7013".parse().unwrap()];
    let a = thread::spawn(move || {
        let controller_id = 0;
        let mut x = Connector::Unconfigured(Unconfigured { controller_id });
        x.configure(
            b"
        primitive main(out a, out b) {
            synchronous {}
            synchronous {}
            synchronous {
                msg m = create(0);
                put(a, m);
            }
            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());
        println!("\n---------\nLOG CID={}\n{}", controller_id, x.get_mut_logger().unwrap());
    });
    let b = thread::spawn(move || {
        let controller_id = 1;
        let mut x = Connector::Unconfigured(Unconfigured { controller_id });
        x.configure(
            b"
        primitive main(in a, in b) {
            while (true) {
                synchronous {
                    if (fires(a)) {
                        get(a);
                    }
                }
                synchronous {
                    if (fires(b)) {
                        get(b);
                    }
                }
            }
        }",
        )
        .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());
        println!("\n---------\nLOG CID={}\n{}", controller_id, x.get_mut_logger().unwrap());
    });
    handle(a.join());
    handle(b.join());
}

#[test]
fn duo_negative() {
    let timeout = Duration::from_millis(500);
    let addrs = ["127.0.0.1:7014".parse().unwrap(), "127.0.0.1:7015".parse().unwrap()];
    let a = thread::spawn(move || {
        let controller_id = 0;
        let mut x = Connector::Unconfigured(Unconfigured { controller_id });
        x.configure(b"
        primitive main(out a, out b) {
            synchronous {}
            synchronous {
                msg m = create(0);
                put(a, m); // fires a on second round
            }
        }").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());
        let r = x.sync(timeout);
        println!("\n---------\nLOG CID={}\n{}", controller_id, x.get_mut_logger().unwrap());
        match r {
            Err(SyncErr::Timeout) => {}
            x => unreachable!("{:?}", x)
        }
    });
    let b = thread::spawn(move || {
        let controller_id = 1;
        let mut x = Connector::Unconfigured(Unconfigured { controller_id });
        x.configure(b"
        primitive main(in a, in b) {
            while (true) {
                synchronous {
                    if (fires(a)) {
                        get(a);
                    }
                }
                synchronous {
                    if (fires(b)) { // never fire a on even round
                        get(b);
                    }
                }
            }
        }").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());
        let r = x.sync(timeout);
        println!("\n---------\nLOG CID={}\n{}", controller_id, x.get_mut_logger().unwrap());
        match r {
            Err(SyncErr::Timeout) => {}
            x => unreachable!("{:?}", x)
        }
    });
    handle(a.join());
    handle(b.join());
}