diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index 2298f124edc741798ada60832c0f541ee13f3594..a5c2aac79bf56dedc089cee2118064d8f49f87c7 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -3,9 +3,9 @@ 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 = 1; // number of test instances constructed -const NUM_LOOPS: u32 = 1500; // number of loops within a single test (not used by all tests) +const NUM_THREADS: u32 = 3; // number of threads in runtime +const NUM_INSTANCES: u32 = 5; // number of test instances constructed +const NUM_LOOPS: u32 = 5; // 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"); @@ -108,7 +108,7 @@ fn test_star_shaped_request() { auto num_edges = length(requests); while (loop_index < loops) { - print(\"starting loop\"); + // print(\"starting loop\"); synchronous { u32 edge_index = 0; u32 sum = 0; @@ -121,7 +121,7 @@ fn test_star_shaped_request() { assert(sum == num_edges * (num_edges - 1)); } - print(\"ending loop\"); + // print(\"ending loop\"); loop_index += 1; } } @@ -152,4 +152,81 @@ fn test_star_shaped_request() { Value::UInt32(NUM_LOOPS), ])); }); +} + +#[test] +fn test_conga_line_request() { + const CODE: &'static str = " + primitive start(out req, in resp, u32 num_nodes, u32 num_loops) { + u32 loop_index = 0; + u32 initial_value = 1337; + while (loop_index < num_loops) { + synchronous { + put(req, initial_value); + auto result = get(resp); + assert(result == initial_value + num_nodes * 2); + } + loop_index += 1; + } + } + + primitive middle( + in req_in, out req_forward, + in resp_in, out resp_forward, + u32 num_loops + ) { + u32 loop_index = 0; + while (loop_index < num_loops) { + synchronous { + auto req = get(req_in); + put(req_forward, req + 1); + auto resp = get(resp_in); + put(resp_forward, resp + 1); + } + loop_index += 1; + } + } + + primitive end(in req_in, out resp_out, u32 num_loops) { + u32 loop_index = 0; + while (loop_index < num_loops) { + synchronous { + auto req = get(req_in); + put(resp_out, req); + } + loop_index += 1; + } + } + + composite constructor(u32 num_nodes, u32 num_loops) { + channel initial_req -> req_in; + channel resp_out -> final_resp; + new start(initial_req, final_resp, num_nodes, num_loops); + + in last_req_in = req_in; + out last_resp_out = resp_out; + + u32 node = 0; + while (node < num_nodes) { + channel new_req_fw -> new_req_in; + channel new_resp_out -> new_resp_in; + new middle(last_req_in, new_req_fw, new_resp_in, last_resp_out, num_loops); + + last_req_in = new_req_in; + last_resp_out = new_resp_out; + + node += 1; + } + + new end(last_req_in, last_resp_out, num_loops); + } + "; + + let thing = TestTimer::new("conga_line_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