Files
@ 6e3f85de2a0a
Branch filter:
Location: CSY/reowolf/src/runtime2/tests/mod.rs - annotation
6e3f85de2a0a
2.1 KiB
application/rls-services+xml
initial version of new consensus
665aa326769e 665aa326769e 7d01f1245b7c 7d01f1245b7c 7d01f1245b7c 665aa326769e 665aa326769e f3664eb428e9 154e5e08b93a 154e5e08b93a c502fc0c252a c502fc0c252a 7d01f1245b7c c502fc0c252a 665aa326769e 7d01f1245b7c 7d01f1245b7c 665aa326769e c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a 7d01f1245b7c 7d01f1245b7c c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a 7d01f1245b7c 665aa326769e 7d01f1245b7c c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a 3f2759e5fc57 c502fc0c252a c502fc0c252a 665aa326769e 7d01f1245b7c c502fc0c252a 665aa326769e c502fc0c252a c502fc0c252a 665aa326769e c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a 665aa326769e c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a c502fc0c252a ff6ade8b8097 | use std::sync::Arc;
use super::*;
use crate::{PortId, ProtocolDescription};
use crate::common::Id;
use crate::protocol::eval::*;
const NUM_THREADS: u32 = 1; // number of threads in runtime
const NUM_INSTANCES: u32 = 10; // number of test instances constructed
const NUM_LOOPS: u32 = 10; // number of loops within a single test (not used by all tests)
fn create_runtime(pdl: &str) -> Runtime {
let protocol = ProtocolDescription::parse(pdl.as_bytes()).expect("parse pdl");
let runtime = Runtime::new(NUM_THREADS, protocol);
return runtime;
}
fn run_test_in_runtime<F: Fn(&mut ApplicationInterface)>(pdl: &str, constructor: F) {
let protocol = ProtocolDescription::parse(pdl.as_bytes())
.expect("parse PDL");
let runtime = Runtime::new(NUM_THREADS, protocol);
let mut api = runtime.create_interface();
for _ in 0..NUM_INSTANCES {
constructor(&mut api);
}
// Wait until done :)
}
#[test]
fn test_put_and_get() {
const CODE: &'static str = "
primitive putter(out<bool> sender, u32 loops) {
u32 index = 0;
while (index < loops) {
synchronous {
print(\"putting!\");
put(sender, true);
}
index += 1;
}
}
primitive getter(in<bool> receiver, u32 loops) {
u32 index = 0;
while (index < loops) {
synchronous {
print(\"getting!\");
auto result = get(receiver);
assert(result);
}
index += 1;
}
}
";
run_test_in_runtime(CODE, |api| {
let channel = api.create_channel();
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");
});
}
|