Files @ a1b2108ed856
Branch filter:

Location: CSY/reowolf/src/runtime2/tests/transfer_ports.rs

a1b2108ed856 2.9 KiB application/rls-services+xml Show Annotation Show as Raw Download as Raw
mh
Prepare fixing another blocking/transfer bug
use super::*;

#[test]
fn test_transfer_precreated_port_with_owned_peer() {
    compile_and_create_component("
    primitive port_sender(out<in<u32>> tx) {
        channel a -> b;
        sync put(tx, b);
    }

    primitive port_receiver(in<in<u32>> rx) {
        sync auto a = get(rx);
    }

    composite constructor() {
        channel a -> b;
        new port_sender(a);
        new port_receiver(b);
    }
    ", "constructor", no_args());
}

#[test]
fn test_transfer_precreated_port_with_foreign_peer() {
    compile_and_create_component("
    primitive port_sender(out<in<u32>> tx, in<u32> to_send) {
        sync put(tx, to_send);
    }

    primitive port_receiver(in<in<u32>> rx) {
        sync auto a = get(rx);
    }

    composite constructor() {
        channel tx -> rx;
        channel forgotten -> to_send;
        new port_sender(tx, to_send);
        new port_receiver(rx);
    }
    ", "constructor", no_args());
}

#[test]
fn test_transfer_synccreated_port() {
    compile_and_create_component("
    primitive port_sender(out<in<u32>> tx) {
        sync {
            channel a -> b;
            put(tx, b);
        }
    }

    primitive port_receiver(in<in<u32>> rx) {
        sync auto a = get(rx);
    }

    composite constructor() {
        channel a -> b;
        new port_sender(a);
        new port_receiver(b);
    }
    ", "constructor", no_args());
}

#[test]
fn test_transfer_precreated_port_with_owned_peer_back_and_forth() {

}

#[test]
fn test_transfer_precreated_port_with_foreign_peer_back_and_forth() {

}

#[test]
fn test_transfer_precreated_port_with_owned_peer_and_communication() {
    compile_and_create_component("
    primitive port_sender(out<in<u32>> tx) {
        channel a -> b;
        sync put(tx, b);
        sync put(a, 1337);
    }

    primitive port_receiver(in<in<u32>> rx) {
        channel a -> b; // this is stupid, but we need to have a variable to use
        sync b = get(rx);
        u32 value = 0;
        sync value = get(b);
        while (value != 1337) {}
    }
    composite constructor() {
        channel a -> b;
        new port_sender(a);
        new port_receiver(b);
    }
    ", "constructor", no_args());
}

#[test]
fn test_transfer_precreated_port_with_foreign_peer_and_communication() {
    compile_and_create_component("
    primitive port_sender(out<in<u32>> tx, in<u32> to_send) {
        sync put(tx, to_send);
    }

    primitive message_transmitter(out<u32> tx) {
        sync put(tx, 1337);
    }

    primitive port_receiver(in<in<u32>> rx) {
        channel unused -> b;
        sync b = get(rx);
        u32 value = 0;
        sync value = get(b);
        while (value != 1337) {}
    }

    composite constructor() {
        channel port_tx -> port_rx;
        channel value_tx -> value_rx;
        new port_sender(port_tx, value_rx);
        new port_receiver(port_rx);
        new message_transmitter(value_tx);
    }
    ", "constructor", no_args());
}