diff --git a/src/runtime2/tests/api_component.rs b/src/runtime2/tests/api_component.rs index f4271190e131654ae8379ae6fed02e85a782ecfa..38cf5059ddfd035ffc2249a4e39ae2bfaca7415d 100644 --- a/src/runtime2/tests/api_component.rs +++ b/src/runtime2/tests/api_component.rs @@ -47,4 +47,46 @@ fn test_put_and_get() { assert!(false); } } +} + +#[test] +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!\"); + } + }"; + + 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_sender", ValueGroup::new_stack(vec![ + Value::Output(PortId::new(channel.putter_id.index)), + Value::UInt32(1337), + Value::UInt32(1337 + NUM_LOOPS) + ])).unwrap(); + + for loop_idx in 0..NUM_LOOPS { + api.perform_sync_round(vec![ + ApplicationSyncAction::Get(channel.getter_id), + ]).expect("start sync round"); + + let result = api.wait().expect("finish sync round"); + + assert!(result.len() == 1 && result[0].values.len() == 1); + if let Value::UInt32(gotten) = result[0].values[0] { + assert_eq!(gotten, 1337 + loop_idx); + } else { + assert!(false); + } + } } \ No newline at end of file