diff --git a/src/runtime2/tests/api_component.rs b/src/runtime2/tests/api_component.rs index 38cf5059ddfd035ffc2249a4e39ae2bfaca7415d..1e8055b09758b6f63091deb8f3cc8f6ba5f1cd40 100644 --- a/src/runtime2/tests/api_component.rs +++ b/src/runtime2/tests/api_component.rs @@ -54,13 +54,10 @@ fn test_getting_from_component() { const CODE: &'static str =" primitive loop_sender(out numbers, u32 cur, u32 last) { while (cur < last) { - print(\"sync start\"); synchronous { - print(\"sending\"); put(numbers, cur); cur += 1; } - print(\"sync solution!\"); } }"; @@ -89,4 +86,39 @@ fn test_getting_from_component() { assert!(false); } } +} + +#[test] +fn test_putting_to_component() { + const CODE: &'static str = " + primitive loop_receiver(in numbers, u32 cur, u32 last) { + while (cur < last) { + synchronous { + auto number = get(numbers); + assert(number == cur); + cur += 1; + } + } + } + "; + + let pd = ProtocolDescription::parse(CODE.as_bytes()).unwrap(); + let rt = Runtime::new(NUM_THREADS, pd); + let mut api = rt.create_interface(); + + let channel = api.create_channel().unwrap(); + api.create_connector("", "loop_receiver", ValueGroup::new_stack(vec![ + Value::Input(PortId::new(channel.getter_id.index)), + Value::UInt32(42), + Value::UInt32(42 + NUM_LOOPS) + ])).unwrap(); + + for loop_idx in 0..NUM_LOOPS { + api.perform_sync_round(vec![ + ApplicationSyncAction::Put(channel.putter_id, ValueGroup::new_stack(vec![Value::UInt32(42 + loop_idx)])), + ]).expect("start sync round"); + + // Note: if we finish a round, then it must have succeeded :) + api.wait().expect("finish sync round"); + } } \ No newline at end of file