Changeset - 42c130e76c4b
[Not reviewed]
0 3 0
mh - 3 years ago 2022-03-30 15:18:21
contact@maxhenger.nl
Add number of rounds to random test component
3 files changed with 27 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/runtime2/component/component_ip.rs
Show inline comments
 
@@ -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,
src/runtime2/tests/mod.rs
Show inline comments
 
@@ -225,16 +225,21 @@ fn test_empty_select() {
 
#[test]
 
fn test_random_u32_temporary_thingo() {
 
    let pd = ProtocolDescription::parse(b"
 
    primitive random_taker(in<u32> generator) {
 
        sync {
 
            auto a = get(generator);
 
    primitive random_taker(in<u32> 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);
std/std.random.pdl
Show inline comments
 
#module std.random
 

	
 
primitive random_u32(out<u32> generator, u32 min, u32 max) { #builtin }
 
primitive random_u32(out<u32> generator, u32 min, u32 max, u32 num_sends) { #builtin }
0 comments (0 inline, 0 general)