Changeset - db94fb636c02
[Not reviewed]
0 1 0
MH - 4 years ago 2021-11-12 13:52:35
contact@maxhenger.nl
Test for API only putting to component
1 file changed with 35 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/runtime2/tests/api_component.rs
Show inline comments
 
@@ -54,13 +54,10 @@ fn test_getting_from_component() {
 
    const CODE: &'static str ="
 
    primitive loop_sender(out<u32> 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<u32> 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
0 comments (0 inline, 0 general)