Files
@ 233468b578e8
Branch filter:
Location: CSY/reowolf/src/runtime2/tests/basics.rs
233468b578e8
3.8 KiB
application/rls-services+xml
WIP on handling messages intended for future sync block of failing component
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 125 126 127 128 129 130 131 132 133 134 |
use super::*;
#[test]
fn test_doing_nothing() {
// If this thing does not get into an infinite loop, (hence: the runtime
// exits), then the test works
const CODE: &'static str ="
primitive silent_willy(u32 loops) {
u32 index = 0;
while (index < loops) {
sync { index += 1; }
}
}
";
let thing = TestTimer::new("doing_nothing");
run_test_in_runtime(CODE, |api| {
api.create_connector("", "silent_willy", ValueGroup::new_stack(vec![
Value::UInt32(NUM_LOOPS),
])).expect("create component");
});
}
#[test]
fn test_local_sync_failure() {
// If the component exits cleanly, then the runtime exits cleanly, and the
// test will finish
const CODE: &'static str = "
primitive immediate_failure() {
u32[] only_allows_index_0 = { 1 };
while (true) sync { // note the infinite loop
auto value = only_allows_index_0[1];
}
}
";
let thing = TestTimer::new("immediate_local_failure");
run_test_in_runtime(CODE, |api| {
api.create_connector("", "immediate_failure", ValueGroup::new_stack(Vec::new()))
.expect("create component");
})
}
#[test]
fn test_single_put_and_get() {
const CODE: &'static str = "
primitive putter(out<bool> sender, u32 loops) {
u32 index = 0;
while (index < loops) {
sync {
put(sender, true);
}
index += 1;
}
}
primitive getter(in<bool> receiver, u32 loops) {
u32 index = 0;
while (index < loops) {
sync {
auto result = get(receiver);
assert(result);
}
index += 1;
}
}
";
let thing = TestTimer::new("single_put_and_get");
run_test_in_runtime(CODE, |api| {
let channel = api.create_channel().unwrap();
api.create_connector("", "putter", ValueGroup::new_stack(vec![
Value::Output(PortId(Id{ connector_id: 0, u32_suffix: channel.putter_id.index })),
Value::UInt32(NUM_LOOPS)
])).expect("create putter");
api.create_connector("", "getter", ValueGroup::new_stack(vec![
Value::Input(PortId(Id{ connector_id: 0, u32_suffix: channel.getter_id.index })),
Value::UInt32(NUM_LOOPS)
])).expect("create getter");
});
}
#[test]
fn test_multi_put_and_get() {
const CODE: &'static str = "
primitive putter_static(out<u8> vals, u32 num_loops) {
u32 index = 0;
while (index < num_loops) {
sync {
put(vals, 0b00000001);
put(vals, 0b00000100);
put(vals, 0b00010000);
put(vals, 0b01000000);
}
index += 1;
}
}
primitive getter_dynamic(in<u8> vals, u32 num_loops) {
u32 loop_index = 0;
while (loop_index < num_loops) {
sync {
u32 recv_index = 0;
u8 expected = 1;
while (recv_index < 4) {
auto gotten = get(vals);
assert(gotten == expected);
expected <<= 2;
recv_index += 1;
}
}
loop_index += 1;
}
}
";
let thing = TestTimer::new("multi_put_and_get");
run_test_in_runtime(CODE, |api| {
let channel = api.create_channel().unwrap();
api.create_connector("", "putter_static", ValueGroup::new_stack(vec![
Value::Output(PortId::new(channel.putter_id.index)),
Value::UInt32(NUM_LOOPS),
])).unwrap();
api.create_connector("", "getter_dynamic", ValueGroup::new_stack(vec![
Value::Input(PortId::new(channel.getter_id.index)),
Value::UInt32(NUM_LOOPS),
])).unwrap();
})
}
|