From 269638d6b62f0bd8ac225cff04f5dc125a8ec1df Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 25 May 2023 07:01:00 -0700 Subject: [PATCH 1/2] Added test of documented STP_offset parameter --- test/C/src/federated/STPParameter.lf | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/C/src/federated/STPParameter.lf diff --git a/test/C/src/federated/STPParameter.lf b/test/C/src/federated/STPParameter.lf new file mode 100644 index 0000000000..0eb6788bfe --- /dev/null +++ b/test/C/src/federated/STPParameter.lf @@ -0,0 +1,57 @@ +target C { + timeout: 5 sec, + coordination: decentralized +} +import Count from "../lib/Count.lf" + +/* FIXME: inheritance not working! See issue #1733 +import TestCount from "../lib/TestCount.lf" + +reactor PrintTimer(STP_offset:time = 10 msec) extends TestCount { + timer t(0, 1 sec); + reaction(t) {= + lf_print("Timer ticked at (%lld, %d).", + lf_time_logical_elapsed(), lf_tag().microstep + ); + =} +} +* +*/ + +reactor PrintTimer(STP_offset:time = 1 sec, start: int = 1, stride: int = 1, num_inputs: int = 6) { + state count: int = start + state inputs_received: int = 0 + input in: int + + reaction(in) {= + lf_print("Received %d.", in->value); + if (in->value != self->count) { + lf_print_error_and_exit("Expected %d.", self->count); + } + self->count += self->stride; + self->inputs_received++; + =} + + reaction(shutdown) {= + lf_print("Shutdown invoked."); + if (self->inputs_received != self->num_inputs) { + lf_print_error_and_exit("Expected to receive %d inputs, but got %d.", + self->num_inputs, + self->inputs_received + ); + } + =} + + timer t(0, 1 sec); + reaction(t) {= + lf_print("Timer ticked at (%lld, %d).", + lf_time_logical_elapsed(), lf_tag().microstep + ); + =} +} + +federated reactor { + c = new Count(); + p = new PrintTimer(); + c.out -> p.in; +} From 5719ab4ea3a3b2496f39e7c2a454205778efdc87 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Thu, 25 May 2023 07:45:22 -0700 Subject: [PATCH 2/2] Formatted --- test/C/src/federated/STPParameter.lf | 44 +++++++++++++++------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/test/C/src/federated/STPParameter.lf b/test/C/src/federated/STPParameter.lf index 0eb6788bfe..701974748d 100644 --- a/test/C/src/federated/STPParameter.lf +++ b/test/C/src/federated/STPParameter.lf @@ -2,27 +2,30 @@ target C { timeout: 5 sec, coordination: decentralized } -import Count from "../lib/Count.lf" - -/* FIXME: inheritance not working! See issue #1733 -import TestCount from "../lib/TestCount.lf" -reactor PrintTimer(STP_offset:time = 10 msec) extends TestCount { - timer t(0, 1 sec); - reaction(t) {= - lf_print("Timer ticked at (%lld, %d).", - lf_time_logical_elapsed(), lf_tag().microstep - ); - =} -} -* -*/ +import Count from "../lib/Count.lf" -reactor PrintTimer(STP_offset:time = 1 sec, start: int = 1, stride: int = 1, num_inputs: int = 6) { +/** + * FIXME: inheritance not working! See issue #1733 import TestCount from + * "../lib/TestCount.lf" + * + * reactor PrintTimer(STP_offset:time = 10 msec) extends TestCount { timer t(0, + * 1 sec); reaction(t) {= lf_print("Timer ticked at (%lld, %d).", + * lf_time_logical_elapsed(), lf_tag().microstep ); + * =} } + */ +reactor PrintTimer( + STP_offset: time = 1 sec, + start: int = 1, + stride: int = 1, + num_inputs: int = 6 +) { state count: int = start state inputs_received: int = 0 input in: int + timer t(0, 1 sec) + reaction(in) {= lf_print("Received %d.", in->value); if (in->value != self->count) { @@ -41,17 +44,16 @@ reactor PrintTimer(STP_offset:time = 1 sec, start: int = 1, stride: int = 1, num ); } =} - - timer t(0, 1 sec); + reaction(t) {= - lf_print("Timer ticked at (%lld, %d).", + lf_print("Timer ticked at (%lld, %d).", lf_time_logical_elapsed(), lf_tag().microstep ); =} } federated reactor { - c = new Count(); - p = new PrintTimer(); - c.out -> p.in; + c = new Count() + p = new PrintTimer() + c.out -> p.in }