Changeset - 9936bb801409
[Not reviewed]
0 2 0
mh - 3 years ago 2022-04-26 10:54:48
contact@maxhenger.nl
Add multithreading testing
2 files changed with 44 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/runtime2/tests/error_handling.rs
Show inline comments
 
use super::*;
 

	
 
#[test]
 
fn test_unconnected_component_error() {
 
    compile_and_create_component("
 
    primitive interact_with_noone() {
 
        u8[] array = { 5 };
 
        auto value = array[1];
 
    }", "interact_with_noone", no_args());
 
}
 

	
 
#[test]
 
fn test_connected_uncommunicating_component_error() {
 
    compile_and_create_component("
 
    primitive crashing_and_burning(out<u32> unused) {
 
        u8[] array = { 1337 };
 
        auto value = array[1337];
 
    }
 
    primitive sitting_idly_waiting(in<u32> never_providing) {
 
        sync auto a = get(never_providing);
 
    }
 
    composite constructor() {
 
        // Test one way
 
        channel a -> b;
 
        new sitting_idly_waiting(b);
 
        new crashing_and_burning(a);
 

	
 
        // And the other way around
 
        channel c -> d;
 
        new crashing_and_burning(c);
 
        new sitting_idly_waiting(d);
 
    }", "constructor", no_args())
 
}
 

	
 
#[test]
 
fn test_connected_communicating_component_error() {
 
    compile_and_create_component("
 
    primitive send_and_fail(out<u32> tx) {
 
        u8[] array = {};
 
        sync {
 
            put(tx, 0);
 
            array[0] = 5;
 
        }
 
    }
 
    primitive receive_once(in<u32> rx) {
 
        sync auto a = get(rx);
 
    }
 
    composite constructor() {
 
        channel a -> b;
 
        new send_and_fail(a);
 
        new receive_once(b);
 

	
 
        channel c -> d;
 
        new receive_once(d);
 
        new send_and_fail(c);
 
    }
 
    ", "constructor", no_args())
 
}
 

	
 
#[test]
 
fn test_failing_after_successful_sync() {
 
    compile_and_create_component("
 
    primitive put_and_fail(out<u8> tx) { sync put(tx, 1); u8 a = {}[0]; }
 
    primitive get_and_fail(in<u8> rx) { sync auto a = get(rx); u8 a = {}[0]; }
 
    primitive put_and_exit(out<u8> tx) { sync put(tx, 2); }
 
    primitive get_and_exit(in<u8> rx) { sync auto a = get(rx); }
 

	
 
    composite constructor() {
 
        {
 
            channel a -> b;
 
            new put_and_fail(a);
 
            new get_and_exit(b);
 
        }
 
        {
 
            channel a -> b;
 
            new get_and_exit(b);
 
            new put_and_fail(a);
 
        }
 
        {
 
            channel a -> b;
 
            new put_and_exit(a);
 
            new get_and_fail(b);
 
        }
 
        {
 
            channel a -> b;
 
            new get_and_fail(b);
 
            new put_and_exit(a);
 
        }
 
    }
 
    ", "constructor", no_args());
 
}
 
\ No newline at end of file
src/runtime2/tests/mod.rs
Show inline comments
 
use crate::protocol::*;
 
use crate::protocol::eval::*;
 
use crate::runtime2::runtime::*;
 
use crate::runtime2::component::{CompCtx, CompPDL};
 

	
 
mod error_handling;
 

	
 
const NUM_THREADS: u32 = 1;
 
const NUM_THREADS: u32 = 4;
 
const DEBUG_LOGGING: bool = true;
 

	
 
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, DEBUG_LOGGING, 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");
 
    let reserved = rt.inner.start_create_pdl_component();
 
    let ctx = CompCtx::new(&reserved);
 
    let component = Box::new(CompPDL::new(prompt, 0));
 
    let (key, _) = rt.inner.finish_create_pdl_component(reserved, component, ctx, false);
 
    rt.inner.enqueue_work(key);
 
}
 

	
 
pub(crate) fn no_args() -> ValueGroup { ValueGroup::new_stack(Vec::new()) }
 

	
 
#[test]
0 comments (0 inline, 0 general)