diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index 007407b42484808e587f36c85deed563a28efd0d..ed151bc3431831455d0c16588626da6b1c9778a9 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -82,4 +82,53 @@ 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!\"); } + } + + 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\"); + infinite_assert(v, num_from_a); + num_from_a += 1; + } + auto v = get(in_b) -> { + print(\"got something from B\"); + 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 = 3; + 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(1, true, pd); + create_component(&rt, "", "constructor", no_args()); } \ No newline at end of file