diff --git a/src/runtime2/tests/messaging.rs b/src/runtime2/tests/messaging.rs new file mode 100644 index 0000000000000000000000000000000000000000..fc4a0dd65f241980bcc60e866ee705620648a501 --- /dev/null +++ b/src/runtime2/tests/messaging.rs @@ -0,0 +1,119 @@ +use super::*; + + +#[test] +fn test_component_communication() { + let pd = ProtocolDescription::parse(b" + primitive sender(out o, u32 outside_loops, u32 inside_loops) { + u32 outside_index = 0; + while (outside_index < outside_loops) { + u32 inside_index = 0; + sync while (inside_index < inside_loops) { + put(o, inside_index); + inside_index += 1; + } + outside_index += 1; + } + } + + primitive receiver(in i, u32 outside_loops, u32 inside_loops) { + u32 outside_index = 0; + while (outside_index < outside_loops) { + u32 inside_index = 0; + sync while (inside_index < inside_loops) { + auto val = get(i); + while (val != inside_index) {} // infinite loop if incorrect value is received + inside_index += 1; + } + outside_index += 1; + } + } + + composite constructor() { + channel o_orom -> i_orom; + channel o_mrom -> i_mrom; + channel o_ormm -> i_ormm; + channel o_mrmm -> i_mrmm; + + // one round, one message per round + new sender(o_orom, 1, 1); + new receiver(i_orom, 1, 1); + + // multiple rounds, one message per round + new sender(o_mrom, 5, 1); + new receiver(i_mrom, 5, 1); + + // one round, multiple messages per round + new sender(o_ormm, 1, 5); + new receiver(i_ormm, 1, 5); + + // multiple rounds, multiple messages per round + new sender(o_mrmm, 5, 5); + new receiver(i_mrmm, 5, 5); + }").expect("compilation"); + let rt = Runtime::new(3, LOG_LEVEL, pd).unwrap(); + create_component(&rt, "", "constructor", no_args()); +} + +#[test] +fn test_send_to_self() { + compile_and_create_component(" + primitive insane_in_the_membrane() { + channel a -> b; + sync { + put(a, 1); + auto v = get(b); + while (v != 1) {} + } + } + ", "insane_in_the_membrane", no_args()); +} + +#[test] +fn test_intermediate_messenger() { + let pd = ProtocolDescription::parse(b" + primitive receiver(in rx, u32 num) { + auto index = 0; + while (index < num) { + sync { auto v = get(rx); } + index += 1; + } + } + + primitive middleman(in rx, out tx, u32 num) { + auto index = 0; + while (index < num) { + sync { put(tx, get(rx)); } + index += 1; + } + } + + primitive sender(out tx, u32 num) { + auto index = 0; + while (index < num) { + sync put(tx, 1337); + index += 1; + } + } + + composite constructor_template() { + auto num = 0; + channel tx_a -> rx_a; + channel tx_b -> rx_b; + new sender(tx_a, 3); + new middleman(rx_a, tx_b, 3); + new receiver(rx_b, 3); + } + + composite constructor() { + new constructor_template(); + new constructor_template(); + new constructor_template(); + new constructor_template(); + new constructor_template(); + new constructor_template(); + } + ").expect("compilation"); + let rt = Runtime::new(3, LOG_LEVEL, pd).unwrap(); + create_component(&rt, "", "constructor", no_args()); +}