Files
@ 2982ea49738a
Branch filter:
Location: CSY/reowolf/src/runtime2/tests/api_component.rs - annotation
2982ea49738a
3.8 KiB
application/rls-services+xml
rename 'synchronous' statement to 'sync'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 1b179e5f4579 2982ea49738a 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 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 2982ea49738a 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 32d9f23a4c87 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 2982ea49738a db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 db94fb636c02 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) {
sync {
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);
}
}
}
#[test]
fn test_getting_from_component() {
const CODE: &'static str ="
primitive loop_sender(out<u32> numbers, u32 cur, u32 last) {
while (cur < last) {
sync {
put(numbers, 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_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);
}
}
}
#[test]
fn test_putting_to_component() {
const CODE: &'static str = "
primitive loop_receiver(in<u32> numbers, u32 cur, u32 last) {
while (cur < last) {
sync {
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");
}
}
|