Files
@ 1b179e5f4579
Branch filter:
Location: CSY/reowolf/src/runtime2/tests/api_component.rs - annotation
1b179e5f4579
1.6 KiB
application/rls-services+xml
Bugfixes in initial API component
1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 | // Testing the api component.
//
// These tests explicitly do not use the "NUM_INSTANCES" constant because we're
// doing some communication with the native component. Hence only expect one
use super::*;
#[test]
fn test_put_and_get() {
const CODE: &'static str = "
primitive handler(in<u32> request, out<u32> response, u32 loops) {
u32 index = 0;
while (index < loops) {
synchronous {
auto value = get(request);
put(response, value * 2);
}
index += 1;
}
}
";
let pd = ProtocolDescription::parse(CODE.as_bytes()).unwrap();
let rt = Runtime::new(NUM_THREADS, pd);
let mut api = rt.create_interface();
let req_chan = api.create_channel().unwrap();
let resp_chan = api.create_channel().unwrap();
api.create_connector("", "handler", ValueGroup::new_stack(vec![
Value::Input(PortId::new(req_chan.getter_id.index)),
Value::Output(PortId::new(resp_chan.putter_id.index)),
Value::UInt32(NUM_LOOPS),
])).unwrap();
for loop_idx in 0..NUM_LOOPS {
api.perform_sync_round(vec![
ApplicationSyncAction::Put(req_chan.putter_id, ValueGroup::new_stack(vec![Value::UInt32(loop_idx)])),
ApplicationSyncAction::Get(resp_chan.getter_id)
]).expect("start sync round");
let result = api.wait().expect("finish sync round");
assert!(result.len() == 1);
if let Value::UInt32(gotten) = result[0].values[0] {
assert_eq!(gotten, loop_idx * 2);
} else {
assert!(false);
}
}
}
|