Files
@ 42c130e76c4b
Branch filter:
Location: CSY/reowolf/src/runtime2/tests/mod.rs - annotation
42c130e76c4b
7.0 KiB
application/rls-services+xml
Add number of rounds to random test 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | 53d3950d9b6b 53d3950d9b6b 53d3950d9b6b bf4c0ee5ba65 bf4c0ee5ba65 bf4c0ee5ba65 bf4c0ee5ba65 bf4c0ee5ba65 bf4c0ee5ba65 bf4c0ee5ba65 bf4c0ee5ba65 be8ea413a49a be8ea413a49a bf4c0ee5ba65 bf4c0ee5ba65 bf4c0ee5ba65 bf4c0ee5ba65 53d3950d9b6b 53d3950d9b6b 53d3950d9b6b 53d3950d9b6b 53d3950d9b6b 53d3950d9b6b 53d3950d9b6b 53d3950d9b6b 53d3950d9b6b 560ed3c4dc1d 53d3950d9b6b 637115283740 bf4c0ee5ba65 0781cf1b7abf 0781cf1b7abf 0781cf1b7abf 3d271f7cfd7e 0ec053ef96b5 3d271f7cfd7e 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 3d271f7cfd7e 3d271f7cfd7e 3d271f7cfd7e 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 3d271f7cfd7e 3d271f7cfd7e 3d271f7cfd7e 3d271f7cfd7e 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 0b0b0a9c786b 3d271f7cfd7e 560ed3c4dc1d bf4c0ee5ba65 637115283740 637115283740 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 11fd959b348a 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 637115283740 95e019faaf52 95e019faaf52 95e019faaf52 95e019faaf52 95e019faaf52 42c130e76c4b 42c130e76c4b 42c130e76c4b 42c130e76c4b 42c130e76c4b 42c130e76c4b 42c130e76c4b 95e019faaf52 95e019faaf52 95e019faaf52 95e019faaf52 95e019faaf52 42c130e76c4b 42c130e76c4b 42c130e76c4b 95e019faaf52 95e019faaf52 be8ea413a49a be8ea413a49a 53d3950d9b6b | use crate::protocol::*;
use crate::protocol::eval::*;
use crate::runtime2::runtime::*;
use crate::runtime2::component::{CompCtx, CompPDL};
fn create_component(rt: &Runtime, module_name: &str, routine_name: &str, args: ValueGroup) {
let prompt = rt.inner.protocol.new_component(
module_name.as_bytes(), routine_name.as_bytes(), args
).expect("create prompt");
let reserved = rt.inner.start_create_pdl_component();
let ctx = CompCtx::new(&reserved);
let component = Box::new(CompPDL::new(prompt, 0));
let (key, _) = rt.inner.finish_create_pdl_component(reserved, component, ctx, false);
rt.inner.enqueue_work(key);
}
fn no_args() -> ValueGroup { ValueGroup::new_stack(Vec::new()) }
#[test]
fn test_component_creation() {
let pd = ProtocolDescription::parse(b"
primitive nothing_at_all() {
s32 a = 5;
auto b = 5 + a;
}
").expect("compilation");
let rt = Runtime::new(1, true, pd);
for _i in 0..20 {
create_component(&rt, "", "nothing_at_all", no_args());
}
}
#[test]
fn test_component_communication() {
let pd = ProtocolDescription::parse(b"
primitive sender(out<u32> o, u32 outside_loops, u32 inside_loops) {
u32 outside_index = 0;
while (outside_index < outside_loops) {
u32 inside_index = 0;
sync while (inside_index < inside_loops) {
put(o, inside_index);
inside_index += 1;
}
outside_index += 1;
}
}
primitive receiver(in<u32> i, u32 outside_loops, u32 inside_loops) {
u32 outside_index = 0;
while (outside_index < outside_loops) {
u32 inside_index = 0;
sync while (inside_index < inside_loops) {
auto val = get(i);
while (val != inside_index) {} // infinite loop if incorrect value is received
inside_index += 1;
}
outside_index += 1;
}
}
composite constructor() {
channel o_orom -> i_orom;
channel o_mrom -> i_mrom;
channel o_ormm -> i_ormm;
channel o_mrmm -> i_mrmm;
// one round, one message per round
new sender(o_orom, 1, 1);
new receiver(i_orom, 1, 1);
// multiple rounds, one message per round
new sender(o_mrom, 5, 1);
new receiver(i_mrom, 5, 1);
// one round, multiple messages per round
new sender(o_ormm, 1, 5);
new receiver(i_ormm, 1, 5);
// multiple rounds, multiple messages per round
new sender(o_mrmm, 5, 5);
new receiver(i_mrmm, 5, 5);
}").expect("compilation");
let rt = Runtime::new(3, true, pd);
create_component(&rt, "", "constructor", no_args());
}
#[test]
fn test_intermediate_messenger() {
let pd = ProtocolDescription::parse(b"
primitive receiver<T>(in<T> rx, u32 num) {
auto index = 0;
while (index < num) {
sync { auto v = get(rx); }
index += 1;
}
}
primitive middleman<T>(in<T> rx, out<T> tx, u32 num) {
auto index = 0;
while (index < num) {
sync { put(tx, get(rx)); }
index += 1;
}
}
primitive sender<T>(out<T> tx, u32 num) {
auto index = 0;
while (index < num) {
sync put(tx, 1337);
index += 1;
}
}
composite constructor_template<T>() {
auto num = 0;
channel<T> tx_a -> rx_a;
channel tx_b -> rx_b;
new sender(tx_a, 3);
new middleman(rx_a, tx_b, 3);
new receiver(rx_b, 3);
}
composite constructor() {
new constructor_template<u16>();
new constructor_template<u32>();
new constructor_template<u64>();
new constructor_template<s16>();
new constructor_template<s32>();
new constructor_template<s64>();
}
").expect("compilation");
let rt = Runtime::new(3, true, pd);
create_component(&rt, "", "constructor", no_args());
}
#[test]
fn test_simple_select() {
let pd = ProtocolDescription::parse(b"
func infinite_assert<T>(T val, T expected) -> () {
while (val != expected) { print(\"nope!\"); }
return ();
}
primitive receiver(in<u32> in_a, in<u32> in_b, u32 num_sends) {
auto num_from_a = 0;
auto num_from_b = 0;
while (num_from_a + num_from_b < 2 * num_sends) {
sync select {
auto v = get(in_a) -> {
print(\"got something from A\");
auto _ = infinite_assert(v, num_from_a);
num_from_a += 1;
}
auto v = get(in_b) -> {
print(\"got something from B\");
auto _ = infinite_assert(v, num_from_b);
num_from_b += 1;
}
}
}
}
primitive sender(out<u32> tx, u32 num_sends) {
auto index = 0;
while (index < num_sends) {
sync {
put(tx, index);
index += 1;
}
}
}
composite constructor() {
auto num_sends = 15;
channel tx_a -> rx_a;
channel tx_b -> rx_b;
new sender(tx_a, num_sends);
new receiver(rx_a, rx_b, num_sends);
new sender(tx_b, num_sends);
}
").expect("compilation");
let rt = Runtime::new(3, false, pd);
create_component(&rt, "", "constructor", no_args());
}
#[test]
fn test_unguarded_select() {
let pd = ProtocolDescription::parse(b"
primitive constructor_outside_select() {
u32 index = 0;
while (index < 5) {
sync select { auto v = () -> print(\"hello\"); }
index += 1;
}
}
primitive constructor_inside_select() {
u32 index = 0;
while (index < 5) {
sync select { auto v = () -> index += 1; }
}
}
").expect("compilation");
let rt = Runtime::new(3, false, pd);
create_component(&rt, "", "constructor_outside_select", no_args());
create_component(&rt, "", "constructor_inside_select", no_args());
}
#[test]
fn test_empty_select() {
let pd = ProtocolDescription::parse(b"
primitive constructor() {
u32 index = 0;
while (index < 5) {
sync select {}
index += 1;
}
}
").expect("compilation");
let rt = Runtime::new(3, false, pd);
create_component(&rt, "", "constructor", no_args());
}
#[test]
fn test_random_u32_temporary_thingo() {
let pd = ProtocolDescription::parse(b"
primitive random_taker(in<u32> generator, u32 num_values) {
auto i = 0;
while (i < num_values) {
sync {
auto a = get(generator);
}
i += 1;
}
}
composite constructor() {
channel tx -> rx;
auto num_values = 25;
new random_u32(tx, 1, 100, num_values);
new random_taker(rx, num_values);
}
").expect("compilation");
let rt = Runtime::new(1, true, pd);
create_component(&rt, "", "constructor", no_args());
}
|