diff --git a/src/runtime2/scheduler.rs b/src/runtime2/scheduler.rs index 092b65f090107f47fe0c48f9656a99c6f473e2e6..bb3ec93c94100031abfca83c71057e88ebd8512a 100644 --- a/src/runtime2/scheduler.rs +++ b/src/runtime2/scheduler.rs @@ -348,11 +348,11 @@ impl Scheduler { // TODO: Remove, this is debugging stuff fn debug(&self, message: &str) { - // println!("DEBUG [thrd:{:02} conn: ]: {}", self.scheduler_id, message); + println!("DEBUG [thrd:{:02} conn: ]: {}", self.scheduler_id, message); } fn debug_conn(&self, conn: ConnectorId, message: &str) { - // println!("DEBUG [thrd:{:02} conn:{:02}]: {}", self.scheduler_id, conn.0, message); + println!("DEBUG [thrd:{:02} conn:{:02}]: {}", self.scheduler_id, conn.0, message); } } diff --git a/src/runtime2/tests/basics.rs b/src/runtime2/tests/basics.rs new file mode 100644 index 0000000000000000000000000000000000000000..471394c34e84602b9d7197b13a54b41c0f5b4a79 --- /dev/null +++ b/src/runtime2/tests/basics.rs @@ -0,0 +1,91 @@ + +use super::*; + +#[test] +fn test_single_put_and_get() { + const CODE: &'static str = " + primitive putter(out sender, u32 loops) { + u32 index = 0; + while (index < loops) { + sync { + put(sender, true); + } + index += 1; + } + } + + primitive getter(in receiver, u32 loops) { + u32 index = 0; + while (index < loops) { + sync { + auto result = get(receiver); + assert(result); + } + index += 1; + } + } + "; + + let thing = TestTimer::new("single_put_and_get"); + run_test_in_runtime(CODE, |api| { + let channel = api.create_channel().unwrap(); + + 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"); + }); +} + +#[test] +fn test_multi_put_and_get() { + const CODE: &'static str = " + primitive putter_static(out vals, u32 num_loops) { + u32 index = 0; + while (index < num_loops) { + sync { + put(vals, 0b00000001); + put(vals, 0b00000100); + put(vals, 0b00010000); + put(vals, 0b01000000); + } + index += 1; + } + } + + primitive getter_dynamic(in vals, u32 num_loops) { + u32 loop_index = 0; + while (loop_index < num_loops) { + sync { + u32 recv_index = 0; + u8 expected = 1; + while (recv_index < 4) { + auto gotten = get(vals); + assert(gotten == expected); + expected <<= 2; + recv_index += 1; + } + } + loop_index += 1; + } + } + "; + + let thing = TestTimer::new("multi_put_and_get"); + run_test_in_runtime(CODE, |api| { + let channel = api.create_channel().unwrap(); + api.create_connector("", "putter_static", ValueGroup::new_stack(vec![ + Value::Output(PortId::new(channel.putter_id.index)), + Value::UInt32(NUM_LOOPS), + ])).unwrap(); + api.create_connector("", "getter_dynamic", ValueGroup::new_stack(vec![ + Value::Input(PortId::new(channel.getter_id.index)), + Value::UInt32(NUM_LOOPS), + ])).unwrap(); + }) +} \ No newline at end of file diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index f31961a21b2eac002190fb3c8c9bb557a937082c..f206f105f1c8485276b6d69fd891a5337d2a413a 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -1,6 +1,7 @@ mod network_shapes; mod api_component; mod speculation_basic; +mod basics; use super::*; use crate::{PortId, ProtocolDescription}; @@ -11,9 +12,9 @@ use crate::runtime2::native::{ApplicationSyncAction}; // // Generic testing constants, use when appropriate to simplify stress-testing -pub(crate) const NUM_THREADS: u32 = 3; // number of threads in runtime -pub(crate) const NUM_INSTANCES: u32 = 5; // number of test instances constructed -pub(crate) const NUM_LOOPS: u32 = 5; // number of loops within a single test (not used by all tests) +pub(crate) const NUM_THREADS: u32 = 1; // number of threads in runtime +pub(crate) const NUM_INSTANCES: u32 = 1; // number of test instances constructed +pub(crate) const NUM_LOOPS: u32 = 1; // 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"); diff --git a/src/runtime2/tests/network_shapes.rs b/src/runtime2/tests/network_shapes.rs index 723d039e25fc7675c63ab5e8419ccd10a172f6e1..3797bf0ffea9c0f72e1ae97b735dc4adc97e862d 100644 --- a/src/runtime2/tests/network_shapes.rs +++ b/src/runtime2/tests/network_shapes.rs @@ -2,47 +2,6 @@ use super::*; -#[test] -fn test_put_and_get() { - const CODE: &'static str = " - primitive putter(out sender, u32 loops) { - u32 index = 0; - while (index < loops) { - sync { - put(sender, true); - } - index += 1; - } - } - - primitive getter(in receiver, u32 loops) { - u32 index = 0; - while (index < loops) { - sync { - auto result = get(receiver); - assert(result); - } - index += 1; - } - } - "; - - let thing = TestTimer::new("put_and_get"); - run_test_in_runtime(CODE, |api| { - let channel = api.create_channel().unwrap(); - - 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"); - }); -} - #[test] fn test_star_shaped_request() { const CODE: &'static str = " diff --git a/src/runtime2/tests/speculation_basic.rs b/src/runtime2/tests/speculation_basic.rs index c8522eb56d65352763b2e2f4f57dc142517fde7e..ff1d8d0b1111ff2e7764063380bc3921b0ff2b65 100644 --- a/src/runtime2/tests/speculation_basic.rs +++ b/src/runtime2/tests/speculation_basic.rs @@ -49,21 +49,21 @@ fn test_maybe_do_nothing() { api.create_connector("", "only_puts", ValueGroup::new_stack(vec![ Value::Output(PortId::new(channel.putter_id.index)), Value::UInt32(NUM_LOOPS), - ])); + ])).unwrap(); api.create_connector("", "might_get", ValueGroup::new_stack(vec![ Value::Input(PortId::new(channel.getter_id.index)), Value::UInt32(NUM_LOOPS), - ])); + ])).unwrap(); // maybe putting -> only getting let channel = api.create_channel().unwrap(); api.create_connector("", "might_put", ValueGroup::new_stack(vec![ Value::Output(PortId::new(channel.putter_id.index)), Value::UInt32(NUM_LOOPS), - ])); + ])).unwrap(); api.create_connector("", "only_gets", ValueGroup::new_stack(vec![ Value::Input(PortId::new(channel.getter_id.index)), Value::UInt32(NUM_LOOPS), - ])); + ])).unwrap(); }) } \ No newline at end of file