diff --git a/src/runtime/tests.rs b/src/runtime/tests.rs index dca5f781d734bc85e5d1d00f946c05c7b69240a6..17a6aac7bc715623c08fbdf995688b6dfc39c7e2 100644 --- a/src/runtime/tests.rs +++ b/src/runtime/tests.rs @@ -37,6 +37,19 @@ fn file_logged_configured_connector( Connector::new(file_logger, pd, connector_id) } static MINIMAL_PDL: &'static [u8] = b" +primitive sync(in a, out b) { + while (true) { + synchronous { + if (fires(a) && fires(b)) { + msg x = get(a); + put(b, x); + } else { + assert(!fires(a) && !fires(b)); + } + } + } +} + primitive together(in ia, in ib, out oa, out ob){ while(true) synchronous { if(fires(ia)) { @@ -970,13 +983,15 @@ fn pdl_reo_fifo1full() { let test_log_path = Path::new("./logs/pdl_reo_fifo1full"); let pdl = b" primitive fifo1full(in a, out b) { + bool is_set = true; msg m = create(0); while(true) synchronous { - if(m == null) { + if(!is_set) { if(fires(a)) m=get(a); + is_set = false; } else { if(fires(b)) put(b, m); - m = null; + is_set = true; } } } @@ -1024,7 +1039,7 @@ fn sequencer3_prim() { let test_log_path = Path::new("./logs/sequencer3_prim"); let pdl = b" primitive sequencer3(out a, out b, out c) { - int i = 0; + u32 i = 0; while(true) synchronous { out to = a; if (i==1) to = b; @@ -1070,21 +1085,35 @@ fn sequencer3_prim() { fn sequencer3_comp() { let test_log_path = Path::new("./logs/sequencer3_comp"); let pdl = b" - primitive fifo1_init(T m, in a, out b) { + primitive replicator(in a, out b, out c) { + while (true) { + synchronous { + if (fires(a) && fires(b) && fires(c)) { + msg x = get(a); + put(b, x); + put(c, x); + } else { + assert(!fires(a) && !fires(b) && !fires(c)); + } + } + } + } + primitive fifo1_init(bool has_value, T m, in a, out b) { while(true) synchronous { - if(m != null && fires(b)) { + if(has_value && fires(b)) { put(b, m); - m = null; - } else if (m == null && fires(a)) { + has_value = false; + } else if (!has_value && fires(a)) { m = get(a); + has_value = true; } } } composite fifo1_full(in a, out b) { - new fifo1_init(create(0), a, b); + new fifo1_init(true, create(0), a, b); } composite fifo1(in a, out b) { - new fifo1_init(null, a, b); + new fifo1_init(false, create(0), a, b); } composite sequencer3(out a, out b, out c) { channel d -> e; @@ -1191,6 +1220,34 @@ fn xrouter_prim() { fn xrouter_comp() { let test_log_path = Path::new("./logs/xrouter_comp"); let pdl = b" + primitive replicator(in a, out b, out c) { + while (true) { + synchronous { + if (fires(a) && fires(b) && fires(c)) { + msg x = get(a); + put(b, x); + put(c, x); + } else { + assert(!fires(a) && !fires(b) && !fires(c)); + } + } + } + } + + primitive merger(in a, in b, out c) { + while (true) { + synchronous { + if (fires(a) && !fires(b) && fires(c)) { + put(c, get(a)); + } else if (!fires(a) && fires(b) && fires(c)) { + put(c, get(b)); + } else { + assert(!fires(a) && !fires(b) && !fires(c)); + } + } + } + } + primitive lossy(in a, out b) { while(true) synchronous { if(fires(a)) { @@ -1202,8 +1259,8 @@ fn xrouter_comp() { primitive sync_drain(in a, in b) { while(true) synchronous { if(fires(a)) { - get(a); - get(b); + msg drop_it = get(a); + msg on_the_floor = get(b); } } } @@ -1289,13 +1346,13 @@ fn for_msg_byte() { let test_log_path = Path::new("./logs/for_msg_byte"); let pdl = b" primitive for_msg_byte(out o) { - byte i = 0; - int idx = 0; + u8 i = 0; + u32 idx = 0; while(i<8) { msg m = create(1); m[idx] = i; synchronous put(o, m); - i++; + i += 1; } } "; @@ -1320,8 +1377,8 @@ fn eq_causality() { let test_log_path = Path::new("./logs/eq_causality"); let pdl = b" primitive eq(in a, in b, out c) { - msg ma = null; - msg mb = null; + msg ma = create(0); + msg mb = create(0); while(true) synchronous { if(fires(a)) { // b and c also fire! @@ -1376,8 +1433,8 @@ fn eq_no_causality() { new eqinner(a, b, c, leftfirsto, leftfirsti); } primitive eqinner(in a, in b, out c, out leftfirsto, in leftfirsti) { - msg ma = null; - msg mb = null; + msg ma = create(0); + msg mb = create(0); while(true) synchronous { if(fires(a)) { // b and c also fire! @@ -1389,7 +1446,7 @@ fn eq_no_causality() { // using dummy! put(leftfirsto, ma); - get(leftfirsti); + auto drop_it = get(leftfirsti); } else { // right first! DON'T USE DUMMY mb = get(b); @@ -1400,27 +1457,6 @@ fn eq_no_causality() { } } } - T some_function(int a, int b) { - T something = a; - return something; - } - primitive quick_test(in a, in b) { - // msg ma = null; - auto test1 = 0; - auto test2 = 0; - auto ma = some_function(test1, test2); - while(true) synchronous { - if (fires(a)) { - ma = get(a); - } - if (fires(b)) { - ma = get(b); - } - if (fires(a) && fires(b)) { - ma = get(a) + get(b); - } - } - } "; let pd = reowolf::ProtocolDescription::parse(pdl).unwrap(); let mut c = file_logged_configured_connector(0, test_log_path, Arc::new(pd));