diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index ce820c8a0167bf00581b238e07141be8c6703995..2a481ff71dd208cea4ea0b3705c1192256b281a3 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -25,7 +25,7 @@ fn test_component_creation() { ").expect("compilation"); let rt = Runtime::new(1, true, pd); - for i in 0..20 { + for _i in 0..20 { create_component(&rt, "", "nothing_at_all", no_args()); } } @@ -82,4 +82,92 @@ fn test_component_communication() { }").expect("compilation"); let rt = Runtime::new(3, true, pd); create_component(&rt, "", "constructor", no_args()); +} + +#[test] +fn test_simple_select() { + let pd = ProtocolDescription::parse(b" + func infinite_assert(T val, T expected) -> () { + while (val != expected) { print(\"nope!\"); } + return (); + } + + primitive receiver(in in_a, in in_b, u32 num_sends) { + auto num_from_a = 0; + auto num_from_b = 0; + while (num_from_a + num_from_b < 2 * num_sends) { + sync select { + auto v = get(in_a) -> { + print(\"got something from A\"); + auto _ = infinite_assert(v, num_from_a); + num_from_a += 1; + } + auto v = get(in_b) -> { + print(\"got something from B\"); + auto _ = infinite_assert(v, num_from_b); + num_from_b += 1; + } + } + } + } + + primitive sender(out tx, u32 num_sends) { + auto index = 0; + while (index < num_sends) { + sync { + put(tx, index); + index += 1; + } + } + } + + composite constructor() { + auto num_sends = 15; + channel tx_a -> rx_a; + channel tx_b -> rx_b; + new sender(tx_a, num_sends); + new receiver(rx_a, rx_b, num_sends); + new sender(tx_b, num_sends); + } + ").expect("compilation"); + let rt = Runtime::new(3, false, pd); + create_component(&rt, "", "constructor", no_args()); +} + +#[test] +fn test_unguarded_select() { + let pd = ProtocolDescription::parse(b" + primitive constructor_outside_select() { + u32 index = 0; + while (index < 5) { + sync select { auto v = () -> print(\"hello\"); } + index += 1; + } + } + + primitive constructor_inside_select() { + u32 index = 0; + while (index < 5) { + sync select { auto v = () -> index += 1; } + } + } + ").expect("compilation"); + let rt = Runtime::new(3, false, pd); + create_component(&rt, "", "constructor_outside_select", no_args()); + create_component(&rt, "", "constructor_inside_select", no_args()); +} + +#[test] +fn test_empty_select() { + let pd = ProtocolDescription::parse(b" + primitive constructor() { + u32 index = 0; + while (index < 5) { + sync select {} + index += 1; + } + } + ").expect("compilation"); + let rt = Runtime::new(3, false, pd); + create_component(&rt, "", "constructor", no_args()); } \ No newline at end of file