use super::*; #[test] fn test_transfer_precreated_port_with_owned_peer() { compile_and_create_component(" primitive port_sender(out> tx) { channel a -> b; sync put(tx, b); } primitive port_receiver(in> 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> tx, in to_send) { sync put(tx, to_send); } primitive port_receiver(in> 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> tx) { sync { channel a -> b; put(tx, b); } } primitive port_receiver(in> 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_and_communication() { compile_and_create_component(" primitive port_sender(out> tx) { channel a -> b; sync put(tx, b); sync put(a, 1337); } primitive port_receiver(in> 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> tx, in to_send) { sync put(tx, to_send); } primitive message_transmitter(out tx) { sync put(tx, 1337); } primitive port_receiver(in> 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()); } #[test] fn test_transfer_precreated_port_with_owned_peer_back_and_forth() { compile_and_create_component(" primitive port_send_and_receive(out> tx, in> rx) { channel a -> b; sync { put(tx, b); b = get(rx); } } primitive port_receive_and_send(in> rx, out> tx) { channel unused -> transferred; // same problem as in different tests sync { transferred = get(rx); put(tx, transferred); } } composite constructor() { channel port_tx_forward -> port_rx_forward; channel port_tx_backward -> port_rx_backward; new port_send_and_receive(port_tx_forward, port_rx_backward); new port_receive_and_send(port_rx_forward, port_tx_backward); }", "constructor", no_args()); } #[test] fn test_transfer_precreated_port_with_foreign_peer_back_and_forth_and_communication() { compile_and_create_component(" primitive port_send_and_receive(out> tx, in> rx, in to_transfer) { sync { put(tx, to_transfer); to_transfer = get(rx); } sync { auto value = get(to_transfer); while (value != 1337) {} } } primitive port_receive_and_send(in> rx, out> tx) { channel unused -> transferred; sync { transferred = get(rx); put(tx, transferred); } } primitive value_sender(out tx) { sync put(tx, 1337); } composite constructor() { channel port_tx_forward -> port_rx_forward; channel port_tx_backward -> port_rx_backward; channel message_tx -> message_rx; new port_send_and_receive(port_tx_forward, port_rx_backward, message_rx); new port_receive_and_send(port_rx_forward, port_tx_backward); new value_sender(message_tx); } ", "constructor", no_args()); }