From 42c130e76c4b969ca3a691e82805a4543b7ecb7a 2022-03-30 15:18:21 From: mh Date: 2022-03-30 15:18:21 Subject: [PATCH] Add number of rounds to random test component --- diff --git a/src/runtime2/component/component_ip.rs b/src/runtime2/component/component_ip.rs index 1b9b906d48addf922f4f4edc8312d6aeaee8d9ac..7848835ed25cb158db34797fed309145e0ec0141 100644 --- a/src/runtime2/component/component_ip.rs +++ b/src/runtime2/component/component_ip.rs @@ -16,6 +16,8 @@ pub struct ComponentRandomU32 { output_port_id: PortId, random_minimum: u32, random_maximum: u32, + num_sends: u32, + max_num_sends: u32, generator: random::ThreadRng, // Generic state-tracking exec_state: CompExecState, @@ -65,10 +67,15 @@ impl Component for ComponentRandomU32 { panic!("going to crash 'n burn your system now, please provide valid arguments"); } - sched_ctx.log("Entering sync mode"); - self.did_perform_send = false; - self.consensus.notify_sync_start(comp_ctx); - self.exec_state.mode = CompMode::Sync; + if self.num_sends >= self.max_num_sends { + self.exec_state.mode = CompMode::StartExit; + } else { + sched_ctx.log("Entering sync mode"); + self.did_perform_send = false; + self.consensus.notify_sync_start(comp_ctx); + self.exec_state.mode = CompMode::Sync; + } + return Ok(CompScheduling::Immediate); }, CompMode::Sync => { @@ -105,6 +112,7 @@ impl Component for ComponentRandomU32 { // blocked then the moment we become unblocked (and are back // at the `Sync` mode) we have sent the message. self.did_perform_send = true; + self.num_sends += 1; return Ok(scheduling) } else { // Message was sent, finish this sync round @@ -129,16 +137,19 @@ impl Component for ComponentRandomU32 { impl ComponentRandomU32 { pub(crate) fn new(arguments: ValueGroup) -> Self { - debug_assert_eq!(arguments.values.len(), 3); + debug_assert_eq!(arguments.values.len(), 4); debug_assert!(arguments.regions.is_empty()); let port_id = component::port_id_from_eval(arguments.values[0].as_port_id()); let minimum = arguments.values[1].as_uint32(); let maximum = arguments.values[2].as_uint32(); + let num_sends = arguments.values[3].as_uint32(); return Self{ output_port_id: port_id, random_minimum: minimum, random_maximum: maximum, + num_sends: 0, + max_num_sends: num_sends, generator: random::thread_rng(), exec_state: CompExecState::new(), did_perform_send: false, diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index 30568689f005d5c7ab31d56b024adb674253a55c..28448eebad2897ede211d30682d958c2ac5d8251 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -225,16 +225,21 @@ fn test_empty_select() { #[test] fn test_random_u32_temporary_thingo() { let pd = ProtocolDescription::parse(b" - primitive random_taker(in generator) { - sync { - auto a = get(generator); + primitive random_taker(in generator, u32 num_values) { + auto i = 0; + while (i < num_values) { + sync { + auto a = get(generator); + } + i += 1; } } composite constructor() { channel tx -> rx; - new random_u32(tx, 1, 100); - new random_taker(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); diff --git a/std/std.random.pdl b/std/std.random.pdl index 6d4f24e232aec8ad705392a8fdeca70eff075b6c..840e195232766dd8441b9ecb3ae89210e339739d 100644 --- a/std/std.random.pdl +++ b/std/std.random.pdl @@ -1,3 +1,3 @@ #module std.random -primitive random_u32(out generator, u32 min, u32 max) { #builtin } +primitive random_u32(out generator, u32 min, u32 max, u32 num_sends) { #builtin }