diff --git a/src/runtime2/tests/mod.rs b/src/runtime2/tests/mod.rs index fb47364e1adef4283a1a5f4961be67cd7bead285..6baa362a0c2dd9fc572b89a4c7b005151ed2f6ac 100644 --- a/src/runtime2/tests/mod.rs +++ b/src/runtime2/tests/mod.rs @@ -3,7 +3,20 @@ use crate::protocol::eval::*; use crate::runtime2::runtime::*; use crate::runtime2::component::{CompCtx, CompPDL}; -fn create_component(rt: &Runtime, module_name: &str, routine_name: &str, args: ValueGroup) { +mod error_handling; + +const LOG_LEVEL: LogLevel = LogLevel::Debug; +const NUM_THREADS: u32 = 4; + +pub(crate) fn compile_and_create_component(source: &str, routine_name: &str, args: ValueGroup) { + let protocol = ProtocolDescription::parse(source.as_bytes()) + .expect("successful compilation"); + let runtime = Runtime::new(NUM_THREADS, LOG_LEVEL, protocol) + .expect("successful runtime startup"); + create_component(&runtime, "", routine_name, args); +} + +pub(crate) fn create_component(rt: &Runtime, module_name: &str, routine_name: &str, args: ValueGroup) { let prompt = rt.inner.protocol.new_component( module_name.as_bytes(), routine_name.as_bytes(), args ).expect("create prompt"); @@ -14,7 +27,7 @@ fn create_component(rt: &Runtime, module_name: &str, routine_name: &str, args: V rt.inner.enqueue_work(key); } -fn no_args() -> ValueGroup { ValueGroup::new_stack(Vec::new()) } +pub(crate) fn no_args() -> ValueGroup { ValueGroup::new_stack(Vec::new()) } #[test] fn test_component_creation() { @@ -24,7 +37,7 @@ fn test_component_creation() { auto b = 5 + a; } ").expect("compilation"); - let rt = Runtime::new(1, true, pd).unwrap(); + let rt = Runtime::new(1, LOG_LEVEL, pd).unwrap(); for _i in 0..20 { create_component(&rt, "", "nothing_at_all", no_args()); @@ -81,7 +94,7 @@ fn test_component_communication() { new sender(o_mrmm, 5, 5); new receiver(i_mrmm, 5, 5); }").expect("compilation"); - let rt = Runtime::new(3, true, pd).unwrap(); + let rt = Runtime::new(3, LOG_LEVEL, pd).unwrap(); create_component(&rt, "", "constructor", no_args()); } @@ -130,7 +143,7 @@ fn test_intermediate_messenger() { new constructor_template(); } ").expect("compilation"); - let rt = Runtime::new(3, true, pd).unwrap(); + let rt = Runtime::new(3, LOG_LEVEL, pd).unwrap(); create_component(&rt, "", "constructor", no_args()); } @@ -180,7 +193,7 @@ fn test_simple_select() { new sender(tx_b, num_sends); } ").expect("compilation"); - let rt = Runtime::new(3, true, pd).unwrap(); + let rt = Runtime::new(3, LOG_LEVEL, pd).unwrap(); create_component(&rt, "", "constructor", no_args()); } @@ -202,7 +215,7 @@ fn test_unguarded_select() { } } ").expect("compilation"); - let rt = Runtime::new(3, false, pd).unwrap(); + let rt = Runtime::new(3, LOG_LEVEL, pd).unwrap(); create_component(&rt, "", "constructor_outside_select", no_args()); create_component(&rt, "", "constructor_inside_select", no_args()); } @@ -218,7 +231,7 @@ fn test_empty_select() { } } ").expect("compilation"); - let rt = Runtime::new(3, false, pd).unwrap(); + let rt = Runtime::new(3, LOG_LEVEL, pd).unwrap(); create_component(&rt, "", "constructor", no_args()); } @@ -244,7 +257,7 @@ fn test_random_u32_temporary_thingo() { new random_taker(rx, num_values); } ").expect("compilation"); - let rt = Runtime::new(1, true, pd).unwrap(); + let rt = Runtime::new(1, LOG_LEVEL, pd).unwrap(); create_component(&rt, "", "constructor", no_args()); } @@ -374,6 +387,6 @@ fn test_sending_receiving_union() { new client(cmd_tx, data_rx, num_rounds); } ").expect("compilation"); - let rt = Runtime::new(1, false, pd).unwrap(); + let rt = Runtime::new(1, LOG_LEVEL, pd).unwrap(); create_component(&rt, "", "main", no_args()); } \ No newline at end of file