diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index e2b407475b6e1520689575c2bd93c2ef14b82b44..2298f124edc741798ada60832c0f541ee13f3594 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -4,8 +4,8 @@ use crate::common::Id; use crate::protocol::eval::*; const NUM_THREADS: u32 = 1; // number of threads in runtime -const NUM_INSTANCES: u32 = 4; // number of test instances constructed -const NUM_LOOPS: u32 = 4; // number of loops within a single test (not used by all tests) +const NUM_INSTANCES: u32 = 1; // number of test instances constructed +const NUM_LOOPS: u32 = 1500; // 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"); @@ -73,7 +73,7 @@ fn test_put_and_get() { } "; - let thing = TestTimer::new("hello"); + let thing = TestTimer::new("put_and_get"); run_test_in_runtime(CODE, |api| { let channel = api.create_channel(); @@ -87,4 +87,69 @@ fn test_put_and_get() { Value::UInt32(NUM_LOOPS) ])).expect("create getter"); }); +} + +#[test] +fn test_star_shaped_request() { + const CODE: &'static str = " + primitive edge(in input, out output, u32 loops) { + u32 index = 0; + while (index < loops) { + synchronous { + auto req = get(input); + put(output, req * 2); + } + index += 1; + } + } + + primitive center(out[] requests, in[] responses, u32 loops) { + u32 loop_index = 0; + auto num_edges = length(requests); + + while (loop_index < loops) { + print(\"starting loop\"); + synchronous { + u32 edge_index = 0; + u32 sum = 0; + while (edge_index < num_edges) { + put(requests[edge_index], edge_index); + auto response = get(responses[edge_index]); + sum += response; + edge_index += 1; + } + + assert(sum == num_edges * (num_edges - 1)); + } + print(\"ending loop\"); + loop_index += 1; + } + } + + composite constructor(u32 num_edges, u32 num_loops) { + auto requests = {}; + auto responses = {}; + + u32 edge_index = 0; + while (edge_index < num_edges) { + channel req_put -> req_get; + channel resp_put -> resp_get; + new edge(req_get, resp_put, num_loops); + requests @= { req_put }; + responses @= { resp_get }; + + edge_index += 1; + } + + new center(requests, responses, num_loops); + } + "; + + let thing = TestTimer::new("star_shaped_request"); + run_test_in_runtime(CODE, |api| { + api.create_connector("", "constructor", ValueGroup::new_stack(vec![ + Value::UInt32(5), + Value::UInt32(NUM_LOOPS), + ])); + }); } \ No newline at end of file